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