Search in sources :

Example 36 with NodeTemplate

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

the class BlockStorageEventHandler method updateRuntimeTopology.

private void updateRuntimeTopology(DeploymentTopology runtimeTopo, PaaSInstancePersistentResourceMonitorEvent persistentResourceEvent, Map<String, Object> persistentProperties) {
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(runtimeTopo, persistentResourceEvent.getNodeTemplateId());
    log.info("Updating Runtime topology: Storage NodeTemplate <{}.{}> to add a new volumeId", runtimeTopo.getId(), persistentResourceEvent.getNodeTemplateId());
    for (String key : persistentProperties.keySet()) {
        nodeTemplate.getProperties().put(key, getPropertyValue(persistentProperties.get(key)));
        log.debug("Property [ {} ] to update: [ {} ]. New value is [ {} ]", key, persistentResourceEvent.getPersistentProperties().get(key), persistentProperties.get(key));
    }
    alienMonitorDao.save(runtimeTopo);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate)

Example 37 with NodeTemplate

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

the class ToscaParserAlien140Test method testCapabilitiesComplexProperty.

@Test
public void testCapabilitiesComplexProperty() throws ParsingException {
    Mockito.reset(csarRepositorySearchService);
    Csar csar = new Csar("tosca-normative-types", "1.0.0-ALIEN14");
    Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
    NodeType mockedResult = Mockito.mock(NodeType.class);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
    CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Root"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    DataType mockedDataType = new DataType();
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(DataType.class), Mockito.eq("tosca.datatypes.Root"), Mockito.any(Set.class))).thenReturn(mockedDataType);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "capa_complex_props.yml"));
    Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
    ArchiveRoot archiveRoot = parsingResult.getResult();
    // check the capabilityType
    // ////////////
    CapabilityType capaType = archiveRoot.getCapabilityTypes().values().stream().findFirst().get();
    assertNotNull(capaType.getProperties());
    Assert.assertEquals(3, capaType.getProperties().size());
    // map property
    String map = "map";
    PropertyDefinition propertyDefinition = capaType.getProperties().get(map);
    assertNotNull(propertyDefinition.getDefault());
    assertTrue(propertyDefinition.getDefault() instanceof ComplexPropertyValue);
    Map<String, Object> propertyMapValue = ((ComplexPropertyValue) propertyDefinition.getDefault()).getValue();
    assertNotNull(propertyMapValue);
    Assert.assertEquals(2, propertyMapValue.size());
    Assert.assertEquals("toto_value", propertyMapValue.get("toto"));
    Assert.assertEquals("tata_value", propertyMapValue.get("tata"));
    // custom property
    String custom = "custom";
    propertyDefinition = capaType.getProperties().get(custom);
    assertEquals("alien.test.datatypes.Custom", propertyDefinition.getType());
    assertNull(propertyDefinition.getDefault());
    // custom_with_default property
    String custom_with_default = "custom_with_default";
    propertyDefinition = capaType.getProperties().get(custom_with_default);
    assertNotNull(propertyDefinition.getDefault());
    assertTrue(propertyDefinition.getDefault() instanceof ComplexPropertyValue);
    propertyMapValue = ((ComplexPropertyValue) propertyDefinition.getDefault()).getValue();
    assertNotNull(propertyMapValue);
    assertEquals(2, propertyMapValue.size());
    assertEquals("defaultName", propertyMapValue.get("name"));
    Object list = propertyMapValue.get("groups");
    assertTrue(list instanceof List);
    assertEquals(2, ((List) list).size());
    assertTrue(CollectionUtils.containsAll((List) list, Lists.newArrayList("alien", "fastconnect")));
    // check the node template capability
    // ////////////
    NodeTemplate nodeTemplate = archiveRoot.getTopology().getNodeTemplates().values().stream().findFirst().get();
    Capability capability = nodeTemplate.getCapabilities().values().stream().findFirst().get();
    assertNotNull(capability);
    Assert.assertEquals(3, capability.getProperties().size());
    // map property
    AbstractPropertyValue propertyValue = capability.getProperties().get(map);
    assertNotNull(propertyValue);
    assertTrue(propertyValue instanceof ComplexPropertyValue);
    propertyMapValue = ((ComplexPropertyValue) propertyValue).getValue();
    assertNotNull(propertyMapValue);
    Assert.assertEquals(2, propertyMapValue.size());
    Assert.assertEquals("toto_value", propertyMapValue.get("toto"));
    Assert.assertEquals("tata_value", propertyMapValue.get("tata"));
    // custom property
    propertyValue = capability.getProperties().get(custom);
    assertNotNull(propertyValue);
    assertTrue(propertyValue instanceof ComplexPropertyValue);
    propertyMapValue = ((ComplexPropertyValue) propertyValue).getValue();
    assertNotNull(propertyMapValue);
    assertEquals(2, propertyMapValue.size());
    assertEquals("manual", propertyMapValue.get("name"));
    list = propertyMapValue.get("groups");
    assertTrue(list instanceof List);
    assertEquals(2, ((List) list).size());
    assertTrue(CollectionUtils.containsAll((List) list, Lists.newArrayList("manual_alien", "manual_fastconnect")));
    // custom_with_default property
    propertyValue = capability.getProperties().get(custom_with_default);
    assertNotNull(propertyValue);
    assertTrue(propertyValue instanceof ComplexPropertyValue);
    propertyMapValue = ((ComplexPropertyValue) propertyValue).getValue();
    assertNotNull(propertyMapValue);
    assertEquals(2, propertyMapValue.size());
    assertEquals("defaultName", propertyMapValue.get("name"));
    list = propertyMapValue.get("groups");
    assertTrue(list instanceof List);
    assertEquals(2, ((List) list).size());
    assertTrue(CollectionUtils.containsAll((List) list, Lists.newArrayList("alien", "fastconnect")));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) DataType(org.alien4cloud.tosca.model.types.DataType) List(java.util.List) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 38 with NodeTemplate

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

