Search in sources :

Example 1 with UploadStatusAnswer

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);
}
Also used : UploadEntity(org.apache.cloudstack.storage.template.UploadEntity) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) File(java.io.File) S3Utils.putFile(com.cloud.utils.storage.S3.S3Utils.putFile)

Aggregations

S3Utils.putFile (com.cloud.utils.storage.S3.S3Utils.putFile)1 File (java.io.File)1 UploadStatusAnswer (org.apache.cloudstack.storage.command.UploadStatusAnswer)1 UploadEntity (org.apache.cloudstack.storage.template.UploadEntity)1