use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class ApiValidatorTest method validate_noPathDefinition.
@Test(expected = ValidationException.class)
public void validate_noPathDefinition() {
Api definition = new Api();
definition.setName("api-test");
new ApiValidator().validate(definition);
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class HttpClientValidatorTest method validate_proxy_httpclient_useProxy.
// (expected = ValidationException.class)
@Test
public void validate_proxy_httpclient_useProxy() {
HttpClient httpClientDefinition = new HttpClient();
// httpClientDefinition.setUseProxy(true);
Proxy proxyDefinition = new Proxy();
// proxyDefinition.setHttpClient(httpClientDefinition);
Api definition = new Api();
definition.setProxy(proxyDefinition);
new HttpClientValidator().validate(definition);
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class ProxyValidatorTest method validate_proxy_badContextPath.
@Test(expected = ValidationException.class)
public void validate_proxy_badContextPath() {
Proxy proxyDefinition = new Proxy();
proxyDefinition.setContextPath("context-path");
Api definition = new Api();
definition.setProxy(proxyDefinition);
new ProxyValidator().validate(definition);
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class ApiManagerImpl method undeploy.
@Override
public void undeploy(String apiId) {
MDC.put("api", apiId);
Api currentApi = apis.remove(apiId);
if (currentApi != null) {
logger.info("Undeployment of {}", currentApi);
eventManager.publishEvent(ReactorEvent.UNDEPLOY, currentApi);
logger.info("{} has been undeployed", apiId);
}
MDC.remove("api");
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class LocalApiDefinitionRegistry method doStart.
@Override
protected void doStart() throws Exception {
if (enabled) {
super.doStart();
this.init();
executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "registry-monitor"));
executor.execute(() -> {
Path registry = Paths.get(registryPath);
LOGGER.info("Start local registry monitor for directory {}", registry);
try {
WatchService watcher = registry.getFileSystem().newWatchService();
registry.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
while (true) {
WatchKey key;
try {
key = watcher.take();
} catch (InterruptedException ex) {
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
@SuppressWarnings("unchecked") WatchEvent<Path> ev = (WatchEvent<Path>) event;
Path fileName = registry.resolve(ev.context().getFileName());
LOGGER.info("An event occurs for file {}: {}", fileName, kind.name());
if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
Api loadedDefinition = loadDefinition(fileName.toFile());
Api existingDefinition = definitions.get(fileName);
if (existingDefinition != null) {
if (apiManager.get(existingDefinition.getId()) != null) {
apiManager.update(loadedDefinition);
} else {
apiManager.undeploy(existingDefinition.getId());
definitions.remove(fileName);
apiManager.deploy(loadedDefinition);
definitions.put(fileName, loadedDefinition);
}
}
} else if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
Api loadedDefinition = loadDefinition(fileName.toFile());
Api existingDefinition = apiManager.get(loadedDefinition.getId());
if (existingDefinition != null) {
apiManager.update(loadedDefinition);
} else {
apiManager.deploy(loadedDefinition);
definitions.put(fileName, loadedDefinition);
}
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
Api existingDefinition = definitions.get(fileName);
if (existingDefinition != null && apiManager.get(existingDefinition.getId()) != null) {
apiManager.undeploy(existingDefinition.getId());
definitions.remove(fileName);
}
}
boolean valid = key.reset();
if (!valid) {
break;
}
}
}
} catch (IOException ioe) {
LOGGER.error("Unexpected error while looking for ÀPI definitions from filesystem", ioe);
}
});
}
}
Aggregations