Search in sources :

Example 21 with ToscaNode

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

the class ServiceTemplateComplianceRuleRuleChecker method checkComplianceRules.

public ServiceTemplateCheckingResult checkComplianceRules() {
    StringBuilder checkingResult = new StringBuilder("Rulechecking result for servicetemplate " + serviceTemplate.getIdFromIdOrNameField() + System.lineSeparator());
    ServiceTemplateCheckingResult result = new ServiceTemplateCheckingResult();
    List<ComplianceRuleId> ruleIds = getRuleIds(serviceTemplate);
    if (ruleIds.isEmpty()) {
        checkingResult.append("No rules defined");
    } else {
        IRepository repository = RepositoryFactory.getRepository();
        for (ComplianceRuleId ruleId : ruleIds) {
            OTComplianceRule tComplianceRule = repository.getElement(ruleId);
            ComplianceRuleChecker checker = new ComplianceRuleChecker(tComplianceRule, serviceTemplate.getTopologyTemplate());
            List<GraphMapping> graphMappings;
            try {
                graphMappings = checker.checkComplianceRule();
                if (graphMappings.size() > 0) {
                    result.getUnsatisfied().add(ruleId.getQName());
                    checkingResult.append(ruleId.getQName().toString() + " violated:");
                    checkingResult.append(System.lineSeparator());
                    for (GraphMapping mapping : graphMappings) {
                        Map<ToscaNode, ToscaNode> resultMap = checker.getSubGraphMappingAsMap(mapping, checker.getIdentifierGraph());
                        checkingResult.append(System.lineSeparator());
                        checkingResult.append(resultMap.values().stream().map(node -> node.getTemplate().getIdFromIdOrNameField()).collect(Collectors.joining(";", "NodeTemplateIds: ", "")));
                    }
                } else {
                    result.getSatisfied().add(ruleId.getQName());
                    checkingResult.append(ruleId.getQName().toString() + " satisfied");
                }
            } catch (ComplianceCheckingException e) {
                result.getException().add(ruleId.getQName());
                LOGGER.debug("Could not check compliance at rule " + ruleId.getQName().toString(), e);
            }
        }
    }
    LOGGER.debug(checkingResult.toString());
    return result;
}
Also used : ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) IRepository(org.eclipse.winery.repository.backend.IRepository) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) GraphMapping(org.jgrapht.GraphMapping)

Example 22 with ToscaNode

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

the class ComplianceRuleCheckerTests method validRule_identifierInRequired_findsOne.

@Test
public void validRule_identifierInRequired_findsOne() throws Exception {
    ComplianceRuleChecker checker = new ComplianceRuleChecker(null, null, null);
    checker.setToCheckTemplate(topologyTemplateToSearchIn);
    checker.setIdentifierTemplate(identifier);
    checker.setRequiredStructureTemplate(requiredStructure);
    List<GraphMapping> violatingMappings = checker.checkComplianceRule();
    assertEquals(1, violatingMappings.size());
    ToscaNode identifierNode1 = checker.getIdentifierGraph().getNode("01");
    ToscaNode identifierNode2 = checker.getIdentifierGraph().getNode("02");
    ToscaEdge identifierEdge = checker.getIdentifierGraph().getEdge(identifierNode1, identifierNode2);
    GraphMapping violatingMapping = violatingMappings.stream().findFirst().get();
    assertNotNull(violatingMapping);
    Map<ToscaNode, ToscaNode> resultMap = checker.getSubGraphMappingAsMap(violatingMapping, checker.getIdentifierGraph());
    assertTrue(resultMap.get(identifierNode1).getId().matches("05"));
    assertTrue(resultMap.get(identifierNode2).getId().matches("06"));
    assertTrue(((ToscaEdge) violatingMapping.getEdgeCorrespondence(identifierEdge, false)).getId().matches("3"));
}
Also used : ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) ComplianceRuleChecker(org.eclipse.winery.compliance.checking.ComplianceRuleChecker) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Example 23 with ToscaNode

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

the class ToscaModelHelper method createTOSCANodeOnlyProperties.

public static ToscaNode createTOSCANodeOnlyProperties(ToscaModelPropertiesBuilder propertiesBuilder) {
    ToscaNode node = new ToscaNode();
    node.setNodeTemplate(new TNodeTemplate());
    node.getTemplate().setProperties(propertiesBuilder.build());
    return node;
}
Also used : ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)23 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)15 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)10 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)9 ToscaEdge (org.eclipse.winery.topologygraph.model.ToscaEdge)8 GraphMapping (org.jgrapht.GraphMapping)8 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)7 ToscaGraph (org.eclipse.winery.topologygraph.model.ToscaGraph)7 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)6 ToscaIsomorphismMatcher (org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher)6 QName (javax.xml.namespace.QName)5 RefinementCandidate (org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 TPolicy (org.eclipse.winery.model.tosca.TPolicy)4 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)4 NamespaceManager (org.eclipse.winery.repository.backend.NamespaceManager)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 HashMap (java.util.HashMap)3