Search in sources :

Example 1 with VhdProcessor

use of com.cloud.common.storageprocessor.VhdProcessor in project cosmic by MissionCriticalCloud.

the class DownloadManagerImpl method configure.

@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    this._name = name;
    String value = null;
    this._storage = (StorageLayer) params.get(StorageLayer.InstanceConfigKey);
    if (this._storage == null) {
        value = (String) params.get(StorageLayer.ClassConfigKey);
        if (value == null) {
            throw new ConfigurationException("Unable to find the storage layer");
        }
        final Class<StorageLayer> clazz;
        try {
            clazz = (Class<StorageLayer>) Class.forName(value);
            this._storage = clazz.newInstance();
        } catch (final ClassNotFoundException e) {
            throw new ConfigurationException("Unable to instantiate " + value);
        } catch (final InstantiationException e) {
            throw new ConfigurationException("Unable to instantiate " + value);
        } catch (final IllegalAccessException e) {
            throw new ConfigurationException("Unable to instantiate " + value);
        }
    }
    value = (String) params.get("install.timeout.pergig");
    this.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";
    }
    this.listTmpltScr = Script.findScript(scriptsDir, "listvmtmplt.sh");
    if (this.listTmpltScr == null) {
        throw new ConfigurationException("Unable to find the listvmtmplt.sh");
    }
    s_logger.info("listvmtmplt.sh found in " + this.listTmpltScr);
    this.createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
    if (this.createTmpltScr == null) {
        throw new ConfigurationException("Unable to find createtmplt.sh");
    }
    s_logger.info("createtmplt.sh found in " + this.createTmpltScr);
    this.listVolScr = Script.findScript(scriptsDir, "listvolume.sh");
    if (this.listVolScr == null) {
        throw new ConfigurationException("Unable to find the listvolume.sh");
    }
    s_logger.info("listvolume.sh found in " + this.listVolScr);
    this.createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
    if (this.createVolScr == null) {
        throw new ConfigurationException("Unable to find createvolume.sh");
    }
    s_logger.info("createvolume.sh found in " + this.createVolScr);
    this._processors = new HashMap<>();
    Processor processor = new VhdProcessor();
    processor.configure("VHD Processor", params);
    this._processors.put("VHD Processor", processor);
    processor = new IsoProcessor();
    processor.configure("ISO Processor", params);
    this._processors.put("ISO Processor", processor);
    processor = new QCOW2Processor();
    processor.configure("QCOW2 Processor", params);
    this._processors.put("QCOW2 Processor", processor);
    processor = new RawImageProcessor();
    processor.configure("Raw Image Processor", params);
    this._processors.put("Raw Image Processor", processor);
    processor = new TARProcessor();
    processor.configure("TAR Processor", params);
    this._processors.put("TAR Processor", processor);
    this._templateDir = (String) params.get("public.templates.root.dir");
    if (this._templateDir == null) {
        this._templateDir = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR;
    }
    this._templateDir += File.separator + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR;
    this._volumeDir = TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + File.separator;
    // Add more processors here.
    this.threadPool = Executors.newFixedThreadPool(numInstallThreads);
    return true;
}
Also used : IsoProcessor(com.cloud.common.storageprocessor.IsoProcessor) StorageLayer(com.cloud.utils.storage.StorageLayer) IsoProcessor(com.cloud.common.storageprocessor.IsoProcessor) QCOW2Processor(com.cloud.common.storageprocessor.QCOW2Processor) RawImageProcessor(com.cloud.common.storageprocessor.RawImageProcessor) TARProcessor(com.cloud.common.storageprocessor.TARProcessor) VhdProcessor(com.cloud.common.storageprocessor.VhdProcessor) Processor(com.cloud.common.storageprocessor.Processor) RawImageProcessor(com.cloud.common.storageprocessor.RawImageProcessor) QCOW2Processor(com.cloud.common.storageprocessor.QCOW2Processor) ConfigurationException(javax.naming.ConfigurationException) VhdProcessor(com.cloud.common.storageprocessor.VhdProcessor) TARProcessor(com.cloud.common.storageprocessor.TARProcessor)

Example 2 with VhdProcessor

use of com.cloud.common.storageprocessor.VhdProcessor in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method getVirtualSize.

