use of com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation in project service-proxy by membrane.
the class EtcdBasedConfigurator method setUpClusterNode.
private void setUpClusterNode(EtcdNodeInformation node) {
log.info("Creating " + node);
ServiceProxy sp = runningServiceProxyForModule.get(node.getModule());
LoadBalancingInterceptor lbi = (LoadBalancingInterceptor) sp.getInterceptors().get(0);
lbi.getClusterManager().getClusters().get(0).nodeUp(new Node(node.getTargetHost(), Integer.parseInt(node.getTargetPort())));
runningNodesForModule.get(node.getModule()).add(node);
}
use of com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation in project service-proxy by membrane.
the class EtcdRegistryApiConfig method publishToEtcd.
private boolean publishToEtcd() {
String baseKey = baseKeyPrefix + membraneId;
EtcdResponse respPublishApiUrl = EtcdRequest.create(url, baseKey, "/apiconfig").setValue("url", "").sendRequest();
if (!respPublishApiUrl.is2XX()) {
System.out.println(respPublishApiUrl.getBody());
return false;
}
EtcdResponse respPublishApiFingerprint = EtcdRequest.create(url, baseKey, "/apiconfig").setValue("fingerprint", "").sendRequest();
if (!respPublishApiFingerprint.is2XX()) {
System.out.println(respPublishApiFingerprint.getBody());
return false;
}
EtcdNodeInformation adminConsole = findAdminConsole();
EtcdResponse respPublishEndpointName = EtcdRequest.create(url, baseKey, "/endpoint").setValue("name", adminConsole.getName()).sendRequest();
if (!respPublishEndpointName.is2XX()) {
System.out.println(respPublishEndpointName.getBody());
return false;
}
EtcdResponse respPublishEndpointHost = EtcdRequest.create(url, baseKey, "/endpoint").setValue("host", adminConsole.getTargetHost()).sendRequest();
if (!respPublishEndpointHost.is2XX()) {
System.out.println(respPublishEndpointHost.getBody());
return false;
}
EtcdResponse respPublishEndpointPort = EtcdRequest.create(url, baseKey, "/endpoint").setValue("port", adminConsole.getTargetPort()).sendRequest();
if (!respPublishEndpointPort.is2XX()) {
System.out.println(respPublishEndpointPort.getBody());
return false;
}
return true;
}
use of com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation in project service-proxy by membrane.
the class EtcdRegistryApiConfig method findAdminConsole.
private EtcdNodeInformation findAdminConsole() {
Object routerObj = context.getBean(Router.class);
if (routerObj == null)
throw new RuntimeException("Router not found, cannot publish admin console");
Router router = (Router) routerObj;
for (Rule r : router.getRuleManager().getRules()) {
if (!(r instanceof AbstractServiceProxy))
continue;
for (Interceptor i : r.getInterceptors()) {
if (i instanceof AdminConsoleInterceptor) {
String name = r.getName();
String host = ((ServiceProxy) r).getExternalHostname();
if (host == null)
host = getLocalHostname();
String port = Integer.toString(((AbstractServiceProxy) r).getPort());
EtcdNodeInformation node = new EtcdNodeInformation(null, null, host, port, name);
return node;
}
}
}
throw new RuntimeException("Admin console not found but is needed. Add a service proxy with an admin console.");
}
use of com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation in project service-proxy by membrane.
the class EtcdBasedConfigurator method shutdownRunningClusterNode.
private void shutdownRunningClusterNode(EtcdNodeInformation node) {
log.info("Destroying " + node);
ServiceProxy sp = runningServiceProxyForModule.get(node.getModule());
LoadBalancingInterceptor lbi = (LoadBalancingInterceptor) sp.getInterceptors().get(0);
lbi.getClusterManager().removeNode(Balancer.DEFAULT_NAME, baseUrl, port);
runningNodesForModule.get(node.getModule()).remove(node);
}
use of com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation in project service-proxy by membrane.
the class EtcdPublisher method readConfig.
public void readConfig() {
nodesFromConfig.clear();
for (Rule rule : router.getRuleManager().getRules()) {
if (!(rule instanceof ServiceProxy))
continue;
ServiceProxy sp = (ServiceProxy) rule;
if (sp.getPath() == null)
continue;
nodesFromConfig.add(new EtcdNodeInformation(sp.getPath().getValue(), "/" + UUID.randomUUID().toString(), "localhost", Integer.toString(sp.getPort()), sp.getName()));
}
}
Aggregations