Search in sources :

Example 31 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method deleteTemplate.

protected Answer deleteTemplate(final DeleteCommand cmd) {
    final DataTO obj = cmd.getData();
    final DataStoreTO dstore = obj.getDataStore();
    if (dstore instanceof NfsTO) {
        final NfsTO nfs = (NfsTO) dstore;
        String relativeTemplatePath = obj.getPath();
        String parent = getRootDir(nfs.getUrl());
        if (relativeTemplatePath.startsWith(File.separator)) {
            relativeTemplatePath = relativeTemplatePath.substring(1);
        }
        if (!parent.endsWith(File.separator)) {
            parent += File.separator;
        }
        final String absoluteTemplatePath = parent + relativeTemplatePath;
        final File tmpltPath = new File(absoluteTemplatePath);
        File tmpltParent = null;
        if (tmpltPath.exists() && tmpltPath.isDirectory()) {
            tmpltParent = tmpltPath;
        } else {
            tmpltParent = tmpltPath.getParentFile();
        }
        String details = null;
        if (!tmpltParent.exists()) {
            details = "template parent directory " + tmpltParent.getName() + " doesn't exist";
            s_logger.debug(details);
            return new Answer(cmd, true, details);
        }
        final File[] tmpltFiles = tmpltParent.listFiles();
        if (tmpltFiles == null || tmpltFiles.length == 0) {
            details = "No files under template parent directory " + tmpltParent.getName();
            s_logger.debug(details);
        } else {
            boolean found = false;
            for (final File f : tmpltFiles) {
                if (!found && f.getName().equals("template.properties")) {
                    found = true;
                }
                // Don't let this stop us from cleaning up the template
                if (f.isDirectory() && f.getName().equals("KVMHA")) {
                    s_logger.debug("Deleting KVMHA directory contents from template location");
                    final File[] haFiles = f.listFiles();
                    for (final File haFile : haFiles) {
                        haFile.delete();
                    }
                }
                if (!f.delete()) {
                    return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Template path " + relativeTemplatePath);
                }
            }
            if (!found) {
                details = "Can not find template.properties under " + tmpltParent.getName();
                s_logger.debug(details);
            }
        }
        if (!tmpltParent.delete()) {
            details = "Unable to delete directory " + tmpltParent.getName() + " under Template path " + relativeTemplatePath;
            s_logger.debug(details);
            return new Answer(cmd, false, details);
        }
        return new Answer(cmd, true, null);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + dstore);
    }
}
Also used : ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO) File(java.io.File)

Example 32 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

private Answer execute(final SecStorageSetupCommand cmd) {
    if (!this._inSystemVM) {
        return new Answer(cmd, true, null);
    }
    Answer answer = null;
    final DataStoreTO dStore = cmd.getDataStore();
    if (dStore instanceof NfsTO) {
        final String secUrl = cmd.getSecUrl();
        try {
            final URI uri = new URI(secUrl);
            final String nfsHostIp = getUriHostIp(uri);
            final String dir = mountUri(uri);
            configCerts(cmd.getCerts());
            this.nfsIps.add(nfsHostIp);
            answer = new SecStorageSetupAnswer(dir);
        } catch (final Exception e) {
            final String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
            s_logger.error(msg);
            answer = new Answer(cmd, false, msg);
        }
    } else {
        answer = new Answer(cmd, true, null);
    }
    savePostUploadPSK(cmd.getPostUploadKey());
    startPostUploadServer();
    return answer;
}
Also used : ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 33 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class StorageSubsystemCommandHandlerBase method execute.

protected Answer execute(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcDataStore = srcData.getDataStore();
    final DataStoreTO destDataStore = destData.getDataStore();
    if (srcData.getObjectType() == DataObjectType.TEMPLATE && (srcData.getDataStore().getRole() == DataStoreRole.Image || srcData.getDataStore().getRole() == DataStoreRole.ImageCache) && destData.getDataStore().getRole() == DataStoreRole.Primary) {
        // copy template to primary storage
        return processor.copyTemplateToPrimaryStorage(cmd);
    } else if (srcData.getObjectType() == DataObjectType.TEMPLATE && srcDataStore.getRole() == DataStoreRole.Primary && destDataStore.getRole() == DataStoreRole.Primary) {
        // clone template to a volume
        return processor.cloneVolumeFromBaseTemplate(cmd);
    } else if (srcData.getObjectType() == DataObjectType.VOLUME && (srcData.getDataStore().getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Image)) {
        // copy volume from image cache to primary
        return processor.copyVolumeFromImageCacheToPrimary(cmd);
    } else if (srcData.getObjectType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
        if (destData.getObjectType() == DataObjectType.VOLUME) {
            return processor.copyVolumeFromPrimaryToSecondary(cmd);
        } else if (destData.getObjectType() == DataObjectType.TEMPLATE) {
            return processor.createTemplateFromVolume(cmd);
        }
    } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.SNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
        return processor.backupSnapshot(cmd);
    } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.VOLUME) {
        return processor.createVolumeFromSnapshot(cmd);
    } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
        return processor.createTemplateFromSnapshot(cmd);
    }
    return new Answer(cmd, false, "not implemented yet");
}
Also used : CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO)

