Search in sources :

Example 1 with DiscoveryPluginDescriptor

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;
}
Also used : Arrays(java.util.Arrays) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DiscoveryPluginDescriptor(org.eclipse.winery.model.tosca.DiscoveryPluginDescriptor) LoggerFactory(org.slf4j.LoggerFactory) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) PetClinicRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.PetClinicRefinementPlugin) DockerImageRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.dockerimage.DockerImageRefinementPlugin) TomcatRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.TomcatRefinementPlugin) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) MySqlDbmsRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.MySqlDbmsRefinementPlugin) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Collectors(java.util.stream.Collectors) TTag(org.eclipse.winery.model.tosca.TTag) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) MySqlDbRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.MySqlDbRefinementPlugin) Objects(java.util.Objects) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) Optional(java.util.Optional) Ec2AmiRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.Ec2AmiRefinementPlugin) SpringWebAppRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.SpringWebAppRefinementPlugin) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) Collections(java.util.Collections) ToscaTransformer(org.eclipse.winery.topologygraph.transformation.ToscaTransformer) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IRepository(org.eclipse.winery.repository.backend.IRepository) DiscoveryPluginDescriptor(org.eclipse.winery.model.tosca.DiscoveryPluginDescriptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Ec2AmiRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.Ec2AmiRefinementPlugin)1 MySqlDbRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.MySqlDbRefinementPlugin)1 MySqlDbmsRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.MySqlDbmsRefinementPlugin)1 PetClinicRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.PetClinicRefinementPlugin)1 SpringWebAppRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.SpringWebAppRefinementPlugin)1 TomcatRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.TomcatRefinementPlugin)1 DockerImageRefinementPlugin (org.eclipse.winery.model.adaptation.instance.plugins.dockerimage.DockerImageRefinementPlugin)1 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)1