Search in sources :

Example 76 with Topology

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

the class PropertyValueChecker method checkProperties.

/**
 * Check that the value of a property has the right type and match constraints.
 *
 * @param type The type that defines the properties (NodeType, CapabilityType, RequirementType).
 * @param propertyValues The map of values.
 * @param templateName The name of the node template /capability template / requirement template.
 */
public void checkProperties(final AbstractInheritableToscaType type, final Map<String, AbstractPropertyValue> propertyValues, final String templateName) {
    if (type == null) {
        // if the type is null we cannot check properties against their definition. Error is managed elsewhere.
        return;
    }
    ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
    Topology topology = archiveRoot.getTopology();
    for (Map.Entry<String, AbstractPropertyValue> propertyEntry : safe(propertyValues).entrySet()) {
        String propertyName = propertyEntry.getKey();
        AbstractPropertyValue propertyValue = propertyEntry.getValue();
        Node propertyValueNode = ParsingContextExecution.getObjectToNodeMap().get(propertyValue);
        if (type.getProperties() == null || !type.getProperties().containsKey(propertyName)) {
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.UNRECOGNIZED_PROPERTY, templateName, propertyValueNode.getStartMark(), "Property " + propertyName + " does not exist in type " + type.getElementId(), propertyValueNode.getEndMark(), propertyName));
            continue;
        }
        PropertyDefinition propertyDefinition = type.getProperties().get(propertyName);
        checkProperty(propertyName, propertyValueNode, propertyValue, propertyDefinition, topology.getInputs(), templateName);
    }
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 77 with Topology

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

the class WorkflowPostProcessor method processWorkflows.

/**
 * Process workflows of a topology
 *
 * @param topology     the topology to process workflow
 * @param topologyNode the yaml node of the topology
 */
public void processWorkflows(Topology topology, Node topologyNode) {
    // Workflow validation if any are defined
    TopologyContext topologyContext = workflowBuilderService.buildCachedTopologyContext(new TopologyContext() {

        @Override
        public String getDSLVersion() {
            return ParsingContextExecution.getDefinitionVersion();
        }

        @Override
        public Topology getTopology() {
            return topology;
        }

        @Override
        public <T extends AbstractToscaType> T findElement(Class<T> clazz, String id) {
            return ToscaContext.get(clazz, id);
        }
    });
    // If the workflow contains steps with multiple activities then split them into single activity steps
    splitMultipleActivitiesSteps(topologyContext);
    finalizeParsedWorkflows(topologyContext, topologyNode);
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology) TopologyContext(alien4cloud.paas.wf.TopologyContext)

Example 78 with Topology

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

the class OuputsParser method parse.

@Override
public Void parse(Node node, ParsingContextExecution context) {
    Topology topology = (Topology) context.getParent();
    if (!(node instanceof MappingNode)) {
        context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.YAML_MAPPING_NODE_EXPECTED, null, node.getStartMark(), null, node.getEndMark(), null));
        return null;
    }
    MappingNode mappingNode = (MappingNode) node;
    Map<String, Set<String>> outputAttributes = null;
    Map<String, Set<String>> outputProperties = null;
    Map<String, Map<String, Set<String>>> ouputCapabilityProperties = null;
    List<NodeTuple> children = mappingNode.getValue();
    for (NodeTuple child : children) {
        Node childValueNode = child.getValueNode();
        if (!(childValueNode instanceof MappingNode)) {
            // not a mapping jut ignore the entry
            continue;
        }
        for (NodeTuple childChild : ((MappingNode) childValueNode).getValue()) {
            if (childChild.getKeyNode() instanceof ScalarNode && ((ScalarNode) childChild.getKeyNode()).getValue().equals("value")) {
                // we are only interested by the 'value' node
                Node outputValueNode = childChild.getValueNode();
                // now we have to parse this node
                INodeParser<?> p = context.getRegistry().get("tosca_function");
                FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) p.parse(outputValueNode, context);
                String functionName = functionPropertyValue.getFunction();
                List<String> params = functionPropertyValue.getParameters();
                if (params.size() == 2) {
                    // we need exactly 2 params to be able to do the job : node name & property or attribute name
                    String nodeTemplateName = params.get(0);
                    String nodeTemplatePropertyOrAttributeName = params.get(1);
                    // TODO: should we check they exist ?
                    switch(functionName) {
                        case "get_attribute":
                            outputAttributes = addToMapOfSet(nodeTemplateName, nodeTemplatePropertyOrAttributeName, outputAttributes);
                            break;
                        case "get_property":
                            outputProperties = addToMapOfSet(nodeTemplateName, nodeTemplatePropertyOrAttributeName, outputProperties);
                            break;
                        default:
                            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.OUTPUTS_UNKNOWN_FUNCTION, null, outputValueNode.getStartMark(), null, outputValueNode.getEndMark(), functionName));
                    }
                } else if (params.size() == 3 && functionName.equals("get_property")) {
                    // in case of 3 parameters we only manage capabilities outputs for the moment
                    String nodeTemplateName = params.get(0);
                    String capabilityName = params.get(1);
                    String propertyName = params.get(2);
                    ouputCapabilityProperties = addToMapOfMapOfSet(nodeTemplateName, capabilityName, propertyName, ouputCapabilityProperties);
                } else {
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.OUTPUTS_BAD_PARAMS_COUNT, null, outputValueNode.getStartMark(), null, outputValueNode.getEndMark(), null));
                }
            }
        }
    }
    topology.setOutputProperties(outputProperties);
    topology.setOutputAttributes(outputAttributes);
    topology.setOutputCapabilityProperties(ouputCapabilityProperties);
    return null;
}
Also used : ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) Topology(org.alien4cloud.tosca.model.templates.Topology) ParsingError(alien4cloud.tosca.parser.ParsingError) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 79 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project yorc-a4c-plugin by ystia.

