use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.
the class DefaultApiServicesManager method stopService.
private void stopService(ApiService service, ApiContext context, boolean saveStatus) throws ApiServicesManagerException {
ApiServiceImpl sImpl = (ApiServiceImpl) service;
// call spi onStop
boolean newContext = context == null;
try {
if (newContext) {
context = new DefaultApiContext();
}
service.getSpi().onStop(api, service, context);
} catch (ApiManagementException ex) {
throw new ApiServicesManagerException(ex.getMessage(), ex);
} finally {
if (newContext) {
context.recycle();
}
}
// attach api
sImpl.dettachSpi();
// set service status
sImpl.setStatus(ApiStatus.Stopped, saveStatus);
}
use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.
the class DefaultApiServicesManager method start.
@Override
public void start(ApiVerb verb, String endpoint) throws ApiServicesManagerException {
ApiService service = get(verb, endpoint);
if (service == null) {
throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
}
if (!service.status().equals(ApiStatus.Stopped)) {
throw new ApiServicesManagerException("unnable to start service [" + verb + " " + endpoint + "]. Status=" + service.status());
}
startService(service, null, false);
}
use of com.bluenimble.platform.api.ApiServicesManagerException 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.api.ApiServicesManagerException in project serverless by bluenimble.
the class DefaultApiServicesManager method stop.
@Override
public void stop(ApiVerb verb, String endpoint) throws ApiServicesManagerException {
ApiService service = get(verb, endpoint);
if (service == null) {
throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
}
if (!service.status().equals(ApiStatus.Running) || !service.status().equals(ApiStatus.Paused)) {
throw new ApiServicesManagerException("unnable to stop service [" + verb + " " + endpoint + "]. Status=" + service.status());
}
stopService(service, null, true);
}
use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.
the class DefaultApiServicesManager method load.
@Override
public void load(Api api) throws ApiServicesManagerException {
this.api = (ApiImpl) api;
ApiResourcesManager rmgr = api.getResourcesManager();
try {
load(rmgr, rmgr.get(new String[] { ConfigKeys.Folders.Services }));
} catch (ApiResourcesManagerException e) {
throw new ApiServicesManagerException(e.getMessage(), e);
}
}
Aggregations