Search in sources :

Example 1 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project yorc-a4c-plugin by ystia.

the class ToscaComponentUtils method formatOperationInputs.

public static String formatOperationInputs(int indentLevel, Map<String, ? extends IValue> properties) throws IOException {
    StringBuilder buffer = new StringBuilder();
    for (Map.Entry<String, ? extends IValue> propertyEntry : properties.entrySet()) {
        if (propertyEntry.getValue() != null) {
            if (propertyEntry.getValue() instanceof PropertyValue && ((PropertyValue) propertyEntry.getValue()).getValue() == null) {
                continue;
            }
            buffer.append("\n").append(ToscaPropertySerializerUtils.indent(indentLevel)).append(propertyEntry.getKey()).append(": ");
            if (!propertyEntry.getValue().isDefinition()) {
                buffer.append(ToscaPropertySerializerUtils.formatPropertyValue(indentLevel, (AbstractPropertyValue) propertyEntry.getValue()));
            } else {
                Map<String, Object> velocityContext = ToscaComponentExporter.getVelocityContext();
                velocityContext.put("indent", indentLevel + 1);
                String template;
                if (propertyEntry.getValue() instanceof PropertyDefinition) {
                    velocityContext.put("property", propertyEntry.getValue());
                    template = "org/ystia/yorc/alien4cloud/plugin/tosca/property_def.vm";
                } else if (propertyEntry.getValue() instanceof AttributeDefinition) {
                    velocityContext.put("attribute", propertyEntry.getValue());
                    template = "org/ystia/yorc/alien4cloud/plugin/tosca/attribute_def.vm";
                } else {
                    throw new RuntimeException("Unsupported type: " + propertyEntry.getValue().getClass());
                }
                StringWriter writer = new StringWriter();
                VelocityUtil.generate(template, writer, velocityContext);
                buffer.append("\n").append(ToscaPropertySerializerUtils.indent(indentLevel + 1)).append(writer.toString());
            }
        }
    }
    return buffer.toString();
}
Also used : StringWriter(java.io.StringWriter) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 2 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class IndexedModelTest method mergeInheritableIndexMaps.

@Test
public void mergeInheritableIndexMaps() {
    NodeType son = new NodeType();
    son.setElementId("son");
    son.setArchiveVersion("1");
    PropertyDefinition propDef = new PropertyDefinition();
    AttributeDefinition attrDef = new AttributeDefinition();
    propDef.setType("string");
    propDef.setDefault(new ScalarPropertyValue("default_parent"));
    attrDef.setType("string");
    parent.setProperties(MapUtil.newHashMap(new String[] { "prop1" }, new PropertyDefinition[] { propDef }));
    parent.setAttributes(Maps.<String, IValue>newHashMap());
    parent.getAttributes().put("attr1", attrDef);
    propDef = new PropertyDefinition();
    propDef.setDefault(new ScalarPropertyValue("default_parent2"));
    propDef.setType("string");
    attrDef = new AttributeDefinition();
    attrDef.setType("version");
    parent.getProperties().put("prop2", propDef);
    parent.setAttributes(Maps.<String, IValue>newHashMap());
    parent.getAttributes().put("attr2", attrDef);
    propDef = new PropertyDefinition();
    propDef.setDefault(new ScalarPropertyValue("default_son"));
    propDef.setType("string");
    attrDef = new AttributeDefinition();
    attrDef.setType("integer");
    son.setProperties(MapUtil.newHashMap(new String[] { "prop1" }, new PropertyDefinition[] { propDef }));
    // son.setAttributes(MapUtil.newHashMap(new String[] { "attr1" }, new AttributeDefinition[] { attrDef }));
    son.setAttributes(Maps.<String, IValue>newHashMap());
    son.getAttributes().put("attr1", attrDef);
    propDef = new PropertyDefinition();
    propDef.setDefault(new ScalarPropertyValue("default_son2"));
    propDef.setType("integer");
    attrDef = new AttributeDefinition();
    attrDef.setType("boolean");
    son.getProperties().put("prop3", propDef);
    son.getAttributes().put("attr3", attrDef);
    IndexedModelUtils.mergeInheritableIndex(parent, son);
    // son should have 3 : 1 from himself, 1 from his parent, and one that he overrides from the parent
    assertEquals(3, son.getProperties().size());
    assertEquals(3, son.getAttributes().size());
    // son should'nt have parent's one when both defined the same
    PropertyDefinition propDefSon = son.getProperties().get("prop1");
    assertNotNull(propDefSon);
    assertEquals(new ScalarPropertyValue("default_son"), propDefSon.getDefault());
    AttributeDefinition attrDefSon = (AttributeDefinition) son.getAttributes().get("attr1");
    assertEquals("integer", attrDefSon.getType());
    // son has all parent's
    for (String key : parent.getProperties().keySet()) {
        assertTrue(son.getProperties().containsKey(key));
    }
    for (String key : parent.getAttributes().keySet()) {
        assertTrue(son.getAttributes().containsKey(key));
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 3 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillAttributesFromOutputCapabilitiesProperties.

private void fillAttributesFromOutputCapabilitiesProperties(Topology topology, NodeType substituteNodeType) {
    Map<String, Map<String, Set<String>>> outputCapabilityProperties = topology.getOutputCapabilityProperties();
    if (outputCapabilityProperties != null) {
        for (Map.Entry<String, Map<String, Set<String>>> ocpe : outputCapabilityProperties.entrySet()) {
            String nodeName = ocpe.getKey();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            for (Map.Entry<String, Set<String>> cpe : ocpe.getValue().entrySet()) {
                String capabilityName = cpe.getKey();
                String capabilityTypeName = nodeTemplate.getCapabilities().get(capabilityName).getType();
                CapabilityType capabilityType = ToscaContext.getOrFail(CapabilityType.class, capabilityTypeName);
                for (String propertyName : cpe.getValue()) {
                    PropertyDefinition pd = capabilityType.getProperties().get(propertyName);
                    // there is a conflict
                    addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
                }
            }
        }
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 4 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillSubstituteAttributesFromOutputProperties.

private void fillSubstituteAttributesFromOutputProperties(Topology topology, NodeType substituteNodeType) {
    Map<String, Set<String>> outputProperties = topology.getOutputProperties();
    if (outputProperties != null) {
        for (Map.Entry<String, Set<String>> ope : outputProperties.entrySet()) {
            String nodeName = ope.getKey();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            for (String propertyName : ope.getValue()) {
                PropertyDefinition pd = nodeTemplateType.getProperties().get(propertyName);
                // is a conflict
                addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
            }
        }
    }
}
Also used : Set(java.util.Set) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 5 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class UnsetRelationshipPropertyAsInputProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, UnsetRelationshipPropertyAsInputOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) {
    RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
    PropertyDefinition relationshipPropertyDefinition = getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property {} do not exist for relationship {} of node {}", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(relationshipPropertyDefinition);
    relationshipTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove association from property [ {} ] of relationship template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), topology.getId());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)101 Test (org.junit.Test)42 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)23 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)20 Map (java.util.Map)19 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeType (org.alien4cloud.tosca.model.types.NodeType)15 NotFoundException (alien4cloud.exception.NotFoundException)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)11 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 Capability (org.alien4cloud.tosca.model.templates.Capability)10 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)10 DataType (org.alien4cloud.tosca.model.types.DataType)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)8 Set (java.util.Set)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8