Search in sources :

Example 1 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class ApiDeployerStatement method loadApi.

private Api loadApi(String apiDescriptorPath) throws Exception {
    URL jsonFile = ApiDeployerStatement.class.getResource(apiDescriptorPath);
    Api api = new GraviteeMapper().readValue(jsonFile, Api.class);
    if (ApiLoaderInterceptor.class.isAssignableFrom(target.getClass())) {
        ApiLoaderInterceptor loader = (ApiLoaderInterceptor) target;
        loader.before(api);
    }
    boolean enhanceHttpPort = target.getClass().getAnnotation(ApiDescriptor.class).enhanceHttpPort();
    if (enhanceHttpPort) {
        List<Endpoint> endpoints = new ArrayList<>(api.getProxy().getEndpoints());
        List<Integer> bindPorts = SocketUtils.getBindPorts();
        for (int i = 0; i < bindPorts.size(); i++) {
            int port = SocketUtils.getBindPorts().get(i);
            if (i < endpoints.size()) {
                Endpoint edpt = endpoints.get(i);
                URL target = new URL(edpt.getTarget());
                URL newTarget = new URL(target.getProtocol(), target.getHost(), port, target.getFile());
                edpt.setTarget(newTarget.toString());
                edpt.setName(UUID.random().toString());
            } else {
                // Use the first defined endpoint as reference
                HttpEndpoint first = (HttpEndpoint) endpoints.get(0);
                URL target = new URL(first.getTarget());
                URL newTarget = new URL(target.getProtocol(), target.getHost(), port, target.getFile());
                HttpEndpoint edpt = new HttpEndpoint(UUID.random().toString(), newTarget.toString());
                edpt.setHttpClientOptions(first.getHttpClientOptions());
                api.getProxy().getEndpoints().add(edpt);
            }
        }
    }
    if (ApiLoaderInterceptor.class.isAssignableFrom(target.getClass())) {
        ApiLoaderInterceptor loader = (ApiLoaderInterceptor) target;
        loader.after(api);
    }
    return api;
}
Also used : ApiLoaderInterceptor(io.gravitee.gateway.standalone.ApiLoaderInterceptor) ApiDescriptor(io.gravitee.gateway.standalone.junit.annotation.ApiDescriptor) ArrayList(java.util.ArrayList) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) URL(java.net.URL) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) GraviteeMapper(io.gravitee.definition.jackson.datatype.GraviteeMapper) Api(io.gravitee.gateway.handlers.api.definition.Api)

Example 2 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_upAfterTransitionallyDown.

@Test
public void testEndpointStatus_upAfterTransitionallyDown() {
    Endpoint endpoint = createEndpoint();
    EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint);
    manager.updateStatus(true);
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 3 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_downAfterTransitionallyUpAndFinallyUp.

@Test
public void testEndpointStatus_downAfterTransitionallyUpAndFinallyUp() {
    Endpoint endpoint = createEndpoint();
    EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint);
    manager.updateStatus(false);
    manager.updateStatus(false);
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 4 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_down.

@Test
public void testEndpointStatus_down() {
    Endpoint endpoint = createEndpoint();
    EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint);
    manager.updateStatus(false);
    manager.updateStatus(false);
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 5 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointDiscoveryConsulVerticle method handleDeregisterService.

private void handleDeregisterService(Api api, Service service) {
    LOGGER.info("Remove a de-registered endpoint from Consul.io: id[{}] name[{}]", service.getId(), service.getName());
    Endpoint endpoint = createEndpoint(service);
    api.getProxy().getEndpoints().remove(endpoint);
}
Also used : DiscoveredEndpoint(io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint) Endpoint(io.gravitee.definition.model.Endpoint)

Aggregations

Endpoint (io.gravitee.definition.model.Endpoint)17 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)12 Test (org.junit.Test)10 DiscoveredEndpoint (io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint)3 URL (java.net.URL)3 Api (io.gravitee.gateway.handlers.api.definition.Api)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Event (io.gravitee.common.event.Event)1 EventListener (io.gravitee.common.event.EventListener)1 EventManager (io.gravitee.common.event.EventManager)1 GraviteeMapper (io.gravitee.definition.jackson.datatype.GraviteeMapper)1 Api (io.gravitee.definition.model.Api)1 EndpointType (io.gravitee.definition.model.EndpointType)1 HttpClientOptions (io.gravitee.definition.model.HttpClientOptions)1 EndpointDiscoveryProvider (io.gravitee.definition.model.services.discovery.EndpointDiscoveryProvider)1 EndpointDiscoveryService (io.gravitee.definition.model.services.discovery.EndpointDiscoveryService)1 ConsulEndpointDiscoveryConfiguration (io.gravitee.definition.model.services.discovery.consul.ConsulEndpointDiscoveryConfiguration)1 HealthCheckService (io.gravitee.definition.model.services.healthcheck.HealthCheckService)1 Request (io.gravitee.definition.model.services.healthcheck.Request)1