Package com.cloud.storage

Examples of com.cloud.storage.UploadVO


            resultObj.setResultString("Success");
            asyncMgr.completeAsyncJob(asyncJobId, JobInfo.Status.SUCCEEDED, 1, ApiSerializerHelper.toSerializedString(resultObj));
        } else {
            asyncMgr.completeAsyncJob(asyncJobId, JobInfo.Status.FAILED, 2, ApiSerializerHelper.toSerializedString(resultObj));
        }
        UploadVO updateBuilder = uploadDao.createForUpdate();
        updateBuilder.setUploadPercent(answer.getUploadPct());
        updateBuilder.setUploadState(answer.getUploadStatus());
        updateBuilder.setLastUpdated(new Date());
        updateBuilder.setErrorString(answer.getErrorString());
        updateBuilder.setJobId(answer.getJobId());

        uploadDao.update(getUploadId(), updateBuilder);
    }
View Full Code Here


 
  @Override
  public UploadVO createNewUploadEntry(Long hostId, Long typeId, UploadVO.Status  uploadState,
                                          Type  type, String uploadUrl, Upload.Mode mode){
        
        UploadVO uploadObj = new UploadVO(hostId, typeId, new Date(),
                                          uploadState, type, uploadUrl, mode);
        _uploadDao.persist(uploadObj);
       
        return uploadObj;
     
View Full Code Here

    Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE ;
       
    List<HostVO> storageServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.SecondaryStorage, dataCenterId);
    HostVO sserver = storageServers.get(0);     
   
    UploadVO uploadTemplateObj = new UploadVO(sserver.getId(), template.getId(), new Date(),
                          Upload.Status.NOT_UPLOADED, type, url, Mode.FTP_UPLOAD);
    _uploadDao.persist(uploadTemplateObj);                          
           
    if(vmTemplateHost != null) {
        start();
      UploadCommand ucmd = new UploadCommand(template, url, vmTemplateHost.getInstallPath(), vmTemplateHost.getSize())
      UploadListener ul = new UploadListener(sserver, _timer, _uploadDao, uploadTemplateObj, this, ucmd, template.getAccountId(), template.getName(), type, eventId, asyncJobId, asyncMgr);     
      _listenerMap.put(uploadTemplateObj, ul);

      try {
              send(sserver.getId(), ucmd, ul);
            } catch (AgentUnavailableException e) {
        s_logger.warn("Unable to start upload of " + template.getUniqueName() + " from " + sserver.getName() + " to " +url, e);
        ul.setDisconnected();
        ul.scheduleStatusCheck(RequestType.GET_OR_RESTART);
            }
      return uploadTemplateObj.getId();
    }   
    return null;   
 
View Full Code Here

      if (extractURLList.size() > 0) {
            return extractURLList.get(0);
        }
     
      // It doesn't exist so create a DB entry.     
      UploadVO uploadTemplateObj = new UploadVO(vmTemplateHost.getHostId(), template.getId(), new Date(),
                                                  Status.DOWNLOAD_URL_NOT_CREATED, 0, type, Mode.HTTP_DOWNLOAD);
      uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath());                                                 
      _uploadDao.persist(uploadTemplateObj);
      try{
          // Create Symlink at ssvm
        String path = vmTemplateHost.getInstallPath();
        String uuid = UUID.randomUUID().toString() + "." + template.getFormat().getFileExtension(); // adding "." + vhd/ova... etc.
        CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(secStorage.getParent(), path, uuid);
          try {
              send(ssvm.getId(), cmd, null);
            } catch (AgentUnavailableException e) {
              errorString = "Unable to create a link for " +type+ " id:"+template.getId() + "," + e.getMessage();
                s_logger.error(errorString, e);
                throw new CloudRuntimeException(errorString);
            }

          //Construct actual URL locally now that the symlink exists at SSVM
            String extractURL = generateCopyUrl(ssvm.getPublicIpAddress(), uuid);
            UploadVO vo = _uploadDao.createForUpdate();
            vo.setLastUpdated(new Date());
            vo.setUploadUrl(extractURL);
            vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
            _uploadDao.update(uploadTemplateObj.getId(), vo);
            success = true;
            return _uploadDao.findById(uploadTemplateObj.getId(), true);       
      }finally{
           if(!success){
                UploadVO uploadJob = _uploadDao.createForUpdate(uploadTemplateObj.getId());
                uploadJob.setLastUpdated(new Date());
                uploadJob.setErrorString(errorString);
                uploadJob.setUploadState(Status.ERROR);
                _uploadDao.update(uploadTemplateObj.getId(), uploadJob);
            }
      }
     
  }
