Search in sources :

Example 1 with ApiStatus

use of com.bluenimble.platform.api.ApiStatus 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 2 with ApiStatus

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

the class DefaultStatusManager method get.

@Override
public ApiStatus get(Api api) {
    if (status == null) {
        return null;
    }
    JsonObject oApi = Json.getObject(status, api.getNamespace());
    if (Json.isNullOrEmpty(oApi)) {
        return null;
    }
    String sStatus = Json.getString(oApi, Spec.Status);
    if (Lang.isNullOrEmpty(sStatus)) {
        return null;
    }
    ApiStatus apiStatus = null;
    try {
        apiStatus = ApiStatus.valueOf(sStatus);
    } catch (Exception ex) {
    // ignore
    }
    return apiStatus;
}
Also used : ApiStatus(com.bluenimble.platform.api.ApiStatus) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 3 with ApiStatus

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

the class DefaultStatusManager method get.

@Override
public ApiStatus get(Api api, ApiService service) {
    String sStatus = (String) Json.find(status, api.getNamespace(), Spec.Services, service.getVerb().name() + Json.getString(service.toJson(), ApiService.Spec.Endpoint));
    if (Lang.isNullOrEmpty(sStatus)) {
        return null;
    }
    ApiStatus status = null;
    try {
        status = ApiStatus.valueOf(sStatus);
    } catch (Exception ex) {
    // ignore
    }
    return status;
}
Also used : ApiStatus(com.bluenimble.platform.api.ApiStatus)

Aggregations

ApiStatus (com.bluenimble.platform.api.ApiStatus)3 Api (com.bluenimble.platform.api.Api)1 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 PluginRegistryException (com.bluenimble.platform.plugins.PluginRegistryException)1