Search in sources :

Example 26 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot 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)

Example 27 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaTypePostProcessor method process.

@Override
public void process(AbstractInheritableToscaType instance) {
    ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
    instance.setArchiveName(archiveRoot.getArchive().getName());
    instance.setArchiveVersion(archiveRoot.getArchive().getVersion());
    // FIXME we had a check for element duplication cross types, is it required, do we still want/need that ?
    // FIXME the real thing we may want to check is more on alien side and consider the fact that a type should not be duplicated in multiple archives.
    // String previous = globalElementsMap.put(element.getKey(), parsedArchive.getContext().getFileName());
    // if (previous != null) {
    // parsedArchive.getContext().getParsingErrors().add(new ParsingError(ErrorCode.DUPLICATED_ELEMENT_DECLARATION,
    // "Type is defined twice in archive.", null, parsedArchive.getContext().getFileName(), null, previous));
    // }
    safe(instance.getProperties()).entrySet().stream().forEach(propertyDefinitionPostProcessor);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot)

Example 28 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class LocalRepositoryImpl method getArchive.

@Override
public Csar getArchive(String archiveName, String archiveVersion) {
    CSARDependency dependency = new CSARDependency(archiveName, archiveVersion);
    ArchiveRoot root = parse(dependency).getResult();
    return root == null ? null : root.getArchive();
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 29 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method policyTemplateParsingWithUnknownTypesShouldFail.

@Test
public void policyTemplateParsingWithUnknownTypesShouldFail() throws ParsingException {
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
    NodeType nodeType = new NodeType();
    nodeType.setElementId("tosca.nodes.Compute");
    nodeType.setArchiveName("tosca-normative-types");
    nodeType.setArchiveVersion("1.0.0-ALIEN14");
    nodeType.setDerivedFrom(Lists.newArrayList("tosca.nodes.Root"));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(nodeType);
    nodeType = new NodeType();
    nodeType.setElementId("tosca.nodes.Root");
    nodeType.setArchiveName("tosca-normative-types");
    nodeType.setArchiveVersion("1.0.0-ALIEN14");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(nodeType);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-policy-template-fail.yml"));
    assertEquals(1, parsingResult.getContext().getParsingErrors().size());
    assertEquals(1, countErrorByLevelAndCode(parsingResult, ParsingErrorLevel.ERROR, ErrorCode.TYPE_NOT_FOUND));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 30 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method testPolicyTemplateParsing.

@Test
public void testPolicyTemplateParsing() throws ParsingException {
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
    NodeType nodeType = new NodeType();
    nodeType.setElementId("tosca.nodes.Root");
    nodeType.setArchiveName("tosca-normative-types");
    nodeType.setArchiveVersion("1.0.0-ALIEN14");
    nodeType.setDerivedFrom(Lists.newArrayList("tosca.nodes.Root"));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(nodeType);
    nodeType = new NodeType();
    nodeType.setElementId("tosca.nodes.Root");
    nodeType.setArchiveName("tosca-normative-types");
    nodeType.setArchiveVersion("1.0.0-ALIEN14");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(nodeType);
    PolicyType policyType = Mockito.mock(PolicyType.class);
    policyType.setElementId("tosca.nodes.Root");
    policyType.setArchiveName("tosca-normative-types");
    policyType.setArchiveVersion("1.0.0-ALIEN14");
    Mockito.when(policyType.isAbstract()).thenReturn(true);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(PolicyType.class), Mockito.eq("tosca.policies.Root"), Mockito.any(Set.class))).thenReturn(policyType);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-policy-template.yml"));
    assertEquals(0, parsingResult.getContext().getParsingErrors().size());
    ArchiveRoot archiveRoot = parsingResult.getResult();
    assertNotNull(archiveRoot.getArchive());
    assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
    assertEquals(1, archiveRoot.getPolicyTypes().size());
    PolicyType simplePolicyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.SamplePolicy");
    assertNotNull(simplePolicyType);
    assertEquals("org.alien4cloud.sample.SamplePolicy", simplePolicyType.getElementId());
    assertEquals("This is a sample policy type with simple definition", simplePolicyType.getDescription());
    assertEquals(1, simplePolicyType.getDerivedFrom().size());
    assertEquals("tosca.policies.Root", simplePolicyType.getDerivedFrom().get(0));
    assertEquals(2, simplePolicyType.getTags().size());
    assertEquals("sample_meta", simplePolicyType.getTags().get(0).getName());
    assertEquals("a meta data", simplePolicyType.getTags().get(0).getValue());
    assertEquals("anoter_meta", simplePolicyType.getTags().get(1).getName());
    assertEquals("another meta data", simplePolicyType.getTags().get(1).getValue());
    assertEquals(1, simplePolicyType.getProperties().size());
    assertNotNull(simplePolicyType.getProperties().get("sample_property"));
    assertEquals("string", simplePolicyType.getProperties().get("sample_property").getType());
    assertEquals(2, simplePolicyType.getTargets().size());
    assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Compute"));
    assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Root"));
    // Test that the template is correctly parsed
    assertNotNull(archiveRoot.getTopology());
    assertEquals(1, archiveRoot.getTopology().getPolicies().size());
    assertNotNull(archiveRoot.getTopology().getPolicies().get("anti_affinity_policy"));
    assertEquals("org.alien4cloud.sample.SamplePolicy", archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getType());
    assertEquals(1, archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getProperties().size());
    assertNotNull(archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getProperties().get("sample_property"));
    assertEquals(2, archiveRoot.getTopology().getPolicies().get("anti_affinity_policy").getTags().size());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Aggregations

ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)78 Test (org.junit.Test)45 Csar (org.alien4cloud.tosca.model.Csar)27 Set (java.util.Set)26 NodeType (org.alien4cloud.tosca.model.types.NodeType)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)16 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 ParsingError (alien4cloud.tosca.parser.ParsingError)13 Path (java.nio.file.Path)11 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Node (org.yaml.snakeyaml.nodes.Node)8 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)6 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)6 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)6 ParsingException (alien4cloud.tosca.parser.ParsingException)5 Map (java.util.Map)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4