Search in sources :

Example 6 with ComplianceRuleId

use of org.eclipse.winery.model.ids.extensions.ComplianceRuleId 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)

Aggregations

ComplianceRuleId (org.eclipse.winery.model.ids.extensions.ComplianceRuleId)6 OTComplianceRule (org.eclipse.winery.model.tosca.extensions.OTComplianceRule)6 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 QName (javax.xml.namespace.QName)3 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)3 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)3 GraphMapping (org.jgrapht.GraphMapping)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 ToscaModelHelper.createNodeTypeId (org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId)2 ToscaModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate)2 ToscaModelHelper.createTNodeType (org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType)2 ToscaModelHelper.createTServiceTemplate (org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate)2 ServiceTemplateCheckingResult (org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult)2 ServiceTemplateComplianceRuleRuleChecker (org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker)2