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