Search in sources :

Example 11 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class VmwareResource method configureIso.

private void configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo, DiskTO vol, VirtualDeviceConfigSpec[] deviceConfigSpecArray, int ideUnitNumber, int i) throws Exception {
    TemplateObjectTO iso = (TemplateObjectTO) vol.getData();
    if (iso.getPath() != null && !iso.getPath().isEmpty()) {
        DataStoreTO imageStore = iso.getDataStore();
        if (!(imageStore instanceof NfsTO)) {
            s_logger.debug("unsupported protocol");
            throw new Exception("unsupported protocol");
        }
        NfsTO nfsImageStore = (NfsTO) imageStore;
        String isoPath = nfsImageStore.getUrl() + File.separator + iso.getPath();
        Pair<String, ManagedObjectReference> isoDatastoreInfo = getIsoDatastoreInfo(hyperHost, isoPath);
        assert (isoDatastoreInfo != null);
        assert (isoDatastoreInfo.second() != null);
        deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
        Pair<VirtualDevice, Boolean> isoInfo = VmwareHelper.prepareIsoDevice(vmMo, isoDatastoreInfo.first(), isoDatastoreInfo.second(), true, true, ideUnitNumber, i + 1);
        deviceConfigSpecArray[i].setDevice(isoInfo.first());
        if (isoInfo.second()) {
            if (s_logger.isDebugEnabled())
                s_logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first()));
            deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
        } else {
            if (s_logger.isDebugEnabled())
                s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first()));
            deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT);
        }
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 12 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class VmwareResource method examineStorageSubSystemCommandNfsVersion.

/**
 * Examine StorageSubSystem command to get storage NFS version, if provided
 *
 * @param cmd    command to execute
 * @param params params
 */
