use of com.bluenimble.platform.plugins.PluginRegistryException 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.plugins.PluginRegistryException 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();
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class DefaultPluginsRegistry method install.
@Override
public void install(File file) throws PluginRegistryException {
long timestamp = file.lastModified();
server.tracer().log(Tracer.Level.Info, "\tInstall Plugin {0}", file.getName());
File home = null;
try {
if (file.isFile()) {
String folderName = file.getName().substring(0, file.getName().indexOf(ConfigKeys.PluginExt));
home = new File(file.getParent(), folderName);
InputStream bis = null;
try {
bis = new FileInputStream(file);
ArchiveUtils.decompress(bis, home);
} finally {
IOUtils.closeQuietly(bis);
}
FileUtils.delete(file);
} else {
home = file;
}
JsonObject descriptor = server.resolve(Json.load(new File(home, ConfigKeys.Descriptor.Plugin)));
String pluginName = Json.getString(descriptor, ConfigKeys.Name);
if (Lang.isNullOrEmpty(pluginName)) {
throw new PluginRegistryException("Plugin name not found in descriptor " + home.getAbsolutePath() + "\n" + descriptor);
}
if (!InstallUtils.isValidPluginNs(pluginName)) {
throw new PluginRegistryException("Invalid plugin name " + pluginName);
}
// set system properties
JsonObject sysprops = Json.getObject(descriptor, ConfigKeys.SystemProperties);
if (!Json.isNullOrEmpty(sysprops)) {
Iterator<String> props = sysprops.keys();
while (props.hasNext()) {
String p = props.next();
System.setProperty(p, sysprops.getString(p));
}
}
// load native libraries
boolean nativeLibsRegistered = registerLibrary(home);
if (!nativeLibsRegistered) {
throw new PluginRegistryException("native libraries required by plugin [" + pluginName + "] not found in [Plugin Home]/" + ConfigKeys.Native + Lang.SLASH + OsFamily + Lang.SLASH + OsArc);
}
// create plugin
Plugin plugin = create(pluginName, file, home, timestamp, descriptor);
plugins.put(pluginName, plugin);
if (plugin.isInitOnInstall()) {
_init(server, home, plugin);
}
} catch (PluginRegistryException ex) {
throw ex;
} catch (Exception ex) {
throw new PluginRegistryException(ex.getMessage(), ex);
}
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class DefaultPluginsRegistry method uninstall.
@Override
public void uninstall(Plugin plugin, boolean keepBinaries) throws PluginRegistryException {
ClassLoader serverClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(plugin.getClass().getClassLoader());
try {
plugin.kill();
} finally {
Thread.currentThread().setContextClassLoader(serverClassLoader);
}
if (plugin.isClosable()) {
try {
find(plugin.getName()).clear();
} catch (IOException e) {
server.tracer().log(Tracer.Level.Error, Lang.BLANK, e);
}
}
server.tracer().log(Tracer.Level.Info, "\tPlugin {0} destroyed", plugin.getName());
if (!keepBinaries) {
Plugin ph = plugins.get(plugin.getName());
try {
FileUtils.delete(ph.getHome());
} catch (IOException e) {
throw new PluginRegistryException(e.getMessage(), e);
}
server.tracer().log(Tracer.Level.Info, "\tPlugin {0} binaries deleted", plugin.getName());
}
}
Aggregations