Search in sources :

Example 6 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadMonitorImpl method handleUploadEvent.

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);
        }
    }
}
Also used : UploadVO(com.cloud.storage.UploadVO)

Example 7 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadMonitorImpl method handleUploadSync.

@Override
public void handleUploadSync(long sserverId) {
    HostVO storageHost = _serverDao.findById(sserverId);
    if (storageHost == null) {
        s_logger.warn("Huh? Agent id " + sserverId + " does not correspond to a row in hosts table?");
        return;
    }
    s_logger.debug("Handling upload sserverId " + sserverId);
    List<UploadVO> uploadsInProgress = new ArrayList<UploadVO>();
    uploadsInProgress.addAll(_uploadDao.listByHostAndUploadStatus(sserverId, UploadVO.Status.UPLOAD_IN_PROGRESS));
    uploadsInProgress.addAll(_uploadDao.listByHostAndUploadStatus(sserverId, UploadVO.Status.COPY_IN_PROGRESS));
    if (uploadsInProgress.size() > 0) {
        for (UploadVO uploadJob : uploadsInProgress) {
            uploadJob.setUploadState(UploadVO.Status.UPLOAD_ERROR);
            uploadJob.setErrorString("Could not complete the upload.");
            uploadJob.setLastUpdated(new Date());
            _uploadDao.update(uploadJob.getId(), uploadJob);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) UploadVO(com.cloud.storage.UploadVO) HostVO(com.cloud.host.HostVO) Date(java.util.Date)

Example 8 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadMonitorImpl method createEntityDownloadURL.

@Override
public UploadVO createEntityDownloadURL(VMTemplateVO template, TemplateDataStoreVO vmTemplateHost, Long dataCenterId, long eventId) {
    String errorString = "";
    boolean success = false;
    Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
    // find an endpoint to send command
    DataStore store = storeMgr.getDataStore(vmTemplateHost.getDataStoreId(), DataStoreRole.Image);
    EndPoint ep = _epSelector.select(store);
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        return null;
    }
    //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 (// ssvm publicip and domain suffix not changed
        (token != null) && (token.length == 5) && (token[2].equals(hostname + _ssvmUrlDomain)))
            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();
        // adding "." + vhd/ova... etc.
        String uuid = UUID.randomUUID().toString() + "." + template.getFormat().getFileExtension();
        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 == null ? "" : 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);
        }
    }
}
Also used : CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) Type(com.cloud.storage.Upload.Type) RequestType(com.cloud.agent.api.storage.UploadProgressCommand.RequestType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) UploadVO(com.cloud.storage.UploadVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) Date(java.util.Date)

Example 9 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class ApiResponseHelper method createExtractResponse.

@Override
public ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url) {
    ExtractResponse response = new ExtractResponse();
    response.setObjectName("template");
    VMTemplateVO template = ApiDBUtils.findTemplateById(id);
    response.setId(template.getUuid());
    response.setName(template.getName());
    if (zoneId != null) {
        DataCenter zone = ApiDBUtils.findZoneById(zoneId);
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setMode(mode);
    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;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO) UploadVO(com.cloud.storage.UploadVO)

Example 10 with UploadVO

use of com.cloud.storage.UploadVO in project cloudstack by apache.

the class UploadMonitorImpl method createNewUploadEntry.

@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;
}
Also used : UploadVO(com.cloud.storage.UploadVO) Date(java.util.Date)

Aggregations

UploadVO (com.cloud.storage.UploadVO)11 Date (java.util.Date)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 Answer (com.cloud.agent.api.Answer)3 CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)2 RequestType (com.cloud.agent.api.storage.UploadProgressCommand.RequestType)2 HostVO (com.cloud.host.HostVO)2 Type (com.cloud.storage.Upload.Type)2 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)2 ConfigurationException (javax.naming.ConfigurationException)2 DeleteEntityDownloadURLCommand (com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand)1 UploadCommand (com.cloud.agent.api.storage.UploadCommand)1 DataCenter (com.cloud.dc.DataCenter)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 ProjectAccount (com.cloud.projects.ProjectAccount)1