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;
}
}
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();
}
}
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();
}
});
}
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;
}
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);
}
}
Aggregations