Search in sources :

Example 11 with Plugin

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();
    }
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) OrientDatabase(com.bluenimble.platform.plugins.database.orientdb.impls.OrientDatabase) JsonObject(com.bluenimble.platform.json.JsonObject) Feature(com.bluenimble.platform.Feature) ServerFeature(com.bluenimble.platform.server.ServerFeature) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 12 with Plugin

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();
        }
    });
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) JsonObject(com.bluenimble.platform.json.JsonObject) ServerFeature(com.bluenimble.platform.server.ServerFeature) Feature(com.bluenimble.platform.Feature) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 13 with Plugin

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;
}
Also used : JsonArray(com.bluenimble.platform.json.JsonArray) ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) DescribeOption(com.bluenimble.platform.api.DescribeOption) JsonObject(com.bluenimble.platform.json.JsonObject) DescribeOption(com.bluenimble.platform.api.DescribeOption) ServerFeature(com.bluenimble.platform.server.ServerFeature) Feature(com.bluenimble.platform.Feature) Plugin(com.bluenimble.platform.plugins.Plugin)

Example 14 with Plugin

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);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonObject(com.bluenimble.platform.json.JsonObject) File(java.io.File) FileInputStream(java.io.FileInputStream) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) IOException(java.io.IOException) Plugin(com.bluenimble.platform.plugins.Plugin)

Example 15 with Plugin

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());
    }
}
Also used : PackageClassLoader(com.bluenimble.platform.PackageClassLoader) IOException(java.io.IOException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) Plugin(com.bluenimble.platform.plugins.Plugin)

Aggregations

Plugin (com.bluenimble.platform.plugins.Plugin)15 JsonObject (com.bluenimble.platform.json.JsonObject)11 Feature (com.bluenimble.platform.Feature)10 ApiSpace (com.bluenimble.platform.api.ApiSpace)10 ServerFeature (com.bluenimble.platform.server.ServerFeature)10 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)9 PackageClassLoader (com.bluenimble.platform.PackageClassLoader)4 PluginRegistryException (com.bluenimble.platform.plugins.PluginRegistryException)3 File (java.io.File)3 IOException (java.io.IOException)3 DescribeOption (com.bluenimble.platform.api.DescribeOption)1 ScriptableApiServiceSpi (com.bluenimble.platform.api.impls.scripting.ScriptableApiServiceSpi)1 ScriptableApiSpi (com.bluenimble.platform.api.impls.scripting.ScriptableApiSpi)1 DefaultScriptingEngine (com.bluenimble.platform.api.scripting.impls.DefaultScriptingEngine)1 Tracer (com.bluenimble.platform.api.tracing.Tracer)1 MemCachedCache (com.bluenimble.platform.cache.impls.memcached.MemCachedCache)1 ElasticSearchIndexer (com.bluenimble.platform.indexer.impls.ElasticSearchIndexer)1 JsonArray (com.bluenimble.platform.json.JsonArray)1 MongoDatabaseImpl (com.bluenimble.platform.plugins.database.mongodb.impls.MongoDatabaseImpl)1 OrientDatabase (com.bluenimble.platform.plugins.database.orientdb.impls.OrientDatabase)1