use of com.bluenimble.platform.plugins.Plugin in project serverless by bluenimble.
the class OrientDatabasePlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
weight = server.weight();
Feature aFeature = Database.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
// add features
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 2626039344401539390L;
@Override
public Class<?> type() {
return Database.class;
}
@Override
public Object get(ApiSpace space, String name) {
return new OrientDatabase(OrientDatabasePlugin.this.acquire(space, name), tracer());
}
@Override
public Plugin implementor() {
return OrientDatabasePlugin.this;
}
@Override
public String provider() {
return OrientDatabasePlugin.this.getName();
}
});
if (Orient.instance() != null) {
Orient.instance().removeShutdownHook();
}
}
use of com.bluenimble.platform.plugins.Plugin in project serverless by bluenimble.
the class DataSourcePlugin method init.
@Override
public void init(ApiServer server) throws Exception {
weight = server.weight();
Feature aFeature = RemoteDataSource.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
// add features
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 2626039344401539390L;
@Override
public Class<?> type() {
return RemoteDataSource.class;
}
@Override
public Object get(ApiSpace space, String name) {
// get registered factory and create an EntityManager instance
return entityManager(space, name);
}
@Override
public Plugin implementor() {
return DataSourcePlugin.this;
}
@Override
public String provider() {
return DataSourcePlugin.this.getName();
}
});
}
use of com.bluenimble.platform.plugins.Plugin in project serverless by bluenimble.
the class AbstractApiServer method describe.
@Override
public JsonObject describe(DescribeOption... options) {
if (options == null || options.length == 0) {
return JsonObject.Blank;
}
Map<DescribeOption.Option, DescribeOption> opts = DescribeUtils.toMap(options);
JsonObject describe = new JsonObject();
if (opts.containsKey(DescribeOption.Option.info)) {
describe.set(ConfigKeys.Name, Json.getString(descriptor, ConfigKeys.Name));
describe.set(ConfigKeys.Description, Json.getString(descriptor, ConfigKeys.Description));
describe.set(ConfigKeys.Version, Json.getString(descriptor, ConfigKeys.Version));
}
if (opts.containsKey(DescribeOption.Option.keys)) {
JsonObject okeys = keys.toJson().duplicate();
okeys.remove(KeyPair.Fields.SecretKey);
describe.set(DescribeOption.Option.keys.name(), okeys);
}
if (instanceDescriber != null && opts.containsKey(DescribeOption.Option.hardware)) {
describe.set(DescribeOption.Option.hardware.name(), instanceDescriber.describe());
}
// plugins
if (opts.containsKey(DescribeOption.Option.plugins)) {
JsonArray aPlugins = new JsonArray();
describe.set(DescribeOption.Option.plugins.name(), aPlugins);
Iterator<String> pNames = pluginsRegistry.getNames();
while (pNames.hasNext()) {
String pName = pNames.next();
Plugin plugin = pluginsRegistry.lockup(pName);
JsonObject oPlugin = new JsonObject();
oPlugin.set(ConfigKeys.Namespace, plugin.getName());
oPlugin.set(ConfigKeys.Name, plugin.getTitle());
oPlugin.set(ConfigKeys.Description, plugin.getDescription());
oPlugin.set(ConfigKeys.Version, plugin.getVersion());
oPlugin.set(ConfigKeys.Vendor, plugin.getVendor());
aPlugins.add(oPlugin);
}
}
// features
if (opts.containsKey(DescribeOption.Option.features)) {
JsonObject oFeatures = new JsonObject();
describe.set(DescribeOption.Option.features.name(), oFeatures);
for (ServerFeature feature : features.values()) {
String name = feature.type().getAnnotation(Feature.class).name();
JsonArray aVendors = Json.getArray(oFeatures, name);
if (aVendors == null) {
aVendors = new JsonArray();
oFeatures.set(name, aVendors);
}
JsonObject oVendor = new JsonObject();
oVendor.set(Describe.Vendor, feature.implementor().getVendor());
aVendors.add(oVendor);
}
}
// spaces
if (opts.containsKey(DescribeOption.Option.spaces)) {
Collection<ApiSpace> spaces = spaces();
if (spaces != null && !spaces.isEmpty()) {
JsonArray aSpaces = new JsonArray();
describe.set(DescribeOption.Option.spaces.name(), aSpaces);
for (ApiSpace space : spaces) {
aSpaces.add(space.describe(options));
}
}
}
return describe;
}
use of com.bluenimble.platform.plugins.Plugin 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.Plugin 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