View Full Code Here

                errorString = "No Storage Server found at the datacenter - " +dataCenterId;
                throw new CloudRuntimeException(errorString);  
            }                   
           
            // Update DB for state = DOWNLOAD_URL_NOT_CREATED.       
            UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
            uploadJob.setUploadState(Status.DOWNLOAD_URL_NOT_CREATED);
            uploadJob.setLastUpdated(new Date());
            _uploadDao.update(uploadJob.getId(), uploadJob);

            // Create Symlink at ssvm
            String uuid = UUID.randomUUID().toString() + path.substring(path.length() - 4) ; // last 4 characters of the path specify the format like .vhd
            HostVO secStorage = ApiDBUtils.findHostById(ApiDBUtils.findUploadById(uploadId).getHostId());
            HostVO ssvm = _ssvmMgr.pickSsvmHost(secStorage);
            if( ssvm == null ) {
              errorString = "There is no secondary storage VM for secondary storage host " + secStorage.getName();
              throw new CloudRuntimeException(errorString);
            }
           
            CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(secStorage.getParent(), path, uuid);
            try {
              send(ssvm.getId(), cmd, null);
            } catch (AgentUnavailableException e) {
                errorString = "Unable to create a link for " +type+ " id:"+entityId + "," + e.getMessage();
                s_logger.warn(errorString, e);
                throw new CloudRuntimeException(errorString);
            }

            List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running);
          if (ssVms.size() > 0) {
                SecondaryStorageVmVO ssVm = ssVms.get(0);
                if (ssVm.getPublicIpAddress() == null) {
                    errorString = "A running secondary storage vm has a null public ip?";
                    s_logger.error(errorString);
                    throw new CloudRuntimeException(errorString);
                }
                //Construct actual URL locally now that the symlink exists at SSVM
                String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), uuid);
                UploadVO vo = _uploadDao.createForUpdate();
                vo.setLastUpdated(new Date());
                vo.setUploadUrl(extractURL);
                vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
                _uploadDao.update(uploadId, vo);
                success = true;
                return;
            }
            errorString = "Couldnt find a running SSVM in the zone" + dataCenterId+ ". Couldnt create the extraction URL.";
            throw new CloudRuntimeException(errorString);
      }finally{
          if(!success){
              UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
              uploadJob.setLastUpdated(new Date());
              uploadJob.setErrorString(errorString);
              uploadJob.setUploadState(Status.ERROR);
              _uploadDao.update(uploadId, uploadJob);
          }
      }
    }
View Full Code Here

  }
 
  public void handleUploadEvent(HostVO host, Long accountId, String typeName, Type type, Long uploadId, com.cloud.storage.Upload.Status reason, long eventId) {
   
    if ((reason == Upload.Status.UPLOADED) || (reason==Upload.Status.ABANDONED)){
      UploadVO uploadObj = new UploadVO(uploadId);
      UploadListener oldListener = _listenerMap.get(uploadObj);
      if (oldListener != null) {
        _listenerMap.remove(uploadObj);
      }
    }
View Full Code Here

    resultObj.setResultString(uploadErrorString);
    resultObj.setState(state.toString());
    asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L);
    asyncMgr.updateAsyncJobStatus(asyncJobId, AsyncJobResult.STATUS_IN_PROGRESS, resultObj);

    UploadVO vo = uploadDao.createForUpdate();
    vo.setUploadState(state);
    vo.setLastUpdated(new Date());
    vo.setErrorString(uploadErrorString);
    uploadDao.update(getUploadId(), vo);
  }
View Full Code Here

    resultObj.setState(state.toString());
    asyncMgr.updateAsyncJobAttachment(asyncJobId, type.toString(), 1L);
    asyncMgr.updateAsyncJobStatus(asyncJobId, AsyncJobResult.STATUS_IN_PROGRESS, resultObj);


    UploadVO vo = uploadDao.createForUpdate();
    vo.setUploadState(state);
    vo.setLastUpdated(new Date());
    vo.setUploadUrl(uploadUrl);
    vo.setJobId(null);
    vo.setUploadPercent(0);
    vo.setErrorString(uploadErrorString);

    uploadDao.update(getUploadId(), vo);
  }