Example 34 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class GsonHelper method setDefaultGsonConfig.

static Gson setDefaultGsonConfig(final GsonBuilder builder) {
    final InterfaceTypeAdaptor<DataStoreTO> dsAdaptor = new InterfaceTypeAdaptor<>();
    builder.registerTypeAdapter(DataStoreTO.class, dsAdaptor);
    final InterfaceTypeAdaptor<DataTO> dtAdaptor = new InterfaceTypeAdaptor<>();
    builder.registerTypeAdapter(DataTO.class, dtAdaptor);
    final ArrayTypeAdaptor<Command> cmdAdaptor = new ArrayTypeAdaptor<>();
    builder.registerTypeAdapter(new TypeToken<Command[]>() {
    }.getType(), cmdAdaptor);
    final ArrayTypeAdaptor<Answer> ansAdaptor = new ArrayTypeAdaptor<>();
    builder.registerTypeAdapter(new TypeToken<Answer[]>() {
    }.getType(), ansAdaptor);
    final Gson gson = builder.create();
    dsAdaptor.initGson(gson);
    dtAdaptor.initGson(gson);
    cmdAdaptor.initGson(gson);
    ansAdaptor.initGson(gson);
    return gson;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) Command(com.cloud.legacymodel.communication.command.Command) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson)

Example 35 with DataStoreTO

use of com.cloud.legacymodel.to.DataStoreTO in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method createVolumeFromSnapshot.

@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
    try {
        final DataTO srcData = cmd.getSrcTO();
        final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
        final DataTO destData = cmd.getDestTO();
        final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
        final DataStoreTO imageStore = srcData.getDataStore();
        final VolumeObjectTO volume = snapshot.getVolume();
        if (!(imageStore instanceof NfsTO)) {
            return new CopyCmdAnswer("unsupported protocol");
        }
        final NfsTO nfsImageStore = (NfsTO) imageStore;
        final String snapshotFullPath = snapshot.getPath();
        final int index = snapshotFullPath.lastIndexOf("/");
        final String snapshotPath = snapshotFullPath.substring(0, index);
        final String snapshotName = snapshotFullPath.substring(index + 1);
        final KvmStoragePool secondaryPool = this.storagePoolMgr.getStoragePoolByUri(nfsImageStore.getUrl() + File.separator + snapshotPath);
        final KvmPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName);
        if (volume.getFormat() == ImageFormat.RAW) {
            snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
        } else if (volume.getFormat() == ImageFormat.QCOW2) {
            snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
        }
        final String primaryUuid = pool.getUuid();
        final KvmStoragePool primaryPool = this.storagePoolMgr.getStoragePool(pool.getPoolType(), primaryUuid);
        final String volUuid = UUID.randomUUID().toString();
        final KvmPhysicalDisk disk = this.storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool, cmd.getWaitInMillSeconds());
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(disk.getName());
        newVol.setSize(disk.getVirtualSize());
        newVol.setFormat(ImageFormat.valueOf(disk.getFormat().toString().toUpperCase()));
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        this.logger.debug("Failed to createVolumeFromSnapshot: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(com.cloud.legacymodel.to.SnapshotObjectTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) NfsTO(com.cloud.legacymodel.to.NfsTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Aggregations

DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)49 NfsTO (com.cloud.legacymodel.to.NfsTO)36 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)30 DataTO (com.cloud.legacymodel.to.DataTO)30 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)25 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)24 Answer (com.cloud.legacymodel.communication.answer.Answer)19 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)17 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)15 XenAPIException (com.xensource.xenapi.Types.XenAPIException)15 XmlRpcException (org.apache.xmlrpc.XmlRpcException)15 Connection (com.xensource.xenapi.Connection)14 SR (com.xensource.xenapi.SR)13 VDI (com.xensource.xenapi.VDI)13 URI (java.net.URI)12 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)11 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)9 GetStorageStatsAnswer (com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer)9 CheckHealthAnswer (com.cloud.legacymodel.communication.answer.CheckHealthAnswer)8 ListTemplateAnswer (com.cloud.legacymodel.communication.answer.ListTemplateAnswer)8