use of com.bluenimble.platform.Feature 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.Feature 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);
}
use of com.bluenimble.platform.Feature 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;
}
Aggregations