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