the class ToscaParserSimpleProfileAlien120Test method testDataTypesExtendsNative.

@Test
public void testDataTypesExtendsNative() throws ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-data-types-extends-native.yml"));
    ParserTestUtil.displayErrors(parsingResult);
    Assert.assertEquals(3, parsingResult.getResult().getDataTypes().size());
    Assert.assertEquals(2, parsingResult.getResult().getNodeTypes().size());
    Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
    Assert.assertEquals(1, parsingResult.getResult().getTopology().getNodeTemplates().size());
    NodeTemplate nodeTemplate = parsingResult.getResult().getTopology().getNodeTemplates().values().iterator().next();
    Assert.assertEquals(3, nodeTemplate.getProperties().size());
    // check url property
    Assert.assertTrue(nodeTemplate.getProperties().containsKey("url"));
    AbstractPropertyValue url = nodeTemplate.getProperties().get("url");
    Assert.assertTrue(url instanceof ScalarPropertyValue);
    Assert.assertEquals("https://kikoo.com", ((ScalarPropertyValue) url).getValue());
    // check ipv6_addresses property
    Assert.assertTrue(nodeTemplate.getProperties().containsKey("ipv6_addresses"));
    AbstractPropertyValue ipv6_addresses = nodeTemplate.getProperties().get("ipv6_addresses");
    Assert.assertTrue(ipv6_addresses instanceof ListPropertyValue);
    List<Object> ipv6_addresses_list = ((ListPropertyValue) ipv6_addresses).getValue();
    Assert.assertEquals(2, ipv6_addresses_list.size());
    Assert.assertEquals("192.168.0.10", ipv6_addresses_list.get(0));
    Assert.assertEquals("10.0.0.10", ipv6_addresses_list.get(1));
    // check passwords property
    Assert.assertTrue(nodeTemplate.getProperties().containsKey("passwords"));
    AbstractPropertyValue passwords = nodeTemplate.getProperties().get("passwords");
    Assert.assertTrue(passwords instanceof ComplexPropertyValue);
    Map<String, Object> passwords_map = ((ComplexPropertyValue) passwords).getValue();
    Assert.assertEquals(2, passwords_map.size());
    Assert.assertEquals("123456789", passwords_map.get("user1"));
    Assert.assertEquals("abcdefghij", passwords_map.get("user2"));
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 39 with NodeTemplate

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

the class RelationshipPostProcessor method process.

