Search in sources :

Example 41 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method location_resource_should_be_matched_only_if_capabilities_are_satisfied.

@Test
public void location_resource_should_be_matched_only_if_capabilities_are_satisfied() throws Exception {
    // Given
    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));
    // Matching configuration
    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);
    // When
    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);
    // Then
    assertThat(proposition).hasSize(0);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) MatchingFilterDefinition(alien4cloud.model.deployment.matching.MatchingFilterDefinition) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) Test(org.junit.Test)

Example 42 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class ToscaSerializerUtilsTest method testHasCapabilitiesContainingNotNullProperties.

@Test
public void testHasCapabilitiesContainingNotNullProperties() {
    NodeTemplate nt = new NodeTemplate();
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    Map<String, Capability> capabilities = Maps.newHashMap();
    nt.setCapabilities(capabilities);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    Capability capability1 = new Capability();
    capabilities.put("capa1", capability1);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    Capability capability2 = new Capability();
    Map<String, AbstractPropertyValue> properties = new HashMap<String, AbstractPropertyValue>();
    capability2.setProperties(properties);
    capabilities.put("capa2", capability2);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    properties.put("prop1", null);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    properties.put("prop2", new ScalarPropertyValue("value"));
    Assert.assertTrue(utils.hasCapabilitiesContainingNotNullProperties(nt));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) HashMap(java.util.HashMap) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 43 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class PaaSUtilsTest method buildFakeCapability.

private Capability buildFakeCapability() {
    Map<String, AbstractPropertyValue> props = Maps.newHashMap();
    props.put(fake1, new ScalarPropertyValue("1_capa"));
    props.put(fake2, null);
    props.put(fake3, new ComplexPropertyValue(MapUtil.newHashMap(new String[] { "toto" }, new String[] { "tata" })));
    props.put(fake5, new ScalarPropertyValue("5_capa"));
    Capability fakeCapability = Mockito.mock(Capability.class);
    Mockito.when(fakeCapability.getProperties()).thenReturn(props);
    return fakeCapability;
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability)

Example 44 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class CapabilityMatcherServiceTest method addCapabilityToNodeTemplateAndToscaContext.

private void addCapabilityToNodeTemplateAndToscaContext(String name, String type, String... derivedFrom) {
    CapabilityType capabilityType = new CapabilityType();
    capabilityType.setDerivedFrom(Arrays.asList(derivedFrom));
    capabilityType.setElementId(type);
    capabilityTypeByTypeName.put(type, capabilityType);
    Capability capability = new Capability();
    capability.setType(type);
    nodeTemplate.getCapabilities().put(name, capability);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability)

Example 45 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class CapabilityMatcherServiceTest method should_not_crash_even_if_node_template_capacities_is_incorrect.

@Test
public void should_not_crash_even_if_node_template_capacities_is_incorrect() throws Exception {
    nodeTemplate.getCapabilities().clear();
    Capability unknownCapacity = new Capability();
    unknownCapacity.setType("alien.typo.in.capa");
    nodeTemplate.getCapabilities().put("incorrect", unknownCapacity);
    Map<String, Capability> compatibleCapabilities = service.getCompatibleCapabilityByType(nodeTemplate, "alien.capability.test.Unknown");
    assertThat(compatibleCapabilities).hasSize(0);
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) Test(org.junit.Test)

Aggregations

Capability (org.alien4cloud.tosca.model.templates.Capability)50 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)27 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)26 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)14 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)12 Map (java.util.Map)10 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 NotFoundException (alien4cloud.exception.NotFoundException)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 Test (org.junit.Test)9 Set (java.util.Set)8 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 Location (alien4cloud.model.orchestrators.locations.Location)3 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)3