mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
[WIP] S3 Upload of JSON log
This commit is contained in:
parent
7f94c724af
commit
7c7f88ab3c
4 changed files with 70 additions and 2 deletions
|
@ -15,6 +15,7 @@
|
|||
<name>Mage Client</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mage</groupId>
|
||||
<artifactId>mage</artifactId>
|
||||
|
@ -68,6 +69,11 @@
|
|||
<artifactId>jetlang</artifactId>
|
||||
<version>0.2.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>1.11.286</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jgoodies</groupId>
|
||||
<artifactId>forms</artifactId>
|
||||
|
|
|
@ -35,6 +35,7 @@ import javax.swing.*;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.remote.S3Uploader;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.SessionHandler;
|
||||
import mage.client.chat.ChatPanelBasic;
|
||||
|
@ -194,9 +195,16 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
break;
|
||||
}
|
||||
case GAME_OVER: {
|
||||
|
||||
GamePanel panel = MageFrame.getGame(callback.getObjectId());
|
||||
|
||||
if (panel != null) {
|
||||
appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData());
|
||||
ActionData actionData = appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData());
|
||||
String logFileName = "game-" + actionData.gameId + ".json";
|
||||
|
||||
S3Uploader.upload(logFileName, actionData.gameId.toString());
|
||||
|
||||
panel.endMessage((String) callback.getData(), callback.getMessageId());
|
||||
}
|
||||
break;
|
||||
|
@ -304,8 +312,8 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
break;
|
||||
}
|
||||
case END_GAME_INFO:
|
||||
appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData());
|
||||
MageFrame.getInstance().showGameEndDialog((GameEndView) callback.getData());
|
||||
|
||||
break;
|
||||
case SHOW_USERMESSAGE:
|
||||
List<String> messageData = (List<String>) callback.getData();
|
||||
|
@ -402,11 +410,12 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
});
|
||||
}
|
||||
private void appendJsonEvent(String name, UUID gameId, Object value) {
|
||||
private ActionData appendJsonEvent(String name, UUID gameId, Object value) {
|
||||
Session session = SessionHandler.getSession();
|
||||
ActionData actionData = new ActionData(name, gameId);
|
||||
actionData.value = value;
|
||||
session.appendJsonLog(actionData);
|
||||
return actionData;
|
||||
}
|
||||
private void createChatStartMessage(ChatPanelBasic chatPanel) {
|
||||
chatPanel.setStartMessageDone(true);
|
||||
|
|
47
Mage.Client/src/main/java/mage/client/remote/S3Uploader.java
Normal file
47
Mage.Client/src/main/java/mage/client/remote/S3Uploader.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package mage.client.remote;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.amazonaws.AmazonClientException;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.services.s3.transfer.TransferManager;
|
||||
import com.amazonaws.services.s3.transfer.Upload;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
|
||||
|
||||
public class S3Uploader {
|
||||
private static final Logger logger = Logger.getLogger(S3Uploader.class);
|
||||
|
||||
public static Boolean upload(String filePath, String keyName) throws Exception {
|
||||
String existingBucketName = System.getenv("S3_BUCKET") != null ? System.getenv("S3_BUCKET")
|
||||
: "xmage-game-logs-dev";
|
||||
|
||||
String accessKeyId = System.getenv("AWS_ACCESS_ID");
|
||||
String secretKeyId = System.getenv("AWS_SECRET_KEY");
|
||||
|
||||
if(accessKeyId == "" || secretKeyId == "" || existingBucketName == "") {
|
||||
logger.info("Aborting json log sync.");
|
||||
return false;
|
||||
}
|
||||
|
||||
String path = new File("./" + filePath).getCanonicalPath();
|
||||
logger.info("Syncing " + path + " to bucket: " + existingBucketName + " with AWS Access Id: " + accessKeyId);
|
||||
|
||||
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKeyId, secretKeyId);
|
||||
TransferManager tm = new TransferManager(awsCreds);
|
||||
Upload upload = tm.upload(existingBucketName, "/game/" + keyName + ".json", new File(path));
|
||||
|
||||
try {
|
||||
upload.waitForUploadResult();
|
||||
logger.info("Sync Complete For " + path + " to bucket: " + existingBucketName + " with AWS Access Id: " + accessKeyId);
|
||||
new File(path);
|
||||
return true;
|
||||
} catch (AmazonClientException amazonClientException) {
|
||||
System.out.println("Unable to upload file, upload was aborted.");
|
||||
amazonClientException.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -76,6 +76,12 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>mage-game-commanderfreeforall</artifactId>
|
||||
|
|
Loading…
Reference in a new issue