DefaultNodeMatcher extends AbstractTemplateMatcher<LocationResourceTemplate, NodeTemplate, NodeType> implements INodeMatcherPlugin { public List<LocationResourceTemplate> matchNode(NodeTemplate nodeTemplate, NodeType nodeType, LocationResources locationResources, Map<String, MatchingConfiguration> matchingConfigurations) { return super.match(nodeTemplate, nodeType, locationResources.getNodeTemplates(), locationResources.getNodeTypes(), locationResources, matchingConfigurations); }  List<LocationResourceTemplate> matchNode(NodeTemplate nodeTemplate, NodeType nodeType, LocationResources locationResources,
            Map<String, MatchingConfiguration> matchingConfigurations);  }
@Test public void real_world_location_resource_compute_should_be_able_to_match_an_abstract_compute_from_topology() throws Exception { Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>(); NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Compute"); NodeType wantedNodeType = new NodeType(); List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations); assertThat(proposition).hasSize(1); }
@Test public void unknown_type_from_topology_should_not_match_any_location_resource() throws Exception { Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>(); NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Unknown"); NodeType wantedNodeType = new NodeType(); List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations); assertThat(proposition).hasSize(0); }
@Test public void location_resource_should_be_matched_only_if_capabilities_are_satisfied() throws Exception { CapabilityDefinition capabilityArchitecture = new CapabilityDefinition("tosca.capabilities.OperatingSystem"); computeNodeType.setCapabilities(Arrays.asList(capabilityArchitecture)); Capability capability = new Capability(); capability.setType("tosca.capabilities.OperatingSystem"); capability.setProperties(ImmutableMap.of("architecture", new ScalarPropertyValue("x86"))); computeNodeTemplate.setCapabilities(ImmutableMap.of("os", capability)); CapabilityType capabilityType = new CapabilityType(); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("string"); capabilityType.setElementId("tosca.capabilities.OperatingSystem"); capabilityType.setProperties(ImmutableMap.of("architecture", propertyDefinition)); locationResources.setCapabilityTypes(ImmutableMap.of("tosca.capabilities.OperatingSystem", capabilityType)); Map<String, MatchingConfiguration> capabilityFilterConfiguration = new HashMap<>(); MatchingConfiguration matchingConfiguration = new MatchingConfiguration(); MatchingFilterDefinition matchingFilterDefinition = new MatchingConfiguration(); matchingFilterDefinition.setProperties(ImmutableMap.of("architecture", Arrays.asList(new EqualConstraint()))); matchingConfiguration.setCapabilities(ImmutableMap.of("os", matchingFilterDefinition)); capabilityFilterConfiguration.put("org.alien4cloud.nodes.mock.aws.Compute", matchingConfiguration); NodeTemplate wantedNodeTemplate = new NodeTemplate(); wantedNodeTemplate.setType("tosca.nodes.Compute"); Capability wantedCapability = new Capability(); wantedCapability.setType("tosca.capabilities.OperatingSystem"); wantedCapability.setProperties(ImmutableMap.of("architecture", new ScalarPropertyValue("power_pc"))); wantedNodeTemplate.setCapabilities(ImmutableMap.of("os", wantedCapability)); NodeType nodeType = new NodeType(); List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, nodeType, locationResources, capabilityFilterConfiguration); assertThat(proposition).hasSize(0); }
@Test public void abstract_template_should_be_matched_if_service_is_available() throws Exception { Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>(); NodeTemplate wantedNodeTemplate = nodeTemplate("test.nodes.DB"); NodeType wantedNodeType = new NodeType(); wantedNodeType.setAbstract(true); List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations); assertThat(proposition).hasSize(1); assertThat(proposition.get(0).isService()).isTrue(); }
@Test @Ignore public void concrete_template_cannot_be_matched_even_if_service_is_available() throws Exception { Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>(); NodeTemplate wantedNodeTemplate = nodeTemplate("test.nodes.DB"); NodeType wantedNodeType = new NodeType(); wantedNodeType.setAbstract(false); List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations); assertThat(proposition).hasSize(0); }
@Test public void abstract_template_should_be_matched_if_service_is_available_2() throws Exception { Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>(); NodeTemplate wantedNodeTemplate = nodeTemplate("alien.service.MongoDB"); NodeType wantedNodeType = new NodeType(); wantedNodeType.setAbstract(true); List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations); assertThat(proposition).hasSize(1); assertThat(proposition.get(0).isService()).isTrue(); }