use of org.opencastproject.serviceregistry.impl.jmx.HostsStatistics in project opencast by opencast.
the class ServiceRegistryJpaImpl method activate.
public void activate(ComponentContext cc) {
logger.info("Activate service registry");
// Find this host's url
if (cc == null || StringUtils.isBlank(cc.getBundleContext().getProperty(OpencastConstants.SERVER_URL_PROPERTY))) {
hostName = UrlSupport.DEFAULT_BASE_URL;
} else {
hostName = cc.getBundleContext().getProperty(OpencastConstants.SERVER_URL_PROPERTY);
}
// Check hostname for sanity. It should be the hosts URL with protocol but without any part of the service paths.
if (hostName.endsWith("/")) {
logger.warn("The configured value of {} ends with '/'. This is very likely a configuration error which could " + "lead to services not working properly. Note that this configuration should not contain any part of " + "the service paths.", OpencastConstants.SERVER_URL_PROPERTY);
}
// Clean all undispatchable jobs that were orphaned when this host was last deactivated
cleanUndispatchableJobs(hostName);
// Register JMX beans with statistics
try {
List<ServiceStatistics> serviceStatistics = getServiceStatistics();
hostsStatistics = new HostsStatistics(serviceStatistics);
servicesStatistics = new ServicesStatistics(hostName, serviceStatistics);
jobsStatistics = new JobsStatistics(hostName);
jmxBeans.add(JmxUtil.registerMXBean(hostsStatistics, JMX_HOSTS_STATISTICS_TYPE));
jmxBeans.add(JmxUtil.registerMXBean(servicesStatistics, JMX_SERVICES_STATISTICS_TYPE));
jmxBeans.add(JmxUtil.registerMXBean(jobsStatistics, JMX_JOBS_STATISTICS_TYPE));
} catch (ServiceRegistryException e) {
logger.error("Error registering JMX statistic beans", e);
}
// Find the jobs URL
if (cc == null || StringUtils.isBlank(cc.getBundleContext().getProperty("org.opencastproject.jobs.url"))) {
jobHost = hostName;
} else {
jobHost = cc.getBundleContext().getProperty("org.opencastproject.jobs.url");
}
// Register this host
try {
float maxLoad = Runtime.getRuntime().availableProcessors();
if (cc != null && StringUtils.isNotBlank(cc.getBundleContext().getProperty(OPT_MAXLOAD))) {
try {
maxLoad = Float.parseFloat(cc.getBundleContext().getProperty(OPT_MAXLOAD));
logger.info("Max load has been manually to {}", maxLoad);
} catch (NumberFormatException e) {
logger.warn("Configuration key '{}' is not an integer. Falling back to the number of cores ({})", OPT_MAXLOAD, maxLoad);
}
}
logger.info("Node maximum load set to {}", maxLoad);
String address = InetAddress.getByName(URI.create(hostName).getHost()).getHostAddress();
long maxMemory = Runtime.getRuntime().maxMemory();
int cores = Runtime.getRuntime().availableProcessors();
registerHost(hostName, address, maxMemory, cores, maxLoad);
} catch (Exception e) {
throw new IllegalStateException("Unable to register host " + hostName + " in the service registry", e);
}
// Track any services from this host that need to be added to the service registry
if (cc != null) {
try {
tracker = new RestServiceTracker(cc.getBundleContext());
tracker.open(true);
} catch (InvalidSyntaxException e) {
logger.error("Invalid filter syntax:", e);
throw new IllegalStateException(e);
}
}
// Whether a service accepts a job whose load exceeds the host’s max load
if (cc != null) {
acceptJobLoadsExeedingMaxLoad = getOptContextProperty(cc, ACCEPT_JOB_LOADS_EXCEEDING_PROPERTY).map(Strings.toBool).getOrElse(DEFAULT_ACCEPT_JOB_LOADS_EXCEEDING);
}
systemLoad = getHostLoads(emf.createEntityManager());
}
Aggregations