Search in sources :

Example 11 with CloudRuntimeException

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

the class LibvirtStorageAdaptor method deletePhysicalDisk.

@Override
public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    try {
        StorageVol vol = this.getVolume(libvirtPool.getPool(), uuid);
        vol.delete(0);
        vol.free();
        return true;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 12 with CloudRuntimeException

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

the class FakeComputingResource method getSimulatorProperties.

private Map<String, Object> getSimulatorProperties() throws ConfigurationException {
    final File file = PropertiesUtil.findConfigFile("simulator.properties");
    if (file == null) {
        throw new ConfigurationException("Unable to find simulator.properties.");
    }
    s_logger.info("simulator.properties found at " + file.getAbsolutePath());
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream(file));
        final Map<String, Object> params = PropertiesUtil.toMap(properties);
        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 13 with CloudRuntimeException

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

the class LibvirtStorageAdaptor method listPhysicalDisks.

@Override
public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
    try {
        String[] vols = virtPool.listVolumes();
        for (String volName : vols) {
            KVMPhysicalDisk disk = this.getPhysicalDisk(volName, pool);
            disks.add(disk);
        }
        return disks;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList)

Example 14 with CloudRuntimeException

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

the class AgentShell method loadProperties.

private void loadProperties() 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.load(new FileInputStream(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) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 15 with CloudRuntimeException

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

the class HypervisorHostHelper method createPortProfile.

public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vlanId, Integer networkRateMbps, long peakBandwidth, long burstSize) throws Exception {
    Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
    String vsmIp = vsmCredentials.get("vsmip");
    String vsmUserName = vsmCredentials.get("vsmusername");
    String vsmPassword = vsmCredentials.get("vsmpassword");
    String msg;
    NetconfHelper netconfClient;
    try {
        s_logger.info("Connecting to Nexus 1000v: " + vsmIp);
        netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
        s_logger.info("Successfully connected to Nexus 1000v : " + vsmIp);
    } catch (CloudRuntimeException e) {
        msg = "Failed to connect to Nexus 1000v " + vsmIp + " with credentials of user " + vsmUserName + ". Exception: " + e.toString();
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    String policyName = s_policyNamePrefix;
    int averageBandwidth = 0;
    if (networkRateMbps != null) {
        averageBandwidth = networkRateMbps.intValue();
        policyName += averageBandwidth;
    }
    try {
        // PolicyMap to long.
        if (averageBandwidth > 0) {
            s_logger.debug("Adding policy map " + policyName);
            netconfClient.addPolicyMap(policyName, averageBandwidth, (int) peakBandwidth, (int) burstSize);
        }
    } catch (CloudRuntimeException e) {
        msg = "Failed to add policy map of " + policyName + " with parameters " + "committed rate = " + averageBandwidth + "peak bandwidth = " + peakBandwidth + "burst size = " + burstSize + ". Exception: " + e.toString();
        s_logger.error(msg);
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        throw new CloudRuntimeException(msg);
    }
    List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
    if (vlanId != null) {
        // No need to update ethernet port profile for untagged vlans
        params.add(new Pair<OperationType, String>(OperationType.addvlanid, vlanId.toString()));
        try {
            s_logger.info("Updating Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId);
            netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params);
            s_logger.info("Added " + vlanId + " to Ethernet port profile " + ethPortProfileName);
        } catch (CloudRuntimeException e) {
            msg = "Failed to update Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId + ". Exception: " + e.toString();
            s_logger.error(msg);
            if (netconfClient != null) {
                netconfClient.disconnect();
                s_logger.debug("Disconnected Nexus 1000v session.");
            }
            throw new CloudRuntimeException(msg);
        }
    }
    try {
        if (vlanId == null) {
            s_logger.info("Adding port profile configured over untagged VLAN.");
            netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, 0);
        } else {
            s_logger.info("Adding port profile configured over VLAN : " + vlanId.toString());
            netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vlanId.intValue());
        }
    } catch (CloudRuntimeException e) {
        msg = "Failed to add vEthernet port profile " + networkName + "." + ". Exception: " + e.toString();
        s_logger.error(msg);
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        throw new CloudRuntimeException(msg);
    }
    try {
        if (averageBandwidth > 0) {
            s_logger.info("Associating policy map " + policyName + " with port profile " + networkName + ".");
            netconfClient.attachServicePolicy(policyName, networkName);
        }
    } catch (CloudRuntimeException e) {
        msg = "Failed to associate policy map " + policyName + " with port profile " + networkName + ". Exception: " + e.toString();
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    } finally {
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) OperationType(com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType) NetconfHelper(com.cloud.utils.cisco.n1kv.vsm.NetconfHelper) Pair(com.cloud.utils.Pair)

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