Examples of UploadVO


Examples of com.cloud.storage.UploadVO

                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

Examples of com.cloud.storage.UploadVO

  }
 
  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

Examples of com.cloud.storage.UploadVO

    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

Examples of com.cloud.storage.UploadVO

    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

Examples of com.cloud.storage.UploadVO

        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

Examples of com.cloud.storage.UploadVO

            }
       
            return _uploadMonitor.extractTemplate(template, url, tmpltHostRef, zoneId, eventId, job.getId(), mgr);           
        }
       
        UploadVO vo = _uploadMonitor.createEntityDownloadURL(template, tmpltHostRef, zoneId, eventId);
        if (vo != null){                                 
            return vo.getId();
        }else{
            return null;
        }
    }
View Full Code Here

Examples of com.cloud.storage.UploadVO

        List<UploadVO> extractURLList = _uploadDao.listByTypeUploadStatus(volumeId, Upload.Type.VOLUME, UploadVO.Status.DOWNLOAD_URL_CREATED);

        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(volumeId, volume.getName(), accountId, UploadVO.Status.COPY_IN_PROGRESS.toString(), uploadJob.getId());
            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

Examples of com.cloud.storage.UploadVO

 
  @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

Examples of com.cloud.storage.UploadVO

    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

Examples of com.cloud.storage.UploadVO

     
      //Check if it already exists.
      List<UploadVO> extractURLList = _uploadDao.listByTypeUploadStatus(template.getId(), type, UploadVO.Status.DOWNLOAD_URL_CREATED);     
      if (extractURLList.size() > 0) {
               // do some check here
               UploadVO upload = extractURLList.get(0);
               String uploadUrl = extractURLList.get(0).getUploadUrl();
               String[] token = uploadUrl.split("/");
               // example: uploadUrl = https://10-11-101-112.realhostip.com/userdata/2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
               // then token[2] = 10-11-101-112.realhostip.com, token[4] = 2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
               String hostname = ssvm.getPublicIpAddress().replace(".", "-") + ".";
               if ((token != null) && (token.length == 5) && (token[2].equals(hostname + _ssvmUrlDomain))) // ssvm publicip and domain suffix not changed
                   return extractURLList.get(0);
               else if ((token != null) && (token.length == 5) && (token[2].startsWith(hostname))) { // domain suffix changed
                   String uuid = token[4];
                   uploadUrl = generateCopyUrl(ssvm.getPublicIpAddress(), uuid);
                   UploadVO vo = _uploadDao.createForUpdate();
                   vo.setLastUpdated(new Date());
                   vo.setUploadUrl(uploadUrl);
                   _uploadDao.update(upload.getId(), vo);
                   return _uploadDao.findById(upload.getId(), true);
               } else { // ssvm publicip changed
                   return null;
               }
        }
     
      // 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
TOP
Copyright © 2018 www.massapi.com. 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.