public void process(NodeType nodeTemplateType, Map.Entry<String, RelationshipTemplate> instance) {
    RelationshipTemplate relationshipTemplate = instance.getValue();
    if (relationshipTemplate.getTarget() == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
        // the node template name is required
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.REQUIREMENT_TARGET_NODE_TEMPLATE_NAME_REQUIRED, null, node.getStartMark(), null, node.getEndMark(), null));
    }
    RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
    propertyValueChecker.checkProperties(relationshipType, relationshipTemplate.getProperties(), instance.getKey());
    RequirementDefinition rd = getRequirementDefinitionByName(nodeTemplateType, relationshipTemplate.getRequirementName());
    if (rd == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(relationshipTemplate.getRequirementName());
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.REQUIREMENT_NOT_FOUND, null, node.getStartMark(), null, node.getEndMark(), relationshipTemplate.getRequirementName()));
        return;
    }
    if (relationshipTemplate.getType() == null) {
        // if the relationship type has not been defined on the requirement assignment it may be defined on the requirement definition.
        relationshipTemplate.setType(rd.getRelationshipType());
    }
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(relationshipTemplate, relationshipTemplate.getType(), RelationshipType.class));
    relationshipTemplate.setRequirementType(rd.getType());
    ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
    // now find the target of the relation
    NodeTemplate targetNodeTemplate = archiveRoot.getTopology().getNodeTemplates().get(relationshipTemplate.getTarget());
    if (targetNodeTemplate == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(relationshipTemplate.getTarget());
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.REQUIREMENT_TARGET_NOT_FOUND, null, node.getStartMark(), null, node.getEndMark(), relationshipTemplate.getTarget()));
        return;
    }
    // alien actually supports a capability type in the TOSCA yaml
    String capabilityStr = relationshipTemplate.getTargetedCapabilityName();
    Capability capability = null;
    if (capabilityStr == null) {
        // the capability type is not known, we assume that we are parsing a Short notation (node only)
        if (targetNodeTemplate.getCapabilities() != null) {
            // let's try to find all match for a given type
            capability = getCapabilityByType(targetNodeTemplate, relationshipTemplate, relationshipTemplate.getRequirementType());
            if (capability == null) {
                capability = targetNodeTemplate.getCapabilities().get(relationshipTemplate.getRequirementName());
                if (capability != null) {
                    relationshipTemplate.setTargetedCapabilityName(rd.getId());
                }
            }
        }
    } else {
        // Let's try to find if the target node has a capability as named in the capability string of the relationship (requirement assignment)
        if (targetNodeTemplate.getCapabilities() != null) {
            capability = targetNodeTemplate.getCapabilities().get(capabilityStr);
        }
        if (capability == null) {
            // The capabilityStr may be the name of a type
            capability = getCapabilityByType(targetNodeTemplate, relationshipTemplate, capabilityStr);
        }
    }
    if (capability == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(relationshipTemplate);
        // we should fail
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.REQUIREMENT_CAPABILITY_NOT_FOUND, null, node.getStartMark(), null, node.getEndMark(), relationshipTemplate.getRequirementName()));
        return;
    }
    RelationshipType indexedRelationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
    if (indexedRelationshipType == null) {
        // Error managed by the reference post processor.
        return;
    }
    Map<String, AbstractPropertyValue> properties = Maps.newLinkedHashMap();
    TemplateBuilder.fillProperties(properties, indexedRelationshipType.getProperties(), relationshipTemplate.getProperties(), false);
    relationshipTemplate.setProperties(properties);
    relationshipTemplate.setAttributes(indexedRelationshipType.getAttributes());
    // FIXME we should check that the artifact is defined at the type level.
    safe(instance.getValue().getArtifacts()).values().forEach(templateDeploymentArtifactPostProcessor);
    Map<String, DeploymentArtifact> mergedArtifacts = instance.getValue().getArtifacts();
    if (mergedArtifacts == null) {
        mergedArtifacts = new HashMap<>();
    }
    mergedArtifacts.putAll(safe(indexedRelationshipType.getArtifacts()));
    relationshipTemplate.setArtifacts(mergedArtifacts);
    // TODO Manage interfaces inputs to copy them to all operations.
    for (Interface anInterface : safe(instance.getValue().getInterfaces()).values()) {
        safe(anInterface.getOperations()).values().stream().map(Operation::getImplementationArtifact).filter(Objects::nonNull).forEach(implementationArtifactPostProcessor);
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) Node(org.yaml.snakeyaml.nodes.Node) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate)

Example 40 with NodeTemplate

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

the class TopologyPostProcessor method process.

@Override
public void process(Topology instance) {
    if (instance == null) {
        return;
    }
    ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
    // The yaml node for the topology
    Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
    setDependencies(instance, archiveRoot);
    if (instance.isEmpty()) {
        // if the topology doesn't contains any node template it won't be imported so add a warning.
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.EMPTY_TOPOLOGY, null, node.getStartMark(), null, node.getEndMark(), ""));
    }
    // archive name and version
    instance.setArchiveName(archiveRoot.getArchive().getName());
    instance.setArchiveVersion(archiveRoot.getArchive().getVersion());
    // Inputs validation
    safe(instance.getInputs()).entrySet().forEach(propertyDefinitionPostProcessor);
    safe(instance.getInputArtifacts()).values().forEach(typeDeploymentArtifactPostProcessor);
    int groupIndex = 0;
    // Groups validation
    for (NodeGroup nodeGroup : safe(instance.getGroups()).values()) {
        nodeGroup.setIndex(groupIndex++);
        groupPostProcessor.process(nodeGroup);
    }
    // Policies templates validation
    safe(instance.getPolicies()).forEach((policyName, policyTemplate) -> {
        // set the templateName
        policyTemplate.setName(policyName);
        policyTemplatePostProcessor.process(policyTemplate);
    });
    // Node templates validation
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : safe(instance.getNodeTemplates()).entrySet()) {
        nodeTemplateEntry.getValue().setName(nodeTemplateEntry.getKey());
        nodeTemplatePostProcessor.process(nodeTemplateEntry.getValue());
    }
    safe(instance.getNodeTemplates()).values().forEach(nodeTemplateRelationshipPostProcessor);
    substitutionMappingPostProcessor.process(instance.getSubstitutionMapping());
    // first validate names
    TopologyUtils.normalizeAllNodeTemplateName(instance, ParsingContextExecution.getParsingErrors(), ParsingContextExecution.getObjectToNodeMap());
    // Post process workflows
    workflowPostProcessor.processWorkflows(instance, node);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Node(org.yaml.snakeyaml.nodes.Node) Map(java.util.Map) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10