Search in sources :

Example 1 with CreateEntityDownloadURLCommand

use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.

the class VmwareSecondaryStorageResourceHandler method executeRequest.

@Override
public Answer executeRequest(Command cmd) {
    try {
        Answer answer;
        NDC.push(getCommandLogTitle(cmd));
        if (s_logger.isDebugEnabled())
            s_logger.debug("Executing " + _gson.toJson(cmd));
        if (cmd instanceof PrimaryStorageDownloadCommand) {
            answer = execute((PrimaryStorageDownloadCommand) cmd);
        } else if (cmd instanceof BackupSnapshotCommand) {
            answer = execute((BackupSnapshotCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
            answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
            answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (cmd instanceof CopyVolumeCommand) {
            answer = execute((CopyVolumeCommand) cmd);
        } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
            answer = execute((CreateVolumeFromSnapshotCommand) cmd);
        } else if (cmd instanceof StorageSubSystemCommand) {
            answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
        } else if (cmd instanceof CreateEntityDownloadURLCommand) {
            answer = execute((CreateEntityDownloadURLCommand) cmd);
        } else {
            answer = _resource.defaultAction(cmd);
        }
        // special handling to pass-back context info for cleanups
        if (cmd.getContextParam("execid") != null) {
            answer.setContextParam("execid", cmd.getContextParam("execid"));
        }
        if (cmd.getContextParam("checkpoint") != null) {
            answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
        }
        if (cmd.getContextParam("checkpoint2") != null) {
            answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
        }
        if (s_logger.isDebugEnabled())
            s_logger.debug("Command execution answer: " + _gson.toJson(answer));
        return answer;
    } finally {
        if (s_logger.isDebugEnabled())
            s_logger.debug("Done executing " + _gson.toJson(cmd));
        recycleServiceContext();
        NDC.pop();
    }
}
Also used : BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)

Example 2 with CreateEntityDownloadURLCommand

use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.

the class CloudStackImageStoreDriverImpl method createEntityExtractUrl.

@Override
public String createEntityExtractUrl(DataStore store, String installPath, ImageFormat format, DataObject dataObject) {
    // find an endpoint to send command
    EndPoint ep = _epSelector.select(store);
    // Create Symlink at ssvm
    String path = installPath;
    String uuid = UUID.randomUUID().toString() + "." + format.getFileExtension();
    CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) store).getMountPoint(), path, uuid, dataObject.getTO());
    Answer ans = null;
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        ans = new Answer(cmd, false, errMsg);
    } else {
        ans = ep.sendMessage(cmd);
    }
    if (ans == null || !ans.getResult()) {
        String errorString = "Unable to create a link for entity at " + installPath + " on ssvm," + ans.getDetails();
        s_logger.error(errorString);
        throw new CloudRuntimeException(errorString);
    }
    // Construct actual URL locally now that the symlink exists at SSVM
    return generateCopyUrl(ep.getPublicAddr(), uuid);
}
Also used : CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)

Example 3 with CreateEntityDownloadURLCommand

use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand 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 4 with CreateEntityDownloadURLCommand

use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.

the class VMwareGuru method getCommandHostDelegation.

@Override
@DB
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
    boolean needDelegation = false;
    if (cmd instanceof StorageSubSystemCommand) {
        Boolean fullCloneEnabled = VmwareFullClone.value();
        StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(fullCloneEnabled);
    }
    //type is empty, so we need to check the format of volume at first.
    if (cmd instanceof CopyCommand) {
        CopyCommand cpyCommand = (CopyCommand) cmd;
        DataTO srcData = cpyCommand.getSrcTO();
        DataStoreTO srcStoreTO = srcData.getDataStore();
        DataTO destData = cpyCommand.getDestTO();
        DataStoreTO destStoreTO = destData.getDataStore();
        boolean inSeq = true;
        if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
            inSeq = false;
        } else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) {
            inSeq = false;
        } else if (!VmwareFullClone.value()) {
            inSeq = false;
        }
        cpyCommand.setExecuteInSequence(inSeq);
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
        if (!needDelegation && !(HypervisorType.VMware == srcData.getHypervisorType() || HypervisorType.VMware == destData.getHypervisorType())) {
            return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
        }
        if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
            needDelegation = false;
        } else {
            needDelegation = true;
        }
    } else if (cmd instanceof CreateEntityDownloadURLCommand) {
        DataTO srcData = ((CreateEntityDownloadURLCommand) cmd).getData();
        if ((HypervisorType.VMware == srcData.getHypervisorType())) {
            needDelegation = true;
        }
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
    }
    if (!needDelegation) {
        return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
    }
    HostVO host = _hostDao.findById(hostId);
    long dcId = host.getDataCenterId();
    Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
    if (cmdTarget != null) {
        // TODO, we need to make sure agent is actually connected too
        cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
        if (host.getType() == Host.Type.Routing) {
            Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
            cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
            cmd.setContextParam("username", hostDetails.get("username"));
            cmd.setContextParam("password", hostDetails.get("password"));
            cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
            cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
        }
        CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
        _cmdExecLogDao.persist(execLog);
        cmd.setContextParam("execid", String.valueOf(execLog.getId()));
        cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
        cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
        if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand || cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand || cmd instanceof CreateVolumeOVACommand || cmd instanceof PrepareOVAPackingCommand || cmd instanceof CreateVolumeFromSnapshotCommand) {
            String workerName = _vmwareMgr.composeWorkerName();
            long checkPointId = 1;
            // FIXME: Fix                    long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
            cmd.setContextParam("worker", workerName);
            cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
            // some commands use 2 workers
            String workerName2 = _vmwareMgr.composeWorkerName();
            long checkPointId2 = 1;
            // FIXME: Fix                    long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
            cmd.setContextParam("worker2", workerName2);
            cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
        }
        return new Pair<Boolean, Long>(Boolean.TRUE, cmdTarget.first().getId());
    }
    return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
Also used : BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) HostVO(com.cloud.host.HostVO) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) DataTO(com.cloud.agent.api.to.DataTO) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 5 with CreateEntityDownloadURLCommand

use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.

the class UploadMonitorImpl method createVolumeDownloadURL.

@Override
public void createVolumeDownloadURL(Long entityId, String path, Type type, Long dataCenterId, Long uploadId, ImageFormat format) {
    String errorString = "";
    boolean success = false;
    try {
        List<HostVO> storageServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.SecondaryStorage, dataCenterId);
        if (storageServers == null) {
            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 = 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 == null ? "" : 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);
        }
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UploadVO(com.cloud.storage.UploadVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) Date(java.util.Date) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Aggregations

CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)5 Answer (com.cloud.agent.api.Answer)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)3 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)2 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)2 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)2 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)2 CopyVolumeCommand (com.cloud.agent.api.storage.CopyVolumeCommand)2 HostVO (com.cloud.host.HostVO)2 UploadVO (com.cloud.storage.UploadVO)2 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)2 Date (java.util.Date)2 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)2 StorageSubSystemCommand (org.apache.cloudstack.storage.command.StorageSubSystemCommand)2 CreateVolumeOVACommand (com.cloud.agent.api.storage.CreateVolumeOVACommand)1 PrepareOVAPackingCommand (com.cloud.agent.api.storage.PrepareOVAPackingCommand)1 PrimaryStorageDownloadCommand (com.cloud.agent.api.storage.PrimaryStorageDownloadCommand)1 RequestType (com.cloud.agent.api.storage.UploadProgressCommand.RequestType)1 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)1