Search in sources :

Example 1 with ServiceSupplierDependency

use of org.wildfly.clustering.service.ServiceSupplierDependency in project wildfly by wildfly.

the class RemoteCacheContainerConfigurationServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.connectionTimeout = Attribute.CONNECTION_TIMEOUT.resolveModelAttribute(context, model).asInt();
    this.defaultRemoteCluster = Attribute.DEFAULT_REMOTE_CLUSTER.resolveModelAttribute(context, model).asString();
    this.maxRetries = Attribute.MAX_RETRIES.resolveModelAttribute(context, model).asInt();
    this.protocolVersion = Attribute.PROTOCOL_VERSION.resolveModelAttribute(context, model).asString();
    this.socketTimeout = Attribute.SOCKET_TIMEOUT.resolveModelAttribute(context, model).asInt();
    this.tcpNoDelay = Attribute.TCP_NO_DELAY.resolveModelAttribute(context, model).asBoolean();
    this.tcpKeepAlive = Attribute.TCP_KEEP_ALIVE.resolveModelAttribute(context, model).asBoolean();
    this.statisticsEnabled = Attribute.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    this.transactionTimeout = Attribute.TRANSACTION_TIMEOUT.resolveModelAttribute(context, model).asLong();
    this.marshallerFactory = HotRodMarshallerFactory.valueOf(Attribute.MARSHALLER.resolveModelAttribute(context, model).asString());
    this.clusters.clear();
    Resource container = context.readResource(PathAddress.EMPTY_ADDRESS);
    for (Resource.ResourceEntry entry : container.getChildren(RemoteClusterResourceDefinition.WILDCARD_PATH.getKey())) {
        String clusterName = entry.getName();
        ModelNode cluster = entry.getModel();
        List<String> bindings = StringListAttributeDefinition.unwrapValue(context, RemoteClusterResourceDefinition.Attribute.SOCKET_BINDINGS.resolveModelAttribute(context, cluster));
        List<SupplierDependency<OutboundSocketBinding>> bindingDependencies = new ArrayList<>(bindings.size());
        for (String binding : bindings) {
            bindingDependencies.add(new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, binding)));
        }
        this.clusters.put(clusterName, bindingDependencies);
    }
    this.server = context.hasOptionalCapability(CommonRequirement.MBEAN_SERVER.getName(), null, null) ? new ServiceSupplierDependency<>(CommonRequirement.MBEAN_SERVER.getServiceName(context)) : null;
    this.properties.clear();
    for (Property property : Attribute.PROPERTIES.resolveModelAttribute(context, model).asPropertyListOrEmpty()) {
        this.properties.setProperty(property.getName(), property.getValue().asString());
    }
    return this;
}
Also used : Resource(org.jboss.as.controller.registry.Resource) ArrayList(java.util.ArrayList) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) ModelNode(org.jboss.dmr.ModelNode) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) Property(org.jboss.dmr.Property)

Example 2 with ServiceSupplierDependency

use of org.wildfly.clustering.service.ServiceSupplierDependency in project wildfly by wildfly.

the class CacheDependenciesProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) {
    DeploymentUnit unit = context.getDeploymentUnit();
    final ServiceName name = unit.getServiceName();
    EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
    final ServiceTarget target = context.getServiceTarget();
    Set<SupplierDependency<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>>> dependencies = new HashSet<>();
    for (ComponentDescription description : moduleDescription.getComponentDescriptions()) {
        if (description instanceof StatefulComponentDescription) {
            StatefulComponentDescription statefulDescription = (StatefulComponentDescription) description;
            dependencies.add(new ServiceSupplierDependency<>(getCacheFactoryBuilderServiceName(statefulDescription)));
        }
    }
    Service service = new ChildTargetService(new Consumer<ServiceTarget>() {

        @Override
        public void accept(ServiceTarget target) {
            // Cache factory builder dependencies might still contain duplicates (if referenced via alias), so ensure we collect only distinct instances.
            Set<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> builders = new HashSet<>(dependencies.size());
            for (Supplier<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> dependency : dependencies) {
                builders.add(dependency.get());
            }
            for (CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance> builder : builders) {
                for (CapabilityServiceConfigurator configurator : builder.getDeploymentServiceConfigurators(unit)) {
                    configurator.configure(support).build(target).install();
                }
            }
        }
    });
    ServiceBuilder<?> builder = target.addService(name.append("cache-dependencies-installer"));
    for (Dependency dependency : dependencies) {
        dependency.register(builder);
    }
    builder.setInstance(service).install();
    // Install versioned marshalling configuration
    new MarshallingConfigurationRepositoryServiceConfigurator(unit).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
Also used : StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashSet(java.util.HashSet) Set(java.util.Set) StatefulSessionComponentInstance(org.jboss.as.ejb3.component.stateful.StatefulSessionComponentInstance) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) CacheFactoryBuilder(org.jboss.as.ejb3.cache.CacheFactoryBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) ServiceTarget(org.jboss.msc.service.ServiceTarget) MarshallingConfigurationRepositoryServiceConfigurator(org.jboss.as.ejb3.component.stateful.MarshallingConfigurationRepositoryServiceConfigurator) Service(org.jboss.msc.Service) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) Dependency(org.wildfly.clustering.service.Dependency) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionID(org.jboss.ejb.client.SessionID)

