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);
}
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());
}
}
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();
}
}
}
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);
}
}
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);
}
}
Aggregations