Search in sources :

Example 11 with ServerFeature

use of com.bluenimble.platform.server.ServerFeature in project serverless by bluenimble.

the class AbstractApiServer method addFeature.

@Override
public void addFeature(ServerFeature feature) {
    Feature aFeature = feature.type().getAnnotation(Feature.class);
    if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
        throw new FeatureNotFoundException("feature " + feature.type().getSimpleName() + " not registered in this instance");
    }
    features.put(aFeature.name() + FeatureProtocol + feature.provider(), feature);
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) Feature(com.bluenimble.platform.Feature) FeatureNotFoundException(com.bluenimble.platform.server.FeatureNotFoundException)

Example 12 with ServerFeature

use of com.bluenimble.platform.server.ServerFeature 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)

Aggregations

Feature (com.bluenimble.platform.Feature)12 ServerFeature (com.bluenimble.platform.server.ServerFeature)12 ApiSpace (com.bluenimble.platform.api.ApiSpace)10 JsonObject (com.bluenimble.platform.json.JsonObject)10 Plugin (com.bluenimble.platform.plugins.Plugin)10 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)9 PackageClassLoader (com.bluenimble.platform.PackageClassLoader)3 FeatureNotFoundException (com.bluenimble.platform.server.FeatureNotFoundException)2 File (java.io.File)2 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 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 Remote (com.bluenimble.platform.remote.Remote)1 HttpRemote (com.bluenimble.platform.remote.impls.http.HttpRemote)1