use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class DeleteInputProcessor method removeInputIdInProperties.
/**
* Remove the inputId for the {@link FunctionPropertyValue} of a Map of properties.
*
* @param properties the list of properties values currently defined in the topology.
* @param propertyDefinitions the list of definitions of properties (matching the list of values).
* @param inputId The id of the input to remove.
*/
private void removeInputIdInProperties(final Map<String, AbstractPropertyValue> properties, final Map<String, PropertyDefinition> propertyDefinitions, final String inputId) {
if (properties == null) {
return;
}
for (Map.Entry<String, AbstractPropertyValue> propertyEntry : properties.entrySet()) {
if (propertyEntry.getValue() instanceof FunctionPropertyValue) {
FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) propertyEntry.getValue();
if (ToscaFunctionConstants.GET_INPUT.equals(functionPropertyValue.getFunction()) && functionPropertyValue.getTemplateName().equals(inputId)) {
PropertyDefinition pd = propertyDefinitions.get(propertyEntry.getKey());
AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(pd);
propertyEntry.setValue(pv);
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class ReplaceNodeProcessor method updateRelationshipsCapabilitiesRelationships.
private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) {
List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates());
for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship();
Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName());
if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) {
Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType());
targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey());
// check that the relationship type is still valid with the new capability
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType());
if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) {
NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType());
RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName());
NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey());
RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition);
targetRelationship.setType(validRelationshipType.getElementId());
targetRelationship.setType(validRelationshipType.getElementId());
targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts())));
targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes())));
Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null);
targetRelationship.setProperties(properties);
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluator method getFromPath.
private static AbstractPropertyValue getFromPath(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, Map<String, AbstractPropertyValue> properties, String propertyPath) {
if (propertyPath.contains(".")) {
String propertyName = propertyPath.split("\\.")[0];
AbstractPropertyValue propertyValue = properties.get(propertyName);
if (!(propertyValue instanceof PropertyValue)) {
// if the value is not a property value resolve it first
propertyValue = tryResolveValue(evaluatorContext, targetTemplate, properties, propertyValue);
if (propertyValue == null) {
return null;
}
}
// now it is a property value
Object value = MapUtil.get(((PropertyValue) propertyValue).getValue(), propertyPath.substring(propertyName.length() + 1));
if (value == null) {
return null;
} else if (value instanceof String) {
return new ScalarPropertyValue((String) value);
} else if (value instanceof List) {
return new ListPropertyValue((List<Object>) value);
} else if (value instanceof Map) {
return new ComplexPropertyValue((Map<String, Object>) value);
}
throw new IllegalArgumentException("The value of a property must be a scalar, a list or a map.");
}
return safe(properties).get(propertyPath);
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class UnsetNodePropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
// check if the node property value is a get_secret
AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName());
if (currentValue != null && !isGetSecret(currentValue)) {
throw new NotFoundException("Property {} of node {} is not associated to an secret.", operation.getPropertyName(), operation.getNodeName());
}
NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition);
nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
log.debug("Remove secret property [ {} ] of the node template [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method concatOfAnGetSecretShouldFailed.
@Test
public void concatOfAnGetSecretShouldFailed() {
FunctionEvaluatorContext context = getEvaluationContext();
NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
AbstractPropertyValue resolved = FunctionEvaluator.tryResolveValue(context, template, template.getProperties(), template.getProperties().get("concat_prop_and_get_secret"));
Assert.assertNotNull(resolved);
Assert.assertEquals(ConcatPropertyValue.class, resolved.getClass());
ConcatPropertyValue resolvedConcat = (ConcatPropertyValue) resolved;
Assert.assertEquals(ScalarPropertyValue.class, resolvedConcat.getParameters().get(0).getClass());
Assert.assertEquals(FunctionPropertyValue.class, resolvedConcat.getParameters().get(1).getClass());
}
Aggregations