use of com.cloud.utils.component.ComponentLocator 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 com.cloud.utils.component.ComponentLocator in project CloudStack-archive by CloudStack-extras.
the class CheckPointManagerTest method testCompleteCase.
public void testCompleteCase() throws Exception {
ComponentLocator locator = ComponentLocator.getCurrentLocator();
CheckPointManagerImpl taskMgr = ComponentLocator.inject(CheckPointManagerImpl.class);
assertTrue(taskMgr.configure("TaskManager", new HashMap<String, Object>()));
assertTrue(taskMgr.start());
MockMaid delegate = new MockMaid();
delegate.setValue("first");
long taskId = taskMgr.pushCheckPoint(delegate);
StackMaidDao maidDao = locator.getDao(StackMaidDao.class);
CheckPointVO task = maidDao.findById(taskId);
assertEquals(task.getDelegate(), MockMaid.class.getName());
MockMaid retrieved = (MockMaid) SerializerHelper.fromSerializedString(task.getContext());
assertEquals(retrieved.getValue(), delegate.getValue());
delegate.setValue("second");
taskMgr.updateCheckPointState(taskId, delegate);
task = maidDao.findById(taskId);
assertEquals(task.getDelegate(), MockMaid.class.getName());
retrieved = (MockMaid) SerializerHelper.fromSerializedString(task.getContext());
assertEquals(retrieved.getValue(), delegate.getValue());
taskMgr.popCheckPoint(taskId);
assertNull(maidDao.findById(taskId));
}
use of com.cloud.utils.component.ComponentLocator in project CloudStack-archive by CloudStack-extras.
the class UsageAlertManagerImpl method configure.
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_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("management-server", params);
// set up the email system for alerts
String emailAddressList = configs.get("alert.email.addresses");
String[] emailAddresses = null;
if (emailAddressList != null) {
emailAddresses = emailAddressList.split(",");
}
String smtpHost = configs.get("alert.smtp.host");
int smtpPort = NumbersUtil.parseInt(configs.get("alert.smtp.port"), 25);
String useAuthStr = configs.get("alert.smtp.useAuth");
boolean useAuth = ((useAuthStr == null) ? false : Boolean.parseBoolean(useAuthStr));
String smtpUsername = configs.get("alert.smtp.username");
String smtpPassword = configs.get("alert.smtp.password");
String emailSender = configs.get("alert.email.sender");
String smtpDebugStr = configs.get("alert.smtp.debug");
boolean smtpDebug = false;
if (smtpDebugStr != null) {
smtpDebug = Boolean.parseBoolean(smtpDebugStr);
}
_emailAlert = new EmailAlert(emailAddresses, smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpDebug);
_alertDao = locator.getDao(AlertDao.class);
if (_alertDao == null) {
s_logger.error("Unable to get the alert dao.");
return false;
}
return true;
}
use of com.cloud.utils.component.ComponentLocator in project CloudStack-archive by CloudStack-extras.
the class UsageServer method main.
/**
* @param args
*/
public static void main(String[] args) {
// TODO: do we need to communicate with mgmt server?
final ComponentLocator _locator = ComponentLocator.getLocator(UsageServer.Name, "usage-components.xml", "log4j-cloud_usage");
UsageManager mgr = _locator.getManager(UsageManager.class);
if (mgr != null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("UsageServer ready...");
}
}
}
use of com.cloud.utils.component.ComponentLocator in project CloudStack-archive by CloudStack-extras.
the class AgentShell method init.
private void init(String[] args) throws ConfigurationException {
final ComponentLocator locator = ComponentLocator.getLocator("agent");
final Class<?> c = this.getClass();
_version = c.getPackage().getImplementationVersion();
if (_version == null) {
throw new CloudRuntimeException("Unable to find the implementation version of this agent");
}
s_logger.info("Implementation Version is " + _version);
parseCommand(args);
_storage = locator.getManager(StorageComponent.class);
if (_storage == null) {
s_logger.info("Defaulting to using properties file for storage");
_storage = new PropertiesStorage();
_storage.configure("Storage", new HashMap<String, Object>());
}
// command line parameters
for (Map.Entry<String, Object> cmdLineProp : getCmdLineProperties().entrySet()) {
_properties.put(cmdLineProp.getKey(), cmdLineProp.getValue());
}
final Adapters adapters = locator.getAdapters(BackoffAlgorithm.class);
final Enumeration en = adapters.enumeration();
while (en.hasMoreElements()) {
_backoff = (BackoffAlgorithm) en.nextElement();
break;
}
if (en.hasMoreElements()) {
s_logger.info("More than one backoff algorithm specified. Using the first one ");
}
if (_backoff == null) {
s_logger.info("Defaulting to the constant time backoff algorithm");
_backoff = new ConstantTimeBackoff();
_backoff.configure("ConstantTimeBackoff", new HashMap<String, Object>());
}
}
Aggregations