Search in sources :

Example 1 with EtcdResponse

use of com.predic8.membrane.core.cloud.etcd.EtcdResponse in project service-proxy by membrane.

the class ApiManagementConfiguration method handleEtcd.

private void handleEtcd(String location) throws IOException {
    // assumption: location is of type "etcd://[url]"
    final String etcdLocation = location.substring(7);
    final String baseKey = etcdPathPrefix + getMembraneName();
    EtcdResponse respGetConfigUrl = EtcdRequest.create(etcdLocation, baseKey, "/apiconfig").getValue("url").sendRequest();
    if (!respGetConfigUrl.is2XX()) {
        log.warn("Could not get config url at " + etcdLocation + baseKey + "/apiconfig");
        return;
    }
    final String configLocation = respGetConfigUrl.getValue();
    // this gets the resource and loads the config
    setLocation(configLocation);
    updateAfterLocationChange();
    setLocation(location);
    if (etcdConfigFingerprintLongPollThread == null) {
        etcdConfigFingerprintLongPollThread = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    while (!getContextLost()) {
                        if (!EtcdRequest.create(etcdLocation, baseKey, "/apiconfig").getValue("fingerprint").longPoll().sendRequest().is2XX()) {
                            log.warn("Could not get config fingerprint at " + etcdLocation);
                        }
                        if (!getContextLost()) {
                            log.info("Noticed configuration change, updating...");
                            updateAfterLocationChange();
                        }
                    }
                } catch (Exception ignored) {
                }
            }
        });
        etcdConfigFingerprintLongPollThread.start();
    }
}
Also used : EtcdResponse(com.predic8.membrane.core.cloud.etcd.EtcdResponse) URISyntaxException(java.net.URISyntaxException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException)

Example 2 with EtcdResponse

use of com.predic8.membrane.core.cloud.etcd.EtcdResponse 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)

Aggregations

EtcdResponse (com.predic8.membrane.core.cloud.etcd.EtcdResponse)2 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)1 ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 BeansException (org.springframework.beans.BeansException)1