Search in sources :

Example 36 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(final SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        // at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
        final DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        final SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
        // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
        _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
        final AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        final VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    }
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    volumeInfo.processEvent(Event.MigrationRequested);
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        final Map<String, String> destDetails = getVolumeDetails(volumeInfo);
        copyCommand.setOptions2(destDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        try {
            _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    String errMsg = null;
    if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
        if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
            errMsg = copyCmdAnswer.getDetails();
        } else {
            errMsg = "Unable to perform host-side operation";
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CopyCommand(com.cloud.storage.command.CopyCommand) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 37 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method createTemplateFromSnapshot.

protected Answer createTemplateFromSnapshot(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcDataStore = srcData.getDataStore();
    final DataStoreTO destDataStore = destData.getDataStore();
    if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
        if (!(srcDataStore instanceof NfsTO)) {
            s_logger.debug("only support nfs storage as src, when create template from snapshot");
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        if (destDataStore instanceof NfsTO) {
            return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) destDataStore);
        }
    }
    s_logger.debug("Failed to create templat from snapshot");
    return new CopyCmdAnswer("Unsupported prototcol");
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 38 with CopyCmdAnswer

use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.

protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(final CopyCommand cmd, final SnapshotObjectTO srcData, final NfsTO srcDataStore, final TemplateObjectTO destData, final NfsTO destDataStore) {
    final String srcMountPoint = getRootDir(srcDataStore.getUrl());
    String snapshotPath = srcData.getPath();
    final int index = snapshotPath.lastIndexOf("/");
    String snapshotName = snapshotPath.substring(index + 1);
    if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
        snapshotName = snapshotName + ".vhd";
    }
    snapshotPath = snapshotPath.substring(0, index);
    snapshotPath = srcMountPoint + File.separator + snapshotPath;
    final String destMountPoint = getRootDir(destDataStore.getUrl());
    final String destPath = destMountPoint + File.separator + destData.getPath();
    String errMsg = null;
    try {
        _storage.mkdir(destPath);
        final String templateUuid = UUID.randomUUID().toString();
        final String templateName = templateUuid + ".vhd";
        final Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
        command.add("-p", snapshotPath);
        command.add("-s", snapshotName);
        command.add("-n", templateName);
        command.add("-t", destPath);
        final String result = command.execute();
        if (result != null && !result.equalsIgnoreCase("")) {
            return new CopyCmdAnswer(result);
        }
        final Map<String, Object> params = new HashMap<>();
        params.put(StorageLayer.InstanceConfigKey, _storage);
        final Processor processor = new VhdProcessor();
        processor.configure("Vhd Processor", params);
        final FormatInfo info = processor.process(destPath, null, templateUuid);
        final TemplateLocation loc = new TemplateLocation(_storage, destPath);
        loc.create(1, true, templateUuid);
        loc.addFormat(info);
        loc.save();
        final TemplateProp prop = loc.getTemplateInfo();
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(destData.getPath() + File.separator + templateName);
        newTemplate.setFormat(ImageFormat.VHD);
        newTemplate.setSize(prop.getSize());
        newTemplate.setPhysicalSize(prop.getPhysicalSize());
        newTemplate.setName(templateUuid);
        return new CopyCmdAnswer(newTemplate);
    } catch (final ConfigurationException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    } catch (final InternalErrorException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    } catch (final IOException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    }
    return new CopyCmdAnswer(errMsg);
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) Script(com.cloud.utils.script.Script) VhdProcessor(com.cloud.storage.template.VhdProcessor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) TARProcessor(com.cloud.storage.template.TARProcessor) Processor(com.cloud.storage.template.Processor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) HashMap(java.util.HashMap) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) VhdProcessor(com.cloud.storage.template.VhdProcessor) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Aggregations

CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)38 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)33 NfsTO (com.cloud.agent.api.to.NfsTO)22 InternalErrorException (com.cloud.exception.InternalErrorException)22 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)20 DataTO (com.cloud.agent.api.to.DataTO)19 VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)19 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)18 Connection (com.xensource.xenapi.Connection)18 XenAPIException (com.xensource.xenapi.Types.XenAPIException)18 XmlRpcException (org.apache.xmlrpc.XmlRpcException)18 SR (com.xensource.xenapi.SR)17 VDI (com.xensource.xenapi.VDI)17 TemplateObjectTO (com.cloud.storage.to.TemplateObjectTO)15 URI (java.net.URI)15 SnapshotObjectTO (com.cloud.storage.to.SnapshotObjectTO)11 Task (com.xensource.xenapi.Task)7 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)6 ConfigurationException (javax.naming.ConfigurationException)5 VolumeVO (com.cloud.storage.VolumeVO)4