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