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());
}
}
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);
}
}
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.");
}
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade302to40 method addHostDetailsUniqueKey.
private void addHostDetailsUniqueKey(Connection conn) {
s_logger.debug("Checking if host_details unique key exists, if not we will add it");
try (PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'");
ResultSet rs = pstmt.executeQuery()) {
if (rs.next()) {
s_logger.debug("Unique key already exists on host_details - not adding new one");
} else {
//add the key
PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER IGNORE TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)");
pstmtUpdate.executeUpdate();
s_logger.debug("Unique key did not exist on host_details - added new one");
pstmtUpdate.close();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to check/update the host_details unique key ", e);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade302to40 method correctVRProviders.
private void correctVRProviders(Connection conn) {
PreparedStatement pstmtVR = null;
ResultSet rsVR = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmtVR = conn.prepareStatement("SELECT id, nsp_id FROM `cloud`.`virtual_router_providers` where type = 'VirtualRouter' AND removed IS NULL");
rsVR = pstmtVR.executeQuery();
while (rsVR.next()) {
long vrId = rsVR.getLong(1);
long nspId = rsVR.getLong(2);
//check that this nspId points to a VR provider.
pstmt = conn.prepareStatement("SELECT physical_network_id, provider_name FROM `cloud`.`physical_network_service_providers` where id = ?");
pstmt.setLong(1, nspId);
rs = pstmt.executeQuery();
if (rs.next()) {
long physicalNetworkId = rs.getLong(1);
String providerName = rs.getString(2);
if (!providerName.equalsIgnoreCase("VirtualRouter")) {
//mismatch, correct the nsp_id in VR
PreparedStatement pstmt1 = null;
ResultSet rs1 = null;
pstmt1 = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network_service_providers` where physical_network_id = ? AND provider_name = ? AND removed IS NULL");
pstmt1.setLong(1, physicalNetworkId);
pstmt1.setString(2, "VirtualRouter");
rs1 = pstmt1.executeQuery();
if (rs1.next()) {
long correctNSPId = rs1.getLong(1);
//update VR entry
PreparedStatement pstmtUpdate = null;
String updateNSPId = "UPDATE `cloud`.`virtual_router_providers` SET nsp_id = ? WHERE id = ?";
pstmtUpdate = conn.prepareStatement(updateNSPId);
pstmtUpdate.setLong(1, correctNSPId);
pstmtUpdate.setLong(2, vrId);
pstmtUpdate.executeUpdate();
pstmtUpdate.close();
}
rs1.close();
pstmt1.close();
}
}
rs.close();
pstmt.close();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while correcting Virtual Router Entries", e);
} finally {
closeAutoCloseable(rsVR);
closeAutoCloseable(pstmtVR);
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
Aggregations