use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluator method doGetProperty.
private static AbstractPropertyValue doGetProperty(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, FunctionPropertyValue function) {
if (targetTemplate == null) {
return null;
}
// If a requirement or capability name is defined then it is applied to the node template.
if (function.getCapabilityOrRequirementName() != null) {
if (targetTemplate instanceof RelationshipTemplate) {
throw new IllegalArgumentException("Get property that specifies a capability or relationship target must be placed on a node template and not a relationship template.");
}
AbstractPropertyValue propertyValue = null;
Capability targetCapability = safe(((NodeTemplate) targetTemplate).getCapabilities()).get(function.getCapabilityOrRequirementName());
if (targetCapability != null) {
propertyValue = getFromPath(evaluatorContext, targetTemplate, targetCapability.getProperties(), function.getElementNameToFetch());
}
if (propertyValue == null) {
Requirement requirement = safe(((NodeTemplate) targetTemplate).getRequirements()).get(function.getCapabilityOrRequirementName());
if (requirement != null) {
propertyValue = getFromPath(evaluatorContext, targetTemplate, requirement.getProperties(), function.getElementNameToFetch());
}
}
if (propertyValue == null) {
// try to find the value from the host node.
propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
}
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
// Try to fetch from the node.
AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, targetTemplate, targetTemplate.getProperties(), function.getElementNameToFetch());
if (propertyValue == null && targetTemplate instanceof NodeTemplate) {
propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
}
// if the property refers to a function (get_input/get_property then try to resolve it).
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class RebuildRelationshipProcessor method processRelationshipOperation.
@Override
protected void processRelationshipOperation(Csar csar, Topology topology, RebuildRelationshipOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) {
// rebuild a relationship template based on the current relationship type
log.debug("Rebuilding the relationship [ {} ] in the node template [ {} ] of topology [ {} ] .", operation.getRelationshipName(), operation.getNodeName(), topology.getId());
RelationshipType relType = ToscaContext.getOrFail(RelationshipType.class, relationshipTemplate.getType());
Map<String, AbstractPropertyValue> properties = Maps.newHashMap();
TemplateBuilder.fillProperties(properties, relType.getProperties(), relationshipTemplate.getProperties());
relationshipTemplate.setProperties(properties);
relationshipTemplate.setAttributes(relType.getAttributes());
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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());
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class UnsetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
// check if the node property value is a get_secret
AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
if (currentValue != null && !isGetSecret(currentValue)) {
throw new NotFoundException("Property {} of node {} is not an secret.", operation.getPropertyName(), operation.getNodeName());
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
log.debug("Remove secret property [ {} ] of capability template [ {} ] of node [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Aggregations