use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.
the class DefaultApiServicesManager method put.
@Override
public ApiService put(ApiResource resource) throws ApiServicesManagerException {
Exception failure = null;
JsonObject source = null;
InputStream stream = null;
try {
stream = resource.toInput();
source = Json.load(stream);
} catch (Exception ex) {
failure = ex;
;
} finally {
IOUtils.closeQuietly(stream);
}
if (failure != null) {
source = (JsonObject) new JsonObject().set(ApiService.Spec.Status, ApiStatus.Failed.name()).set(ApiService.Spec.Endpoint, resource.path());
}
ApiServiceImpl service = new ApiServiceImpl(resource, source, api);
if (failure != null) {
service.failed(failure);
}
if (failure == null) {
if (exists(service.getVerb(), service.getEndpoint())) {
delete(service.getVerb(), service.getEndpoint());
}
}
ApiServiceSet set = services.get(service.getVerb());
if (set == null) {
set = new ApiServiceSet();
services.put(service.getVerb(), set);
}
set.add(service);
return service;
}
use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.
the class DefaultApiServicesManager method get.
@Override
public ApiService get(ApiVerb verb, String endpoint) {
ApiServiceSet set = services.get(verb);
if (set == null) {
return null;
}
ApiService service = set.get(resolveEndpoint(endpoint));
if (service == null) {
return null;
}
return service;
}
use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.
the class DefaultApiServicesManager method delete.
@Override
public void delete(ApiVerb verb, String endpoint) throws ApiServicesManagerException {
ApiServiceSet set = services.get(verb);
if (set == null) {
throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
}
ApiService service = set.get(endpoint);
if (service == null) {
throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
}
if (!ApiStatus.Failed.equals(service.status()) && !ApiStatus.Stopped.equals(service.status())) {
throw new ApiServicesManagerException("can't delete service [" + verb + " " + endpoint + "]. Status=" + service.status());
}
set.remove(endpoint);
}
use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.
the class DefaultApiServicesManager method list.
@Override
public void list(Selector selector) {
if (selector == null || services.isEmpty()) {
return;
}
Iterator<ApiVerb> verbs = services.keySet().iterator();
while (verbs.hasNext()) {
ApiVerb verb = verbs.next();
ApiServiceSet set = services.get(verb);
Iterator<String> endpoints = set.endpoints();
if (endpoints == null) {
continue;
}
while (endpoints.hasNext()) {
boolean cancel = selector.select(set.get(endpoints.next()));
if (cancel) {
return;
}
}
}
}
Aggregations