use of org.apache.cloudstack.storage.command.UploadStatusAnswer in project cloudstack by apache.
the class NfsSecondaryStorageResource method execute.
private UploadStatusAnswer execute(UploadStatusCommand cmd) {
String entityUuid = cmd.getEntityUuid();
if (uploadEntityStateMap.containsKey(entityUuid)) {
UploadEntity uploadEntity = uploadEntityStateMap.get(entityUuid);
if (uploadEntity.getUploadState() == UploadEntity.Status.ERROR) {
uploadEntityStateMap.remove(entityUuid);
return new UploadStatusAnswer(cmd, UploadStatus.ERROR, uploadEntity.getErrorMessage());
} else if (uploadEntity.getUploadState() == UploadEntity.Status.COMPLETED) {
UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.COMPLETED);
answer.setVirtualSize(uploadEntity.getVirtualSize());
answer.setInstallPath(uploadEntity.getTmpltPath());
answer.setPhysicalSize(uploadEntity.getPhysicalSize());
answer.setDownloadPercent(100);
if (uploadEntity.getOvfInformationTO() != null) {
answer.setOvfInformationTO(uploadEntity.getOvfInformationTO());
}
uploadEntityStateMap.remove(entityUuid);
return answer;
} else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS) {
UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.IN_PROGRESS);
long downloadedSize = FileUtils.sizeOfDirectory(new File(uploadEntity.getInstallPathPrefix()));
int downloadPercent = (int) (100 * downloadedSize / uploadEntity.getContentLength());
answer.setDownloadPercent(Math.min(downloadPercent, 100));
return answer;
}
}
return new UploadStatusAnswer(cmd, UploadStatus.UNKNOWN);
}
Aggregations