use of javax.naming.ConfigurationException in project cloudstack by apache.
the class ProcessUtil method pidCheck.
// paths cannot be hardcoded
public static void pidCheck(String pidDir, String run) throws ConfigurationException {
String dir = pidDir == null ? "/var/run" : pidDir;
try {
final File propsFile = PropertiesUtil.findConfigFile("environment.properties");
if (propsFile == null) {
s_logger.debug("environment.properties could not be opened");
} else {
final Properties props = PropertiesUtil.loadFromFile(propsFile);
dir = props.getProperty("paths.pid");
if (dir == null) {
dir = pidDir == null ? "/var/run" : pidDir;
}
}
} catch (IOException e) {
s_logger.debug("environment.properties could not be opened");
}
final File pidFile = new File(dir + File.separator + run);
try {
if (!pidFile.createNewFile()) {
if (!pidFile.exists()) {
throw new ConfigurationException("Unable to write to " + pidFile.getAbsolutePath() + ". Are you sure you're running as root?");
}
final String pidLine = FileUtils.readFileToString(pidFile).trim();
if (pidLine.isEmpty()) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
try {
final long pid = Long.parseLong(pidLine);
final Script script = new Script("bash", 120000, s_logger);
script.add("-c", "ps -p " + pid);
final String result = script.execute();
if (result == null) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
if (!pidFile.delete()) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
if (!pidFile.createNewFile()) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
} catch (final NumberFormatException e) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
}
pidFile.deleteOnExit();
final Script script = new Script("bash", 120000, s_logger);
script.add("-c", "echo $PPID");
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
script.execute(parser);
final String pid = parser.getLine();
FileUtils.writeStringToFile(pidFile, pid + "\n");
} catch (final IOException e) {
throw new CloudRuntimeException("Unable to create the " + pidFile.getAbsolutePath() + ". Are you running as root?", e);
}
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class RemoteAccessVpnManagerImplTest method validateHandleExceptionOnValidateIpRangeErrorWhenConfigurationExceptionThrowConfigurationException.
@Test
public void validateHandleExceptionOnValidateIpRangeErrorWhenConfigurationExceptionThrowConfigurationException() {
Class<ConfigurationException> exception = ConfigurationException.class;
String expectedMessage = "Test";
ConfigurationException assertThrows = Assert.assertThrows(expectedMessage, exception, () -> {
new RemoteAccessVpnManagerImpl().handleExceptionOnValidateIpRangeError(exception, expectedMessage);
});
assertEquals(expectedMessage, assertThrows.getMessage());
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class LocalSecondaryStorageResource method configure.
@Override
@SuppressWarnings("unchecked")
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
_guid = (String) params.get("guid");
if (_guid == null) {
throw new ConfigurationException("Unable to find the guid");
}
_dc = (String) params.get("zone");
if (_dc == null) {
throw new ConfigurationException("Unable to find the zone");
}
_pod = (String) params.get("pod");
_instance = (String) params.get("instance");
_parent = (String) params.get("mount.path");
if (_parent == null) {
throw new ConfigurationException("No directory specified.");
}
_storage = (StorageLayer) params.get(StorageLayer.InstanceConfigKey);
if (_storage == null) {
String value = (String) params.get(StorageLayer.ClassConfigKey);
if (value == null) {
value = "com.cloud.storage.JavaStorageLayer";
}
try {
Class<StorageLayer> clazz = (Class<StorageLayer>) Class.forName(value);
_storage = ComponentContext.inject(clazz);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Unable to find class " + value);
}
}
if (!_storage.mkdirs(_parent)) {
s_logger.warn("Unable to create the directory " + _parent);
throw new ConfigurationException("Unable to create the directory " + _parent);
}
s_logger.info("Mount point established at " + _parent);
params.put("template.parent", _parent);
params.put(StorageLayer.InstanceConfigKey, _storage);
_dlMgr = new DownloadManagerImpl();
_dlMgr.configure("DownloadManager", params);
return true;
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class SecondaryStorageDiscoverer method createNfsSecondaryStorageResource.
protected Map<? extends ServerResource, Map<String, String>> createNfsSecondaryStorageResource(long dcId, Long podId, URI uri) {
if (_useServiceVM) {
return createDummySecondaryStorageResource(dcId, podId, uri);
}
String mountStr = NfsUtils.uri2Mount(uri);
Script script = new Script(true, "mount", _timeout, s_logger);
String mntPoint = null;
File file = null;
do {
mntPoint = _mountParent + File.separator + Integer.toHexString(_random.nextInt(Integer.MAX_VALUE));
file = new File(mntPoint);
} while (file.exists());
if (!file.mkdirs()) {
s_logger.warn("Unable to make directory: " + mntPoint);
return null;
}
script.add(mountStr, mntPoint);
String result = script.execute();
if (result != null && !result.contains("already mounted")) {
s_logger.warn("Unable to mount " + uri.toString() + " due to " + result);
file.delete();
return null;
}
script = new Script(true, "umount", 0, s_logger);
script.add(mntPoint);
script.execute();
file.delete();
Map<NfsSecondaryStorageResource, Map<String, String>> srs = new HashMap<NfsSecondaryStorageResource, Map<String, String>>();
NfsSecondaryStorageResource storage;
if (_configDao.isPremium()) {
Class<?> impl;
String name = "com.cloud.storage.resource.PremiumSecondaryStorageResource";
try {
impl = Class.forName(name);
final Constructor<?> constructor = impl.getDeclaredConstructor();
constructor.setAccessible(true);
storage = (NfsSecondaryStorageResource) constructor.newInstance();
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to ClassNotFoundException");
return null;
} catch (final SecurityException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to SecurityException");
return null;
} catch (final NoSuchMethodException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to NoSuchMethodException");
return null;
} catch (final IllegalArgumentException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to IllegalArgumentException");
return null;
} catch (final InstantiationException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to InstantiationException");
return null;
} catch (final IllegalAccessException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to IllegalAccessException");
return null;
} catch (final InvocationTargetException e) {
s_logger.error("Unable to load com.cloud.storage.resource.PremiumSecondaryStorageResource due to InvocationTargetException");
return null;
}
} else {
storage = new NfsSecondaryStorageResource();
}
Map<String, String> details = new HashMap<String, String>();
details.put("mount.path", mountStr);
details.put("orig.url", uri.toString());
details.put("mount.parent", _mountParent);
Map<String, Object> params = new HashMap<String, Object>();
params.putAll(details);
params.put("zone", Long.toString(dcId));
if (podId != null) {
params.put("pod", podId.toString());
}
params.put("guid", uri.toString());
params.put("secondary.storage.vm", "false");
params.put("max.template.iso.size", _configDao.getValue("max.template.iso.size"));
try {
storage.configure("Storage", params);
} catch (ConfigurationException e) {
s_logger.warn("Unable to configure the storage ", e);
return null;
}
srs.put(storage, details);
return srs;
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class DownloadManagerImpl method configure.
@Override
@SuppressWarnings("unchecked")
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
String value = null;
_storage = (StorageLayer) params.get(StorageLayer.InstanceConfigKey);
if (_storage == null) {
value = (String) params.get(StorageLayer.ClassConfigKey);
if (value == null) {
throw new ConfigurationException("Unable to find the storage layer");
}
Class<StorageLayer> clazz;
try {
clazz = (Class<StorageLayer>) Class.forName(value);
_storage = clazz.newInstance();
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Unable to instantiate " + value);
} catch (InstantiationException e) {
throw new ConfigurationException("Unable to instantiate " + value);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Unable to instantiate " + value);
}
}
String inSystemVM = (String) params.get("secondary.storage.vm");
if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
LOGGER.info("DownloadManager: starting additional services since we are inside system vm");
_nfsVersion = NfsSecondaryStorageResource.retrieveNfsVersionFromParams(params);
startAdditionalServices();
blockOutgoingOnPrivate();
}
value = (String) params.get("install.timeout.pergig");
installTimeoutPerGig = NumbersUtil.parseInt(value, 15 * 60) * 1000;
value = (String) params.get("install.numthreads");
final int numInstallThreads = NumbersUtil.parseInt(value, 10);
String scriptsDir = (String) params.get("template.scripts.dir");
if (scriptsDir == null) {
scriptsDir = "scripts/storage/secondary";
}
listTmpltScr = Script.findScript(scriptsDir, "listvmtmplt.sh");
if (listTmpltScr == null) {
throw new ConfigurationException("Unable to find the listvmtmplt.sh");
}
LOGGER.info("listvmtmplt.sh found in " + listTmpltScr);
createTmpltScr = Script.findScript(scriptsDir, "createtmplt.sh");
if (createTmpltScr == null) {
throw new ConfigurationException("Unable to find createtmplt.sh");
}
LOGGER.info("createtmplt.sh found in " + createTmpltScr);
listVolScr = Script.findScript(scriptsDir, "listvolume.sh");
if (listVolScr == null) {
throw new ConfigurationException("Unable to find the listvolume.sh");
}
LOGGER.info("listvolume.sh found in " + listVolScr);
createVolScr = Script.findScript(scriptsDir, "createvolume.sh");
if (createVolScr == null) {
throw new ConfigurationException("Unable to find createvolume.sh");
}
LOGGER.info("createvolume.sh found in " + createVolScr);
_processors = new HashMap<String, Processor>();
Processor processor = new VhdProcessor();
processor.configure("VHD Processor", params);
_processors.put("VHD Processor", processor);
processor = new IsoProcessor();
processor.configure("ISO Processor", params);
_processors.put("ISO Processor", processor);
processor = new QCOW2Processor();
processor.configure("QCOW2 Processor", params);
_processors.put("QCOW2 Processor", processor);
processor = new OVAProcessor();
processor.configure("OVA Processor", params);
_processors.put("OVA Processor", processor);
processor = new VmdkProcessor();
processor.configure("VMDK Processor", params);
_processors.put("VMDK Processor", processor);
processor = new RawImageProcessor();
processor.configure("Raw Image Processor", params);
_processors.put("Raw Image Processor", processor);
processor = new TARProcessor();
processor.configure("TAR Processor", params);
_processors.put("TAR Processor", processor);
_templateDir = (String) params.get("public.templates.root.dir");
if (_templateDir == null) {
_templateDir = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR;
}
_templateDir += File.separator + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR;
_volumeDir = TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + File.separator;
// Add more processors here.
threadPool = Executors.newFixedThreadPool(numInstallThreads);
return true;
}
Aggregations