Search in sources :

Example 1 with DiscoveredEndpoint

use of io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint in project gravitee-gateway by gravitee-io.

the class EndpointDiscoveryConsulVerticle method handleRegisterService.

private void handleRegisterService(Api api, Service service) {
    Endpoint createdEndpoint = createEndpoint(service);
    Set<Endpoint> managedEndpoints = api.getProxy().getEndpoints();
    // Get previous endpoint reference
    Endpoint preEndpoint = managedEndpoints.stream().filter(createdEndpoint::equals).findAny().orElse(null);
    // Endpoint does not exist (according to its name)
    if (preEndpoint == null) {
        LOGGER.info("Register a new endpoint from Consul.io: id[{}] name[{}]", service.getId(), service.getName());
        managedEndpoints.add(createdEndpoint);
    } else if (preEndpoint instanceof DiscoveredEndpoint) {
        // Update it only if target has been changed
        DiscoveredEndpoint dynamicEndpoint = (DiscoveredEndpoint) preEndpoint;
        if (!createdEndpoint.getTarget().equals(dynamicEndpoint.getTarget())) {
            LOGGER.info("Update an existing endpoint from Consul.io: id[{}] name[{}] target[{}]", service.getId(), service.getName(), createdEndpoint.getTarget());
            managedEndpoints.remove(preEndpoint);
            managedEndpoints.add(createdEndpoint);
        }
    }
}
Also used : DiscoveredEndpoint(io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint) Endpoint(io.gravitee.definition.model.Endpoint) DiscoveredEndpoint(io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint)

Example 2 with DiscoveredEndpoint

use of io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint in project gravitee-gateway by gravitee-io.

the class EndpointDiscoveryConsulVerticle method createEndpoint.

private Endpoint createEndpoint(Service service) {
    String address = service.getAddress();
    if (address == null || address.trim().isEmpty()) {
        address = service.getNodeAddress();
    }
    DiscoveredEndpoint endpoint = new DiscoveredEndpoint("consul:" + service.getId(), "http://" + address + ':' + service.getPort());
    endpoint.setHttpClientOptions(new HttpClientOptions());
    return endpoint;
}
Also used : DiscoveredEndpoint(io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint) HttpClientOptions(io.gravitee.definition.model.HttpClientOptions)

Aggregations

DiscoveredEndpoint (io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint)2 Endpoint (io.gravitee.definition.model.Endpoint)1 HttpClientOptions (io.gravitee.definition.model.HttpClientOptions)1