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);  }
@Test public void testVersionConstraints() throws Exception{ String aam = new Scanner(new File(Resources.getResource("aams/version_aam.yml").toURI())).useDelimiter("\\Z").next(); assertNotNull(aam); String offerings = new Scanner(new File(Resources.getResource("version_offerings.yml").toURI())).useDelimiter("\\Z").next(); assertNotNull(offerings); ParsingResult<ArchiveRoot> aamResult = ToscaSerializer.fromTOSCA(aam); ParsingResult<ArchiveRoot> offeringsResult = ToscaSerializer.fromTOSCA(offerings); Map<String, NodeTemplate> offNodeTemplates = offeringsResult.getResult().getTopology().getNodeTemplates(); Map<String, Pair<NodeTemplate, String>> off = new HashMap<>(); for(String node : offNodeTemplates.keySet()){ off.put(node, new Pair<NodeTemplate, String>(offNodeTemplates.get(node), "")); } Matchmaker mm = new Matchmaker(); Map<String, HashSet<String>> res = mm.match(aamResult, off); assertEquals(res.get("db1").size(), 3); }
@Test public void testMultipleConstraints() throws Exception{ String aam = new Scanner(new File(Resources.getResource("aams/multiplereq.yml").toURI())).useDelimiter("\\Z").next(); assertNotNull(aam); String offerings = new Scanner(new File(Resources.getResource("offering_examples2.yaml").toURI())).useDelimiter("\\Z").next(); assertNotNull(offerings); ParsingResult<ArchiveRoot> aamResult = ToscaSerializer.fromTOSCA(aam); ParsingResult<ArchiveRoot> offeringsResult = ToscaSerializer.fromTOSCA(offerings); Map<String, NodeTemplate> offNodeTemplates = offeringsResult.getResult().getTopology().getNodeTemplates(); Map<String, Pair<NodeTemplate, String>> off = new HashMap<>(); for(String node : offNodeTemplates.keySet()){ off.put(node, new Pair<NodeTemplate, String>(offNodeTemplates.get(node), "")); } Matchmaker mm = new Matchmaker(); Map<String, HashSet<String>> res = mm.match(aamResult, off); assertEquals(res.get("MessageDatabase").size(), 3); }
@Test public void testFilterOfferings() throws Exception { ToscaParser parser = new ToscaParserSupplier().get(); assertNotNull(parser); ParsingResult<ArchiveRoot> aamResult = parser.parseFile(Paths.get(Resources.getResource("aams/offeringsfilteraam.yml").toURI())); assertNotNull(aamResult); ParsingResult<ArchiveRoot> offeringResult = parser.parseFile(Paths.get(Resources.getResource("global.yaml").toURI())); Map<String, Pair<NodeTemplate, String>> offeringsToMatch = new HashMap<>(); Map<String, NodeTemplate> offeringsNt = offeringResult.getResult().getTopology().getNodeTemplates(); for(String ntn : offeringsNt.keySet()){ offeringsToMatch.put(ntn, new Pair<NodeTemplate, String>(offeringsNt.get(ntn), ntn)); } Matchmaker mm = new Matchmaker(); Map<String, HashSet<String>> res = mm.match(aamResult, offeringsToMatch); assertNotNull(res); for(String moduleName : res.keySet()){ for(String of : res.get(moduleName)){ NodeTemplate nt = offeringsNt.get(of); AbstractPropertyValue offeringProperty = nt.getProperties().get("num_cpus"); String spv = ((ScalarPropertyValue) offeringProperty).getValue(); assertTrue(new Integer("2").compareTo(new Integer(spv)) >= 0); ; } } ParsingResult<ArchiveRoot> aamResult2 = parser.parseFile(Paths.get(Resources.getResource("aams/offeringsfilteraam2.yml").toURI())); assertNotNull(aamResult2); res = mm.match(aamResult2, offeringsToMatch); assertNotNull(res); for(String moduleName : res.keySet()){ for(String of : res.get(moduleName)){ NodeTemplate nt = offeringsNt.get(of); AbstractPropertyValue offeringProperty = nt.getProperties().get("num_cpus"); String spv = ((ScalarPropertyValue) offeringProperty).getValue(); assertTrue(new Integer("2").compareTo(new Integer(spv)) > 0); ; } } ParsingResult<ArchiveRoot> aamResult3 = parser.parseFile(Paths.get(Resources.getResource("aams/offeringsfilteraam3.yml").toURI())); assertNotNull(aamResult3); res = mm.match(aamResult3, offeringsToMatch); assertNotNull(res); for(String moduleName : res.keySet()){ for(String of : res.get(moduleName)){ NodeTemplate nt = offeringsNt.get(of); AbstractPropertyValue offeringProperty = nt.getProperties().get("num_cpus"); String spv = ((ScalarPropertyValue) offeringProperty).getValue(); assertTrue(new Integer("2").compareTo(new Integer(spv)) == 0); ; } } }
@Test public void testMatchmakerOutput() throws Exception { ToscaParser parser = new ToscaParserSupplier().get(); assertNotNull(parser); ParsingResult<ArchiveRoot> aam = parser.parseFile(Paths.get(Resources.getResource("aams/atos_aam.yml").toURI())); ParsingResult<ArchiveRoot> offerings = parser.parseFile(Paths.get(Resources.getResource("aams/atos_offerings.yml").toURI())); Map<String, Pair<NodeTemplate, String>> offeringsToMatch = new HashMap<>(); Map<String, NodeTemplate> offeringsNt = offerings.getResult().getTopology().getNodeTemplates(); for(String ntn : offeringsNt.keySet()){ offeringsToMatch.put(ntn, new Pair<NodeTemplate, String>(offeringsNt.get(ntn), ntn)); } Map<String, HashSet<String>> res = new Matchmaker().match(aam, offeringsToMatch); assertNotNull(res); assertEquals(res.get("webservices").size(), 1); assertEquals(res.get("db1").size(), 4); assertEquals(res.get("www").size(), 3); }
@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); }