use of javax.naming.ConfigurationException in project cloudstack by apache.
the class NfsSecondaryStorageResource method copyLocalToNfs.
protected void copyLocalToNfs(File localFile, File isoFile, DataStoreTO destData) throws ConfigurationException, IOException {
String scriptsDir = "scripts/storage/secondary";
String createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
if (createVolScr == null) {
throw new ConfigurationException("Unable to find createvolume.sh");
}
s_logger.info("createvolume.sh found in " + createVolScr);
int installTimeoutPerGig = 180 * 60 * 1000;
int imgSizeGigs = (int) Math.ceil(localFile.length() * 1.0d / (1024 * 1024 * 1024));
// add one just in case
imgSizeGigs++;
long timeout = imgSizeGigs * installTimeoutPerGig;
Script scr = new Script(createVolScr, timeout, s_logger);
scr.add("-s", Integer.toString(imgSizeGigs));
scr.add("-n", isoFile.getName());
scr.add("-t", getRootDir(destData.getUrl(), _nfsVersion) + "/" + isoFile.getParent());
scr.add("-f", localFile.getAbsolutePath());
scr.add("-d", "configDrive");
String result;
result = scr.execute();
if (result != null) {
// script execution failure
throw new CloudRuntimeException("Failed to run script " + createVolScr);
}
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class NfsSecondaryStorageResource method execute.
private Answer execute(HandleConfigDriveIsoCommand cmd) {
if (cmd.isCreate()) {
if (cmd.getIsoData() == null) {
return new HandleConfigDriveIsoAnswer(cmd, "Invalid config drive ISO data");
}
String nfsMountPoint = getRootDir(cmd.getDestStore().getUrl(), _nfsVersion);
File isoFile = new File(nfsMountPoint, cmd.getIsoFile());
if (isoFile.exists()) {
s_logger.debug("config drive iso already exists");
}
Path tempDir = null;
try {
tempDir = java.nio.file.Files.createTempDirectory(ConfigDrive.CONFIGDRIVEDIR);
File tmpIsoFile = ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), tempDir.toAbsolutePath().toString(), cmd.getIsoFile());
copyLocalToNfs(tmpIsoFile, new File(cmd.getIsoFile()), cmd.getDestStore());
} catch (IOException | ConfigurationException e) {
return new HandleConfigDriveIsoAnswer(cmd, "Failed due to exception: " + e.getMessage());
} finally {
try {
if (tempDir != null) {
FileUtils.deleteDirectory(tempDir.toFile());
}
} catch (IOException ioe) {
s_logger.warn("Failed to delete ConfigDrive temporary directory: " + tempDir.toString(), ioe);
}
}
return new HandleConfigDriveIsoAnswer(cmd, NetworkElement.Location.SECONDARY, "Successfully saved config drive at secondary storage");
} else {
DataStoreTO dstore = cmd.getDestStore();
if (dstore instanceof NfsTO) {
NfsTO nfs = (NfsTO) dstore;
String relativeTemplatePath = new File(cmd.getIsoFile()).getPath();
String nfsMountPoint = getRootDir(nfs.getUrl(), _nfsVersion);
File tmpltPath = new File(nfsMountPoint, relativeTemplatePath);
try {
Files.deleteIfExists(tmpltPath.toPath());
} catch (IOException e) {
return new HandleConfigDriveIsoAnswer(cmd, e);
}
return new HandleConfigDriveIsoAnswer(cmd);
} else {
return new HandleConfigDriveIsoAnswer(cmd, "Not implemented yet");
}
}
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.
protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) {
String srcMountPoint = getRootDir(srcDataStore.getUrl(), _nfsVersion);
String snapshotPath = srcData.getPath();
int index = snapshotPath.lastIndexOf("/");
String snapshotName = snapshotPath.substring(index + 1);
if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
snapshotName = snapshotName + ".vhd";
}
snapshotPath = snapshotPath.substring(0, index);
snapshotPath = srcMountPoint + File.separator + snapshotPath;
String destMountPoint = getRootDir(destDataStore.getUrl(), _nfsVersion);
String destPath = destMountPoint + File.separator + destData.getPath();
String errMsg = null;
try {
_storage.mkdir(destPath);
String templateUuid = UUID.randomUUID().toString();
String templateName = templateUuid + ".vhd";
Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
command.add("-p", snapshotPath);
command.add("-s", snapshotName);
command.add("-n", templateName);
command.add("-t", destPath);
String result = command.execute();
if (result != null && !result.equalsIgnoreCase("")) {
return new CopyCmdAnswer(result);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(StorageLayer.InstanceConfigKey, _storage);
Processor processor = new VhdProcessor();
processor.configure("Vhd Processor", params);
FormatInfo info = processor.process(destPath, null, templateUuid);
TemplateLocation loc = new TemplateLocation(_storage, destPath);
loc.create(1, true, templateUuid);
loc.addFormat(info);
loc.save();
TemplateProp prop = loc.getTemplateInfo();
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(destData.getPath() + File.separator + templateName);
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(prop.getSize());
newTemplate.setPhysicalSize(prop.getPhysicalSize());
newTemplate.setName(templateUuid);
return new CopyCmdAnswer(newTemplate);
} catch (ConfigurationException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
} catch (InternalErrorException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
} catch (IOException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
}
return new CopyCmdAnswer(errMsg);
}
use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class AgentShell method parseCommand.
protected boolean parseCommand(final String[] args) throws ConfigurationException {
final Properties commandLineProperties = PropertiesUtil.parse(Arrays.stream(args));
logPropertiesFound(commandLineProperties);
agentProperties.load(commandLineProperties);
allProperties.putAll(convertPropertiesToStringObjectMap(commandLineProperties));
final String guid = agentProperties.getGuid();
if (guid == null && !agentProperties.isDeveloper()) {
throw new ConfigurationException("Unable to find the guid");
}
return true;
}
use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class AgentShell method loadProperties.
public void loadProperties() throws ConfigurationException {
final File file = PropertiesUtil.findConfigFile(FILE_NAME_AGENT_PROPERTIES);
if (null == file) {
throw new ConfigurationException("Unable to find agent.properties.");
}
logger.info("Found {} at {}", FILE_NAME_AGENT_PROPERTIES, file.getAbsolutePath());
final Properties properties = loadPropertiesFromFile(file);
allProperties.putAll(convertPropertiesToStringObjectMap(properties));
agentProperties.load(properties);
}
Aggregations