Search in sources :

Example 1 with VmdkProcessor

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

the class DownloadManagerImpl method configure.

@Override
@SuppressWarnings("unchecked")
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    _name = name;
    String value = null;
    _storage = (StorageLayer) params.get(StorageLayer.InstanceConfigKey);
    if (_storage == null) {
        value = (String) params.get(StorageLayer.ClassConfigKey);
        if (value == null) {
            throw new ConfigurationException("Unable to find the storage layer");
        }
        Class<StorageLayer> clazz;
        try {
            clazz = (Class<StorageLayer>) Class.forName(value);
            _storage = clazz.newInstance();
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("Unable to instantiate " + value);
        } catch (InstantiationException e) {
            throw new ConfigurationException("Unable to instantiate " + value);
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Unable to instantiate " + value);
        }
    }
    String inSystemVM = (String) params.get("secondary.storage.vm");
    if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
        LOGGER.info("DownloadManager: starting additional services since we are inside system vm");
        _nfsVersion = NfsSecondaryStorageResource.retrieveNfsVersionFromParams(params);
        startAdditionalServices();
        blockOutgoingOnPrivate();
    }
    value = (String) params.get("install.timeout.pergig");
    installTimeoutPerGig = NumbersUtil.parseInt(value, 15 * 60) * 1000;
    value = (String) params.get("install.numthreads");
    final int numInstallThreads = NumbersUtil.parseInt(value, 10);
    String scriptsDir = (String) params.get("template.scripts.dir");
    if (scriptsDir == null) {
        scriptsDir = "scripts/storage/secondary";
    }
    listTmpltScr = Script.findScript(scriptsDir, "listvmtmplt.sh");
    if (listTmpltScr == null) {
        throw new ConfigurationException("Unable to find the listvmtmplt.sh");
    }
    LOGGER.info("listvmtmplt.sh found in " + listTmpltScr);
    createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
    if (createTmpltScr == null) {
        throw new ConfigurationException("Unable to find createtmplt.sh");
    }
    LOGGER.info("createtmplt.sh found in " + createTmpltScr);
    listVolScr = Script.findScript(scriptsDir, "listvolume.sh");
    if (listVolScr == null) {
        throw new ConfigurationException("Unable to find the listvolume.sh");
    }
    LOGGER.info("listvolume.sh found in " + listVolScr);
    createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
    if (createVolScr == null) {
        throw new ConfigurationException("Unable to find createvolume.sh");
    }
    LOGGER.info("createvolume.sh found in " + createVolScr);
    _processors = new HashMap<String, Processor>();
    Processor processor = new VhdProcessor();
    processor.configure("VHD Processor", params);
    _processors.put("VHD Processor", processor);
    processor = new IsoProcessor();
    processor.configure("ISO Processor", params);
    _processors.put("ISO Processor", processor);
    processor = new QCOW2Processor();
    processor.configure("QCOW2 Processor", params);
    _processors.put("QCOW2 Processor", processor);
    processor = new OVAProcessor();
    processor.configure("OVA Processor", params);
    _processors.put("OVA Processor", processor);
    processor = new VmdkProcessor();
    processor.configure("VMDK Processor", params);
    _processors.put("VMDK Processor", processor);
    processor = new RawImageProcessor();
    processor.configure("Raw Image Processor", params);
    _processors.put("Raw Image Processor", processor);
    processor = new TARProcessor();
    processor.configure("TAR Processor", params);
    _processors.put("TAR Processor", processor);
    _templateDir = (String) params.get("public.templates.root.dir");
    if (_templateDir == null) {
        _templateDir = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR;
    }
    _templateDir += File.separator + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR;
    _volumeDir = TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + File.separator;
    // Add more processors here.
    threadPool = Executors.newFixedThreadPool(numInstallThreads);
    return true;
}
Also used : IsoProcessor(com.cloud.storage.template.IsoProcessor) StorageLayer(com.cloud.storage.StorageLayer) 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) OVAProcessor(com.cloud.storage.template.OVAProcessor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) ConfigurationException(javax.naming.ConfigurationException) VmdkProcessor(com.cloud.storage.template.VmdkProcessor) VhdProcessor(com.cloud.storage.template.VhdProcessor) TARProcessor(com.cloud.storage.template.TARProcessor)

Example 2 with VmdkProcessor

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

the class DownloadManagerImpl method gatherTemplateInfo.