Example 3 with ServiceSupplierDependency

use of org.wildfly.clustering.service.ServiceSupplierDependency in project wildfly by wildfly.

the class DistributableSingleSignOnManagerServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context) {
    String securityDomainName = this.configuration.getSecurityDomainName();
    Supplier<String> generator = this.configuration.getIdentifierGenerator();
    CapabilityServiceSupport support = context.getCapabilityServiceSupport();
    SupplierDependency<DistributableSSOManagementProvider> provider = getProvider(context, securityDomainName);
    ServiceName managerServiceName = this.getServiceName().append("manager");
    this.manager = new ServiceSupplierDependency<>(managerServiceName);
    this.provider = provider;
    this.installer = new Consumer<ServiceTarget>() {

        @Override
        public void accept(ServiceTarget target) {
            ServiceConfigurator factoryConfigurator = provider.get().getServiceConfigurator(securityDomainName).configure(support);
            factoryConfigurator.build(target).install();
            SupplierDependency<SSOManagerFactory<ElytronAuthentication, String, Map.Entry<String, URI>, Batch>> factoryDependency = new ServiceSupplierDependency<>(factoryConfigurator);
            SupplierDependency<SessionIdGenerator> generatorDependency = new SimpleSupplierDependency<>(new SessionIdGeneratorAdapter(generator));
            new SSOManagerServiceConfigurator<>(managerServiceName, factoryDependency, generatorDependency, new LocalSSOContextFactory()).configure(support).build(target).install();
        }
    };
    return this;
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) SimpleSupplierDependency(org.wildfly.clustering.service.SimpleSupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) SSOManagerServiceConfigurator(org.wildfly.clustering.web.undertow.sso.SSOManagerServiceConfigurator) DistributableSSOManagementProvider(org.wildfly.clustering.web.sso.DistributableSSOManagementProvider) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) Entry(java.util.Map.Entry) ServiceName(org.jboss.msc.service.ServiceName) Batch(org.wildfly.clustering.ee.Batch) ServiceConfigurator(org.wildfly.clustering.service.ServiceConfigurator) SSOManagerServiceConfigurator(org.wildfly.clustering.web.undertow.sso.SSOManagerServiceConfigurator) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator)

Example 4 with ServiceSupplierDependency

use of org.wildfly.clustering.service.ServiceSupplierDependency in project wildfly by wildfly.

the class ProxyConfigurationServiceConfigurator method configure.

