Search in sources :

Example 1 with PluginLoadingException

use of alien4cloud.plugin.exception.PluginLoadingException in project alien4cloud by alien4cloud.

the class PluginManager method isPluginConfigurable.

/**
 * Return true if the plugin can be configured using a configuration object (basically if the plugin spring context contains an instance of
 * {@link IPluginConfigurator}.
 *
 * @param pluginId Id of the plugin for which to know if configurable.
 * @return True if the plugin can be configured, false if not.
 */
public boolean isPluginConfigurable(String pluginId) throws PluginLoadingException {
    if (pluginContexts.containsKey(pluginId)) {
        AnnotationConfigApplicationContext pluginContext = pluginContexts.get(pluginId).getPluginContext();
        Map<String, IPluginConfigurator> configurators = pluginContext.getBeansOfType(IPluginConfigurator.class);
        return MapUtils.isNotEmpty(configurators);
    }
    throw new PluginLoadingException("Failed to get plugin configuration for <" + pluginId + "> since it is not yet loaded.");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException)

Example 2 with PluginLoadingException

use of alien4cloud.plugin.exception.PluginLoadingException in project alien4cloud by alien4cloud.

the class PluginManager method loadPlugins.

/**
 * Load all the plugins that have their dependencies fulfilled by loaded plugin.
 *
 * @param plugins the plugins to load.
 */
private void loadPlugins(Plugin[] plugins) {
    List<Plugin> missingDependencyPlugins = Lists.newArrayList();
    for (Plugin plugin : plugins) {
        // if the plugin has no unresolved dependency, load it
        if (getMissingDependencies(plugin).size() == 0) {
            try {
                loadPlugin(plugin);
            } catch (PluginLoadingException e) {
                log.error("Alien server Initialization: failed to load plugin <" + plugin.getId() + ">", e);
                disablePlugin(plugin.getId());
            }
        } else {
            missingDependencyPlugins.add(plugin);
        }
    }
    if (missingDependencyPlugins.size() == plugins.length) {
        // No plugins have been loaded meaning that remaining plugins are not loadable because some dependencies are missing
        for (Plugin plugin : plugins) {
            log.error("Failed to load plugin <" + plugin.getId() + "> as some dependencies are missing <" + getMissingDependencies(plugin) + ">");
            disablePlugin(plugin.getId());
        }
    } else {
        if (missingDependencyPlugins.size() > 0) {
            loadPlugins(missingDependencyPlugins.toArray(new Plugin[missingDependencyPlugins.size()]));
        }
    }
}
Also used : PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException) ManagedPlugin(alien4cloud.plugin.model.ManagedPlugin)

Example 3 with PluginLoadingException

use of alien4cloud.plugin.exception.PluginLoadingException in project alien4cloud by alien4cloud.

the class PluginManager method loadPlugin.

private void loadPlugin(Plugin plugin) throws PluginLoadingException {
    if (pluginContexts.containsKey(plugin.getId())) {
        log.debug("Do not load plugin {} as it is already loaded.", plugin.getId());
        return;
    }
    try {
        Path pluginPath = getPluginPath(plugin.getPluginPathId());
        Path pluginUiPath = getPluginUiPath(plugin.getPluginPathId());
        loadPlugin(plugin, pluginPath, pluginUiPath);
    } catch (Exception e) {
        log.error("Failed to load plugin <" + plugin.getId() + ">. Alien will not enable this plugin.", e);
        throw new PluginLoadingException("Failed to load plugin [ " + plugin.getId() + " ]. " + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException) NoSuchFileException(java.nio.file.NoSuchFileException) MissingPlugingDescriptorFileException(alien4cloud.plugin.exception.MissingPlugingDescriptorFileException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NotFoundException(alien4cloud.exception.NotFoundException) IOException(java.io.IOException) PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException)

Example 4 with PluginLoadingException

use of alien4cloud.plugin.exception.PluginLoadingException in project alien4cloud by alien4cloud.

the class PluginController method upload.

@ApiOperation(value = "Upload a plugin archive.", notes = "Content of the zip file must be compliant with the expected alien 4 cloud plugin structure.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<Void> upload(@ApiParam(value = "Zip file that contains the plugin.", required = true) @RequestParam("file") MultipartFile pluginArchive) {
    Path pluginPath = null;
    try {
        // save the plugin archive in the temp directory
        pluginPath = Files.createTempFile(tempDirPath, null, ".zip");
        FileUploadUtil.safeTransferTo(pluginPath, pluginArchive);
        // upload the plugin archive
        Plugin plugin = pluginManager.uploadPlugin(pluginPath);
        // TODO as we do not manage many version of a same plugin, is this still relevant ?
        if (plugin.isConfigurable()) {
            tryReusePreviousVersionConf(plugin);
        }
    } catch (MissingPlugingDescriptorFileException e) {
        log.error("Your plugin don't have the META-INF/plugin.yml file.", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.MISSING_PLUGIN_DESCRIPTOR_FILE_EXCEPTION.getCode(), "Your plugin don't have the META-INF/plugin.yml file.")).build();
    } catch (IOException e) {
        log.error("Unexpected IO error on plugin upload.", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.INDEXING_SERVICE_ERROR.getCode(), "A technical issue occurred during the plugin upload <" + e.getMessage() + ">.")).build();
    } catch (PluginLoadingException e) {
        log.error("Fail to enable and load the plugin. The plugin will remain disabled", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.ENABLE_PLUGIN_ERROR.getCode(), e.getMessage())).build();
    } finally {
        if (pluginPath != null) {
            try {
                FileUtil.delete(pluginPath);
            } catch (IOException e) {
                log.error("Failed to cleanup temporary file <" + pluginPath.toString() + ">", e);
            }
        }
    }
    return RestResponseBuilder.<Void>builder().build();
}
Also used : Path(java.nio.file.Path) PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException) RestError(alien4cloud.rest.model.RestError) IOException(java.io.IOException) Plugin(alien4cloud.plugin.Plugin) MissingPlugingDescriptorFileException(alien4cloud.plugin.exception.MissingPlugingDescriptorFileException) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PluginLoadingException (alien4cloud.plugin.exception.PluginLoadingException)4 MissingPlugingDescriptorFileException (alien4cloud.plugin.exception.MissingPlugingDescriptorFileException)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Audit (alien4cloud.audit.annotation.Audit)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Plugin (alien4cloud.plugin.Plugin)1 ManagedPlugin (alien4cloud.plugin.model.ManagedPlugin)1 RestError (alien4cloud.rest.model.RestError)1 ApiOperation (io.swagger.annotations.ApiOperation)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1