use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition 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);
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method The_in_the_response_should_all_have_the.
@Then("^The \"([^\"]*)\" in the response should all have the \"([^\"]*)\" \"([^\"]*)\"$")
public void The_in_the_response_should_all_have_the(String searchedComponentType, String propertyValue, String property) throws Throwable {
RestResponse<FacetedSearchResult> restResponse = JsonUtil.read(Context.getInstance().takeRestResponse(), FacetedSearchResult.class);
FacetedSearchResult searchResp = restResponse.getData();
List<Object> resultData = Lists.newArrayList(searchResp.getData());
if (searchedComponentType.equalsIgnoreCase("node types")) {
for (Object object : resultData) {
NodeType idnt = JsonUtil.readObject(JsonUtil.toString(object), NodeType.class);
switch(property) {
case "capability":
assertNotNull(idnt.getCapabilities());
assertTrue(idnt.getCapabilities().contains(new CapabilityDefinition(propertyValue, propertyValue, 1)));
break;
case "requirement":
assertNotNull(idnt.getRequirements());
assertTrue(idnt.getRequirements().contains(new RequirementDefinition(propertyValue, propertyValue)));
break;
default:
break;
}
}
} else if (searchedComponentType.equalsIgnoreCase("relationship types")) {
for (Object object : resultData) {
RelationshipType idrt = JsonUtil.readObject(JsonUtil.toString(object), RelationshipType.class);
switch(property) {
case "validSource":
assertNotNull(idrt.getValidSources());
assertTrue(Arrays.equals(new String[] { propertyValue }, idrt.getValidSources()));
break;
default:
break;
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method getMockedCompute.
private NodeType getMockedCompute() {
NodeType mockedCompute = new NodeType();
mockedCompute.setArchiveName("tosca-normative-types");
mockedCompute.setArchiveVersion("1.0.0.wd03-SNAPSHOT");
CapabilityDefinition capabilityDefinition = new CapabilityDefinition("host", "tosca.capabilities.Container", Integer.MAX_VALUE);
mockedCompute.setCapabilities(Lists.newArrayList(capabilityDefinition));
mockedCompute.setElementId("tosca.nodes.Compute");
return mockedCompute;
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parsingInvalidRelationshipTargetInWorkflowStepShouldFail.
@Test
public void parsingInvalidRelationshipTargetInWorkflowStepShouldFail() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
NodeType mockType = Mockito.mock(NodeType.class);
Mockito.when(mockType.isAbstract()).thenReturn(true);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockType);
Mockito.when(mockType.getCapabilities()).thenReturn(Lists.newArrayList(new CapabilityDefinition("host", "tosca.capabilities.Container", 1)));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
mockType = Mockito.mock(NodeType.class);
Mockito.when(mockType.getRequirements()).thenReturn(Lists.newArrayList(new RequirementDefinition("host", "tosca.capabilities.Container")));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockType);
CapabilityType mockCapaType = Mockito.mock(CapabilityType.class);
Mockito.when(mockCapaType.getElementId()).thenReturn("tosca.capabilities.Container");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockCapaType);
RelationshipType mockRelType = Mockito.mock(RelationshipType.class);
Mockito.when(mockRelType.getElementId()).thenReturn("tosca.relationships.HostedOn");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(mockRelType);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation-invalid-target.yml"));
// Same error is duplicated but is it that bad ?
assertEquals(2, parsingResult.getContext().getParsingErrors().size());
assertEquals(ErrorCode.UNKNWON_WORKFLOW_STEP_RELATIONSHIP_TARGET, parsingResult.getContext().getParsingErrors().get(0).getErrorCode());
}
Aggregations