use of alien4cloud.plugin.model.PluginConfiguration 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.model.PluginConfiguration 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.");
}
use of alien4cloud.plugin.model.PluginConfiguration in project alien4cloud by alien4cloud.
the class PluginController method getPluginConfiguration.
@ApiOperation(value = "Get a plugin configuration object.", notes = "Retrieve a plugin configuration object. Role required [ ADMIN ]")
@RequestMapping(value = "/{pluginId:.+}/config", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<Object> getPluginConfiguration(@PathVariable String pluginId) throws PluginLoadingException {
RestResponse<Object> response = RestResponseBuilder.<Object>builder().build();
// check if a config object already exist in the repository
PluginConfiguration pluginConf = alienDAO.findById(PluginConfiguration.class, pluginId);
if (pluginConf != null && pluginConf.getConfiguration() != null) {
response.setData(pluginConf.getConfiguration());
return response;
}
if (pluginManager.isPluginConfigurable(pluginId)) {
Object configObject = pluginManager.getConfiguratorFor(pluginId).getDefaultConfiguration();
response.setData(configObject);
}
return response;
}
use of alien4cloud.plugin.model.PluginConfiguration in project alien4cloud by alien4cloud.
the class PluginController method savePluginConfiguration.
@SuppressWarnings({ "unchecked", "rawtypes" })
@ApiOperation(value = "Save a configuration object for a plugin.", notes = "Save a configuration object for a plugin. Returns the newly saved configuration. Role required [ ADMIN ]")
@RequestMapping(value = "/{pluginId:.+}/config", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<Object> savePluginConfiguration(@PathVariable String pluginId, @RequestBody Object configObjectRequest) throws PluginLoadingException {
RestResponse<Object> response = RestResponseBuilder.<Object>builder().build();
if (pluginManager.isPluginConfigurable(pluginId)) {
Class<?> configType = pluginManager.getConfigurationType(pluginId);
try {
Object configObject = JsonUtil.readObject(JsonUtil.toString(configObjectRequest), configType);
IPluginConfigurator configurator = pluginManager.getConfiguratorFor(pluginId);
configurator.setConfiguration(configObject);
PluginConfiguration pluginConf = new PluginConfiguration(pluginId, configObject);
alienDAO.save(pluginConf);
response.setData(configObject);
} catch (IOException e) {
response.setError(RestErrorBuilder.builder(RestErrorCode.INVALID_PLUGIN_CONFIGURATION).message("The posted configuration is not of type <" + configType.getName() + ">").build());
log.error("The posted configuration is not of type <" + configType.getName() + ">", e);
} catch (PluginConfigurationException e) {
response.setError(RestErrorBuilder.builder(RestErrorCode.INVALID_PLUGIN_CONFIGURATION).message("The plugin configuration failed for plugin <" + pluginId + ">: configuration parameters are invalid.").build());
}
}
return response;
}
Aggregations