Search in sources :

Example 21 with TemplateProp

use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.

the class NfsSecondaryStorageResource method s3ListTemplate.

Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
    String bucket = s3.getBucketName();
    // List the objects in the source directory on S3
    final List<S3ObjectSummary> objectSummaries = S3Utils.listDirectory(s3, bucket, TEMPLATE_ROOT_DIR);
    if (objectSummaries == null) {
        return null;
    }
    Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
    for (S3ObjectSummary objectSummary : objectSummaries) {
        String key = objectSummary.getKey();
        // String installPath = StringUtils.substringBeforeLast(key,
        // S3Utils.SEPARATOR);
        String uniqueName = determineS3TemplateNameFromKey(key);
        // TODO: isPublic value, where to get?
        TemplateProp tInfo = new TemplateProp(uniqueName, key, objectSummary.getSize(), objectSummary.getSize(), true, false);
        tmpltInfos.put(uniqueName, tInfo);
    }
    return tmpltInfos;
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 22 with TemplateProp

use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.

the class DownloadManagerImpl method gatherVolumeInfo.

@Override
public Map<Long, TemplateProp> gatherVolumeInfo(String rootDir) {
    Map<Long, TemplateProp> result = new HashMap<Long, TemplateProp>();
    String volumeDir = rootDir + File.separator + _volumeDir;
    if (!_storage.exists(volumeDir)) {
        _storage.mkdirs(volumeDir);
    }
    List<String> vols = listVolumes(volumeDir);
    for (String vol : vols) {
        String path = vol.substring(0, vol.lastIndexOf(File.separator));
        TemplateLocation loc = new TemplateLocation(_storage, path);
        try {
            if (!loc.load()) {
                s_logger.warn("Post download installation was not completed for " + path);
                // loc.purge();
                _storage.cleanup(path, volumeDir);
                continue;
            }
        } catch (IOException e) {
            s_logger.warn("Unable to load volume location " + path, e);
            continue;
        }
        TemplateProp vInfo = loc.getTemplateInfo();
        if ((vInfo.getSize() == vInfo.getPhysicalSize()) && (vInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
            try {
                Processor processor = _processors.get("OVA Processor");
                OVAProcessor vmdkProcessor = (OVAProcessor) processor;
                long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.getInstallPath().substring(vInfo.getInstallPath().lastIndexOf(File.separator) + 1));
                vInfo.setSize(vSize);
                loc.updateVirtualSize(vSize);
                loc.save();
            } catch (Exception e) {
                s_logger.error("Unable to get the virtual size of the volume: " + vInfo.getInstallPath() + " due to " + e.getMessage());
            }
        }
        result.put(vInfo.getId(), vInfo);
        s_logger.debug("Added volume name: " + vInfo.getTemplateName() + ", path: " + vol);
    }
    return result;
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) VhdProcessor(com.cloud.storage.template.VhdProcessor) OVAProcessor(com.cloud.storage.template.OVAProcessor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) TARProcessor(com.cloud.storage.template.TARProcessor) IsoProcessor(com.cloud.storage.template.IsoProcessor) Processor(com.cloud.storage.template.Processor) VmdkProcessor(com.cloud.storage.template.VmdkProcessor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OVAProcessor(com.cloud.storage.template.OVAProcessor) TemplateLocation(com.cloud.storage.template.TemplateLocation) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException)

Aggregations

TemplateProp (com.cloud.storage.template.TemplateProp)22 HashMap (java.util.HashMap)18 Answer (com.cloud.agent.api.Answer)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 ConfigurationException (javax.naming.ConfigurationException)11 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)9 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)7 URISyntaxException (java.net.URISyntaxException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)6 IOException (java.io.IOException)6 ListTemplateAnswer (com.cloud.agent.api.storage.ListTemplateAnswer)5 ListVolumeAnswer (com.cloud.agent.api.storage.ListVolumeAnswer)5 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)5 InternalErrorException (com.cloud.exception.InternalErrorException)5 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)4 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)4 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)4 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)4 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)4