Search in sources :

Example 1 with UploadStatusAnswer

use of com.cloud.storage.command.UploadStatusAnswer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

private UploadStatusAnswer execute(final UploadStatusCommand cmd) {
    final String entityUuid = cmd.getEntityUuid();
    if (uploadEntityStateMap.containsKey(entityUuid)) {
        final 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) {
            final UploadStatusAnswer answer = new UploadStatusAnswer(cmd, UploadStatus.COMPLETED);
            answer.setVirtualSize(uploadEntity.getVirtualSize());
            answer.setInstallPath(uploadEntity.getTmpltPath());
            answer.setPhysicalSize(uploadEntity.getPhysicalSize());
            answer.setDownloadPercent(100);
            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);
}
Also used : UploadEntity(com.cloud.storage.template.UploadEntity) UploadStatusAnswer(com.cloud.storage.command.UploadStatusAnswer) File(java.io.File)

Aggregations

UploadStatusAnswer (com.cloud.storage.command.UploadStatusAnswer)1 UploadEntity (com.cloud.storage.template.UploadEntity)1 File (java.io.File)1