Search in sources :

Example 1 with FileProperties

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.

the class Ovm3StoragePool method prepareSecondaryStorageStore.

/**
     * Copy the systemvm.iso in if it doesn't exist or the size differs.
     *
     * @param storageUrl
     * @param poolUuid
     * @param host
     */
private void prepareSecondaryStorageStore(String storageUrl, String poolUuid, String host) {
    String mountPoint = storageUrl;
    GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
    try {
        /* double check */
        if (config.getAgentHasMaster() && config.getAgentInOvm3Pool()) {
            LOGGER.debug("Skip systemvm iso copy, leave it to the master");
            return;
        }
        if (lock.lock(3600)) {
            try {
                /*
                     * save src iso real name for reuse, so we don't depend on
                     * other happy little accidents.
                     */
                File srcIso = getSystemVMPatchIsoFile();
                String destPath = mountPoint + "/ISOs/";
                try {
                    StoragePlugin sp = new StoragePlugin(c);
                    FileProperties fp = sp.storagePluginGetFileInfo(poolUuid, host, destPath + "/" + srcIso.getName());
                    if (fp.getSize() != srcIso.getTotalSpace()) {
                        LOGGER.info(" System VM patch ISO file already exists: " + srcIso.getAbsolutePath().toString() + ", destination: " + destPath);
                    }
                } catch (Exception e) {
                    LOGGER.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destPath);
                    try {
                        /* Perhaps use a key instead ? */
                        SshHelper.scpTo(c.getIp(), 22, config.getAgentSshUserName(), null, config.getAgentSshPassword(), destPath, srcIso.getAbsolutePath().toString(), "0644");
                    } catch (Exception es) {
                        LOGGER.error("Unexpected exception ", es);
                        String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destPath;
                        LOGGER.error(msg);
                        throw new CloudRuntimeException(msg, es);
                    }
                }
            } finally {
                lock.unlock();
            }
        }
    } finally {
        lock.releaseRef();
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) File(java.io.File) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 2 with FileProperties

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.

the class Ovm3StorageProcessor method createVolume.

/**
     * Creates a volume, just a normal empty volume.
     */
@Override
public Answer createVolume(CreateObjectCommand cmd) {
    LOGGER.debug("execute createVolume: " + cmd.getClass());
    DataTO data = cmd.getData();
    VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        /*
             * public Boolean storagePluginCreate(String uuid, String ssuuid,
             * String host, String file, Integer size)
             */
        String poolUuid = data.getDataStore().getUuid();
        String storeUrl = data.getDataStore().getUrl();
        URI uri = new URI(storeUrl);
        String host = uri.getHost();
        String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
        Long size = volume.getSize();
        StoragePlugin sp = new StoragePlugin(c);
        FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
        if (!fp.getName().equals(file)) {
            return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
        }
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setName(volume.getName());
        newVol.setSize(fp.getSize());
        newVol.setPath(volume.getUuid());
        return new CreateObjectAnswer(newVol);
    } catch (Ovm3ResourceException | URISyntaxException e) {
        LOGGER.info("Volume creation failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 3 with FileProperties

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.

the class StoragePluginTest method testStorageFileCreation.

@Test
public void testStorageFileCreation() throws Ovm3ResourceException {
    con.setResult(results.simpleResponseWrapWrapper(FILECREATEXML));
    FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false);
    file.getOnDiskSize();
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) Test(org.junit.Test)

Example 4 with FileProperties

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

public CreateAnswer execute(CreateCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    StorageFilerTO primaryStorage = cmd.getPool();
    DiskProfile disk = cmd.getDiskCharacteristics();
    /* disk should have a uuid */
    // should also be replaced with getVirtualDiskPath ?
    String fileName = UUID.randomUUID().toString() + ".raw";
    String dst = primaryStorage.getPath() + "/" + primaryStorage.getUuid() + "/" + fileName;
    try {
        StoragePlugin store = new StoragePlugin(c);
        if (cmd.getTemplateUrl() != null) {
            LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst);
            Linux host = new Linux(c);
            host.copyFile(cmd.getTemplateUrl(), dst);
        } else {
            /* this is a dup with the createVolume ? */
            LOGGER.debug("CreateCommand " + dst);
            store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false);
        }
        FileProperties fp = store.storagePluginGetFileInfo(primaryStorage.getUuid(), primaryStorage.getHost(), dst);
        VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null);
        return new CreateAnswer(cmd, volume);
    } catch (Exception e) {
        LOGGER.debug("CreateCommand failed", e);
        return new CreateAnswer(cmd, e.getMessage());
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) VolumeTO(com.cloud.agent.api.to.VolumeTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) URISyntaxException(java.net.URISyntaxException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 5 with FileProperties

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.

the class StoragePluginTest method testStorageFileCreationFileExistS.

@Test(expected = Ovm3ResourceException.class)
public void testStorageFileCreationFileExistS() throws Ovm3ResourceException {
    con.setResult(results.errorResponseWrap("exceptions OSError:[Errno.17] File exists " + FILE));
    FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false);
    file.getSize();
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) Test(org.junit.Test)

Aggregations

FileProperties (com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties)6 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)3 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)3 Test (org.junit.Test)3 URISyntaxException (java.net.URISyntaxException)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1 DataTO (com.cloud.agent.api.to.DataTO)1 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)1 VolumeTO (com.cloud.agent.api.to.VolumeTO)1 Linux (com.cloud.hypervisor.ovm3.objects.Linux)1 GlobalLock (com.cloud.utils.db.GlobalLock)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DiskProfile (com.cloud.vm.DiskProfile)1 File (java.io.File)1 URI (java.net.URI)1 ConfigurationException (javax.naming.ConfigurationException)1 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)1 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1