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;
}
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;
}
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;
}
Aggregations