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);
}
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);
}
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();
}
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));
}
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());
}
Aggregations