Search in sources :

Example 1 with LoadBalanceFactorProvider

use of org.jboss.modcluster.load.LoadBalanceFactorProvider 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 LoadBalanceFactorProvider

use of org.jboss.modcluster.load.LoadBalanceFactorProvider in project wildfly by wildfly.

the class ModClusterSubsystemAdd method getModClusterLoadProvider.

private LoadBalanceFactorProvider getModClusterLoadProvider(final Set<LoadMetric> metrics, final OperationContext context, ModelNode model) throws OperationFailedException {
    LoadBalanceFactorProvider load = null;
    if (model.hasDefined(CommonAttributes.SIMPLE_LOAD_PROVIDER_FACTOR)) {
        // TODO it seems we don't support that stuff.
        int value = ModClusterConfigResourceDefinition.SIMPLE_LOAD_PROVIDER.resolveModelAttribute(context, model).asInt(1);
        SimpleLoadBalanceFactorProvider myload = new SimpleLoadBalanceFactorProvider();
        myload.setLoadBalanceFactor(value);
        load = myload;
    }
    if (model.get(DynamicLoadProviderDefinition.PATH.getKeyValuePair()).isDefined()) {
        final ModelNode node = model.get(DynamicLoadProviderDefinition.PATH.getKeyValuePair());
        int decayFactor = DynamicLoadProviderDefinition.DECAY.resolveModelAttribute(context, node).asInt();
        int history = DynamicLoadProviderDefinition.HISTORY.resolveModelAttribute(context, node).asInt();
        if (node.hasDefined(CommonAttributes.LOAD_METRIC)) {
            addLoadMetrics(metrics, node.get(CommonAttributes.LOAD_METRIC), context);
        }
        if (node.hasDefined(CommonAttributes.CUSTOM_LOAD_METRIC)) {
            addLoadMetrics(metrics, node.get(CommonAttributes.CUSTOM_LOAD_METRIC), context);
        }
        if (!metrics.isEmpty()) {
            DynamicLoadBalanceFactorProvider loader = new DynamicLoadBalanceFactorProvider(metrics);
            loader.setDecayFactor(decayFactor);
            loader.setHistory(history);
            load = loader;
        }
    }
    if (load == null) {
        // Use a default one...
        ROOT_LOGGER.useDefaultLoadBalancer();
        SimpleLoadBalanceFactorProvider myload = new SimpleLoadBalanceFactorProvider();
        myload.setLoadBalanceFactor(1);
        load = myload;
    }
    return load;
}
Also used : DynamicLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider) SimpleLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider) LoadBalanceFactorProvider(org.jboss.modcluster.load.LoadBalanceFactorProvider) SimpleLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider) DynamicLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

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