protected long getVirtualSize(final File file, final ImageFormat format) {
    Processor processor = null;
    try {
        if (format == null) {
            return file.length();
        } else if (format == ImageFormat.QCOW2) {
            processor = new QCOW2Processor();
        } else if (format == ImageFormat.VHD) {
            processor = new VhdProcessor();
        } else if (format == ImageFormat.RAW) {
            processor = new RawImageProcessor();
        }
        if (format == ImageFormat.TAR) {
            processor = new TARProcessor();
        }
        if (processor == null) {
            return file.length();
        }
        final Map<String, Object> params = new HashMap<>();
        params.put(StorageLayer.InstanceConfigKey, this._storage);
        processor.configure("template processor", params);
        return processor.getVirtualSize(file);
    } catch (final 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.common.storageprocessor.QCOW2Processor) VhdProcessor(com.cloud.common.storageprocessor.VhdProcessor) QCOW2Processor(com.cloud.common.storageprocessor.QCOW2Processor) RawImageProcessor(com.cloud.common.storageprocessor.RawImageProcessor) TARProcessor(com.cloud.common.storageprocessor.TARProcessor) Processor(com.cloud.common.storageprocessor.Processor) HashMap(java.util.HashMap) VhdProcessor(com.cloud.common.storageprocessor.VhdProcessor) RawImageProcessor(com.cloud.common.storageprocessor.RawImageProcessor) TARProcessor(com.cloud.common.storageprocessor.TARProcessor) 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 3 with VhdProcessor

use of com.cloud.common.storageprocessor.VhdProcessor in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.

protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(final CopyCommand cmd, final SnapshotObjectTO srcData, final NfsTO srcDataStore, final TemplateObjectTO destData, final NfsTO destDataStore) {
    final String srcMountPoint = getRootDir(srcDataStore.getUrl());
    String snapshotPath = srcData.getPath();
    final int index = snapshotPath.lastIndexOf("/");
    String snapshotName = snapshotPath.substring(index + 1);
    if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
        snapshotName = snapshotName + ".vhd";
    }
    snapshotPath = snapshotPath.substring(0, index);
    snapshotPath = srcMountPoint + File.separator + snapshotPath;
    final String destMountPoint = getRootDir(destDataStore.getUrl());
    final String destPath = destMountPoint + File.separator + destData.getPath();
    String errMsg = null;
    try {
        this._storage.mkdir(destPath);
        final String templateUuid = UUID.randomUUID().toString();
        final String templateName = templateUuid + ".vhd";
        final Script command = new Script(this.createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
        command.add("-p", snapshotPath);
        command.add("-s", snapshotName);
        command.add("-n", templateName);
        command.add("-t", destPath);
        final String result = command.execute();
        if (result != null && !result.equalsIgnoreCase("")) {
            return new CopyCmdAnswer(result);
        }
        final Map<String, Object> params = new HashMap<>();
        params.put(StorageLayer.InstanceConfigKey, this._storage);
        final Processor processor = new VhdProcessor();
        processor.configure("Vhd Processor", params);
        final TemplateFormatInfo info = processor.process(destPath, null, templateUuid);
        final TemplateLocation loc = new TemplateLocation(this._storage, destPath);
        loc.create(1, true, templateUuid);
        loc.addFormat(info);
        loc.save();
        final TemplateProp prop = loc.getTemplateInfo();
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(destData.getPath() + File.separator + templateName);
        newTemplate.setFormat(ImageFormat.VHD);
        newTemplate.setSize(prop.getSize());
        newTemplate.setPhysicalSize(prop.getPhysicalSize());
        newTemplate.setName(templateUuid);
        return new CopyCmdAnswer(newTemplate);
    } catch (final ConfigurationException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    } catch (final InternalErrorException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    } catch (final IOException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    }
    return new CopyCmdAnswer(errMsg);
}
Also used : TemplateProp(com.cloud.legacymodel.storage.TemplateProp) Script(com.cloud.utils.script.Script) VhdProcessor(com.cloud.common.storageprocessor.VhdProcessor) QCOW2Processor(com.cloud.common.storageprocessor.QCOW2Processor) RawImageProcessor(com.cloud.common.storageprocessor.RawImageProcessor) TARProcessor(com.cloud.common.storageprocessor.TARProcessor) Processor(com.cloud.common.storageprocessor.Processor) HashMap(java.util.HashMap) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.common.storageprocessor.TemplateLocation) VhdProcessor(com.cloud.common.storageprocessor.VhdProcessor) TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Aggregations

Processor (com.cloud.common.storageprocessor.Processor)3 QCOW2Processor (com.cloud.common.storageprocessor.QCOW2Processor)3 RawImageProcessor (com.cloud.common.storageprocessor.RawImageProcessor)3 TARProcessor (com.cloud.common.storageprocessor.TARProcessor)3 VhdProcessor (com.cloud.common.storageprocessor.VhdProcessor)3 ConfigurationException (javax.naming.ConfigurationException)3 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 IsoProcessor (com.cloud.common.storageprocessor.IsoProcessor)1 TemplateLocation (com.cloud.common.storageprocessor.TemplateLocation)1 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 TemplateFormatInfo (com.cloud.legacymodel.storage.TemplateFormatInfo)1 TemplateProp (com.cloud.legacymodel.storage.TemplateProp)1 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)1 Script (com.cloud.utils.script.Script)1 StorageLayer (com.cloud.utils.storage.StorageLayer)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1