@Test public void testSimpleMatchingProp() throws Exception{ ToscaParser parser = new ToscaParserSupplier().get(); assertNotNull(parser); ParsingResult<ArchiveRoot> pr = parser.parseFile(Paths.get(Resources.getResource("aams/matchingProp.yml").toURI())); Topology t = pr.getResult().getTopology(); assertNotNull(t); NodeTemplate offering = t.getNodeTemplates().get("my_app"); assertNotNull(offering); IndexedNodeType reqModule = pr.getResult().getNodeTypes().get("moduleReq"); assertNotNull(reqModule); Matchmaker mm = new Matchmaker(); Map<String, HashSet<String>> matchmakeRes = mm.match(pr.getResult().getNodeTypes(), t.getNodeTemplates()); assertNotNull(matchmakeRes); assertEquals(1, matchmakeRes.size()); assertEquals(1, matchmakeRes.get("moduleReq").size()); AbstractPropertyValue offProp = offering.getProperties().get("num_cpus"); assertNotNull(offProp); PropertyDefinition reqProp = reqModule.getProperties().get("num_cpus"); assertNotNull(reqProp); }
private boolean match(IndexedNodeType module, NodeTemplate offering){ if(module.getProperties() == null) return true; PropertyValue offeringType = getPropertyValue("", offering.getProperties().get("resource_type")); for(String p:module.getProperties().keySet()) { if (!offering.getProperties().containsKey(p) && offeringType.getValue().equals("compute") && p.endsWith("_support")) continue; if (!offering.getProperties().containsKey(p) && p.endsWith("_version")) continue; if(!offering.getProperties().containsKey(p)) return false; PropertyDefinition moduleProperty = module.getProperties().get(p); AbstractPropertyValue offeringProperty = offering.getProperties().get(p); if(!matchProperty(moduleProperty, offeringProperty)) return false; } return true; }
Matchmaker { private boolean match(IndexedNodeType module, NodeTemplate offering){ if(module.getProperties() == null) return true; PropertyValue offeringType = getPropertyValue("", offering.getProperties().get("resource_type")); for(String p:module.getProperties().keySet()) { if (!offering.getProperties().containsKey(p) && offeringType.getValue().equals("compute") && p.endsWith("_support")) continue; if (!offering.getProperties().containsKey(p) && p.endsWith("_version")) continue; if(!offering.getProperties().containsKey(p)) return false; PropertyDefinition moduleProperty = module.getProperties().get(p); AbstractPropertyValue offeringProperty = offering.getProperties().get(p); if(!matchProperty(moduleProperty, offeringProperty)) return false; } return true; } }
Matchmaker { private boolean match(IndexedNodeType module, NodeTemplate offering){ if(module.getProperties() == null) return true; PropertyValue offeringType = getPropertyValue("", offering.getProperties().get("resource_type")); for(String p:module.getProperties().keySet()) { if (!offering.getProperties().containsKey(p) && offeringType.getValue().equals("compute") && p.endsWith("_support")) continue; if (!offering.getProperties().containsKey(p) && p.endsWith("_version")) continue; if(!offering.getProperties().containsKey(p)) return false; PropertyDefinition moduleProperty = module.getProperties().get(p); AbstractPropertyValue offeringProperty = offering.getProperties().get(p); if(!matchProperty(moduleProperty, offeringProperty)) return false; } return true; } Matchmaker(); }
Matchmaker { private boolean match(IndexedNodeType module, NodeTemplate offering){ if(module.getProperties() == null) return true; PropertyValue offeringType = getPropertyValue("", offering.getProperties().get("resource_type")); for(String p:module.getProperties().keySet()) { if (!offering.getProperties().containsKey(p) && offeringType.getValue().equals("compute") && p.endsWith("_support")) continue; if (!offering.getProperties().containsKey(p) && p.endsWith("_version")) continue; if(!offering.getProperties().containsKey(p)) return false; PropertyDefinition moduleProperty = module.getProperties().get(p); AbstractPropertyValue offeringProperty = offering.getProperties().get(p); if(!matchProperty(moduleProperty, offeringProperty)) return false; } return true; } Matchmaker(); PropertyValue getPropertyValue(String name, AbstractPropertyValue p); Constraint getConstraint(String name, PropertyConstraint c); @Deprecated Map<String, HashSet<String>> match(Map<String, IndexedNodeType> aamModules, Map<String, NodeTemplate> offerings); Map<String, HashSet<String>> match(ParsingResult<ArchiveRoot> aam, Map<String, Pair<NodeTemplate, String>> offerings); }
Matchmaker { private boolean match(IndexedNodeType module, NodeTemplate offering){ if(module.getProperties() == null) return true; PropertyValue offeringType = getPropertyValue("", offering.getProperties().get("resource_type")); for(String p:module.getProperties().keySet()) { if (!offering.getProperties().containsKey(p) && offeringType.getValue().equals("compute") && p.endsWith("_support")) continue; if (!offering.getProperties().containsKey(p) && p.endsWith("_version")) continue; if(!offering.getProperties().containsKey(p)) return false; PropertyDefinition moduleProperty = module.getProperties().get(p); AbstractPropertyValue offeringProperty = offering.getProperties().get(p); if(!matchProperty(moduleProperty, offeringProperty)) return false; } return true; } Matchmaker(); PropertyValue getPropertyValue(String name, AbstractPropertyValue p); Constraint getConstraint(String name, PropertyConstraint c); @Deprecated Map<String, HashSet<String>> match(Map<String, IndexedNodeType> aamModules, Map<String, NodeTemplate> offerings); Map<String, HashSet<String>> match(ParsingResult<ArchiveRoot> aam, Map<String, Pair<NodeTemplate, String>> offerings);  }