use of javax.naming.ConfigurationException 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 javax.naming.ConfigurationException in project CloudStack-archive by CloudStack-extras.
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 FileInputStream finputstream = new FileInputStream(propsFile);
final Properties props = new Properties();
props.load(finputstream);
finputstream.close();
dir = props.getProperty("paths.pid");
if (dir == null) {
dir = "/var/run";
}
}
} 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 FileInputStream is = new FileInputStream(pidFile);
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
final String pidLine = reader.readLine();
if (pidLine == null) {
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();
final FileOutputStream strm = new FileOutputStream(pidFile);
strm.write((pid + "\n").getBytes());
strm.close();
} 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-archive by CloudStack-extras.
the class UsageManagerImpl method configure.
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
final String run = "usage.vmops.pid";
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking to see if " + run + " exists.");
}
final Class<?> c = UsageServer.class;
m_version = c.getPackage().getImplementationVersion();
if (m_version == null) {
throw new CloudRuntimeException("Unable to find the implementation version of this usage server");
}
if (s_logger.isInfoEnabled()) {
s_logger.info("Implementation Version is " + m_version);
}
m_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
if (configDao == null) {
s_logger.error("Unable to get the configuration dao.");
return false;
}
Map<String, String> configs = configDao.getConfiguration(params);
if (params != null) {
mergeConfigs(configs, params);
}
String execTime = configs.get("usage.stats.job.exec.time");
String aggregationRange = configs.get("usage.stats.job.aggregation.range");
String execTimeZone = configs.get("usage.execution.timezone");
String aggreagationTimeZone = configs.get("usage.aggregation.timezone");
String sanityCheckInterval = configs.get("usage.sanity.check.interval");
if (sanityCheckInterval != null) {
m_sanityCheckInterval = Integer.parseInt(sanityCheckInterval);
}
if (aggreagationTimeZone != null && !aggreagationTimeZone.isEmpty()) {
m_usageTimezone = TimeZone.getTimeZone(aggreagationTimeZone);
}
s_logger.debug("Usage stats aggregation time zone: " + aggreagationTimeZone);
try {
if ((execTime == null) || (aggregationRange == null)) {
s_logger.error("missing configuration values for usage job, usage.stats.job.exec.time = " + execTime + ", usage.stats.job.aggregation.range = " + aggregationRange);
throw new ConfigurationException("Missing configuration values for usage job, usage.stats.job.exec.time = " + execTime + ", usage.stats.job.aggregation.range = " + aggregationRange);
}
String[] execTimeSegments = execTime.split(":");
if (execTimeSegments.length != 2) {
s_logger.error("Unable to parse usage.stats.job.exec.time");
throw new ConfigurationException("Unable to parse usage.stats.job.exec.time '" + execTime + "'");
}
int hourOfDay = Integer.parseInt(execTimeSegments[0]);
int minutes = Integer.parseInt(execTimeSegments[1]);
m_jobExecTime.setTime(new Date());
m_jobExecTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
m_jobExecTime.set(Calendar.MINUTE, minutes);
m_jobExecTime.set(Calendar.SECOND, 0);
m_jobExecTime.set(Calendar.MILLISECOND, 0);
if (execTimeZone != null && !execTimeZone.isEmpty()) {
m_jobExecTime.setTimeZone(TimeZone.getTimeZone(execTimeZone));
}
// if the hour to execute the job has already passed, roll the day forward to the next day
Date execDate = m_jobExecTime.getTime();
if (execDate.before(new Date())) {
m_jobExecTime.roll(Calendar.DAY_OF_YEAR, true);
}
s_logger.debug("Execution Time: " + execDate.toString());
Date currentDate = new Date(System.currentTimeMillis());
s_logger.debug("Current Time: " + currentDate.toString());
m_aggregationDuration = Integer.parseInt(aggregationRange);
if (m_aggregationDuration < USAGE_AGGREGATION_RANGE_MIN) {
s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + USAGE_AGGREGATION_RANGE_MIN);
m_aggregationDuration = USAGE_AGGREGATION_RANGE_MIN;
}
m_hostname = InetAddress.getLocalHost().getHostName() + "/" + InetAddress.getLocalHost().getHostAddress();
} catch (NumberFormatException ex) {
throw new ConfigurationException("Unable to parse usage.stats.job.exec.time '" + execTime + "' or usage.stats.job.aggregation.range '" + aggregationRange + "', please check configuration values");
} catch (Exception e) {
s_logger.error("Unhandled exception configuring UsageManger", e);
throw new ConfigurationException("Unhandled exception configuring UsageManager " + e.toString());
}
m_pid = Integer.parseInt(System.getProperty("pid"));
return true;
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class ClusterManagerImpl method checkConflicts.
private void checkConflicts() throws ConfigurationException {
final Date cutTime = DateUtil.currentGMTTime();
final List<ManagementServerHostVO> peers = _mshostDao.getActiveList(new Date(cutTime.getTime() - HeartbeatThreshold.value()));
for (final ManagementServerHostVO peer : peers) {
final String peerIP = peer.getServiceIP().trim();
if (_clusterNodeIP.equals(peerIP)) {
if ("127.0.0.1".equals(_clusterNodeIP)) {
if (pingManagementNode(peer.getMsid())) {
final String msg = "Detected another management node with localhost IP is already running, please check your cluster configuration";
s_logger.error(msg);
throw new ConfigurationException(msg);
} else {
final String msg = "Detected another management node with localhost IP is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node";
s_logger.info(msg);
}
} else {
if (pingManagementNode(peer.getMsid())) {
final String msg = "Detected that another management node with the same IP " + peer.getServiceIP() + " is already running, please check your cluster configuration";
s_logger.error(msg);
throw new ConfigurationException(msg);
} else {
final String msg = "Detected that another management node with the same IP " + peer.getServiceIP() + " is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node";
s_logger.info(msg);
}
}
}
}
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class ClusterManagerImpl method configure.
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
if (s_logger.isInfoEnabled()) {
s_logger.info("Start configuring cluster manager : " + name);
}
final Properties dbProps = DbProperties.getDbProperties();
_clusterNodeIP = dbProps.getProperty("cluster.node.IP");
if (_clusterNodeIP == null) {
_clusterNodeIP = "127.0.0.1";
}
_clusterNodeIP = _clusterNodeIP.trim();
if (s_logger.isInfoEnabled()) {
s_logger.info("Cluster node IP : " + _clusterNodeIP);
}
if (!NetUtils.isLocalAddress(_clusterNodeIP)) {
throw new ConfigurationException("cluster node IP should be valid local address where the server is running, please check your configuration");
}
for (int i = 0; i < DEFAULT_OUTGOING_WORKERS; i++) {
_executor.execute(getClusterPduSendingTask());
}
// notification task itself in turn works as a task dispatcher
_executor.execute(getClusterPduNotificationTask());
if (_serviceAdapters == null) {
throw new ConfigurationException("Unable to get cluster service adapters");
}
_currentServiceAdapter = _serviceAdapters.get(0);
if (_currentServiceAdapter == null) {
throw new ConfigurationException("Unable to set current cluster service adapter");
}
checkConflicts();
if (s_logger.isInfoEnabled()) {
s_logger.info("Cluster manager is configured.");
}
return true;
}
Aggregations