Search in sources :

Example 11 with ApiManagementException

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());
}
Also used : IOException(java.io.IOException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 12 with ApiManagementException

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);
}
Also used : ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException)

Example 13 with ApiManagementException

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));
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) JsonObject(com.bluenimble.platform.json.JsonObject) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput)

Example 14 with ApiManagementException

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));
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) JsonObject(com.bluenimble.platform.json.JsonObject) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput)

Example 15 with ApiManagementException

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);
    }
}
Also used : ApiResource(com.bluenimble.platform.api.ApiResource) InputStream(java.io.InputStream) ApiResourcesManagerException(com.bluenimble.platform.api.ApiResourcesManagerException) ApiResourcesManagerException(com.bluenimble.platform.api.ApiResourcesManagerException) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException)

Aggregations

ApiManagementException (com.bluenimble.platform.api.ApiManagementException)23 JsonObject (com.bluenimble.platform.json.JsonObject)13 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)8 PluginRegistryException (com.bluenimble.platform.plugins.PluginRegistryException)8 ApiSpace (com.bluenimble.platform.api.ApiSpace)6 ApiResourcesManagerException (com.bluenimble.platform.api.ApiResourcesManagerException)5 IOException (java.io.IOException)5 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)4 ApiAuthenticationException (com.bluenimble.platform.api.security.ApiAuthenticationException)4 ScriptingEngine (com.bluenimble.platform.scripting.ScriptingEngine)4 ScriptingEngineException (com.bluenimble.platform.scripting.ScriptingEngineException)4 Crypto (com.bluenimble.platform.Crypto)3 ApiResource (com.bluenimble.platform.api.ApiResource)3 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)3 File (java.io.File)3 Date (java.util.Date)3 Api (com.bluenimble.platform.api.Api)2 ApiSpaceImpl (com.bluenimble.platform.api.impls.ApiSpaceImpl)2 ApiRequestSignerException (com.bluenimble.platform.api.security.ApiRequestSignerException)2 SpaceKeyStoreException (com.bluenimble.platform.security.SpaceKeyStoreException)2