Search in sources :

Example 41 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.

the class OrientDatabasePlugin method onEvent.

@Override
public void onEvent(Event event, Object target) throws PluginRegistryException {
    if (!ApiSpace.class.isAssignableFrom(target.getClass())) {
        return;
    }
    tracer().log(Tracer.Level.Info, "onEvent {0}, target {1}", event, target.getClass().getSimpleName());
    ApiSpace space = (ApiSpace) target;
    switch(event) {
        case Create:
            createPools(space);
            break;
        case AddFeature:
            // if it's database and provider is 'platform or orientdb' create factory
            createPools(space);
            break;
        case DeleteFeature:
            // if it's database and provider is 'platform or orientdb' stop factory
            dropPools(space);
            break;
        default:
            break;
    }
}
Also used : ApiSpace(com.bluenimble.platform.api.ApiSpace)

Example 42 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace 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 43 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace 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 44 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace 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 45 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.

the class FileSystemApiServer method drop.

@Override
public void drop(String spaceNs) throws ApiManagementException {
    if (Spaces.Sys.equals(spaceNs)) {
        throw new ApiManagementException("access denied");
    }
    ApiSpace space = space(spaceNs);
    if (space == null) {
        throw new ApiManagementException("space " + spaceNs + " not found");
    }
    ApiSpaceImpl spaceImpl = (ApiSpaceImpl) space;
    // stop space
    spaceImpl.stop();
    try {
        FileUtils.delete(spaceImpl.home());
    } catch (IOException e) {
        throw new ApiManagementException(e.getMessage(), e);
    }
}
Also used : ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiSpaceImpl(com.bluenimble.platform.api.impls.ApiSpaceImpl) IOException(java.io.IOException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException)

Aggregations

ApiSpace (com.bluenimble.platform.api.ApiSpace)48 JsonObject (com.bluenimble.platform.json.JsonObject)33 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)31 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)27 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)27 Feature (com.bluenimble.platform.Feature)10 Plugin (com.bluenimble.platform.plugins.Plugin)10 ServerFeature (com.bluenimble.platform.server.ServerFeature)10 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)9 Database (com.bluenimble.platform.db.Database)8 DatabaseException (com.bluenimble.platform.db.DatabaseException)8 Storage (com.bluenimble.platform.storage.Storage)6 StorageException (com.bluenimble.platform.storage.StorageException)6 StorageObject (com.bluenimble.platform.storage.StorageObject)6 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)5 KeyPair (com.bluenimble.platform.security.KeyPair)5 Api (com.bluenimble.platform.api.Api)4 DatabaseObject (com.bluenimble.platform.db.DatabaseObject)4 JsonArray (com.bluenimble.platform.json.JsonArray)4 PackageClassLoader (com.bluenimble.platform.PackageClassLoader)3