use of org.eclipse.winery.model.tosca.DiscoveryPluginDescriptor in project winery by eclipse.
the class InstanceModelRefinement method refine.
public TTopologyTemplate refine(ServiceTemplateId serviceTemplateId) {
IRepository repository = RepositoryFactory.getRepository();
TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
List<DiscoveryPluginDescriptor> discoveryPluginDescriptors = extractDiscoveryPluginsFromServiceTemplate(serviceTemplate, new ObjectMapper());
if (topologyTemplate == null) {
logger.error("Cannot refine empty instance model!");
return null;
}
boolean pluginsAreAvailable = true;
do {
ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topologyTemplate);
List<InstanceModelRefinementPlugin> executablePlugins = this.plugins.stream().filter(plugin -> plugin.isApplicable(topologyTemplate, topologyGraph)).collect(Collectors.toList());
InstanceModelRefinementPlugin selectedPlugin = pluginChooser.selectPlugin(topologyTemplate, executablePlugins);
if (selectedPlugin != null) {
DiscoveryPluginDescriptor discoveryPlugin = discoveryPluginDescriptors.stream().filter(discoveryPluginDescriptor -> Objects.equals(discoveryPluginDescriptor.getId(), selectedPlugin.getId())).findAny().orElseGet(() -> {
DiscoveryPluginDescriptor discoveryPluginDescriptor = new DiscoveryPluginDescriptor();
discoveryPluginDescriptor.setId(selectedPlugin.getId());
discoveryPluginDescriptor.setDiscoveredIds(Collections.emptyList());
discoveryPluginDescriptors.add(discoveryPluginDescriptor);
return discoveryPluginDescriptor;
});
Set<String> pluginDiscoveredNodeIds = selectedPlugin.apply(topologyTemplate);
List<String> discoveredIds = new ArrayList<>();
discoveredIds.addAll(pluginDiscoveredNodeIds);
discoveredIds.addAll(discoveryPlugin.getDiscoveredIds());
discoveryPlugin.setDiscoveredIds(discoveredIds);
updateDiscoveryPluginsInServiceTemplate(serviceTemplate, new ObjectMapper(), discoveryPluginDescriptors);
try {
repository.setElement(serviceTemplateId, serviceTemplate);
} catch (IOException e) {
logger.error("Error persisting Service Template {}", serviceTemplateId.toReadableString());
}
} else {
pluginsAreAvailable = false;
}
} while (pluginsAreAvailable);
return topologyTemplate;
}
Aggregations