Search in sources :

Example 1 with HostsStatistics

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());
}
Also used : JobsStatistics(org.opencastproject.serviceregistry.impl.jmx.JobsStatistics) HostsStatistics(org.opencastproject.serviceregistry.impl.jmx.HostsStatistics) ServicesStatistics(org.opencastproject.serviceregistry.impl.jmx.ServicesStatistics) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) URISyntaxException(java.net.URISyntaxException) NoResultException(javax.persistence.NoResultException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) PersistenceException(javax.persistence.PersistenceException) RollbackException(javax.persistence.RollbackException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceStatistics(org.opencastproject.serviceregistry.api.ServiceStatistics) JaxbServiceStatistics(org.opencastproject.serviceregistry.api.JaxbServiceStatistics) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 NoResultException (javax.persistence.NoResultException)1 PersistenceException (javax.persistence.PersistenceException)1 RollbackException (javax.persistence.RollbackException)1 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)1 JaxbServiceStatistics (org.opencastproject.serviceregistry.api.JaxbServiceStatistics)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)1 ServiceStatistics (org.opencastproject.serviceregistry.api.ServiceStatistics)1 HostsStatistics (org.opencastproject.serviceregistry.impl.jmx.HostsStatistics)1 JobsStatistics (org.opencastproject.serviceregistry.impl.jmx.JobsStatistics)1 ServicesStatistics (org.opencastproject.serviceregistry.impl.jmx.ServicesStatistics)1 NotFoundException (org.opencastproject.util.NotFoundException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1