protected void examineStorageSubSystemCommandNfsVersion(CopyCommand cmd, EnumMap<VmwareStorageProcessorConfigurableFields, Object> params) {
    DataStoreTO srcDataStore = cmd.getSrcTO().getDataStore();
    boolean nfsVersionFound = false;
    if (srcDataStore instanceof NfsTO) {
        nfsVersionFound = getStorageNfsVersionFromNfsTO((NfsTO) srcDataStore);
    }
    if (nfsVersionFound) {
        params.put(VmwareStorageProcessorConfigurableFields.NFS_VERSION, storageNfsVersion);
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 13 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class VmwareStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
    VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        NfsTO srcStore = (NfsTO) srcVolume.getDataStore();
        DataStoreTO destStore = destVolume.getDataStore();
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
        String uuid = destStore.getUuid();
        ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, uuid);
        if (morDatastore == null) {
            URI uri = new URI(destStore.getUrl());
            morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), destStore.getUuid().replace("-", ""), true);
            if (morDatastore == null) {
                throw new Exception("Unable to mount storage pool on host. storeUrl: " + uri.getHost() + ":/" + uri.getPath());
            }
        }
        Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long) cmd.getWait() * 1000, _nfsVersion);
        deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl(), _nfsVersion);
        VolumeObjectTO newVolume = new VolumeObjectTO();
        newVolume.setPath(result.second());
        return new CopyCmdAnswer(newVolume);
    } catch (Throwable t) {
        return new CopyCmdAnswer(hostService.createLogMessageException(t, cmd));
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 14 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class VmwareStorageSubsystemCommandHandler method execute.

@Override
protected Answer execute(CopyCommand cmd) {
    DataTO srcData = cmd.getSrcTO();
    DataTO destData = cmd.getDestTO();
    DataStoreTO srcDataStore = srcData.getDataStore();
    DataStoreTO destDataStore = destData.getDataStore();
    int timeout = NumbersUtil.parseInt(cmd.getContextParam(VmwareManager.s_vmwareOVAPackageTimeout.key()), Integer.valueOf(VmwareManager.s_vmwareOVAPackageTimeout.defaultValue()) * VmwareManager.s_vmwareOVAPackageTimeout.multiplier());
    // if copied between s3 and nfs cache, go to resource
    boolean needDelegation = false;
    if (destDataStore instanceof NfsTO && destDataStore.getRole() == DataStoreRole.ImageCache) {
        if (srcDataStore instanceof S3TO || srcDataStore instanceof SwiftTO) {
            needDelegation = true;
        }
    }
    if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
        // need to take extra processing for vmware, such as packing to ova, before sending to S3
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            NfsTO cacheStore = (NfsTO) srcDataStore;
            String parentPath = storageResource.getRootDir(cacheStore.getUrl(), _nfsVersion);
            VolumeObjectTO vol = (VolumeObjectTO) srcData;
            String path = vol.getPath();
            int index = path.lastIndexOf(File.separator);
            String name = path.substring(index + 1);
            storageManager.createOva(parentPath + File.separator + path, name, timeout);
            vol.setPath(path + File.separator + name + ".ova");
        } else if (srcData.getObjectType() == DataObjectType.TEMPLATE) {
            // sync template from NFS cache to S3 in NFS migration to S3 case
            storageManager.createOvaForTemplate((TemplateObjectTO) srcData, timeout);
        } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT) {
            // pack ova first
            // sync snapshot from NFS cache to S3 in NFS migration to S3 case
            String parentPath = storageResource.getRootDir(srcDataStore.getUrl(), _nfsVersion);
            SnapshotObjectTO snap = (SnapshotObjectTO) srcData;
            String path = snap.getPath();
            int index = path.lastIndexOf(File.separator);
            String name = path.substring(index + 1);
            String snapDir = path.substring(0, index);
            storageManager.createOva(parentPath + File.separator + snapDir, name, timeout);
            if (destData.getObjectType() == DataObjectType.TEMPLATE) {
                // create template from snapshot on src at first, then copy it to s3
                TemplateObjectTO cacheTemplate = (TemplateObjectTO) destData;
                cacheTemplate.setDataStore(srcDataStore);
                CopyCmdAnswer answer = (CopyCmdAnswer) processor.createTemplateFromSnapshot(cmd);
                if (!answer.getResult()) {
                    return answer;
                }
                cacheTemplate.setDataStore(destDataStore);
                TemplateObjectTO template = (TemplateObjectTO) answer.getNewData();
                template.setDataStore(srcDataStore);
                CopyCommand newCmd = new CopyCommand(template, destData, cmd.getWait(), cmd.executeInSequence());
                Answer result = storageResource.defaultAction(newCmd);
                // clean up template data on staging area
                try {
                    DeleteCommand deleteCommand = new DeleteCommand(template);
                    storageResource.defaultAction(deleteCommand);
                } catch (Exception e) {
                    s_logger.debug("Failed to clean up staging area:", e);
                }
                return result;
            }
        }
        needDelegation = true;
    }
    if (srcData.getObjectType() == DataObjectType.SNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
        // for back up snapshot, we need to do backup to cache, then to object store if object store is used.
        if (cmd.getCacheTO() != null) {
            cmd.setDestTO(cmd.getCacheTO());
            CopyCmdAnswer answer = (CopyCmdAnswer) processor.backupSnapshot(cmd);
            if (!answer.getResult()) {
                return answer;
            }
            NfsTO cacheStore = (NfsTO) cmd.getCacheTO().getDataStore();
            String parentPath = storageResource.getRootDir(cacheStore.getUrl(), _nfsVersion);
            SnapshotObjectTO newSnapshot = (SnapshotObjectTO) answer.getNewData();
            String path = newSnapshot.getPath();
            int index = path.lastIndexOf(File.separator);
            String name = path.substring(index + 1);
            String dir = path.substring(0, index);
            storageManager.createOva(parentPath + File.separator + dir, name, timeout);
            newSnapshot.setPath(newSnapshot.getPath() + ".ova");
            newSnapshot.setDataStore(cmd.getCacheTO().getDataStore());
            CopyCommand newCmd = new CopyCommand(newSnapshot, destData, cmd.getWait(), cmd.executeInSequence());
            Answer result = storageResource.defaultAction(newCmd);
            // clean up data on staging area
            try {
                newSnapshot.setPath(path);
                DeleteCommand deleteCommand = new DeleteCommand(newSnapshot);
                storageResource.defaultAction(deleteCommand);
            } catch (Exception e) {
                s_logger.debug("Failed to clean up staging area:", e);
            }
            return result;
        }
    }
    if (needDelegation) {
        return storageResource.defaultAction(cmd);
    } else {
        return super.execute(cmd);
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) SwiftTO(com.cloud.agent.api.to.SwiftTO) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) NfsTO(com.cloud.agent.api.to.NfsTO) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) Answer(com.cloud.agent.api.Answer) DataTO(com.cloud.agent.api.to.DataTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) S3TO(com.cloud.agent.api.to.S3TO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 15 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class VmwareStorageProcessor method createTemplateFromSnapshot.

@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
    String details;
    SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getSrcTO();
    TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
    DataStoreTO imageStore = template.getDataStore();
    String uniqueName = UUID.randomUUID().toString();
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        if (!(imageStore instanceof NfsTO)) {
            return new CopyCmdAnswer("Creating a template from a snapshot is only supported when the destination store is NFS.");
        }
        NfsTO nfsSvr = (NfsTO) imageStore;
        if (snapshot.getDataStore() instanceof PrimaryDataStoreTO && template.getDataStore() instanceof NfsTO) {
            return handleManagedStorageCreateTemplateFromSnapshot(cmd, template, nfsSvr);
        }
        Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqueName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), cmd.getWait() * 1000, _nfsVersion);
        TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(result.first());
        newTemplate.setPhysicalSize(result.second());
        newTemplate.setSize(result.third());
        newTemplate.setFormat(ImageFormat.OVA);
        newTemplate.setName(uniqueName);
        return new CopyCmdAnswer(newTemplate);
    } catch (Throwable e) {
        return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

NfsTO (com.cloud.agent.api.to.NfsTO)142 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)110 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)79 DataTO (com.cloud.agent.api.to.DataTO)71 InternalErrorException (com.cloud.exception.InternalErrorException)58 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)52 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)39 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)38 XmlRpcException (org.apache.xmlrpc.XmlRpcException)37 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 URI (java.net.URI)36 Connection (com.xensource.xenapi.Connection)34 SR (com.xensource.xenapi.SR)34 VDI (com.xensource.xenapi.VDI)34 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)32 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)32 Answer (com.cloud.agent.api.Answer)29 IOException (java.io.IOException)28 File (java.io.File)27 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)26