use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class UnSetNodeCapabilityPropertyAsOutputProcessor method check.
@SuppressWarnings("unchecked")
private void check(UnSetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) {
if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) {
throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName());
}
Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true);
if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) {
throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName());
}
Set<String> values = (Set<String>) MapUtil.get(topology.getOutputCapabilityProperties(), operation.getNodeName().concat(".").concat(operation.getCapabilityName()));
if (!AlienUtils.safe(values).contains(operation.getPropertyName())) {
throw new NotFoundException("Node " + operation.getNodeName() + " capability " + operation.getCapabilityName() + " 's property " + operation.getPropertyName() + " not found in outputs");
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ToscaWithDependenciesBuilder method buildNodeTypeWithDependencies.
private TypeWithDependenciesResult buildNodeTypeWithDependencies(NodeType nodeType) {
TypeWithDependenciesResult result = new TypeWithDependenciesResult();
result.setToscaType(nodeType);
for (CapabilityDefinition capabilityDefinition : nodeType.getCapabilities()) {
result.add(ToscaContext.getOrFail(CapabilityType.class, capabilityDefinition.getType()));
}
for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
if (capabilityType != null) {
result.add(capabilityType);
} else {
// requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
result.add(ToscaContext.get(NodeType.class, requirementDefinition.getType()));
}
}
result.setDependencies(ToscaContext.get().getDependencies());
// Fetch data types for the given type
DataTypesFetcher.getDataTypesDependencies(Collections.singleton(nodeType), ToscaContext::get).values().forEach(result::add);
return result;
}
use of org.alien4cloud.tosca.model.types.CapabilityType 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.types.CapabilityType in project alien4cloud by alien4cloud.
the class PostMatchingNodeSetupModifierTest method testPropertiesCleanup.
@Test
public void testPropertiesCleanup() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-SNAPSHOT")).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);
CapabilityType mockCapaType = Mockito.mock(CapabilityType.class);
Mockito.when(mockCapaType.getElementId()).thenReturn("tosca.capabilities.Root");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Root"), Mockito.any(Set.class))).thenReturn(mockCapaType);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get("../alien4cloud-test-common/src/test/resources/data/csars/matching-change-cleanup/tosca.yml"));
for (Entry<String, CapabilityType> capabilityTypeEntry : parsingResult.getResult().getCapabilityTypes().entrySet()) {
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq(capabilityTypeEntry.getKey()), Mockito.any(Set.class))).thenReturn(capabilityTypeEntry.getValue());
}
for (Entry<String, NodeType> nodeTypeEntry : parsingResult.getResult().getNodeTypes().entrySet()) {
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq(nodeTypeEntry.getKey()), Mockito.any(Set.class))).thenReturn(nodeTypeEntry.getValue());
}
try {
ToscaContext.init(Sets.newHashSet());
PostMatchingNodeSetupModifier postMatchingNodeSetupModifier = new PostMatchingNodeSetupModifier();
Topology topology = new Topology();
topology.setNodeTemplates(Maps.newHashMap());
topology.getNodeTemplates().put("my_node", TemplateBuilder.buildNodeTemplate(parsingResult.getResult().getNodeTypes().get("org.alien4cloud.test.matching.nodes.LocationCustomImplOne")));
// Configure the deployment config
DeploymentMatchingConfiguration matchingConfiguration = new DeploymentMatchingConfiguration();
matchingConfiguration.setMatchedLocationResources(Maps.newHashMap());
matchingConfiguration.getMatchedLocationResources().put("my_node", "a_location_resource");
NodePropsOverride nodePropsOverride = new NodePropsOverride();
nodePropsOverride.getProperties().put("common_property", new ScalarPropertyValue("p_val"));
nodePropsOverride.getProperties().put("unique_prop", new ScalarPropertyValue("p_val"));
nodePropsOverride.getProperties().put("type_variant_prop", new ScalarPropertyValue("p_val"));
nodePropsOverride.getProperties().put("constraint_variant_prop", new ScalarPropertyValue("p_val"));
NodeCapabilitiesPropsOverride nodeCapabilitiesPropsOverride = new NodeCapabilitiesPropsOverride();
nodeCapabilitiesPropsOverride.getProperties().put("common_property", new ScalarPropertyValue("p_val"));
nodeCapabilitiesPropsOverride.getProperties().put("unique_prop", new ScalarPropertyValue("p_val"));
nodeCapabilitiesPropsOverride.getProperties().put("type_variant_prop", new ScalarPropertyValue("p_val"));
nodeCapabilitiesPropsOverride.getProperties().put("constraint_variant_prop", new ScalarPropertyValue("p_val"));
nodePropsOverride.getCapabilities().put("my_capability", nodeCapabilitiesPropsOverride);
matchingConfiguration.setMatchedNodesConfiguration(Maps.newHashMap());
matchingConfiguration.getMatchedNodesConfiguration().put("my_node", nodePropsOverride);
FlowExecutionContext mockContext = Mockito.mock(FlowExecutionContext.class);
Mockito.when(mockContext.log()).thenReturn(Mockito.mock(FlowExecutionLog.class));
Mockito.when(mockContext.getConfiguration(DeploymentMatchingConfiguration.class, AbstractPostMatchingSetupModifier.class.getSimpleName())).thenReturn(Optional.of(matchingConfiguration));
// All properties resources should be remain as matched type is compliant
postMatchingNodeSetupModifier.process(topology, mockContext);
Assert.assertEquals(4, nodePropsOverride.getProperties().size());
Assert.assertEquals(4, nodePropsOverride.getCapabilities().get("my_capability").getProperties().size());
// Change the type and check that properties are cleared
topology.getNodeTemplates().clear();
topology.getNodeTemplates().put("my_node", TemplateBuilder.buildNodeTemplate(parsingResult.getResult().getNodeTypes().get("org.alien4cloud.test.matching.nodes.LocationCustomImplTwo")));
postMatchingNodeSetupModifier.process(topology, mockContext);
Assert.assertEquals(1, nodePropsOverride.getProperties().size());
Assert.assertEquals(1, nodePropsOverride.getCapabilities().get("my_capability").getProperties().size());
} finally {
ToscaContext.destroy();
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testCapabilityType.
@SuppressWarnings("unchecked")
@Test
public void testCapabilityType() throws FileNotFoundException, ParsingException {
CapabilityType mockedResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Feature"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.capabilities.Root"));
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-capability-type.yml"));
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(1, archiveRoot.getCapabilityTypes().size());
Entry<String, CapabilityType> entry = archiveRoot.getCapabilityTypes().entrySet().iterator().next();
Assert.assertEquals("mycompany.mytypes.myapplication.MyFeature", entry.getKey());
CapabilityType capability = entry.getValue();
Assert.assertEquals(Lists.newArrayList("tosca.capabilities.Feature", "tosca.capabilities.Root"), capability.getDerivedFrom());
Assert.assertEquals("a custom feature of my company’s application", capability.getDescription());
}
Aggregations