Examples of UploadVO


Examples of com.cloud.storage.UploadVO

        if (uploadId == null) {
            // region-wide image store
            response.setUrl(url);
            response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
        } else {
            UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
            response.setUploadId(uploadInfo.getUuid());
            response.setState(uploadInfo.getUploadState().toString());
            response.setUrl(uploadInfo.getUploadUrl());
        }
        Account account = ApiDBUtils.findAccountById(accountId);
        response.setAccountId(account.getUuid());

        return response;
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 ;

    DataStore secStore = this.storeMgr.getImageStore(dataCenterId);

    UploadVO uploadTemplateObj = new UploadVO(secStore.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(secStore, _timer, _uploadDao, uploadTemplateObj, this, ucmd, template.getAccountId(), template.getName(), type, eventId, asyncJobId, asyncMgr);
      _listenerMap.put(uploadTemplateObj, ul);
      try{
          EndPoint ep = _epSelector.select(secStore);
                ep.sendMessageAsync(ucmd, new UploadListener.Callback(ep.getId(), ul));
            } catch (Exception e) {
        s_logger.warn("Unable to start upload of " + template.getUniqueName() + " from " + secStore.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 = ep.getPublicAddr().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(ep.getPublicAddr(), 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.getDataStoreId(), 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(((ImageStoreEntity)store).getMountPoint(), path, uuid, null);
        Answer ans = ep.sendMessage(cmd);
          if (ans == null || !ans.getResult()) {
              errorString = "Unable to create a link for " +type+ " id:"+template.getId() + "," + ans.getDetails();
                s_logger.error(errorString);
                throw new CloudRuntimeException(errorString);
            }

          //Construct actual URL locally now that the symlink exists at SSVM
            String extractURL = generateCopyUrl(ep.getPublicAddr(), 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

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() + "." + format.toString().toLowerCase() ;
            DataStore secStore = this.storeMgr.getDataStore(ApiDBUtils.findUploadById(uploadId).getDataStoreId(), DataStoreRole.Image);
            EndPoint ep = _epSelector.select(secStore);
            if( ep == null ) {
              errorString = "There is no secondary storage VM for secondary storage host " + secStore.getName();
              throw new CloudRuntimeException(errorString);
            }

            CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity)secStore).getMountPoint(), path, uuid, null);
            Answer ans = ep.sendMessage(cmd);
            if (ans == null || !ans.getResult()) {
                errorString = "Unable to create a link for " +type+ " id:"+entityId + "," + ans.getDetails();
                s_logger.warn(errorString);
                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(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

    }

    @Override
    public ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode) {
        UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
        ExtractResponse response = new ExtractResponse();
        response.setObjectName("template");
        response.setId(id);
        response.setName(ApiDBUtils.findTemplateById(id).getName());
        if (zoneId != null) {
            response.setZoneId(zoneId);
            response.setZoneName(ApiDBUtils.findZoneById(zoneId).getName());
        }
        response.setMode(mode);
        response.setUploadId(uploadId);
        response.setState(uploadInfo.getUploadState().toString());
        response.setAccountId(accountId);
        response.setUrl(uploadInfo.getUploadUrl());
        return response;

    }
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

      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
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.