@SuppressWarnings("deprecation")
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    // Advertise
    String advertiseSocket = ADVERTISE_SOCKET.resolveModelAttribute(context, model).asStringOrNull();
    this.advertiseSocketDependency = (advertiseSocket != null) ? new ServiceSupplierDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, advertiseSocket)) : null;
    this.builder.advertise().setAdvertiseSecurityKey(ADVERTISE_SECURITY_KEY.resolveModelAttribute(context, model).asStringOrNull());
    // MCMP
    builder.mcmp().setAdvertise(ADVERTISE.resolveModelAttribute(context, model).asBoolean()).setProxyURL(PROXY_URL.resolveModelAttribute(context, model).asString()).setAutoEnableContexts(AUTO_ENABLE_CONTEXTS.resolveModelAttribute(context, model).asBoolean()).setStopContextTimeout(STOP_CONTEXT_TIMEOUT.resolveModelAttribute(context, model).asInt()).setStopContextTimeoutUnit(TimeUnit.valueOf(STOP_CONTEXT_TIMEOUT.getDefinition().getMeasurementUnit().getName())).setSocketTimeout(SOCKET_TIMEOUT.resolveModelAttribute(context, model).asInt() * 1000).setSessionDrainingStrategy(Enum.valueOf(SessionDrainingStrategyEnum.class, SESSION_DRAINING_STRATEGY.resolveModelAttribute(context, model).asString()));
    if (model.hasDefined(EXCLUDED_CONTEXTS.getName())) {
        String contexts = EXCLUDED_CONTEXTS.resolveModelAttribute(context, model).asString();
        Map<String, Set<String>> excludedContextsPerHost;
        if (contexts == null) {
            excludedContextsPerHost = Collections.emptyMap();
        } else {
            String trimmedContexts = contexts.trim();
            if (trimmedContexts.isEmpty()) {
                excludedContextsPerHost = Collections.emptyMap();
            } else {
                excludedContextsPerHost = new HashMap<>();
                for (String c : trimmedContexts.split(",")) {
                    String[] parts = c.trim().split(":");
                    if (parts.length > 2) {
                        throw ROOT_LOGGER.excludedContextsWrongFormat(trimmedContexts);
                    }
                    String host = null;
                    String trimmedContext = parts[0].trim();
                    if (parts.length == 2) {
                        host = trimmedContext;
                        trimmedContext = parts[1].trim();
                    }
                    String path;
                    switch(trimmedContext) {
                        case "ROOT":
                            ROOT_LOGGER.excludedContextsUseSlashInsteadROOT();
                        case "/":
                            path = "";
                            break;
                        default:
                            // normalize the context by pre-pending or removing trailing slash
                            trimmedContext = trimmedContext.startsWith("/") ? trimmedContext : ("/" + trimmedContext);
                            path = trimmedContext.endsWith("/") ? trimmedContext.substring(0, trimmedContext.length() - 1) : trimmedContext;
                            break;
                    }
                    Set<String> paths = excludedContextsPerHost.computeIfAbsent(host, k -> new HashSet<>());
                    paths.add(path);
                }
            }
        }
        builder.mcmp().setExcludedContextsPerHost(excludedContextsPerHost);
    }
    // Balancer
    builder.balancer().setStickySession(STICKY_SESSION.resolveModelAttribute(context, model).asBoolean()).setStickySessionRemove(STICKY_SESSION_REMOVE.resolveModelAttribute(context, model).asBoolean()).setStickySessionForce(STICKY_SESSION_FORCE.resolveModelAttribute(context, model).asBoolean()).setWorkerTimeout(WORKER_TIMEOUT.resolveModelAttribute(context, model).asInt()).setMaxAttempts(MAX_ATTEMPTS.resolveModelAttribute(context, model).asInt());
    // Node
    builder.node().setFlushPackets(FLUSH_PACKETS.resolveModelAttribute(context, model).asBoolean()).setFlushWait(FLUSH_WAIT.resolveModelAttribute(context, model).asInt()).setPing(PING.resolveModelAttribute(context, model).asInt()).setSmax(SMAX.resolveModelAttribute(context, model).asInt()).setTtl(TTL.resolveModelAttribute(context, model).asInt()).setNodeTimeout(NODE_TIMEOUT.resolveModelAttribute(context, model).asInt());
    ModelNode node = BALANCER.resolveModelAttribute(context, model);
    if (node.isDefined()) {
        builder.node().setBalancer(node.asString());
    }
    node = LOAD_BALANCING_GROUP.resolveModelAttribute(context, model);
    if (node.isDefined()) {
        builder.node().setLoadBalancingGroup(node.asString());
    }
    node = PROXIES.resolveModelAttribute(context, model);
    if (node.isDefined()) {
        for (ModelNode ref : node.asList()) {
            String asString = ref.asString();
            this.outboundSocketBindings.add(new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, asString)));
        }
    }
    String proxyList = PROXY_LIST.resolveModelAttribute(context, model).asStringOrNull();
    if (proxyList != null && proxyList.length() != 0) {
        Collection<ProxyConfiguration> proxyConfigurations;
        String[] tokens = proxyList.split(",");
        proxyConfigurations = new ArrayList<>(tokens.length);
        for (String token : tokens) {
            try {
                final InetSocketAddress remoteAddress = Utils.parseSocketAddress(token.trim(), ModClusterService.DEFAULT_PORT);
                proxyConfigurations.add(new ProxyConfiguration() {

                    @Override
                    public InetSocketAddress getRemoteAddress() {
                        return remoteAddress;
                    }

                    @Override
                    public InetSocketAddress getLocalAddress() {
                        return null;
                    }
                });
            } catch (UnknownHostException e) {
                throw new IllegalArgumentException(e);
            }
        }
        builder.mcmp().setProxyConfigurations(proxyConfigurations);
    }
    // Elytron-based security support
    node = SSL_CONTEXT.resolveModelAttribute(context, model);
    if (node.isDefined()) {
        this.sslContextDependency = new ServiceSupplierDependency<>(CommonUnaryRequirement.SSL_CONTEXT.getServiceName(context, node.asString()));
    }
    if (model.get(SSLResourceDefinition.PATH.getKeyValuePair()).isDefined()) {
        if (node.isDefined()) {
            throw ROOT_LOGGER.bothElytronAndLegacySslContextDefined();
        }
        ModelNode sslModel = model.get(SSLResourceDefinition.PATH.getKeyValuePair());
        ModClusterConfig sslConfiguration = new ModClusterConfig();
        node = SSLResourceDefinition.Attribute.KEY_ALIAS.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            sslConfiguration.setSslKeyAlias(node.asString());
        }
        node = SSLResourceDefinition.Attribute.PASSWORD.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            String password = node.asString();
            sslConfiguration.setSslTrustStorePassword(password);
            sslConfiguration.setSslKeyStorePassword(password);
        }
        node = SSLResourceDefinition.Attribute.CERTIFICATE_KEY_FILE.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            sslConfiguration.setSslKeyStore(node.asString());
        }
        node = SSLResourceDefinition.Attribute.CIPHER_SUITE.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            sslConfiguration.setSslCiphers(node.asString());
        }
        node = SSLResourceDefinition.Attribute.PROTOCOL.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            sslConfiguration.setSslProtocol(node.asString());
        }
        node = SSLResourceDefinition.Attribute.CA_CERTIFICATE_FILE.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            sslConfiguration.setSslTrustStore(node.asString());
        }
        node = SSLResourceDefinition.Attribute.CA_REVOCATION_URL.resolveModelAttribute(context, sslModel);
        if (node.isDefined()) {
            sslConfiguration.setSslCrlFile(node.asString());
        }
        builder.mcmp().setSocketFactory(new JSSESocketFactory(sslConfiguration));
    }
    return this;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) SessionDrainingStrategyEnum(org.jboss.modcluster.config.impl.SessionDrainingStrategyEnum) ProxyConfiguration(org.jboss.modcluster.config.ProxyConfiguration) ModClusterConfig(org.jboss.modcluster.config.impl.ModClusterConfig) ModelNode(org.jboss.dmr.ModelNode) JSSESocketFactory(org.jboss.modcluster.mcmp.impl.JSSESocketFactory)

