use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class ApiSpaceImpl method start.
@Override
public void start(String apiNs) throws ApiManagementException {
ApiImpl api = (ApiImpl) api(apiNs);
if (api == null) {
throw new ApiManagementException("api " + apiNs + " not found");
}
if (ApiStatus.Failed.equals(api.status())) {
throw new ApiManagementException("can't start api " + apiNs + ". Status=" + api.status());
}
if (ApiStatus.Running.equals(api.status())) {
return;
}
if (ApiStatus.Paused.equals(api.status())) {
api.setStatus(ApiStatus.Running, true);
return;
}
// start api
api.start(false);
// notify plugins
try {
server.getPluginsRegistry().onEvent(Event.Start, api);
} catch (PluginRegistryException e) {
throw new ApiManagementException(e.getMessage(), e);
}
}
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 SchedulerPlugin method stopJobs.
private void stopJobs(ApiSpace space) throws PluginRegistryException {
JsonObject schedulerFeature = Json.getObject(space.getFeatures(), feature);
if (schedulerFeature == null || schedulerFeature.isEmpty()) {
return;
}
Iterator<String> keys = schedulerFeature.keys();
while (keys.hasNext()) {
String key = keys.next();
JsonObject source = Json.getObject(schedulerFeature, key);
if (!this.getName().equalsIgnoreCase(Json.getString(source, ApiSpace.Features.Provider))) {
continue;
}
JsonObject spec = Json.getObject(source, ApiSpace.Features.Spec);
if (spec == null) {
continue;
}
String id = space.getNamespace() + Lang.DASH + key;
try {
oScheduler.deleteJob(jobKey(Prefix.Job + id, Prefix.Group + id));
} catch (SchedulerException e) {
throw new PluginRegistryException(e.getMessage(), e);
}
}
}
use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.
the class SchedulerPlugin method startJobs.
private void startJobs(ApiSpace space) throws PluginRegistryException {
JsonObject schedulerFeature = Json.getObject(space.getFeatures(), feature);
if (schedulerFeature == null || schedulerFeature.isEmpty()) {
return;
}
Iterator<String> keys = schedulerFeature.keys();
while (keys.hasNext()) {
String key = keys.next();
JsonObject source = Json.getObject(schedulerFeature, key);
if (!this.getName().equalsIgnoreCase(Json.getString(source, ApiSpace.Features.Provider))) {
continue;
}
JsonObject spec = Json.getObject(source, ApiSpace.Features.Spec);
if (spec == null) {
continue;
}
String expression = Json.getString(source, Spec.Expression);
if (Lang.isNullOrEmpty(expression)) {
continue;
}
String api = Json.getString(source, Spec.Api);
if (Lang.isNullOrEmpty(api)) {
continue;
}
String service = Json.getString(source, Spec.Service);
if (Lang.isNullOrEmpty(service)) {
continue;
}
String id = space.getNamespace() + Lang.DASH + key;
JobBuilder builder = newJob(ServiceJob.class).withIdentity(Prefix.Job + id, Prefix.Group + id);
builder.usingJobData(_Space, space.getNamespace());
builder.usingJobData(_Api, api);
builder.usingJobData(_Service, service);
JsonObject data = Json.getObject(spec, Spec.Data);
if (!Json.isNullOrEmpty(data)) {
Iterator<String> dataKeys = data.keys();
while (dataKeys.hasNext()) {
String dataKey = dataKeys.next();
builder.usingJobData(dataKey, String.valueOf(data.get(dataKey)));
}
}
JobDetail job = builder.build();
String timeZone = Json.getString(source, Spec.TimeZone);
CronScheduleBuilder csb = cronSchedule(Json.getString(source, Spec.Expression));
if (!Lang.isNullOrEmpty(timeZone)) {
csb.inTimeZone(TimeZone.getTimeZone(timeZone));
}
Trigger trigger = newTrigger().withIdentity(Prefix.Trigger + id, Prefix.Group + id).withSchedule(csb).forJob(job.getKey()).build();
try {
oScheduler.scheduleJob(trigger);
} catch (SchedulerException e) {
throw new PluginRegistryException(e.getMessage(), e);
}
}
}
Aggregations