View Full Code Here

        resultObj.setResultString("Success");
      asyncMgr.completeAsyncJob(asyncJobId, AsyncJobResult.STATUS_SUCCEEDED, 1, resultObj);
    }else{
      asyncMgr.completeAsyncJob(asyncJobId, AsyncJobResult.STATUS_FAILED, 2, resultObj);
    }
        UploadVO updateBuilder = uploadDao.createForUpdate();
    updateBuilder.setUploadPercent(answer.getUploadPct());
    updateBuilder.setUploadState(answer.getUploadStatus());
    updateBuilder.setLastUpdated(new Date());
    updateBuilder.setErrorString(answer.getErrorString());
    updateBuilder.setJobId(answer.getJobId());

    uploadDao.update(getUploadId(), updateBuilder);
  }
View Full Code Here

        if (extractMode == Upload.Mode.HTTP_DOWNLOAD && extractURLList.size() > 0) {
            return extractURLList.get(0).getId(); // If download url already
            // exists then return
        } else {
            UploadVO uploadJob = _uploadMonitor.createNewUploadEntry(sserver.getId(), volumeId, UploadVO.Status.COPY_IN_PROGRESS, Upload.Type.VOLUME,
                    url, extractMode);
            s_logger.debug("Extract Mode - " + uploadJob.getMode());
            uploadJob = _uploadDao.createForUpdate(uploadJob.getId());

            // Update the async Job

            ExtractResponse resultObj = new ExtractResponse(ApiDBUtils.findVolumeById(volumeId).getUuid(),
                    volume.getName(), ApiDBUtils.findAccountById(accountId).getUuid(), UploadVO.Status.COPY_IN_PROGRESS.toString(),
                    uploadJob.getUuid());
            resultObj.setResponseName(cmd.getCommandName());
            AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
            if (asyncExecutor != null) {
                job = asyncExecutor.getJob();
                _asyncMgr.updateAsyncJobAttachment(job.getId(), Upload.Type.VOLUME.toString(), volumeId);
                _asyncMgr.updateAsyncJobStatus(job.getId(), AsyncJobResult.STATUS_IN_PROGRESS, resultObj);
            }
            String value = _configs.get(Config.CopyVolumeWait.toString());
            int copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
            // Copy the volume from the source storage pool to secondary storage
            CopyVolumeCommand cvCmd = new CopyVolumeCommand(volume.getId(), volume.getPath(), srcPool, secondaryStorageURL, true, copyvolumewait);
            CopyVolumeAnswer cvAnswer = null;
            try {
                cvAnswer = (CopyVolumeAnswer) _storageMgr.sendToPool(srcPool, cvCmd);
            } catch (StorageUnavailableException e) {
                s_logger.debug("Storage unavailable");
            }

            // Check if you got a valid answer.
            if (cvAnswer == null || !cvAnswer.getResult()) {
                String errorString = "Failed to copy the volume from the source primary storage pool to secondary storage.";

                // Update the async job.
                resultObj.setResultString(errorString);
                resultObj.setUploadStatus(UploadVO.Status.COPY_ERROR.toString());
                if (asyncExecutor != null) {
                    _asyncMgr.completeAsyncJob(job.getId(), AsyncJobResult.STATUS_FAILED, 0, resultObj);
                }

                // Update the DB that volume couldn't be copied
                uploadJob.setUploadState(UploadVO.Status.COPY_ERROR);
                uploadJob.setErrorString(errorString);
                uploadJob.setLastUpdated(new Date());
                _uploadDao.update(uploadJob.getId(), uploadJob);

                throw new CloudRuntimeException(errorString);
            }

            String volumeLocalPath = "volumes/" + volume.getId() + "/" + cvAnswer.getVolumePath() + "." + getFormatForPool(srcPool);
            // Update the DB that volume is copied and volumePath
            uploadJob.setUploadState(UploadVO.Status.COPY_COMPLETE);
            uploadJob.setLastUpdated(new Date());
            uploadJob.setInstallPath(volumeLocalPath);
            _uploadDao.update(uploadJob.getId(), uploadJob);

            if (extractMode == Mode.FTP_UPLOAD) { // Now that the volume is
                // copied perform the actual
                // uploading
                _uploadMonitor.extractVolume(uploadJob, sserver, volume, url, zoneId, volumeLocalPath, cmd.getStartEventId(), job.getId(), _asyncMgr);
                return uploadJob.getId();
            } else { // Volume is copied now make it visible under apache and
                // create a URL.
                _uploadMonitor.createVolumeDownloadURL(volumeId, volumeLocalPath, Upload.Type.VOLUME, zoneId, uploadJob.getId());
                return uploadJob.getId();
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.cloud.storage.UploadVO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.