Search in sources :

Example 6 with Processor

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

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandConfigurationException.

@Test
public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    final TemplateFormatInfo info = Mockito.mock(TemplateFormatInfo.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(this.libvirtComputingResource.getStorage()).thenReturn(storage);
    when(this.libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(this.libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenThrow(ConfigurationException.class);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StorageLayer(com.cloud.utils.storage.StorageLayer) Processor(com.cloud.common.storageprocessor.Processor) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.common.storageprocessor.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromSnapshotCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 7 with Processor

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

the class KvmStorageProcessor method createTemplateFromVolume.

@Override
public Answer createTemplateFromVolume(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final int wait = cmd.getWaitInMillSeconds();
    final TemplateObjectTO template = (TemplateObjectTO) destData;
    final DataStoreTO imageStore = template.getDataStore();
    final VolumeObjectTO volume = (VolumeObjectTO) srcData;
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    final NfsTO nfsImageStore = (NfsTO) imageStore;
    KvmStoragePool secondaryStorage = null;
    final KvmStoragePool primary;
    try {
        final String templateFolder = template.getPath();
        secondaryStorage = this.storagePoolMgr.getStoragePoolByUri(nfsImageStore.getUrl());
        primary = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        final KvmPhysicalDisk disk = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volume.getPath());
        final String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateFolder;
        this.storageLayer.mkdirs(tmpltPath);
        final String templateName = UUID.randomUUID().toString();
        if (primary.getType() != StoragePoolType.RBD) {
            final Script command = new Script(this.createTmplPath, wait, this.logger);
            command.add("-f", disk.getPath());
            command.add("-t", tmpltPath);
            command.add("-n", templateName + ".qcow2");
            final String result = command.execute();
            if (result != null) {
                this.logger.debug("failed to create template: " + result);
                return new CopyCmdAnswer(result);
            }
        } else {
            this.logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName);
            final QemuImgFile srcFile = new QemuImgFile(KvmPhysicalDisk.rbdStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), primary.getAuthSecret(), disk.getPath()));
            srcFile.setFormat(PhysicalDiskFormat.RAW);
            final QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + templateName + ".qcow2");
            destFile.setFormat(PhysicalDiskFormat.QCOW2);
            final QemuImg q = new QemuImg(cmd.getWaitInMillSeconds());
            try {
                q.convert(srcFile, destFile);
            } catch (final QemuImgException e) {
                final String message = "Failed to create new template while converting " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage();
                throw new QemuImgException(message);
            }
            final File templateProp = new File(tmpltPath + "/template.properties");
            if (!templateProp.exists()) {
                templateProp.createNewFile();
            }
            String templateContent = "filename=" + templateName + ".qcow2" + System.getProperty("line.separator");
            final DateFormat dateFormat = new SimpleDateFormat("MM_dd_yyyy");
            final Date date = new Date();
            templateContent += "snapshot.name=" + dateFormat.format(date) + System.getProperty("line.separator");
            try (final FileOutputStream templFo = new FileOutputStream(templateProp)) {
                templFo.write(templateContent.getBytes());
                templFo.flush();
            } catch (final IOException e) {
                throw e;
            }
        }
        final Map<String, Object> params = new HashMap<>();
        params.put(StorageLayer.InstanceConfigKey, this.storageLayer);
        final Processor qcow2Processor = new QCOW2Processor();
        qcow2Processor.configure("QCOW2 Processor", params);
        final TemplateFormatInfo info = qcow2Processor.process(tmpltPath, null, templateName);
        final TemplateLocation loc = new TemplateLocation(this.storageLayer, tmpltPath);
        loc.create(1, true, templateName);
        loc.addFormat(info);
        loc.save();
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(templateFolder + File.separator + templateName + ".qcow2");
        newTemplate.setSize(info.virtualSize);
        newTemplate.setPhysicalSize(info.size);
        newTemplate.setFormat(ImageFormat.QCOW2);
        newTemplate.setName(templateName);
        return new CopyCmdAnswer(newTemplate);
    } catch (final QemuImgException e) {
        this.logger.error(e.getMessage());
        return new CopyCmdAnswer(e.toString());
    } catch (final Exception e) {
        this.logger.debug("Failed to createTemplateFromVolume: ", e);
        return new CopyCmdAnswer(e.toString());
    } finally {
        if (secondaryStorage != null) {
            secondaryStorage.delete();
        }
    }
}
Also used : QCOW2Processor(com.cloud.common.storageprocessor.QCOW2Processor) StorageProcessor(com.cloud.common.storageprocessor.resource.StorageProcessor) Processor(com.cloud.common.storageprocessor.Processor) HashMap(java.util.HashMap) DataTO(com.cloud.legacymodel.to.DataTO) TemplateLocation(com.cloud.common.storageprocessor.TemplateLocation) QemuImgException(com.cloud.agent.resource.kvm.storage.utils.QemuImgException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) Script(com.cloud.utils.script.Script) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) IOException(java.io.IOException) NfsTO(com.cloud.legacymodel.to.NfsTO) Date(java.util.Date) LibvirtException(org.libvirt.LibvirtException) QemuImgException(com.cloud.agent.resource.kvm.storage.utils.QemuImgException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) QemuImg(com.cloud.agent.resource.kvm.storage.utils.QemuImg) QCOW2Processor(com.cloud.common.storageprocessor.QCOW2Processor) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) QemuImgFile(com.cloud.agent.resource.kvm.storage.utils.QemuImgFile) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) FileOutputStream(java.io.FileOutputStream) TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO) File(java.io.File) QemuImgFile(com.cloud.agent.resource.kvm.storage.utils.QemuImgFile) SimpleDateFormat(java.text.SimpleDateFormat) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 8 with Processor

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

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandIOException.

@Test
public void testCreatePrivateTemplateFromSnapshotCommandIOException() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    final TemplateFormatInfo info = Mockito.mock(TemplateFormatInfo.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(this.libvirtComputingResource.getStorage()).thenReturn(storage);
    when(this.libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(this.libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenReturn(qcow2Processor);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
        when(location.create(1, true, tmplName)).thenThrow(IOException.class);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } catch (final IOException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StorageLayer(com.cloud.utils.storage.StorageLayer) Processor(com.cloud.common.storageprocessor.Processor) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) IOException(java.io.IOException) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.common.storageprocessor.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromSnapshotCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 9 with Processor

use of com.cloud.common.storageprocessor.Processor 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 10 with Processor

use of com.cloud.common.storageprocessor.Processor 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)

Aggregations

Processor (com.cloud.common.storageprocessor.Processor)13 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)11 TemplateLocation (com.cloud.common.storageprocessor.TemplateLocation)10 ConfigurationException (javax.naming.ConfigurationException)10 TemplateFormatInfo (com.cloud.legacymodel.storage.TemplateFormatInfo)9 QCOW2Processor (com.cloud.common.storageprocessor.QCOW2Processor)8 IOException (java.io.IOException)8 StorageLayer (com.cloud.utils.storage.StorageLayer)7 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)6 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)6 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)6 Script (com.cloud.utils.script.Script)6 RawImageProcessor (com.cloud.common.storageprocessor.RawImageProcessor)5 TARProcessor (com.cloud.common.storageprocessor.TARProcessor)5 VhdProcessor (com.cloud.common.storageprocessor.VhdProcessor)5 HashMap (java.util.HashMap)5 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)4 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)4 Answer (com.cloud.legacymodel.communication.answer.Answer)4