use of alien4cloud.plugin.Plugin 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();
}
use of alien4cloud.plugin.Plugin in project alien4cloud by alien4cloud.
the class PluginController method tryReusePreviousVersionConf.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void tryReusePreviousVersionConf(Plugin plugin) {
// search for a previous version
// TODO manage the case there are many previous versions
QueryBuilder macthNameQuerybuilder = QueryBuilders.matchQuery("descriptor.id", plugin.getDescriptor().getId());
QueryBuilder idQueryBuilder = QueryBuilders.idsQuery(MappingBuilder.indexTypeFromClass(Plugin.class)).ids(plugin.getId());
QueryBuilder boolQuery = QueryBuilders.boolQuery().must(macthNameQuerybuilder).mustNot(idQueryBuilder);
Plugin oldVersionPlugin = alienDAO.customFind(Plugin.class, boolQuery);
if (oldVersionPlugin != null && oldVersionPlugin.isConfigurable()) {
// get the configuration type
Class<?> configType = pluginManager.getConfigurationType(plugin.getId());
PluginConfiguration oldPluginConf = alienDAO.findById(PluginConfiguration.class, oldVersionPlugin.getId());
// try to de-serialize it into the config of the new version
if (oldPluginConf != null && oldPluginConf.getConfiguration() != null) {
try {
Object configObject = JsonUtil.readObject(JsonUtil.toString(oldPluginConf.getConfiguration()), configType);
IPluginConfigurator configurator = pluginManager.getConfiguratorFor(plugin.getId());
configurator.setConfiguration(configObject);
PluginConfiguration pluginConf = new PluginConfiguration(plugin.getId(), configObject);
alienDAO.save(pluginConf);
} catch (IOException e) {
log.warn("Plugin [" + plugin.getId() + "]: Failed to re-use the configuration of the previous version " + oldVersionPlugin.getId() + ". The configuration beans are not comptible", e);
} catch (PluginConfigurationException e) {
log.warn("Plugin [" + plugin.getId() + "]: Failed to re-use the configuration of the previous version " + oldVersionPlugin.getId() + ". Error while applying the configuration", e);
}
}
}
}
use of alien4cloud.plugin.Plugin in project alien4cloud by alien4cloud.
the class UiController method modules.
/**
* Get the list of modules to be loaded.
*
* @return The list of modules to be loaded.
*/
@ApiOperation(value = "Get the list of ui modules to be loaded.")
@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, PluginInfo> modules() {
Map<String, ManagedPlugin> plugins = pluginManager.getPluginContexts();
Map<String, PluginInfo> entryPoints = Maps.newHashMap();
for (ManagedPlugin managedPlugin : plugins.values()) {
Plugin plugin = managedPlugin.getPlugin();
String uiEntryPoint = plugin.getDescriptor().getUiEntryPoint();
if (uiEntryPoint != null) {
String pluginBase = root + plugin.getPluginPathId() + "/";
String entryPoint = pluginBase + uiEntryPoint;
entryPoints.put(managedPlugin.getPlugin().getDescriptor().getId(), new PluginInfo(entryPoint, pluginBase));
}
}
return entryPoints;
}
use of alien4cloud.plugin.Plugin in project alien4cloud by alien4cloud.
the class ApplicationBootstrap method migration.
/**
* Performs data migration for 1.3.1 version where plugin ids are not generated using the version anymore.
*/
private void migration() {
log.debug("Initializing plugin id migrations");
int count = 0;
// This code updates the ids of plugin configurations and plugins in elasticsearch to remove the version reference.
GetMultipleDataResult<Plugin> pluginResult = alienDAO.buildQuery(Plugin.class).prepareSearch().search(0, Integer.MAX_VALUE);
for (Plugin plugin : pluginResult.getData()) {
if (plugin.getEsId().contains(":")) {
PluginConfiguration pluginConfiguration = alienDAO.findById(PluginConfiguration.class, plugin.getEsId());
if (pluginConfiguration != null) {
pluginConfiguration.setPluginId(plugin.getId());
alienDAO.save(pluginConfiguration);
alienDAO.delete(PluginConfiguration.class, plugin.getEsId());
}
alienDAO.save(plugin);
alienDAO.delete(Plugin.class, plugin.getEsId());
count++;
}
}
if (count > 0) {
log.info("{} plugins migrated", count);
}
count = 0;
// This code updates the plugin id in the orchestrators.
GetMultipleDataResult<Orchestrator> orchestratorResult = alienDAO.buildQuery(Orchestrator.class).prepareSearch().search(0, Integer.MAX_VALUE);
for (Orchestrator orchestrator : orchestratorResult.getData()) {
if (orchestrator.getPluginId().contains(":")) {
orchestrator.setPluginId(orchestrator.getPluginId().split(":")[0]);
alienDAO.save(orchestrator);
count++;
}
}
if (count > 0) {
log.info("Orchestrator migrated: {}.", count);
}
log.debug("plugin id migration done.");
}
Aggregations