Search in sources :

Example 1 with ModCluster

use of io.undertow.server.handlers.proxy.mod_cluster.ModCluster in project undertow by undertow-io.

the class ModClusterProxyServer method main.

public static void main(final String[] args) throws IOException {
    final XnioWorker worker = Xnio.getInstance().createWorker(OptionMap.EMPTY);
    final Undertow server;
    final ModCluster modCluster = ModCluster.builder(worker).build();
    try {
        if (chost == null) {
            // We are going to guess it.
            chost = java.net.InetAddress.getLocalHost().getHostName();
            System.out.println("Using: " + chost + ":" + cport);
        }
        modCluster.start();
        // Create the proxy and mgmt handler
        final HttpHandler proxy = modCluster.createProxyHandler();
        final MCMPConfig config = MCMPConfig.webBuilder().setManagementHost(chost).setManagementPort(cport).enableAdvertise().getParent().build();
        final HttpHandler mcmp = config.create(modCluster, proxy);
        server = Undertow.builder().addHttpListener(cport, chost).addHttpListener(pport, phost).setHandler(mcmp).build();
        server.start();
        // Start advertising the mcmp handler
        modCluster.advertise(config);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) XnioWorker(org.xnio.XnioWorker) MCMPConfig(io.undertow.server.handlers.proxy.mod_cluster.MCMPConfig) Undertow(io.undertow.Undertow) IOException(java.io.IOException)

Example 2 with ModCluster

use of io.undertow.server.handlers.proxy.mod_cluster.ModCluster in project wildfly by wildfly.

the class ModClusterBalancerResource method getChildrenNames.

@Override
public Set<String> getChildrenNames(final String childType) {
    if (NODE.equals(childType)) {
        ModClusterService service = ModClusterResource.service(modClusterName);
        if (service == null) {
            return Collections.emptySet();
        }
        ModCluster modCluster = service.getModCluster();
        ModClusterStatus status = modCluster.getController().getStatus();
        final Set<String> result = new LinkedHashSet<>();
        ModClusterStatus.LoadBalancer balancer = status.getLoadBalancer(this.name);
        for (ModClusterStatus.Node node : balancer.getNodes()) {
            result.add(node.getName());
        }
        return result;
    } else if (LOAD_BALANCING_GROUP.equals(childType)) {
        ModClusterService service = ModClusterResource.service(modClusterName);
        if (service == null) {
            return Collections.emptySet();
        }
        ModCluster modCluster = service.getModCluster();
        ModClusterStatus status = modCluster.getController().getStatus();
        final Set<String> result = new LinkedHashSet<>();
        ModClusterStatus.LoadBalancer balancer = status.getLoadBalancer(this.name);
        for (ModClusterStatus.Node node : balancer.getNodes()) {
            result.add(node.getDomain());
        }
        return result;
    }
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) ModelNode(org.jboss.dmr.ModelNode) ModClusterStatus(io.undertow.server.handlers.proxy.mod_cluster.ModClusterStatus)

Example 3 with ModCluster

use of io.undertow.server.handlers.proxy.mod_cluster.ModCluster in project wildfly by wildfly.

the class ModClusterNodeResource method getChildrenNames.

@Override
public Set<String> getChildrenNames(final String childType) {
    if (CONTEXT.equals(childType)) {
        ModClusterService service = ModClusterResource.service(modClusterName);
        if (service == null) {
            return Collections.emptySet();
        }
        ModCluster modCluster = service.getModCluster();
        ModClusterStatus status = modCluster.getController().getStatus();
        final Set<String> result = new LinkedHashSet<>();
        ModClusterStatus.LoadBalancer balancer = status.getLoadBalancer(this.balancerName);
        ModClusterStatus.Node node = balancer.getNode(this.name);
        for (ModClusterStatus.Context context : node.getContexts()) {
            result.add(context.getName());
        }
        return result;
    }
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) ModClusterStatus(io.undertow.server.handlers.proxy.mod_cluster.ModClusterStatus)

Example 4 with ModCluster

use of io.undertow.server.handlers.proxy.mod_cluster.ModCluster in project wildfly by wildfly.

the class ModClusterResource method getChildrenNames.

@Override
public Set<String> getChildrenNames(final String childType) {
    if (BALANCER.equals(childType)) {
        ModClusterService service = service(name);
        if (service == null) {
            return Collections.emptySet();
        }
        ModCluster modCluster = service.getModCluster();
        if (modCluster == null) {
            return Collections.emptySet();
        }
        ModClusterController controller = modCluster.getController();
        if (controller == null) {
            return Collections.emptySet();
        }
        ModClusterStatus status = controller.getStatus();
        final Set<String> result = new LinkedHashSet<>();
        for (ModClusterStatus.LoadBalancer balancer : status.getLoadBalancers()) {
            result.add(balancer.getName());
        }
        return result;
    }
    return delegate.getChildrenNames(childType);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) ModClusterController(io.undertow.server.handlers.proxy.mod_cluster.ModClusterController) ModClusterStatus(io.undertow.server.handlers.proxy.mod_cluster.ModClusterStatus)

Example 5 with ModCluster

use of io.undertow.server.handlers.proxy.mod_cluster.ModCluster in project wildfly by wildfly.

the class ModClusterService method start.

@Override
public synchronized void start(StartContext context) throws StartException {
    super.start(context);
    SSLContext sslContext = this.sslContext != null ? this.sslContext.get() : null;
    // TODO: SSL support for the client
    final ModCluster.Builder modClusterBuilder;
    final XnioWorker worker = this.worker.get();
    if (sslContext == null) {
        modClusterBuilder = ModCluster.builder(worker);
    } else {
        OptionMap.Builder builder = OptionMap.builder();
        builder.set(Options.USE_DIRECT_BUFFERS, true);
        OptionMap combined = builder.getMap();
        XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
        modClusterBuilder = ModCluster.builder(worker, UndertowClient.getInstance(), xnioSsl);
    }
    modClusterBuilder.setMaxRetries(maxRetries).setClientOptions(clientOptions).setHealthCheckInterval(healthCheckInterval).setMaxRequestTime(maxRequestTime).setCacheConnections(cachedConnections).setQueueNewRequests(requestQueueSize > 0).setRequestQueueSize(requestQueueSize).setRemoveBrokenNodes(removeBrokenNodes).setTtl(connectionIdleTimeout).setMaxConnections(connectionsPerThread).setUseAlias(useAlias).setRouteParsingStrategy(routeParsingStrategy).setRankedAffinityDelimiter(routeDelimiter);
    if (FailoverStrategy.DETERMINISTIC.equals(failoverStrategy)) {
        modClusterBuilder.setDeterministicFailover(true);
    }
    modCluster = modClusterBuilder.build();
    MCMPConfig.Builder builder = MCMPConfig.builder();
    final SocketBinding advertiseBinding = advertiseSocketBinding != null ? advertiseSocketBinding.get() : null;
    if (advertiseBinding != null) {
        InetAddress multicastAddress = advertiseBinding.getMulticastAddress();
        if (multicastAddress == null) {
            throw UndertowLogger.ROOT_LOGGER.advertiseSocketBindingRequiresMulticastAddress();
        }
        if (advertiseFrequency > 0) {
            builder.enableAdvertise().setAdvertiseAddress(advertiseBinding.getSocketAddress().getAddress().getHostAddress()).setAdvertiseGroup(multicastAddress.getHostAddress()).setAdvertisePort(advertiseBinding.getMulticastPort()).setAdvertiseFrequency(advertiseFrequency).setPath(advertisePath).setProtocol(advertiseProtocol).setSecurityKey(securityKey);
        }
    }
    builder.setManagementHost(managementSocketBinding.get().getSocketAddress().getHostString());
    builder.setManagementPort(managementSocketBinding.get().getSocketAddress().getPort());
    config = builder.build();
    if (advertiseBinding != null && advertiseFrequency > 0) {
        try {
            modCluster.advertise(config);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    modCluster.start();
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) XnioWorker(org.xnio.XnioWorker) MCMPConfig(io.undertow.server.handlers.proxy.mod_cluster.MCMPConfig) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) OptionMap(org.xnio.OptionMap) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) InetAddress(java.net.InetAddress)

Aggregations

ModCluster (io.undertow.server.handlers.proxy.mod_cluster.ModCluster)5 ModClusterStatus (io.undertow.server.handlers.proxy.mod_cluster.ModClusterStatus)3 LinkedHashSet (java.util.LinkedHashSet)3 MCMPConfig (io.undertow.server.handlers.proxy.mod_cluster.MCMPConfig)2 IOException (java.io.IOException)2 XnioWorker (org.xnio.XnioWorker)2 Undertow (io.undertow.Undertow)1 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)1 HttpHandler (io.undertow.server.HttpHandler)1 ModClusterController (io.undertow.server.handlers.proxy.mod_cluster.ModClusterController)1 InetAddress (java.net.InetAddress)1 Set (java.util.Set)1 SSLContext (javax.net.ssl.SSLContext)1 SocketBinding (org.jboss.as.network.SocketBinding)1 ModelNode (org.jboss.dmr.ModelNode)1 OptionMap (org.xnio.OptionMap)1 XnioSsl (org.xnio.ssl.XnioSsl)1