Search in sources :

Example 1 with PluginRegistryException

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);
    }
}
Also used : ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 2 with PluginRegistryException

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);
}
Also used : ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 3 with PluginRegistryException

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());
}
Also used : IOException(java.io.IOException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 4 with PluginRegistryException

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);
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JsonObject(com.bluenimble.platform.json.JsonObject) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 5 with PluginRegistryException

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);
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronScheduleBuilder(org.quartz.CronScheduleBuilder) Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException) JobBuilder(org.quartz.JobBuilder) JsonObject(com.bluenimble.platform.json.JsonObject) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Aggregations

PluginRegistryException (com.bluenimble.platform.plugins.PluginRegistryException)14 JsonObject (com.bluenimble.platform.json.JsonObject)7 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)6 IOException (java.io.IOException)6 Plugin (com.bluenimble.platform.plugins.Plugin)3 File (java.io.File)3 SchedulerException (org.quartz.SchedulerException)2 PackageClassLoader (com.bluenimble.platform.PackageClassLoader)1 Api (com.bluenimble.platform.api.Api)1 ApiStatus (com.bluenimble.platform.api.ApiStatus)1 RemoteDataSource (com.bluenimble.platform.datasource.RemoteDataSource)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 FileFilter (java.io.FileFilter)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 DataSource (javax.sql.DataSource)1 ConnectionFactoryBuilder (net.spy.memcached.ConnectionFactoryBuilder)1 MemcachedClient (net.spy.memcached.MemcachedClient)1 AuthDescriptor (net.spy.memcached.auth.AuthDescriptor)1