Search in sources :

Example 31 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 32 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 33 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)

Example 34 with CloudRuntimeException

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

the class LibvirtComputingResource method getDeveloperProperties.

private Map<String, Object> getDeveloperProperties() throws ConfigurationException {
    final File file = PropertiesUtil.findConfigFile("developer.properties");
    if (file == null) {
        throw new ConfigurationException("Unable to find developer.properties.");
    }
    s_logger.info("developer.properties found at " + file.getAbsolutePath());
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream(file));
        String startMac = (String) properties.get("private.macaddr.start");
        if (startMac == null) {
            throw new ConfigurationException("Developers must specify start mac for private ip range");
        }
        String startIp = (String) properties.get("private.ipaddr.start");
        if (startIp == null) {
            throw new ConfigurationException("Developers must specify start ip for private ip range");
        }
        final Map<String, Object> params = PropertiesUtil.toMap(properties);
        String endIp = (String) properties.get("private.ipaddr.end");
        if (endIp == null) {
            endIp = getEndIpFromStartIp(startIp, 16);
            params.put("private.ipaddr.end", endIp);
        }
        return params;
    } catch (final FileNotFoundException ex) {
        throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
    } catch (final IOException ex) {
        throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 35 with CloudRuntimeException

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

the class LibvirtComputingResource method saveProperties.

private void saveProperties(Map<String, Object> params) throws ConfigurationException {
    final File file = PropertiesUtil.findConfigFile("agent.properties");
    if (file == null) {
        throw new ConfigurationException("Unable to find agent.properties.");
    }
    s_logger.info("agent.properties found at " + file.getAbsolutePath());
    try {
        Properties _properties = new Properties();
        _properties.load(new FileInputStream(file));
        Set<String> names = _properties.stringPropertyNames();
        for (String key : params.keySet()) {
            if (!names.contains(key)) {
                _properties.setProperty(key, (String) params.get(key));
            }
        }
        _properties.store(new FileOutputStream(file), "");
    } catch (final FileNotFoundException ex) {
        throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
    } catch (final IOException ex) {
        throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

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