use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class LocalApiDefinitionRegistry method initRegistry.
private void initRegistry(File registryDir) {
LOGGER.info("Loading API definitions from {}", registryDir.getAbsoluteFile());
File[] definitionFiles = searchForDefinitions(registryDir);
LOGGER.info("\t{} API definitions have been found.", definitionFiles.length);
for (File definitionFile : definitionFiles) {
try {
Api api = loadDefinition(definitionFile);
apiManager.deploy(api);
definitions.put(Paths.get(definitionFile.toURI()), api);
} catch (IOException e) {
LOGGER.error("Unable to load API definition from {}", definitionFile, e);
}
}
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class EndpointHealthcheckVerticle method onEvent.
@Override
public void onEvent(Event<ReactorEvent, Reactable> event) {
final Api api = (Api) event.content().item();
switch(event.type()) {
case DEPLOY:
startHealthCheck(api);
break;
case UNDEPLOY:
stopHealthCheck(api);
break;
case UPDATE:
stopHealthCheck(api);
startHealthCheck(api);
break;
}
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method test_newApi.
@Test
public void test_newApi() throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
final Api mockApi = mockApi(api);
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
syncManager.refresh();
verify(apiManager).deploy(mockApi);
verify(apiManager, never()).update(any(Api.class));
verify(apiManager, never()).undeploy(any(String.class));
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method mockApi.
private Api mockApi(final io.gravitee.repository.management.model.Api api, final String[] tags) throws Exception {
final Api mockApi = new Api();
mockApi.setId(api.getId());
mockApi.setDeployedAt(api.getUpdatedAt());
mockApi.setTags(new HashSet<>(Arrays.asList(tags)));
when(objectMapper.readValue(api.getDefinition(), Api.class)).thenReturn(mockApi);
return mockApi;
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method shouldDeployApiWithTags.
public void shouldDeployApiWithTags(final String tags, final String[] apiTags) throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
final Api mockApi = mockApi(api, apiTags);
when(gatewayConfiguration.shardingTags()).thenReturn(Optional.of(Arrays.asList(tags.split(","))));
when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
when(apiManager.apis()).thenReturn(Collections.singleton(mockApi));
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
syncManager.refresh();
verify(apiManager).deploy(mockApi);
verify(apiManager, never()).update(any(Api.class));
verify(apiManager, never()).undeploy(any(String.class));
}
Aggregations