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;
}
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"));
}
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;
}
Aggregations