Search in sources :

Example 1 with ToscaEntity

use of org.eclipse.winery.topologygraph.model.ToscaEntity in project winery by eclipse.

the class BehaviorPatternDetection method addCompatibleBehaviorPatterns.

private void addCompatibleBehaviorPatterns(TEntityTemplate refinementElement, RefinementCandidate refinement) {
    OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
    TEntityTemplate detectorElement = prm.getStayMappings().stream().filter(stayMapping -> stayMapping.getRefinementElement().getId().equals(refinementElement.getId())).findFirst().get().getDetectorElement();
    ToscaEntity detectorEntity = refinement.getDetectorGraph().getVertexOrEdge(detectorElement.getId()).get();
    TEntityTemplate stayingElement = getEntityCorrespondence(detectorEntity, refinement.getGraphMapping());
    List<TPolicy> refinementPolicies = ((HasPolicies) refinementElement).getPolicies();
    List<TPolicy> stayingPolicies = ((HasPolicies) stayingElement).getPolicies();
    if (refinementPolicies != null) {
        if (stayingPolicies != null) {
            // avoid duplicates
            refinementPolicies.forEach(refinementPolicy -> {
                boolean policyExists = stayingPolicies.stream().anyMatch(stayingPolicy -> stayingPolicy.getPolicyType().equals(refinementPolicy.getPolicyType()));
                if (!policyExists) {
                    stayingPolicies.add(refinementPolicy);
                }
            });
        } else {
            ((HasPolicies) stayingElement).setPolicies(new ArrayList<>(refinementPolicies));
        }
        removeIncompatibleBehaviorPatterns(refinementElement, stayingElement, refinement);
    }
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) TopologyFragmentRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.topologyrefinement.TopologyFragmentRefinement) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) List(java.util.List) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) Map(java.util.Map) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) PatternDetectionUtils.getEntityCorrespondence(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils.getEntityCorrespondence) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 2 with ToscaEntity

use of org.eclipse.winery.topologygraph.model.ToscaEntity in project winery by eclipse.

the class BehaviorPatternDetection method removeIncompatibleBehaviorPatterns.

private void removeIncompatibleBehaviorPatterns(TEntityTemplate refinementElement, TEntityTemplate addedElement, RefinementCandidate refinement) {
    OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
    List<TPolicy> addedElementPolicies = ((HasPolicies) addedElement).getPolicies();
    prm.getBehaviorPatternMappings().stream().filter(bpm -> bpm.getRefinementElement().getId().equals(refinementElement.getId())).forEach(bpm -> {
        ToscaEntity detectorElement = refinement.getDetectorGraph().getVertexOrEdge(bpm.getDetectorElement().getId()).get();
        TEntityTemplate candidateElement = getEntityCorrespondence(detectorElement, refinement.getGraphMapping());
        if (ModelUtilities.hasKvProperties(detectorElement.getTemplate()) && ModelUtilities.hasKvProperties(candidateElement)) {
            String detectorValue = ModelUtilities.getPropertiesKV(detectorElement.getTemplate()).get(bpm.getProperty().getKey());
            String candidateValue = ModelUtilities.getPropertiesKV(candidateElement).get(bpm.getProperty().getKey());
            boolean propsNotCompatible = (detectorValue != null && !detectorValue.isEmpty()) && !detectorValue.equalsIgnoreCase(candidateValue) && (!detectorValue.equals("*") || (candidateValue == null || candidateValue.isEmpty()));
            if (propsNotCompatible) {
                TPolicy behaviorPattern = ((HasPolicies) refinementElement).getPolicies().stream().filter(policy -> bpm.getBehaviorPattern().equals(policy.getName())).findFirst().get();
                addedElementPolicies.removeIf(policy -> policy.getPolicyType().equals(behaviorPattern.getPolicyType()));
            }
        }
    });
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) TopologyFragmentRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.topologyrefinement.TopologyFragmentRefinement) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) List(java.util.List) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) Map(java.util.Map) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) PatternDetectionUtils.getEntityCorrespondence(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils.getEntityCorrespondence) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 3 with ToscaEntity

use of org.eclipse.winery.topologygraph.model.ToscaEntity in project winery by eclipse.

the class ToscaComponentPatternMatcher method componentPatternsCompatible.

protected boolean componentPatternsCompatible(ToscaEntity left, ToscaEntity right) {
    // By convention, the left node is always the element to search in right.
    TEntityTemplate detectorElement = left.getTemplate();
    TEntityTemplate candidateElement = right.getTemplate();
    if (!(detectorElement instanceof TNodeTemplate) || !(candidateElement instanceof TNodeTemplate)) {
        return false;
    }
    if (prm.getPermutationMappings() == null || prm.getPermutationMappings().isEmpty()) {
        return false;
    }
    List<OTPermutationMapping> detectorMappings = prm.getPermutationMappings().stream().filter(mapping -> isOneToOne(mapping, prm) && mapping.getDetectorElement().getId().equals(detectorElement.getId())).collect(Collectors.toList());
    if (detectorMappings.isEmpty()) {
        return false;
    }
    TEntityTemplate refinementElement = detectorMappings.get(0).getRefinementElement();
    return refinementModels.stream().map(OTPatternRefinementModel.class::cast).filter(otherPrm -> otherPrm.getPermutationMappings() != null && !otherPrm.getPermutationMappings().isEmpty()).anyMatch(otherPrm -> {
        List<OTPermutationMapping> matchingDetectorMappings = otherPrm.getPermutationMappings().stream().filter(mapping -> isOneToOne(mapping, otherPrm) && super.isCompatible(mapping.getDetectorElement(), candidateElement) && mapping.getRefinementElement().getType().equals(refinementElement.getType())).collect(Collectors.toList());
        if (!matchingDetectorMappings.isEmpty()) {
            componentPatternCandidates.get(prm).add(new ComponentPatternCandidate((TNodeTemplate) detectorElement, (TNodeTemplate) refinementElement, otherPrm, (TNodeTemplate) matchingDetectorMappings.get(0).getDetectorElement()));
            return true;
        }
        return false;
    });
}
Also used : TEntityType(org.eclipse.winery.model.tosca.TEntityType) Set(java.util.Set) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) List(java.util.List) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) Map(java.util.Map) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)3 OTRefinementModel (org.eclipse.winery.model.tosca.extensions.OTRefinementModel)3 ToscaEntity (org.eclipse.winery.topologygraph.model.ToscaEntity)3 RefinementCandidate (org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate)2 RefinementChooser (org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser)2 TopologyFragmentRefinement (org.eclipse.winery.model.adaptation.substitution.refinement.topologyrefinement.TopologyFragmentRefinement)2 PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)2 HasPolicies (org.eclipse.winery.model.tosca.HasPolicies)2 TPolicy (org.eclipse.winery.model.tosca.TPolicy)2 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)2 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)2 IToscaMatcher (org.eclipse.winery.topologygraph.matching.IToscaMatcher)2 PatternDetectionUtils (org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils)2 PatternDetectionUtils.getEntityCorrespondence (org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils.getEntityCorrespondence)2 ToscaBehaviorPatternMatcher (org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher)2