Search in sources :

Example 21 with ApiManagementException

use of com.bluenimble.platform.api.ApiManagementException in project serverless by bluenimble.

the class ApiSpaceImpl method install.

/*	
	@Override
	public void update (String apiNs, JsonObject descriptor) throws ApiManagementException {
		ApiImpl api = (ApiImpl)api (apiNs);
		if (api == null) {
			throw new ApiManagementException ("Api " + apiNs + " not found");
		}
		
		// update descriptor
		JsonObject oldDescriptor = api.getDescriptor ();
		oldDescriptor.set (Api.Spec.Name, Json.getString (descriptor, Api.Spec.Name, api.getName ()));
		oldDescriptor.set (Api.Spec.Description, Json.getString (descriptor, Api.Spec.Description, api.getDescription ()));
		
		JsonObject oLogging = Json.getObject (descriptor, Api.Spec.Logging);
		if (oLogging != null) {
			oldDescriptor.set (Api.Spec.Logging, oLogging);
			api.createtracer ();
		}
		
		JsonObject oFeatures = Json.getObject (descriptor, Api.Spec.Features);
		if (oFeatures != null) {
			oldDescriptor.set (Api.Spec.Features, oFeatures);
		}
		
		// write descriptor
		api.updateDescriptor ();
		
		// remove old
		remove (apiNs);
		
		// add new
		register (api);		
	}
*/
@Override
public Api install(String spaceFolder, String apiFile) throws ApiManagementException {
    String externalSpacesFolder = Json.getString(server.getDescriptor(), ConfigKeys.Spaces);
    if (Lang.isNullOrEmpty(externalSpacesFolder)) {
        throw new ApiManagementException("Node doesn't support external spaces");
    }
    File externalSpaces = new File(externalSpacesFolder);
    if (!externalSpaces.exists() || !externalSpaces.isDirectory()) {
        throw new ApiManagementException("External spaces folder not found");
    }
    File fSpaceFolder = new File(externalSpaces, spaceFolder);
    if (!fSpaceFolder.exists() || !fSpaceFolder.isDirectory()) {
        throw new ApiManagementException("Space folder " + spaceFolder + " not found");
    }
    File fApiFile = new File(fSpaceFolder, apiFile);
    if (!fApiFile.exists() || !fApiFile.isFile()) {
        throw new ApiManagementException("Api file " + apiFile + " not found");
    }
    ApiFileStreamSource is = new ApiFileStreamSource(fApiFile, ConfigKeys.ApiExt);
    try {
        return install(is);
    } finally {
        IOUtils.closeQuietly(is.stream());
    }
}
Also used : ApiManagementException(com.bluenimble.platform.api.ApiManagementException) File(java.io.File)

Example 22 with ApiManagementException

use of com.bluenimble.platform.api.ApiManagementException in project serverless by bluenimble.

the class ApiSpaceImpl method install.

public Api install(File apiHome) throws ApiManagementException {
    Api api = new ApiImpl(this, apiHome);
    // stop any existing version of the api
    ApiImpl old = (ApiImpl) api(api.getNamespace());
    if (old != null) {
        if (old.status().equals(ApiStatus.Running) || old.status().equals(ApiStatus.Paused)) {
            // clear memory
            old.stop(false);
        }
        // clear memory
        old.clear();
        // remove status
        statusManager.delete(old);
    }
    // register api
    register(api);
    tracer.log(Tracer.Level.Info, "api {0} / {1} installed", getNamespace(), api.getNamespace());
    // call plugins onEvent Install
    try {
        server.getPluginsRegistry().onEvent(Event.Install, api);
    } catch (PluginRegistryException e) {
        throw new ApiManagementException(e.getMessage(), e);
    }
    // get api status if any
    ApiStatus status = statusManager.get(api);
    tracer.log(Tracer.Level.Info, "\t\tfound with status {0}", status);
    if (ApiStatus.Running.equals(status) || ApiStatus.Paused.equals(status)) {
        // start api
        ((ApiImpl) api).start(ApiStatus.Paused.equals(api.status()));
        // notify plugins
        try {
            server.getPluginsRegistry().onEvent(Event.Start, api);
        } catch (PluginRegistryException e) {
            throw new ApiManagementException(e.getMessage(), e);
        }
    }
    return api;
}
Also used : ApiStatus(com.bluenimble.platform.api.ApiStatus) Api(com.bluenimble.platform.api.Api) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 23 with ApiManagementException

use of com.bluenimble.platform.api.ApiManagementException in project serverless by bluenimble.

the class ApiSpaceImpl method deleteFeature.

@Override
public void deleteFeature(String name, String feature) throws ApiManagementException {
    JsonObject oFeature = Json.getObject(getFeatures(), feature);
    if (oFeature == null || !oFeature.containsKey(name)) {
        throw new ApiManagementException("feature '" + feature + "/" + name + "' not available for space " + getNamespace());
    }
    oFeature.remove(name);
    try {
        server.getPluginsRegistry().onEvent(Event.DeleteFeature, this);
    } catch (PluginRegistryException e) {
        throw new ApiManagementException(e.getMessage(), e);
    }
    // save
    save();
}
Also used : JsonObject(com.bluenimble.platform.json.JsonObject) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

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