Search in sources :

Example 1 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected CreatePrivateTemplateAnswer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
    String secondaryStorageURL = cmd.getSecondaryStorageUrl();
    KVMStoragePool secondaryStorage = null;
    try {
        Connect conn = LibvirtConnection.getConnection();
        String templateFolder = cmd.getAccountId() + File.separator + cmd.getTemplateId() + File.separator;
        String templateInstallFolder = "/template/tmpl/" + templateFolder;
        secondaryStorage = _storagePoolMgr.getStoragePoolByURI(secondaryStorageURL);
        KVMStoragePool primary = _storagePoolMgr.getStoragePool(cmd.getPrimaryStoragePoolNameLabel());
        KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
        String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateInstallFolder;
        _storage.mkdirs(tmpltPath);
        Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
        command.add("-f", disk.getPath());
        command.add("-t", tmpltPath);
        command.add("-n", cmd.getUniqueName() + ".qcow2");
        String result = command.execute();
        if (result != null) {
            s_logger.debug("failed to create template: " + result);
            return new CreatePrivateTemplateAnswer(cmd, false, result);
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(StorageLayer.InstanceConfigKey, _storage);
        Processor qcow2Processor = new QCOW2Processor();
        qcow2Processor.configure("QCOW2 Processor", params);
        FormatInfo info = qcow2Processor.process(tmpltPath, null, cmd.getUniqueName());
        TemplateLocation loc = new TemplateLocation(_storage, tmpltPath);
        loc.create(1, true, cmd.getUniqueName());
        loc.addFormat(info);
        loc.save();
        return new CreatePrivateTemplateAnswer(cmd, true, null, templateInstallFolder + cmd.getUniqueName() + ".qcow2", info.virtualSize, info.size, cmd.getUniqueName(), ImageFormat.QCOW2);
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get secondary storage pool: " + e.toString());
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (InternalErrorException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (IOException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (ConfigurationException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (CloudRuntimeException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } finally {
        if (secondaryStorage != null) {
            secondaryStorage.delete();
        }
    }
}
Also used : Script(com.cloud.utils.script.Script) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) Processor(com.cloud.storage.template.Processor) LibvirtException(org.libvirt.LibvirtException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) FormatInfo(com.cloud.storage.template.Processor.FormatInfo)

Example 2 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected Answer execute(CreateCommand cmd) {
    StorageFilerTO pool = cmd.getPool();
    DiskProfile dskch = cmd.getDiskCharacteristics();
    KVMPhysicalDisk BaseVol = null;
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    long disksize;
    try {
        primaryPool = _storagePoolMgr.getStoragePool(pool.getUuid());
        if (cmd.getTemplateUrl() != null) {
            BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
            vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), primaryPool);
            if (vol == null) {
                return new Answer(cmd, false, " Can't create storage volume on storage pool");
            }
            disksize = vol.getSize();
        } else {
            disksize = dskch.getSize();
            vol = primaryPool.createPhysicalDisk(UUID.randomUUID().toString(), dskch.getSize());
        }
        VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null);
        return new CreateAnswer(cmd, volume);
    } catch (CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: " + e.toString());
        return new CreateAnswer(cmd, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 3 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected Answer execute(DeleteSnapshotsDirCommand cmd) {
    Long dcId = cmd.getDcId();
    Long accountId = cmd.getAccountId();
    Long volumeId = cmd.getVolumeId();
    KVMStoragePool secondaryStoragePool = null;
    try {
        secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(cmd.getSecondaryStorageUrl());
        String ssPmountPath = secondaryStoragePool.getLocalPath();
        String snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId;
        final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
        command.add("-d", snapshotDestPath);
        command.add("-f");
        command.execute();
    } catch (CloudRuntimeException e) {
        return new Answer(cmd, false, e.toString());
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
    return new Answer(cmd, true, null);
}
Also used : Script(com.cloud.utils.script.Script) FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 4 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

public Answer execute(DestroyCommand cmd) {
    VolumeTO vol = cmd.getVolume();
    try {
        KVMStoragePool pool = _storagePoolMgr.getStoragePool(vol.getPoolUuid());
        pool.deletePhysicalDisk(vol.getPath());
        return new Answer(cmd, true, "Success");
    } catch (CloudRuntimeException e) {
        s_logger.debug("Failed to delete volume: " + e.toString());
        return new Answer(cmd, false, e.toString());
    }
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
    boolean copyToSecondary = cmd.toSecondaryStorage();
    String volumePath = cmd.getVolumePath();
    StorageFilerTO pool = cmd.getPool();
    String secondaryStorageUrl = cmd.getSecondaryStorageURL();
    KVMStoragePool secondaryStoragePool = null;
    try {
        KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(pool.getUuid());
        String volumeName = UUID.randomUUID().toString();
        if (copyToSecondary) {
            String destVolumeName = volumeName + ".qcow2";
            KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd.getVolumePath());
            String volumeDestPath = "/volumes/" + cmd.getVolumeId() + File.separator;
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
            secondaryStoragePool.createFolder(volumeDestPath);
            secondaryStoragePool.delete();
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumeDestPath);
            _storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, secondaryStoragePool);
            return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
        } else {
            volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumePath);
            KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
            _storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool);
            return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
        }
    } catch (CloudRuntimeException e) {
        return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1279 PreparedStatement (java.sql.PreparedStatement)320 SQLException (java.sql.SQLException)320 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)236 ResultSet (java.sql.ResultSet)217 ArrayList (java.util.ArrayList)217 ConfigurationException (javax.naming.ConfigurationException)171 HashMap (java.util.HashMap)129 DB (com.cloud.utils.db.DB)118 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)115 IOException (java.io.IOException)95 HostVO (com.cloud.host.HostVO)94 Answer (com.cloud.agent.api.Answer)84 Account (com.cloud.user.Account)84 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)82 URISyntaxException (java.net.URISyntaxException)82 ActionEvent (com.cloud.event.ActionEvent)70 TransactionStatus (com.cloud.utils.db.TransactionStatus)65 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)63 InternalErrorException (com.cloud.exception.InternalErrorException)57