Search in sources :

Example 1 with EtcdNodeInformation

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);
}
Also used : LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Node(com.predic8.membrane.core.interceptor.balancer.Node)

Example 2 with EtcdNodeInformation

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;
}
Also used : EtcdNodeInformation(com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation) EtcdResponse(com.predic8.membrane.core.cloud.etcd.EtcdResponse)

Example 3 with EtcdNodeInformation

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.");
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) EtcdNodeInformation(com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation) Router(com.predic8.membrane.core.Router) Rule(com.predic8.membrane.core.rules.Rule) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor)

Example 4 with EtcdNodeInformation

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);
}
Also used : LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy)

Example 5 with EtcdNodeInformation

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()));
    }
}
Also used : ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)2 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)2 Rule (com.predic8.membrane.core.rules.Rule)2 Router (com.predic8.membrane.core.Router)1 EtcdResponse (com.predic8.membrane.core.cloud.etcd.EtcdResponse)1 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)1 AdminConsoleInterceptor (com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor)1 Node (com.predic8.membrane.core.interceptor.balancer.Node)1 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)1