the class ToscaExportersTest method generateImports.

@Test
public void generateImports() {
    Mockito.reset(repositorySearchService);
    Csar csar = new Csar("tosca-normative-types", "2.0.0");
    csar.setImportSource(CSARSource.ALIEN.name());
    csar.setYamlFilePath("tosca-normative-types.yaml");
    Mockito.when(repositorySearchService.getArchive("tosca-normative-types", "2.0.0")).thenReturn(csar);
    csar = new Csar("yorc-types", "1.0.0");
    csar.setImportSource(CSARSource.ORCHESTRATOR.name());
    csar.setYamlFilePath("yorc-types.yaml");
    Mockito.when(repositorySearchService.getArchive("yorc-types", "1.0.0")).thenReturn(csar);
    csar = new Csar("yorc-openstack-types", "1.0.0");
    csar.setImportSource(CSARSource.ORCHESTRATOR.name());
    csar.setYamlFilePath("yorc-openstack-types.yaml");
    Mockito.when(repositorySearchService.getArchive("yorc-openstack-types", "1.0.0")).thenReturn(csar);
    csar = new Csar("mycomponent-pub", "3.0.0");
    csar.setImportSource(CSARSource.GIT.name());
    csar.setYamlFilePath("mycomponent-pub.yaml");
    Mockito.when(repositorySearchService.getArchive("mycomponent-pub", "3.0.0")).thenReturn(csar);
    csar = new Csar("mycomponent-impl", "3.0.0");
    csar.setImportSource(CSARSource.UPLOAD.name());
    csar.setYamlFilePath("mycomponent-impl.yaml");
    Mockito.when(repositorySearchService.getArchive("mycomponent-impl", "3.0.0")).thenReturn(csar);
    // Use linked hashset here to ensure ordering
    Set<CSARDependency> deps = new LinkedHashSet<>();
    deps.add(new CSARDependency("tosca-normative-types", "2.0.0"));
    deps.add(new CSARDependency("yorc-types", "1.0.0"));
    deps.add(new CSARDependency("yorc-openstack-types", "1.0.0"));
    deps.add(new CSARDependency("mycomponent-pub", "3.0.0"));
    deps.add(new CSARDependency("mycomponent-impl", "3.0.0"));
    csar = new Csar("mytopo", "1.0.0");
    csar.setTemplateAuthor("me");
    String expected = "tosca_definitions_version: alien_dsl_2_0_0\n" + "\n" + "metadata:\n" + "  template_name: mytopo\n" + "  template_version: 1.0.0\n" + "  template_author: me\n" + "\n" + "description: \"\"\n" + "\n" + "imports:\n" + "  - <yorc-types.yml>\n" + "  - <yorc-openstack-types.yml>\n" + "  - mycomponent-pub/3.0.0/mycomponent-pub.yaml\n" + "  - mycomponent-impl/3.0.0/mycomponent-impl.yaml\n" + "\n" + "topology_template:\n" + "  node_templates:\n";
    Topology topo = new Topology();
    topo.setDependencies(deps);
    String result = toscaTopologyExporter.getYaml(csar, topo, false);
    Assert.assertEquals(expected, result);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Csar(org.alien4cloud.tosca.model.Csar) Topology(org.alien4cloud.tosca.model.templates.Topology) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test) AbstractPluginTest(org.ystia.yorc.alien4cloud.plugin.AbstractPluginTest)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)79 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)22 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)16 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)9 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 IOException (java.io.IOException)8 List (java.util.List)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8 Component (org.springframework.stereotype.Component)8 Audit (alien4cloud.audit.annotation.Audit)7