use of com.bluenimble.platform.api.ApiManagementException in project serverless by bluenimble.
the class ApiSpaceImpl method uninstall.
/*
@Override
public Api install (JsonObject descriptor) throws ApiManagementException {
if (Lang.isNullOrEmpty (getNamespace ())) {
throw new ApiManagementException (
"Api " + Api.Spec.Namespace + " not found in descriptor "
);
}
// create api home
File apiHome = new File (home, getNamespace () + Lang.UNDERSCORE + Lang.UUID (40));
return install (apiHome, descriptor);
}
*/
@Override
public void uninstall(String apiNs) throws ApiManagementException {
if (Lang.isNullOrEmpty(apiNs)) {
throw new ApiManagementException("api namespace is null or empty");
}
ApiImpl api = (ApiImpl) api(apiNs.trim());
if (api == null) {
throw new ApiManagementException("api '" + apiNs + "' not found");
}
// notify before uninstall
try {
server.getPluginsRegistry().onEvent(Event.Uninstall, api);
} catch (PluginRegistryException e) {
throw new ApiManagementException(e.getMessage(), e);
}
// stop api
if (!api.status().equals(ApiStatus.Stopped)) {
api.stop(false);
}
// remove status
statusManager.delete(api);
// clear memory
api.clear();
try {
FileUtils.delete(((ApiImpl) api).getHome());
} catch (IOException e) {
throw new ApiManagementException(e.getMessage(), e);
}
remove(apiNs);
tracer.log(Tracer.Level.Info, "\tApi [{0}] uninstalled", api.getNamespace());
}
use of com.bluenimble.platform.api.ApiManagementException 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.ApiManagementException in project serverless by bluenimble.
the class AddFeatureSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
JsonObject oFeature = (JsonObject) request.get(ApiRequest.Payload);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.NOT_FOUND);
}
try {
space.addFeature(Json.getString(oFeature, Spec.Name), Json.getString(oFeature, Spec.Feature), Json.getString(oFeature, ApiSpace.Features.Provider), Json.getObject(oFeature, ApiSpace.Features.Spec));
} catch (ApiManagementException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.BAD_REQUEST);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Added, true));
}
use of com.bluenimble.platform.api.ApiManagementException in project serverless by bluenimble.
the class AddSecretsSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
JsonObject oSecrets = (JsonObject) request.get(ApiRequest.Payload);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.NOT_FOUND);
}
try {
space.addSecrets((String) request.get(Spec.Name), oSecrets);
} catch (ApiManagementException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.BAD_REQUEST);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Added, true));
}
use of com.bluenimble.platform.api.ApiManagementException in project serverless by bluenimble.
the class CreateSpaceSpi method onStart.
@Override
public void onStart(Api api, ApiService service, ApiContext context) throws ApiManagementException {
super.onStart(api, service, context);
// load space model
ApiResource resource;
try {
resource = api.getResourcesManager().get(SpaceModel);
} catch (ApiResourcesManagerException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
if (resource == null) {
return;
}
InputStream stream = null;
try {
stream = resource.toInput();
spaceModel = Json.load(stream);
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
} finally {
IOUtils.closeQuietly(stream);
}
}
Aggregations