use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class FileSystemApiServer method stop.
@Override
public void stop() {
tracer.log(Tracer.Level.Info, "Shutting down BlueNimble Node");
Collection<ApiSpace> spaces = spaces();
if (spaces != null) {
for (ApiSpace space : spaces) {
((ApiSpaceImpl) space).shutdown();
}
}
if (pluginsRegistry != null) {
pluginsRegistry.shutdown();
}
if (keyStoreManager != null) {
keyStoreManager.stop();
}
tracer.onShutdown(this);
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class ElasticSearchPlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Indexer.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = -9012279234275100528L;
@Override
public Class<?> type() {
return Indexer.class;
}
@Override
public Object get(ApiSpace space, String name) {
String remotePluginName = Json.getString(remote, Spec.RemotePlugin);
String remoteObjectId = Json.getString(remote, Spec.RemoteObject);
if (Lang.isNullOrEmpty(remotePluginName) || Lang.isNullOrEmpty(remoteObjectId)) {
return null;
}
Plugin pRemote = server.getPluginsRegistry().lockup(Json.getString(remote, Spec.RemotePlugin));
if (pRemote == null) {
return null;
}
PackageClassLoader pcl = (PackageClassLoader) pRemote.getClass().getClassLoader();
Remote iRemote = (Remote) pcl.lookupObject(Json.getString(remote, Spec.RemoteObject));
if (iRemote == null) {
return null;
}
// build basic auth and url
String token = buildAuthToken(space, name);
if (Lang.isNullOrEmpty(token)) {
return null;
}
String url = buildUrl(space, name);
if (Lang.isNullOrEmpty(url)) {
return null;
}
return new ElasticSearchIndexer(iRemote, url, token, tracer());
}
@Override
public String provider() {
return ElasticSearchPlugin.this.getName();
}
@Override
public Plugin implementor() {
return ElasticSearchPlugin.this;
}
});
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class DataSourcePlugin 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:
createDataSources(space);
break;
case AddFeature:
createDataSources(space);
break;
case DeleteFeature:
dropDataSources(space);
break;
default:
break;
}
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class ImportDatabaseSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String[] aEntities = Lang.split((String) request.get(Spec.Entities), Lang.COMMA, true);
Set<String> entities = null;
if (aEntities != null && aEntities.length > 0) {
entities = new HashSet<String>();
for (String entity : aEntities) {
entities.add(entity.toUpperCase());
}
}
String[] aOptions = Lang.split((String) request.get(Spec.Options), Lang.COMMA, true);
Map<ExchangeOption, Boolean> options = null;
if (aOptions != null && aOptions.length > 0) {
for (String o : aOptions) {
try {
options.put(ExchangeOption.valueOf(o.toLowerCase()), true);
} catch (Exception ex) {
// ignore malformed options
}
}
}
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
String file = (String) request.get(Spec.File);
JsonObject result = new JsonObject();
result.set(Spec.File, file);
final StringBuilder sb = new StringBuilder();
try {
space.feature(Database.class, provider, request).imp(entities, space.feature(Storage.class, provider, request).root().get(file).reader(request), options, new Database.ExchangeListener() {
@Override
public void onMessage(String message) {
sb.append(message).append(Lang.ENDLN);
}
});
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
result.set(Output.Feedback, sb.toString());
sb.setLength(0);
return new JsonApiOutput(result);
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class QueryEntitySpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
String serializer = (String) request.get(CommonSpec.Serializer);
String[] levels = Lang.split(serializer, Lang.COMMA);
int allStopLevel = 2;
if (levels != null && levels.length > 0) {
try {
allStopLevel = Integer.valueOf(levels[0]);
} catch (Exception ex) {
}
}
int minStopLevel = 3;
if (levels != null && levels.length > 0) {
try {
minStopLevel = Integer.valueOf(levels[1]);
} catch (Exception ex) {
}
}
JsonObject payload = (JsonObject) request.get(ApiRequest.Payload);
payload.set(Database.Fields.Entity, sEntity);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
List<DatabaseObject> records = null;
try {
Database db = space.feature(Database.class, provider, request);
records = db.find(null, new JsonQuery(payload), null);
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
JsonObject result = new JsonObject();
JsonArray aRecords = new JsonArray();
result.set(Output.Records, aRecords);
if (records == null || records.isEmpty()) {
return new JsonApiOutput(result);
}
for (int i = 0; i < records.size(); i++) {
aRecords.add(records.get(i).toJson(new DefaultDatabaseObjectSerializer(allStopLevel, minStopLevel)));
}
return new JsonApiOutput(result);
}
Aggregations