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.");
}
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()]));
}
}
}
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);
}
}
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();
}
Aggregations