use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class ApiSpaceImpl method stop.
@Override
public void stop(String apiNs) throws ApiManagementException {
ApiImpl api = (ApiImpl) api(apiNs);
if (api == null) {
throw new ApiManagementException("api " + apiNs + " not found");
}
if (!ApiStatus.Running.equals(api.status())) {
throw new ApiManagementException("can't stop api " + apiNs + ". Status=" + api.status());
}
// notify plugins
try {
server.getPluginsRegistry().onEvent(Event.Stop, api);
} catch (PluginRegistryException e) {
throw new ApiManagementException(e.getMessage(), e);
}
// stop api
api.stop(true);
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class ApiSpaceImpl method uninstall.
/*
@Override
public Api install (JsonObject descriptor) throws ApiManagementException {
if (Lang.isNullOrEmpty (getNamespace ())) {
throw new ApiManagementException (
"Api " + Api.Spec.Namespace + " not found in descriptor "
);
}
// create api home
File apiHome = new File (home, getNamespace () + Lang.UNDERSCORE + Lang.UUID (40));
return install (apiHome, descriptor);
}
*/
@Override
public void uninstall(String apiNs) throws ApiManagementException {
if (Lang.isNullOrEmpty(apiNs)) {
throw new ApiManagementException("api namespace is null or empty");
}
ApiImpl api = (ApiImpl) api(apiNs.trim());
if (api == null) {
throw new ApiManagementException("api '" + apiNs + "' not found");
}
// notify before uninstall
try {
server.getPluginsRegistry().onEvent(Event.Uninstall, api);
} catch (PluginRegistryException e) {
throw new ApiManagementException(e.getMessage(), e);
}
// stop api
if (!api.status().equals(ApiStatus.Stopped)) {
api.stop(false);
}
// remove status
statusManager.delete(api);
// clear memory
api.clear();
try {
FileUtils.delete(((ApiImpl) api).getHome());
} catch (IOException e) {
throw new ApiManagementException(e.getMessage(), e);
}
remove(apiNs);
tracer.log(Tracer.Level.Info, "\tApi [{0}] uninstalled", api.getNamespace());
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class MemCachedPlugin method createClients.
private void createClients(ApiSpace space) throws PluginRegistryException {
// create sessions
JsonObject msgFeature = Json.getObject(space.getFeatures(), feature);
if (msgFeature == null || msgFeature.isEmpty()) {
return;
}
Iterator<String> keys = msgFeature.keys();
while (keys.hasNext()) {
String key = keys.next();
JsonObject feature = Json.getObject(msgFeature, key);
if (!this.getName().equalsIgnoreCase(Json.getString(feature, ApiSpace.Features.Provider))) {
continue;
}
String sessionKey = createKey(key);
if (space.containsRecyclable(sessionKey)) {
continue;
}
JsonObject spec = Json.getObject(feature, ApiSpace.Features.Spec);
String[] nodes = Lang.split(Json.getString(spec, Spec.Cluster), Lang.COMMA);
if (nodes == null) {
continue;
}
final JsonObject oAuth = Json.getObject(spec, Spec.Auth);
if (oAuth == null || oAuth.isEmpty()) {
continue;
}
final String user = Json.getString(oAuth, Spec.User);
final String password = Json.getString(oAuth, Spec.Password);
AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" }, new PlainCallbackHandler(user, password));
try {
MemcachedClient client = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setAuthDescriptor(ad).build(), AddrUtil.getAddresses(Arrays.asList(nodes)));
space.addRecyclable(sessionKey, new RecyclableCacheClient(client));
} catch (IOException e) {
throw new PluginRegistryException(e.getMessage(), e);
}
}
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class DataSourcePlugin method createDataSource.
private DataSource createDataSource(String name, ApiSpace space, JsonObject spec) throws PluginRegistryException {
String dataSourceKey = dataSourceKey(name, space);
tracer().log(Tracer.Level.Info, "Create datasource {0}", dataSourceKey);
if (space.containsRecyclable(dataSourceKey)) {
return null;
}
String sVendor = Json.getString(spec, Spec.Vendor);
tracer().log(Tracer.Level.Info, "\tDS Vendor {0}", sVendor);
DataSourceVendor vendor = vendors.get(sVendor);
if (vendor == null) {
File vendorHome = new File(home, Vendors + Lang.SLASH + sVendor);
if (vendorHome.exists()) {
try {
vendor = new DataSourceVendor(vendorHome);
} catch (Exception e) {
throw new PluginRegistryException(e.getMessage(), e);
}
vendors.put(sVendor, vendor);
}
}
tracer().log(Tracer.Level.Info, "\tDS Vendor Instance {0}", vendor);
if (vendor == null) {
return null;
}
DataSource datasource = null;
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(vendor.classLoader());
try {
HikariConfig config = new HikariConfig();
config.setPoolName(dataSourceKey);
config.setDriverClassName(vendor.driver());
config.setJdbcUrl(vendor.url(Json.getString(spec, Spec.Host), Json.getInteger(spec, Spec.Port, 0), Json.getString(spec, Spec.Database)));
config.setUsername(Json.getString(spec, Spec.User));
config.setPassword(Json.getString(spec, Spec.Password));
config.setAutoCommit(false);
config.setMaximumPoolSize(weight);
JsonObject props = Json.getObject(spec, Spec.Properties);
if (!Json.isNullOrEmpty(props)) {
Iterator<String> keys = props.keys();
while (keys.hasNext()) {
String key = keys.next();
config.addDataSourceProperty(key, props.get(key));
}
}
datasource = new HikariDataSource(config);
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
tracer().log(Tracer.Level.Info, "\tSpace DataSource {0}", datasource);
space.addRecyclable(dataSourceKey, new RecyclableDataSource(datasource));
space.addRecyclable(factoryKey(name, space), new RecyclableEntityManagerFactory(null));
return datasource;
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class ApiSpaceImpl method addFeature.
@Override
public void addFeature(String name, String feature, String provider, JsonObject spec) throws ApiManagementException {
feature = feature.toLowerCase();
provider = provider.toLowerCase();
tracer.log(Tracer.Level.Info, "add feature [{0}] -> [{1} / provider {2}] ", name, feature, provider);
JsonObject oFeature = Json.getObject(getFeatures(), feature);
if (oFeature == null) {
oFeature = new JsonObject();
getFeatures().set(feature, oFeature);
}
if (oFeature.containsKey(name)) {
throw new ApiManagementException("feature '" + feature + "/" + name + "/" + provider + "' already available for space " + getNamespace());
}
JsonObject uFeature = new JsonObject();
uFeature.set(ApiSpace.Features.Provider, provider).set(ApiSpace.Features.Spec, spec);
oFeature.set(name, uFeature);
try {
server.getPluginsRegistry().onEvent(Event.AddFeature, this);
} catch (PluginRegistryException e) {
throw new ApiManagementException(e.getMessage(), e);
}
// save
save();
}
Aggregations