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