use of com.google.ce.media.contentuploader.message.AnalyticsMessage in project gcs-uploader by GoogleCloudPlatform.
the class TokenController method swapCode.
@RequestMapping(value = "/swap", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<UserInfo> swapCode(@RequestHeader(value = "x-content-upload-offline-code") String offlineCode, @RequestHeader(value = "host") String host, HttpServletRequest request) throws URISyntaxException {
AuthInfo authInfo = authConfig.swapToken(offlineCode, host);
uiMasterController.validateAuthorization();
UserInfo userInfo = new UserInfo();
userInfo.setPictureUrl(authInfo.getPictureUrl());
userInfo.setEmail(authInfo.getEmail());
userInfo.setUserId(authInfo.getUserId());
userInfo.setName(authInfo.getName());
AnalyticsMessage m1 = AnalyticsMessage.from(authInfo, AnalyticsMessage.Event.LOGIN, "Login");
AnalyticsService.getInstance().enqueue(authInfo, m1);
return new ResponseEntity<>(userInfo, HttpStatus.OK);
}
use of com.google.ce.media.contentuploader.message.AnalyticsMessage in project gcs-uploader by GoogleCloudPlatform.
the class BlobUploadTask method run.
@Override
public void run() {
if (taskInfo.isCancelling()) {
return;
}
Long startTime = System.currentTimeMillis();
AnalyticsMessage m1 = AnalyticsMessage.from(taskInfo.getAuthConfig().getAuthInfo(), tasklet, AnalyticsMessage.Event.SEGMENT_START, "Started Segment Upload");
m1.setStartTime(DateUtils.time(startTime));
AnalyticsService.getInstance().enqueue(taskInfo.getAuthConfig().getAuthInfo(), m1);
storage = taskInfo.getAuthConfig().getStorage();
WriteChannel writeChannel = null;
System.out.println(">> >> writing blobInfo.getName() = " + tasklet.getBlobInfo().getName());
boolean hasException = false;
Exception exception = null;
long uploaded = 0;
try {
// defensively rewind the buffer just in case this is a re-run due to error
buffer.rewind();
Blob blob = storage.create(tasklet.getBlobInfo());
tasklet.setStatus(TaskStatus.RUNNING);
// 4mb
byte[] transferBytes = new byte[4 * 1024 * 1024];
ByteBuffer transferBuffer = null;
int count = 0;
boolean isLast = false;
writeChannel = blob.writer();
while (buffer.remaining() > 0 && !taskInfo.isCancelling()) {
if (transferBytes.length < buffer.remaining()) {
buffer.get(transferBytes);
transferBuffer = ByteBuffer.wrap(transferBytes);
count = transferBytes.length;
} else {
count = buffer.remaining();
buffer.get(transferBytes, 0, count);
transferBuffer = ByteBuffer.wrap(transferBytes, 0, count);
isLast = true;
}
writeChannel.write(transferBuffer);
if (isLast) {
// imporant to set this BEFORE updating the last count
tasklet.setStatus(TaskStatus.FINISHED);
}
uploaded += count;
}
} catch (IOException e) {
e.printStackTrace();
exception = e;
hasException = true;
} finally {
if (taskInfo.isCancelling()) {
System.out.println("==>> CANCELLING tasklet for blob: " + tasklet.getBlobInfo().getName());
storage.delete(tasklet.getBlobInfo().getBlobId());
tasklet.setStatus(TaskStatus.FINISHED);
return;
}
Long endTime = System.currentTimeMillis();
if (writeChannel != null) {
try {
writeChannel.close();
} catch (IOException e) {
e.printStackTrace();
if (exception == null) {
exception = e;
}
hasException = true;
}
}
if (hasException) {
tasklet.setStatus(TaskStatus.FAILED);
AnalyticsMessage m2 = AnalyticsMessage.from(taskInfo.getAuthConfig().getAuthInfo(), tasklet, AnalyticsMessage.Event.ERROR, "Error in Segment Upload: " + exception.getMessage());
m2.setStartTime(DateUtils.time(startTime));
m2.setEndTime(DateUtils.time(endTime));
m2.setTimeTaken(endTime - startTime);
AnalyticsService.getInstance().enqueue(taskInfo.getAuthConfig().getAuthInfo(), m2);
throw new RuntimeException(exception);
} else {
taskInfo.updateUploaded(uploaded);
double den = (endTime - startTime) * 1.0 / 1000d;
double mibs = den == 0 ? 0 : ((tasklet.getSize() * 8d) / den) / (1024d * 1024d);
// tasklet.setStatus(TaskStatus.FINISHED);
// taskInfo.updateUploaded(count);
System.out.println(">> >> COMPLETE blobInfo.getName() = " + tasklet.getBlobInfo().getName());
AnalyticsMessage m2 = AnalyticsMessage.from(taskInfo.getAuthConfig().getAuthInfo(), tasklet, AnalyticsMessage.Event.SEGMENT_END, "End Segment Upload");
m2.setStartTime(DateUtils.time(startTime));
m2.setEndTime(DateUtils.time(endTime));
m2.setTimeTaken(endTime - startTime);
m2.setMbps((int) mibs);
AnalyticsService.getInstance().enqueue(taskInfo.getAuthConfig().getAuthInfo(), m2);
}
}
}
use of com.google.ce.media.contentuploader.message.AnalyticsMessage in project gcs-uploader by GoogleCloudPlatform.
the class StitchTask method run.
@Override
public void run() {
Long startTime = System.currentTimeMillis();
AnalyticsMessage m1 = AnalyticsMessage.from(taskInfo, AnalyticsMessage.Event.STITCH_START, "Started Composite Stitching");
m1.setStartTime(DateUtils.time(startTime));
AnalyticsService.getInstance().enqueue(taskInfo.getAuthConfig().getAuthInfo(), m1);
storage = authConfig.getStorage();
List<BlobInfo> blobInfos = taskInfo.getTasklets().stream().map(Tasklet::getBlobInfo).collect(Collectors.toList());
if (stitch) {
taskInfo.stitchPreparing();
synchronized (STITCH_LOCK) {
try {
STITCH_LOCK.wait(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
doStitch(blobInfos, taskInfo.getBlobInfo(), 0);
}
taskInfo.getUploadTaskPool().enqueue(new CleanupTask(taskInfo, blobInfos));
Long endTime = System.currentTimeMillis();
AnalyticsMessage m2 = AnalyticsMessage.from(taskInfo, AnalyticsMessage.Event.STITCH_END, "End Composite Stitching");
m2.setStartTime(DateUtils.time(startTime));
m2.setEndTime(DateUtils.time(endTime));
m2.setTimeTaken(endTime - startTime);
m2.setMbps(taskInfo.getMbps());
AnalyticsService.getInstance().enqueue(taskInfo.getAuthConfig().getAuthInfo(), m2);
long uploadStartTime = taskInfo.getStartTime();
long time = (endTime - uploadStartTime) / 1000;
AnalyticsMessage m_complete = AnalyticsMessage.from(taskInfo, AnalyticsMessage.Event.COMPLETE, "Complete Composite Upload");
m_complete.setStartTime(DateUtils.time(uploadStartTime));
m_complete.setEndTime(DateUtils.time(endTime));
m_complete.setTimeTaken(time);
m_complete.setMbps(taskInfo.getMbps());
AnalyticsService.getInstance().enqueue(taskInfo.getAuthConfig().getAuthInfo(), m_complete);
}
Aggregations