Search in sources :

Example 1 with LoadMetric

use of org.jboss.modcluster.load.metric.LoadMetric in project wildfly by wildfly.

the class ModClusterSubsystemAdd method performBoottime.

@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceTarget target = context.getServiceTarget();
    final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final ModelNode modelConfig = fullModel.get(ModClusterConfigResourceDefinition.PATH.getKeyValuePair());
    ModClusterConfigurationServiceBuilder configurationBuilder = new ModClusterConfigurationServiceBuilder();
    configurationBuilder.configure(context, modelConfig).build(target).install();
    // Construct LoadBalanceFactorProvider and call pluggable boot time handlers.
    Set<LoadMetric> metrics = new HashSet<>();
    final LoadBalanceFactorProvider loadProvider = getModClusterLoadProvider(metrics, context, modelConfig);
    for (BoottimeHandlerProvider handler : ServiceLoader.load(BoottimeHandlerProvider.class, BoottimeHandlerProvider.class.getClassLoader())) {
        handler.performBoottime(metrics, context, operation, modelConfig);
    }
    final String connector = CONNECTOR.resolveModelAttribute(context, modelConfig).asString();
    final int statusInterval = STATUS_INTERVAL.resolveModelAttribute(context, modelConfig).asInt();
    InjectedValue<ModClusterConfiguration> modClusterConfiguration = new InjectedValue<>();
    ContainerEventHandlerService service = new ContainerEventHandlerService(modClusterConfiguration, loadProvider);
    // Install the main service
    new AsynchronousServiceBuilder<>(ContainerEventHandlerService.SERVICE_NAME, service).build(target).addDependency(configurationBuilder.getServiceName(), ModClusterConfiguration.class, modClusterConfiguration).setInitialMode(Mode.ACTIVE).install();
    // Install services for web container integration
    for (ContainerEventHandlerAdapterBuilder adapterBuilder : ServiceLoader.load(ContainerEventHandlerAdapterBuilder.class, ContainerEventHandlerAdapterBuilder.class.getClassLoader())) {
        adapterBuilder.build(target, connector, statusInterval).setInitialMode(Mode.PASSIVE).install();
    }
}
Also used : ModClusterConfiguration(org.jboss.modcluster.config.ModClusterConfiguration) InjectedValue(org.jboss.msc.value.InjectedValue) ServiceTarget(org.jboss.msc.service.ServiceTarget) LoadBalanceFactorProvider(org.jboss.modcluster.load.LoadBalanceFactorProvider) SimpleLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider) DynamicLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider) LoadMetric(org.jboss.modcluster.load.metric.LoadMetric) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 2 with LoadMetric

use of org.jboss.modcluster.load.metric.LoadMetric in project wildfly by wildfly.

the class ModClusterSubsystemAdd method addLoadMetrics.

private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final OperationContext context) throws OperationFailedException {
    for (Property p : nodes.asPropertyList()) {
        ModelNode node = p.getValue();
        double capacity = CAPACITY.resolveModelAttribute(context, node).asDouble();
        int weight = WEIGHT.resolveModelAttribute(context, node).asInt();
        Map<String, String> propertyMap = PROPERTY.unwrap(context, node);
        Class<? extends LoadMetric> loadMetricClass = null;
        if (node.hasDefined(CommonAttributes.TYPE)) {
            String type = TYPE.resolveModelAttribute(context, node).asString();
            // MODCLUSTER-288 Metric "mem" has been dropped, keep it in the model for versions prior to 8.0
            if (type.equals("mem")) {
                ROOT_LOGGER.unsupportedMetric(type);
                continue;
            }
            LoadMetricEnum metric = LoadMetricEnum.forType(type);
            loadMetricClass = (metric != null) ? metric.getLoadMetricClass() : null;
        } else {
            String className = CustomLoadMetricDefinition.CLASS.resolveModelAttribute(context, node).asString();
            try {
                loadMetricClass = this.getClass().getClassLoader().loadClass(className).asSubclass(LoadMetric.class);
            } catch (ClassNotFoundException e) {
                ROOT_LOGGER.errorAddingMetrics(e);
            }
        }
        if (loadMetricClass != null) {
            try {
                LoadMetric metric = loadMetricClass.newInstance();
                metric.setCapacity(capacity);
                metric.setWeight(weight);
                // Apply Java Bean properties if any are set
                if (propertyMap != null && !propertyMap.isEmpty()) {
                    Properties props = new Properties();
                    props.putAll(propertyMap);
                    try {
                        BeanUtils.mapJavaBeanProperties(metric, props, true);
                    } catch (Exception ex) {
                        ROOT_LOGGER.errorApplyingMetricProperties(ex, loadMetricClass.getCanonicalName());
                        // Do not add this incomplete metric.
                        continue;
                    }
                }
                metrics.add(metric);
            } catch (InstantiationException | IllegalAccessException e) {
                ROOT_LOGGER.errorAddingMetrics(e);
            }
        }
    }
}
Also used : Properties(java.util.Properties) OperationFailedException(org.jboss.as.controller.OperationFailedException) LoadMetric(org.jboss.modcluster.load.metric.LoadMetric) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)2 LoadMetric (org.jboss.modcluster.load.metric.LoadMetric)2 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 Property (org.jboss.dmr.Property)1 ModClusterConfiguration (org.jboss.modcluster.config.ModClusterConfiguration)1 LoadBalanceFactorProvider (org.jboss.modcluster.load.LoadBalanceFactorProvider)1 DynamicLoadBalanceFactorProvider (org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider)1 SimpleLoadBalanceFactorProvider (org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 InjectedValue (org.jboss.msc.value.InjectedValue)1 AsynchronousServiceBuilder (org.wildfly.clustering.service.AsynchronousServiceBuilder)1