Example 5 with ServiceSupplierDependency

use of org.wildfly.clustering.service.ServiceSupplierDependency in project wildfly by wildfly.

the class ElectionPolicyServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    List<ModelNode> socketBindingPreferences = SOCKET_BINDING_PREFERENCES.resolveModelAttribute(context, model).asListOrEmpty();
    List<ModelNode> namePreferences = NAME_PREFERENCES.resolveModelAttribute(context, model).asListOrEmpty();
    List<Preference> preferences = new ArrayList<>(socketBindingPreferences.size() + namePreferences.size());
    List<Dependency> dependencies = new ArrayList<>(socketBindingPreferences.size());
    for (ModelNode preference : socketBindingPreferences) {
        SupplierDependency<OutboundSocketBinding> binding = new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, preference.asString()));
        preferences.add(new OutboundSocketBindingPreference(binding));
        dependencies.add(binding);
    }
    for (ModelNode preference : namePreferences) {
        preferences.add(new NamePreference(preference.asString()));
    }
    this.dependencies = dependencies;
    this.preferences = preferences;
    return this;
}
Also used : OutboundSocketBindingPreference(org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) OutboundSocketBindingPreference(org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference) Preference(org.wildfly.clustering.singleton.election.Preference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) ArrayList(java.util.ArrayList) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) Dependency(org.wildfly.clustering.service.Dependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ServiceSupplierDependency (org.wildfly.clustering.service.ServiceSupplierDependency)10 ModelNode (org.jboss.dmr.ModelNode)5 CapabilityServiceConfigurator (org.jboss.as.clustering.controller.CapabilityServiceConfigurator)4 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 SupplierDependency (org.wildfly.clustering.service.SupplierDependency)4 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)3 ServiceName (org.jboss.msc.service.ServiceName)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Resource (org.jboss.as.controller.registry.Resource)2 ChildTargetService (org.wildfly.clustering.service.ChildTargetService)2 Dependency (org.wildfly.clustering.service.Dependency)2 ServiceConfigurator (org.wildfly.clustering.service.ServiceConfigurator)2 SimpleSupplierDependency (org.wildfly.clustering.service.SimpleSupplierDependency)2 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Consumer (java.util.function.Consumer)1