Search in sources :

Example 36 with ArchiveRoot

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

the class ToscaParserAlien200Test method parseTopologyTemplateWithRelationshipWorkflowMultipleActivities.

@Test
public void parseTopologyTemplateWithRelationshipWorkflowMultipleActivities() throws ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation.yml"));
    assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
    assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
    Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
    assertNotNull(wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source"));
    WorkflowStep step = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source");
    assertTrue(step instanceof RelationshipWorkflowStep);
    RelationshipWorkflowStep relStep = (RelationshipWorkflowStep) step;
    assertTrue(relStep.getTarget().equals("SoftwareComponent"));
    assertTrue(relStep.getTargetRelationship().equals("hostedOnComputeHost"));
    assertTrue(relStep.getOperationHost().equals("SOURCE"));
    assertEquals(1, relStep.getActivities().size());
    assertEquals(1, relStep.getOnSuccess().size());
    assertTrue(relStep.getOnSuccess().contains("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0"));
    // test the second step, create to split activities into steps
    WorkflowStep step_0 = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0");
    assertTrue(step_0 instanceof RelationshipWorkflowStep);
    RelationshipWorkflowStep relStep_0 = (RelationshipWorkflowStep) step_0;
    assertTrue(relStep_0.getTarget().equals("SoftwareComponent"));
    assertTrue(relStep_0.getTargetRelationship().equals("hostedOnComputeHost"));
    assertTrue(relStep_0.getOperationHost().equals("SOURCE"));
    assertEquals(1, relStep_0.getActivities().size());
    assertEquals(1, relStep_0.getOnSuccess().size());
    assertTrue(relStep_0.getOnSuccess().contains("SoftwareComponent_install"));
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) Test(org.junit.Test)

Example 37 with ArchiveRoot

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

the class PolicyTemplatePostProcessor method process.

@Override
public void process(final PolicyTemplate instance) {
    // ensure type exists
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
    final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
    if (policyType == null) {
        // error managed by the reference post processor.
        return;
    }
    final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
    // check that the targets are exiting node templates
    // TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
    safe(instance.getTargets()).forEach(target -> {
        if (!safe((topology.getNodeTemplates())).containsKey(target)) {
            // Dispatch an error.
            Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
        }
    });
    // Merge the policy template with data coming from the type (default values etc.).
    PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
    instance.setProperties(tempObject.getProperties());
    propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 38 with ArchiveRoot

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

the class PropertyDefinitionPostProcessor method validateType.

private void validateType(PropertyDefinition propertyDefinition) {
    String propertyType = propertyDefinition.getType();
    if (propertyType == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
        if (node == null) {
            node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
        }
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Property type must be defined", node.getEndMark(), "type"));
    } else if (!ToscaTypes.isSimple(propertyType)) {
        if (ToscaTypes.LIST.equals(propertyType) || ToscaTypes.MAP.equals(propertyType)) {
            PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
            if (entrySchema == null) {
                Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
                ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " must define entry schema", node.getEndMark(), "type"));
            } else {
                validateType(entrySchema);
            }
        } else {
            // It's data type
            ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
            if (!archiveRoot.getDataTypes().containsKey(propertyType)) {
                DataType dataType = ToscaContext.get(DataType.class, propertyType);
                if (dataType == null) {
                    Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
                    ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " is not found.", node.getEndMark(), "type"));
                }
            }
        }
    }
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Node(org.yaml.snakeyaml.nodes.Node) DataType(org.alien4cloud.tosca.model.types.DataType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 39 with ArchiveRoot

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

the class SuggestionService method postProcessSuggestionFromArchive.

public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
    ArchiveRoot archiveRoot = parsingResult.getResult();
    ParsingContext context = parsingResult.getContext();
    if (archiveRoot.hasToscaTopologyTemplate()) {
        Topology topology = archiveRoot.getTopology();
        Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
        if (MapUtils.isEmpty(nodeTemplateMap)) {
            return;
        }
        for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
            NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
            String nodeName = nodeTemplateEntry.getKey();
            if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
                checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
            }
            Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
            if (MapUtils.isNotEmpty(capabilityMap)) {
                for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
                    String capabilityName = capabilityEntry.getKey();
                    Capability capability = capabilityEntry.getValue();
                    if (MapUtils.isNotEmpty(capability.getProperties())) {
                        checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
                    }
                }
            }
            Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
            if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
                for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
                    String relationshipName = relationshipEntry.getKey();
                    RelationshipTemplate relationship = relationshipEntry.getValue();
                    if (MapUtils.isNotEmpty(relationship.getProperties())) {
                        checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
                    }
                }
            }
        }
    }
    if (archiveRoot.hasToscaTypes()) {
        Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
        if (MapUtils.isNotEmpty(allNodeTypes)) {
            for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
                NodeType nodeType = nodeTypeEntry.getValue();
                if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
                    for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
                        NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
                        if (nodeFilter != null) {
                            Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
                            if (MapUtils.isNotEmpty(capabilitiesFilters)) {
                                for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
                                    FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
                                    for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
                                        List<PropertyConstraint> constraints = constraintEntry.getValue();
                                        checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
                                    }
                                }
                            }
                        // FIXME check also the value properties filter of a node filter
                        }
                    }
                }
            }
        }
    }
}
Also used : RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) List(java.util.List) ArrayList(java.util.ArrayList) ParsingContext(alien4cloud.tosca.parser.ParsingContext) Capability(org.alien4cloud.tosca.model.templates.Capability) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map) NodeFilter(org.alien4cloud.tosca.model.definitions.NodeFilter)

Example 40 with ArchiveRoot

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

the class ArchiveIndexer method performIndexing.

private void performIndexing(ArchiveRoot root) {
    indexerService.indexInheritableElements(root.getArtifactTypes(), root.getArchive().getDependencies());
    indexerService.indexInheritableElements(root.getCapabilityTypes(), root.getArchive().getDependencies());
    indexerService.indexInheritableElements(root.getNodeTypes(), root.getArchive().getDependencies());
    indexerService.indexInheritableElements(root.getRelationshipTypes(), root.getArchive().getDependencies());
    indexerService.indexInheritableElements(root.getDataTypes(), root.getArchive().getDependencies());
    indexerService.indexInheritableElements(root.getPolicyTypes(), root.getArchive().getDependencies());
    if (root.getLocalImports() != null) {
        for (ArchiveRoot child : root.getLocalImports()) {
            performIndexing(child);
        }
    }
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot)

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