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();
}
}
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;
}
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;
}
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);
}
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();
}
Aggregations