Search in sources :

Example 46 with DataStoreTO

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

the class SimulatorStorageProcessor method createTemplateFromVolume.

@Override
public Answer createTemplateFromVolume(CopyCommand cmd) {
    DataTO destData = cmd.getDestTO();
    VolumeObjectTO srcData = (VolumeObjectTO) cmd.getSrcTO();
    TemplateObjectTO template = new TemplateObjectTO();
    template.setPath(template.getName());
    template.setFormat(Storage.ImageFormat.RAW);
    template.setSize(srcData.getSize());
    DataStoreTO imageStore = destData.getDataStore();
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    return new CopyCmdAnswer(template);
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 47 with DataStoreTO

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

the class DownloadManagerImpl method handleDownloadCommand.

@Override
public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd) {
    ResourceType resourceType = cmd.getResourceType();
    if (cmd instanceof DownloadProgressCommand) {
        return handleDownloadProgressCmd(resource, (DownloadProgressCommand) cmd);
    }
    if (cmd.getUrl() == null) {
        return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
    }
    if (cmd.getName() == null) {
        return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
    }
    DataStoreTO dstore = cmd.getDataStore();
    String installPathPrefix = cmd.getInstallPath();
    // for NFS, we need to get mounted path
    if (dstore instanceof NfsTO) {
        installPathPrefix = resource.getRootDir(((NfsTO) dstore).getUrl(), _nfsVersion) + File.separator + installPathPrefix;
    }
    String user = null;
    String password = null;
    if (cmd.getAuth() != null) {
        user = cmd.getAuth().getUserName();
        password = cmd.getAuth().getPassword();
    }
    // TO DO - Define Volume max size as well
    long maxDownloadSizeInBytes = (cmd.getMaxDownloadSizeInBytes() == null) ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : (cmd.getMaxDownloadSizeInBytes());
    String jobId = null;
    if (dstore instanceof S3TO) {
        jobId = downloadS3Template((S3TO) dstore, cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
    } else {
        jobId = downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, cmd.getInstallPath(), user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
    }
    sleep();
    if (jobId == null) {
        return new DownloadAnswer("Internal Error", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
    }
    return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) ResourceType(org.apache.cloudstack.storage.command.DownloadCommand.ResourceType) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) S3TO(com.cloud.agent.api.to.S3TO) DownloadProgressCommand(org.apache.cloudstack.storage.command.DownloadProgressCommand)

Example 48 with DataStoreTO

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

the class NfsSecondaryStorageResource method copyFromNfsToS3.

protected Answer copyFromNfsToS3(CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    DataStoreTO srcDataStore = srcData.getDataStore();
    NfsTO srcStore = (NfsTO) srcDataStore;
    DataStoreTO destDataStore = destData.getDataStore();
    final S3TO s3 = (S3TO) destDataStore;
    try {
        final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _nfsVersion);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
        }
        final String bucket = s3.getBucketName();
        File srcFile = findFile(templatePath);
        if (srcFile == null) {
            return new CopyCmdAnswer("Can't find src file:" + templatePath);
        }
        ImageFormat format = getTemplateFormat(srcFile.getName());
        String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
        putFile(s3, srcFile, bucket, key).waitForCompletion();
        DataTO retObj = null;
        if (destData.getObjectType() == DataObjectType.TEMPLATE) {
            TemplateObjectTO newTemplate = new TemplateObjectTO();
            newTemplate.setPath(key);
            newTemplate.setSize(getVirtualSize(srcFile, format));
            newTemplate.setPhysicalSize(srcFile.length());
            newTemplate.setFormat(format);
            retObj = newTemplate;
        } else if (destData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(key);
            newVol.setSize(srcFile.length());
            retObj = newVol;
        } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
            SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
            newSnapshot.setPath(key);
            retObj = newSnapshot;
        }
        return new CopyCmdAnswer(retObj);
    } catch (Exception e) {
        s_logger.error("failed to upload" + srcData.getPath(), e);
        return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) S3TO(com.cloud.agent.api.to.S3TO) File(java.io.File) S3Utils.putFile(com.cloud.utils.storage.S3.S3Utils.putFile) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) ImageFormat(com.cloud.storage.Storage.ImageFormat)

Example 49 with DataStoreTO

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

the class NfsSecondaryStorageResource method execute.

private Answer execute(ListTemplateCommand cmd) {
    if (!_inSystemVM) {
        return new ListTemplateAnswer(null, null);
    }
    DataStoreTO store = cmd.getDataStore();
    if (store instanceof NfsTO) {
        NfsTO nfs = (NfsTO) store;
        String secUrl = nfs.getUrl();
        String root = getRootDir(secUrl, cmd.getNfsVersion());
        Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
        return new ListTemplateAnswer(secUrl, templateInfos);
    } else if (store instanceof SwiftTO) {
        SwiftTO swift = (SwiftTO) store;
        Map<String, TemplateProp> templateInfos = swiftListTemplate(swift);
        return new ListTemplateAnswer(swift.toString(), templateInfos);
    } else if (store instanceof S3TO) {
        S3TO s3 = (S3TO) store;
        Map<String, TemplateProp> templateInfos = s3ListTemplate(s3);
        return new ListTemplateAnswer(s3.getBucketName(), templateInfos);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) SwiftTO(com.cloud.agent.api.to.SwiftTO) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) Map(java.util.Map) HashMap(java.util.HashMap) S3TO(com.cloud.agent.api.to.S3TO)

Example 50 with DataStoreTO

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

the class NfsSecondaryStorageResource method execute.

protected Answer execute(CopyCommand cmd) {
    DataTO srcData = cmd.getSrcTO();
    DataTO destData = cmd.getDestTO();
    DataStoreTO srcDataStore = srcData.getDataStore();
    DataStoreTO destDataStore = destData.getDataStore();
    if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
        return createTemplateFromSnapshot(cmd);
    }
    if (destDataStore instanceof NfsTO && destDataStore.getRole() == DataStoreRole.ImageCache) {
        NfsTO destImageStore = (NfsTO) destDataStore;
        if (srcDataStore instanceof S3TO) {
            S3TO s3 = (S3TO) srcDataStore;
            return copyFromS3ToNfs(cmd, srcData, s3, destData, destImageStore);
        } else if (srcDataStore instanceof SwiftTO) {
            return copyFromSwiftToNfs(cmd, srcData, (SwiftTO) srcDataStore, destData, destImageStore);
        }
    }
    if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
        return copyFromNfsToImage(cmd);
    }
    return Answer.createUnsupportedCommandAnswer(cmd);
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) SwiftTO(com.cloud.agent.api.to.SwiftTO) NfsTO(com.cloud.agent.api.to.NfsTO) S3TO(com.cloud.agent.api.to.S3TO)

Aggregations

DataStoreTO (com.cloud.agent.api.to.DataStoreTO)91 NfsTO (com.cloud.agent.api.to.NfsTO)66 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)54 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 DataTO (com.cloud.agent.api.to.DataTO)46 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)36 InternalErrorException (com.cloud.exception.InternalErrorException)30 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)28 Answer (com.cloud.agent.api.Answer)26 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)19 IOException (java.io.IOException)17 S3TO (com.cloud.agent.api.to.S3TO)16 ConfigurationException (javax.naming.ConfigurationException)16 XmlRpcException (org.apache.xmlrpc.XmlRpcException)16 XenAPIException (com.xensource.xenapi.Types.XenAPIException)15 RemoteException (java.rmi.RemoteException)15 SwiftTO (com.cloud.agent.api.to.SwiftTO)14 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)14