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