use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testParseTopologyWithWorkflows.
@Test
public void testParseTopologyWithWorkflows() throws FileNotFoundException, ParsingException {
Csar csar = new Csar("tosca-normative-types", "1.0.0.wd03-SNAPSHOT");
NodeType mockedCompute = getMockedCompute();
NodeType mockedSoftware = getMockedSoftwareComponent();
CapabilityType mockedContainer = Mockito.mock(CapabilityType.class);
Mockito.when(mockedContainer.getElementId()).thenReturn("tosca.capabilities.Container");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedSoftware);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedContainer);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedCompute);
RelationshipType hostedOn = Mockito.mock(RelationshipType.class);
Mockito.when(hostedOn.getElementId()).thenReturn("tosca.relationships.HostedOn");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflows.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
Assert.assertEquals(3, parsingResult.getContext().getParsingErrors().size());
assertNotNull(parsingResult.getResult().getTopology());
Assert.assertEquals(5, parsingResult.getResult().getTopology().getWorkflows().size());
// check invalid names were renamed
assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalidName_"));
assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalid_Name"));
assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalid_Name_1"));
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class RequirementPostProcessor method process.
@Override
public void process(Map.Entry<String, Requirement> instance) {
String definitionVersion = ParsingContextExecution.getDefinitionVersion();
// TODO Handle multiple version post processor
switch(definitionVersion) {
case "tosca_simple_yaml_1_0_0_wd03":
case "alien_dsl_1_1_0":
case "alien_dsl_1_2_0":
capabilityOrNodeReferencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getValue().getType()));
break;
default:
// In latest versions we process the capability only.
capabilityReferencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getValue().getType()));
break;
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, instance.getValue().getType());
propertyValueChecker.checkProperties(capabilityType, instance.getValue().getProperties(), instance.getKey());
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class TemplateBuilder method fillCapabilitiesMap.
private static void fillCapabilitiesMap(Map<String, Capability> map, List<CapabilityDefinition> elements, Map<String, Capability> mapToMerge, boolean adaptToType) {
if (elements == null) {
return;
}
for (CapabilityDefinition capa : elements) {
Capability toAddCapa = MapUtils.getObject(mapToMerge, capa.getId());
Map<String, AbstractPropertyValue> capaProperties = null;
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capa.getType());
if (capabilityType != null && capabilityType.getProperties() != null) {
// Inject all default values from the type.
capaProperties = PropertyUtil.getDefaultPropertyValuesFromPropertyDefinitions(capabilityType.getProperties());
// Override them with values as defined in the actual Capability Definition of the node type.
if (capa.getProperties() != null) {
capaProperties.putAll(capa.getProperties());
}
}
// only merge if the types are equals
if (toAddCapa == null || (StringUtils.isNotBlank(toAddCapa.getType()) && !Objects.equals(toAddCapa.getType(), capa.getType()))) {
toAddCapa = new Capability();
toAddCapa.setType(capa.getType());
toAddCapa.setProperties(capaProperties);
} else {
if (StringUtils.isBlank(toAddCapa.getType())) {
toAddCapa.setType(capa.getType());
}
if (MapUtils.isNotEmpty(capaProperties)) {
Map<String, AbstractPropertyValue> nodeCapaProperties = safe(toAddCapa.getProperties());
capaProperties.putAll(nodeCapaProperties);
toAddCapa.setProperties(capaProperties);
}
}
Map<String, AbstractPropertyValue> properties = Maps.newLinkedHashMap();
fillProperties(properties, capabilityType != null ? capabilityType.getProperties() : null, toAddCapa.getProperties(), adaptToType);
toAddCapa.setProperties(properties);
map.put(capa.getId(), toAddCapa);
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class AbstractToscaParserSimpleProfileTest method testNodeType.
@SuppressWarnings("unchecked")
@Test
public void testNodeType() throws FileNotFoundException, ParsingException {
Mockito.reset(csarRepositorySearchService);
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
RelationshipType hostedOn = new RelationshipType();
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type.yml"));
ParserTestUtil.displayErrors(parsingResult);
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
Assert.assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(1, archiveRoot.getNodeTypes().size());
// check node type.
NodeType nodeType = archiveRoot.getNodeTypes().get("my_company.my_types.MyAppNodeType");
Assert.assertNotNull(nodeType);
Assert.assertEquals(Lists.newArrayList("tosca.nodes.SoftwareComponent", "tosca.nodes.Root"), nodeType.getDerivedFrom());
Assert.assertEquals("My company’s custom applicaton", nodeType.getDescription());
// validate properties parsing
Assert.assertEquals(4, nodeType.getProperties().size());
PropertyDefinition def1 = new PropertyDefinition();
def1.setType("string");
def1.setDefault(new ScalarPropertyValue("default"));
def1.setDescription("application password");
List<PropertyConstraint> constraints = Lists.newArrayList();
constraints.add(new MinLengthConstraint(6));
constraints.add(new MaxLengthConstraint(10));
def1.setConstraints(constraints);
PropertyDefinition def2 = new PropertyDefinition();
def2.setType("integer");
def2.setDescription("application port number");
PropertyDefinition def3 = new PropertyDefinition();
def3.setType("scalar-unit.size");
def3.setDefault(new ScalarPropertyValue("1 GB"));
LessThanConstraint ltConstraint = new LessThanConstraint();
ltConstraint.setLessThan("1 TB");
constraints = Lists.<PropertyConstraint>newArrayList(ltConstraint);
def3.setConstraints(constraints);
PropertyDefinition def4 = new PropertyDefinition();
def4.setType("scalar-unit.time");
def4.setDefault(new ScalarPropertyValue("1 d"));
GreaterThanConstraint gtConstraint = new GreaterThanConstraint();
gtConstraint.setGreaterThan("1 h");
constraints = Lists.<PropertyConstraint>newArrayList(gtConstraint);
def4.setConstraints(constraints);
Assert.assertEquals(MapUtil.newHashMap(new String[] { "my_app_password", "my_app_duration", "my_app_size", "my_app_port" }, new PropertyDefinition[] { def1, def4, def3, def2 }), nodeType.getProperties());
// check requirements
Assert.assertEquals(2, nodeType.getRequirements().size());
RequirementDefinition rd0 = nodeType.getRequirements().get(0);
Assert.assertEquals("host", rd0.getId());
Assert.assertEquals(1, rd0.getLowerBound());
Assert.assertEquals(1, rd0.getUpperBound());
RequirementDefinition rd1 = nodeType.getRequirements().get(1);
Assert.assertEquals("other", rd1.getId());
Assert.assertEquals(0, rd1.getLowerBound());
Assert.assertEquals(Integer.MAX_VALUE, rd1.getUpperBound());
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class DeleteInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, DeleteInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + "not found in topology");
}
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
removeInputIdInProperties(nodeTemplate.getProperties(), nodeType.getProperties(), operation.getInputName());
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
removeInputIdInProperties(relationshipTemplate.getProperties(), relationshipType.getProperties(), operation.getInputName());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Capability capability : nodeTemplate.getCapabilities().values()) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
removeInputIdInProperties(capability.getProperties(), capabilityType.getProperties(), operation.getInputName());
}
}
}
deletePreConfiguredInput(csar, topology, operation);
inputs.remove(operation.getInputName());
log.debug("Remove the input " + operation.getInputName() + " from the topology " + topology.getId());
}
Aggregations