Search in sources :

Example 11 with PluginRegistryException

use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.

the class ApiSpaceImpl method install.

public Api install(File apiHome) throws ApiManagementException {
    Api api = new ApiImpl(this, apiHome);
    // stop any existing version of the api
    ApiImpl old = (ApiImpl) api(api.getNamespace());
    if (old != null) {
        if (old.status().equals(ApiStatus.Running) || old.status().equals(ApiStatus.Paused)) {
            // clear memory
            old.stop(false);
        }
        // clear memory
        old.clear();
        // remove status
        statusManager.delete(old);
    }
    // register api
    register(api);
    tracer.log(Tracer.Level.Info, "api {0} / {1} installed", getNamespace(), api.getNamespace());
    // call plugins onEvent Install
    try {
        server.getPluginsRegistry().onEvent(Event.Install, api);
    } catch (PluginRegistryException e) {
        throw new ApiManagementException(e.getMessage(), e);
    }
    // get api status if any
    ApiStatus status = statusManager.get(api);
    tracer.log(Tracer.Level.Info, "\t\tfound with status {0}", status);
    if (ApiStatus.Running.equals(status) || ApiStatus.Paused.equals(status)) {
        // start api
        ((ApiImpl) api).start(ApiStatus.Paused.equals(api.status()));
        // notify plugins
        try {
            server.getPluginsRegistry().onEvent(Event.Start, api);
        } catch (PluginRegistryException e) {
            throw new ApiManagementException(e.getMessage(), e);
        }
    }
    return api;
}
Also used : ApiStatus(com.bluenimble.platform.api.ApiStatus) Api(com.bluenimble.platform.api.Api) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 12 with PluginRegistryException

use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.

the class ApiSpaceImpl method deleteFeature.

@Override
public void deleteFeature(String name, String feature) throws ApiManagementException {
    JsonObject oFeature = Json.getObject(getFeatures(), feature);
    if (oFeature == null || !oFeature.containsKey(name)) {
        throw new ApiManagementException("feature '" + feature + "/" + name + "' not available for space " + getNamespace());
    }
    oFeature.remove(name);
    try {
        server.getPluginsRegistry().onEvent(Event.DeleteFeature, this);
    } catch (PluginRegistryException e) {
        throw new ApiManagementException(e.getMessage(), e);
    }
    // save
    save();
}
Also used : JsonObject(com.bluenimble.platform.json.JsonObject) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException)

Example 13 with PluginRegistryException

use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.

the class DefaultPluginsRegistry method install.

@Override
public void install(File file) throws PluginRegistryException {
    long timestamp = file.lastModified();
    server.tracer().log(Tracer.Level.Info, "\tInstall Plugin {0}", file.getName());
    File home = null;
    try {
        if (file.isFile()) {
            String folderName = file.getName().substring(0, file.getName().indexOf(ConfigKeys.PluginExt));
            home = new File(file.getParent(), folderName);
            InputStream bis = null;
            try {
                bis = new FileInputStream(file);
                ArchiveUtils.decompress(bis, home);
            } finally {
                IOUtils.closeQuietly(bis);
            }
            FileUtils.delete(file);
        } else {
            home = file;
        }
        JsonObject descriptor = server.resolve(Json.load(new File(home, ConfigKeys.Descriptor.Plugin)));
        String pluginName = Json.getString(descriptor, ConfigKeys.Name);
        if (Lang.isNullOrEmpty(pluginName)) {
            throw new PluginRegistryException("Plugin name not found in descriptor " + home.getAbsolutePath() + "\n" + descriptor);
        }
        if (!InstallUtils.isValidPluginNs(pluginName)) {
            throw new PluginRegistryException("Invalid plugin name " + pluginName);
        }
        // set system properties
        JsonObject sysprops = Json.getObject(descriptor, ConfigKeys.SystemProperties);
        if (!Json.isNullOrEmpty(sysprops)) {
            Iterator<String> props = sysprops.keys();
            while (props.hasNext()) {
                String p = props.next();
                System.setProperty(p, sysprops.getString(p));
            }
        }
        // load native libraries
        boolean nativeLibsRegistered = registerLibrary(home);
        if (!nativeLibsRegistered) {
            throw new PluginRegistryException("native libraries required by plugin [" + pluginName + "] not found in [Plugin Home]/" + ConfigKeys.Native + Lang.SLASH + OsFamily + Lang.SLASH + OsArc);
        }
        // create plugin
        Plugin plugin = create(pluginName, file, home, timestamp, descriptor);
        plugins.put(pluginName, plugin);
        if (plugin.isInitOnInstall()) {
            _init(server, home, plugin);
        }
    } catch (PluginRegistryException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new PluginRegistryException(ex.getMessage(), ex);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonObject(com.bluenimble.platform.json.JsonObject) File(java.io.File) FileInputStream(java.io.FileInputStream) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) IOException(java.io.IOException) Plugin(com.bluenimble.platform.plugins.Plugin)

Example 14 with PluginRegistryException

use of com.bluenimble.platform.plugins.PluginRegistryException in project serverless by bluenimble.

the class DefaultPluginsRegistry method uninstall.

@Override
public void uninstall(Plugin plugin, boolean keepBinaries) throws PluginRegistryException {
    ClassLoader serverClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(plugin.getClass().getClassLoader());
    try {
        plugin.kill();
    } finally {
        Thread.currentThread().setContextClassLoader(serverClassLoader);
    }
    if (plugin.isClosable()) {
        try {
            find(plugin.getName()).clear();
        } catch (IOException e) {
            server.tracer().log(Tracer.Level.Error, Lang.BLANK, e);
        }
    }
    server.tracer().log(Tracer.Level.Info, "\tPlugin {0} destroyed", plugin.getName());
    if (!keepBinaries) {
        Plugin ph = plugins.get(plugin.getName());
        try {
            FileUtils.delete(ph.getHome());
        } catch (IOException e) {
            throw new PluginRegistryException(e.getMessage(), e);
        }
        server.tracer().log(Tracer.Level.Info, "\tPlugin {0} binaries deleted", plugin.getName());
    }
}
Also used : PackageClassLoader(com.bluenimble.platform.PackageClassLoader) IOException(java.io.IOException) PluginRegistryException(com.bluenimble.platform.plugins.PluginRegistryException) Plugin(com.bluenimble.platform.plugins.Plugin)

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