@Override
public Map<String, TemplateProp> gatherTemplateInfo(String rootDir) {
    Map<String, TemplateProp> result = new HashMap<String, TemplateProp>();
    String templateDir = rootDir + File.separator + _templateDir;
    if (!_storage.exists(templateDir)) {
        _storage.mkdirs(templateDir);
    }
    List<String> publicTmplts = listTemplates(templateDir);
    for (String tmplt : publicTmplts) {
        String path = tmplt.substring(0, tmplt.lastIndexOf(File.separator));
        TemplateLocation loc = new TemplateLocation(_storage, path);
        try {
            if (!loc.load()) {
                LOGGER.warn("Post download installation was not completed for " + path);
                // loc.purge();
                _storage.cleanup(path, templateDir);
                continue;
            }
        } catch (IOException e) {
            LOGGER.warn("Unable to load template location " + path, e);
            continue;
        }
        TemplateProp tInfo = loc.getTemplateInfo();
        if ((tInfo.getSize() == tInfo.getPhysicalSize()) && (tInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
            try {
                Processor processor = _processors.get("OVA Processor");
                OVAProcessor vmdkProcessor = (OVAProcessor) processor;
                long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.getInstallPath().substring(tInfo.getInstallPath().lastIndexOf(File.separator) + 1));
                tInfo.setSize(vSize);
                loc.updateVirtualSize(vSize);
                loc.save();
            } catch (Exception e) {
                LOGGER.error("Unable to get the virtual size of the template: " + tInfo.getInstallPath() + " due to " + e.getMessage());
            }
        }
        result.put(tInfo.getTemplateName(), tInfo);
        LOGGER.debug("Added template name: " + tInfo.getTemplateName() + ", path: " + tmplt);
    }
    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)

Example 3 with VmdkProcessor

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

the class NfsSecondaryStorageResource method getVirtualSize.

protected long getVirtualSize(File file, ImageFormat format) {
    Processor processor = null;
    try {
        if (format == null) {
            return file.length();
        } else if (format == ImageFormat.QCOW2) {
            processor = new QCOW2Processor();
        } else if (format == ImageFormat.OVA) {
            processor = new OVAProcessor();
        } else if (format == ImageFormat.VHD) {
            processor = new VhdProcessor();
        } else if (format == ImageFormat.RAW) {
            processor = new RawImageProcessor();
        } else if (format == ImageFormat.VMDK) {
            processor = new VmdkProcessor();
        }
        if (format == ImageFormat.TAR) {
            processor = new TARProcessor();
        }
        if (processor == null) {
            return file.length();
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(StorageLayer.InstanceConfigKey, _storage);
        processor.configure("template processor", params);
        return processor.getVirtualSize(file);
    } catch (Exception e) {
        s_logger.warn("Failed to get virtual size of file " + file.getPath() + ", returning file size instead: ", e);
        return file.length();
    }
}
Also used : QCOW2Processor(com.cloud.storage.template.QCOW2Processor) OVAProcessor(com.cloud.storage.template.OVAProcessor) VhdProcessor(com.cloud.storage.template.VhdProcessor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) TARProcessor(com.cloud.storage.template.TARProcessor) Processor(com.cloud.storage.template.Processor) VmdkProcessor(com.cloud.storage.template.VmdkProcessor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) OVAProcessor(com.cloud.storage.template.OVAProcessor) VmdkProcessor(com.cloud.storage.template.VmdkProcessor) HashMap(java.util.HashMap) VhdProcessor(com.cloud.storage.template.VhdProcessor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) TARProcessor(com.cloud.storage.template.TARProcessor) 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)

Example 4 with VmdkProcessor

use of com.cloud.storage.template.VmdkProcessor 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()) {
                LOGGER.warn("Post download installation was not completed for " + path);
                // loc.purge();
                _storage.cleanup(path, volumeDir);
                continue;
            }
        } catch (IOException e) {
            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) {
                LOGGER.error("Unable to get the virtual size of the volume: " + vInfo.getInstallPath() + " due to " + e.getMessage());
            }
        }
        result.put(vInfo.getId(), vInfo);
        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

OVAProcessor (com.cloud.storage.template.OVAProcessor)4 Processor (com.cloud.storage.template.Processor)4 QCOW2Processor (com.cloud.storage.template.QCOW2Processor)4 RawImageProcessor (com.cloud.storage.template.RawImageProcessor)4 TARProcessor (com.cloud.storage.template.TARProcessor)4 VhdProcessor (com.cloud.storage.template.VhdProcessor)4 VmdkProcessor (com.cloud.storage.template.VmdkProcessor)4 ConfigurationException (javax.naming.ConfigurationException)4 InternalErrorException (com.cloud.exception.InternalErrorException)3 IsoProcessor (com.cloud.storage.template.IsoProcessor)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 HashMap (java.util.HashMap)3 TemplateLocation (com.cloud.storage.template.TemplateLocation)2 TemplateProp (com.cloud.storage.template.TemplateProp)2 URISyntaxException (java.net.URISyntaxException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 StorageLayer (com.cloud.storage.StorageLayer)1