use of com.cloud.legacymodel.communication.answer.UploadStatusAnswer in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method execute.
private UploadStatusAnswer execute(final UploadStatusCommand cmd) {
final String entityUuid = cmd.getEntityUuid();
if (this.uploadEntityStateMap.containsKey(entityUuid)) {
final UploadEntity uploadEntity = this.uploadEntityStateMap.get(entityUuid);
if (uploadEntity.getUploadState() == UploadEntity.Status.ERROR) {
this.uploadEntityStateMap.remove(entityUuid);
return new UploadStatusAnswer(cmd, UploadStatus.ERROR, uploadEntity.getErrorMessage());
} else if (uploadEntity.getUploadState() == UploadEntity.Status.COMPLETED) {
final UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.COMPLETED);
answer.setVirtualSize(uploadEntity.getVirtualSize());
answer.setInstallPath(uploadEntity.getTmpltPath());
answer.setPhysicalSize(uploadEntity.getPhysicalSize());
answer.setDownloadPercent(100);
this.uploadEntityStateMap.remove(entityUuid);
return answer;
} else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS) {
final UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.IN_PROGRESS);
final long downloadedSize = FileUtils.sizeOfDirectory(new File(uploadEntity.getInstallPathPrefix()));
final int downloadPercent = (int) (100 * downloadedSize / uploadEntity.getContentLength());
answer.setDownloadPercent(Math.min(downloadPercent, 100));
return answer;
}
}
return new UploadStatusAnswer(cmd, UploadStatus.UNKNOWN);
}
Aggregations