Search in sources :

Example 11 with Api

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

the class ApiSpaceImpl method install.

/*
	@Override
	public Api install (ApiStreamSource source) throws ApiManagementException {
		
		boolean started = isStarted ();
		
		// if the space is new, start it before 
		if (!started) {
			
			// start executor (this is important if the space just created since it will be down)
			try {
				started = start ();
			} catch (Exception e) {
				throw new ApiManagementException (e.getMessage (), e);
			}
			
			// notify space creation if it's new
			if (started) {
				try {
					server.getPluginsRegistry ().onEvent (Event.Create, this);
				} catch (Exception ex) {
					throw new ApiManagementException (ex.getMessage (), ex);
				} 
			}
		}
		
		if (!started) {
			throw new ApiManagementException ("Can't install Api, couldn't start owner space");
		}
		
		return _install (source);
	}
	*/
@Override
public Api install(ApiStreamSource source) throws ApiManagementException {
    if (source == null) {
        throw new ApiManagementException("missing api payload");
    }
    InputStream stream = source.stream();
    if (stream == null) {
        throw new ApiManagementException("missing api stream");
    }
    String name = source.name();
    if (Lang.isNullOrEmpty(name)) {
        name = getNamespace() + Lang.UNDERSCORE + Lang.UUID(40);
    }
    tracer.log(Tracer.Level.Info, "install api {0} / {1}", getNamespace(), source.name());
    File apiHome = new File(home, name);
    try {
        ArchiveUtils.decompress(stream, apiHome);
    } catch (Exception e) {
        throw new ApiManagementException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    Api api = install(apiHome);
    return api;
}
Also used : InputStream(java.io.InputStream) Api(com.bluenimble.platform.api.Api) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) File(java.io.File) ApiRequestSignerException(com.bluenimble.platform.api.security.ApiRequestSignerException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) IOException(java.io.IOException) ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) SpaceKeyStoreException(com.bluenimble.platform.security.SpaceKeyStoreException) FeatureNotFoundException(com.bluenimble.platform.server.FeatureNotFoundException)

Example 12 with Api

use of com.bluenimble.platform.api.Api 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)

Aggregations

Api (com.bluenimble.platform.api.Api)12 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)7 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)6 ApiSpace (com.bluenimble.platform.api.ApiSpace)4 JsonObject (com.bluenimble.platform.json.JsonObject)4 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)3 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)3 IOException (java.io.IOException)3 ApiStatus (com.bluenimble.platform.api.ApiStatus)2 ApiVerb (com.bluenimble.platform.api.ApiVerb)2 PluginRegistryException (com.bluenimble.platform.plugins.PluginRegistryException)2 SpaceKeyStoreException (com.bluenimble.platform.security.SpaceKeyStoreException)2 FeatureNotFoundException (com.bluenimble.platform.server.FeatureNotFoundException)2 File (java.io.File)2 ApiResponse (com.bluenimble.platform.api.ApiResponse)1 Status (com.bluenimble.platform.api.ApiResponse.Status)1 ApiService (com.bluenimble.platform.api.ApiService)1 ApiStreamSource (com.bluenimble.platform.api.ApiStreamSource)1 CodeExecutorException (com.bluenimble.platform.api.CodeExecutorException)1 DescribeOption (com.bluenimble.platform.api.DescribeOption)1