use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class SetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
if (operation.getCapabilityName().equals(FORBIDDEN_CAPABILITY)) {
throw new UnsupportedSecretException("We cannot set a secret on the capability " + operation.getCapabilityName());
}
if ("".equals(operation.getSecretPath())) {
throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + "is null.");
}
FunctionPropertyValue getSecret = new FunctionPropertyValue();
getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
nodeTemplate.getCapabilities().get(operation.getCapabilityName()).getProperties().put(operation.getPropertyName(), getSecret);
log.debug("Set the property [ {} ] of capability template [ {} ] of node [ {} ] to the secret path [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class SetPolicyPropertyAsSecretProcessor method process.
@Override
protected void process(Csar csar, Topology topology, SetPolicyPropertyAsSecretOperation operation, PolicyTemplate policyTemplate) {
PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
AlienUtils.getOrFail(policyType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for policy [ {} ].", operation.getPropertyName(), policyTemplate.getType(), operation.getPolicyName());
FunctionPropertyValue secretFunction = new FunctionPropertyValue();
secretFunction.setFunction(ToscaFunctionConstants.GET_SECRET);
secretFunction.setParameters(Arrays.asList(operation.getSecretPath()));
policyTemplate.getProperties().put(operation.getPropertyName(), secretFunction);
log.debug("Associate the property [ {} ] of the policy template [ {} ] as secret [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getPolicyName(), operation.getSecretPath(), topology.getId());
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method nodeGetSecretProp.
@Test
public void nodeGetSecretProp() {
FunctionEvaluatorContext context = getEvaluationContext();
NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
AbstractPropertyValue resolved = FunctionEvaluator.tryResolveValue(context, template, template.getProperties(), template.getProperties().get("get_secret_prop"));
Assert.assertNotNull(resolved);
Assert.assertEquals(FunctionPropertyValue.class, resolved.getClass());
Assert.assertEquals("get_secret", ((FunctionPropertyValue) resolved).getFunction());
Assert.assertEquals("my/path", ((FunctionPropertyValue) resolved).getParameters().get(0));
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class ToscaSerializerTest method buildSamplePropertyValueMap.
private Map<String, AbstractPropertyValue> buildSamplePropertyValueMap() {
Map<String, AbstractPropertyValue> result = new HashMap<String, AbstractPropertyValue>();
result.put("prop1", new ScalarPropertyValue("value1"));
FunctionPropertyValue fpv1 = new FunctionPropertyValue();
fpv1.setFunction("get_property");
fpv1.setParameters(Lists.newArrayList("p1", "p2"));
result.put("prop2", fpv1);
FunctionPropertyValue fpv2 = new FunctionPropertyValue();
fpv2.setFunction("get_input");
fpv2.setParameters(Lists.newArrayList("p1"));
result.put("prop3", fpv2);
result.put("prop4", null);
result.put("prop5", new ScalarPropertyValue("a value containing a ["));
result.put("prop6", new ScalarPropertyValue("a value containing a ]"));
result.put("prop7", new ScalarPropertyValue("a value containing a {"));
result.put("prop8", new ScalarPropertyValue("a value containing a }"));
result.put("prop9", new ScalarPropertyValue("a value containing a :"));
result.put("prop9", new ScalarPropertyValue("a value containing a \""));
result.put("prop9", new ScalarPropertyValue("a value containing a : and a \""));
result.put("prop10", new ScalarPropertyValue(" a value starting with a space"));
result.put("prop11", new ScalarPropertyValue("a value ending with a space "));
return result;
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluator method parseAttribute.
/**
* Parse an attribute value that can be : {@link ConcatPropertyValue} / {@link AttributeDefinition}
*
* @param attributeId
* @param attributeValue
* @param topology
* @param runtimeInformations
* @param currentInstance
* @param basePaaSTemplate
* @param builtPaaSTemplates
* @return
*/
public static String parseAttribute(String attributeId, IValue attributeValue, Topology topology, Map<String, Map<String, InstanceInformation>> runtimeInformations, String currentInstance, IPaaSTemplate<? extends AbstractToscaType> basePaaSTemplate, Map<String, PaaSNodeTemplate> builtPaaSTemplates) {
if (attributeValue == null) {
return null;
}
// handle AttributeDefinition type
if (attributeValue instanceof AttributeDefinition) {
String runtimeAttributeValue = extractRuntimeInformationAttribute(runtimeInformations, currentInstance, Lists.newArrayList(basePaaSTemplate), attributeId);
if (runtimeAttributeValue != null) {
if (!runtimeAttributeValue.contains("=Error!]") && !runtimeAttributeValue.equals("")) {
return runtimeAttributeValue;
}
}
return ((AttributeDefinition) attributeValue).getDefault();
}
// handle concat function
if (attributeValue instanceof ConcatPropertyValue) {
StringBuilder evaluatedAttribute = new StringBuilder();
ConcatPropertyValue concatPropertyValue = (ConcatPropertyValue) attributeValue;
for (IValue concatParam : concatPropertyValue.getParameters()) {
// scalar type
if (concatParam instanceof ScalarPropertyValue) {
// scalar case
evaluatedAttribute.append(((ScalarPropertyValue) concatParam).getValue());
} else if (concatParam instanceof PropertyDefinition) {
// Definition case
// TODO : ?? what should i do here ?? currently returns default value in the definition
evaluatedAttribute.append(((PropertyDefinition) concatParam).getDefault());
} else if (concatParam instanceof FunctionPropertyValue) {
// Function case
FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) concatParam;
List<? extends IPaaSTemplate> paasTemplates = getPaaSTemplatesFromKeyword(basePaaSTemplate, functionPropertyValue.getTemplateName(), builtPaaSTemplates);
switch(functionPropertyValue.getFunction()) {
case ToscaFunctionConstants.GET_ATTRIBUTE:
evaluatedAttribute.append(extractRuntimeInformationAttribute(runtimeInformations, currentInstance, paasTemplates, functionPropertyValue.getElementNameToFetch()));
break;
case ToscaFunctionConstants.GET_PROPERTY:
evaluatedAttribute.append(extractRuntimeInformationProperty(topology, functionPropertyValue.getElementNameToFetch(), paasTemplates));
break;
case ToscaFunctionConstants.GET_OPERATION_OUTPUT:
String defaultValue = "<" + functionPropertyValue.getElementNameToFetch() + ">";
evaluatedAttribute.append(extractRuntimeInformationOperationOutput(runtimeInformations, currentInstance, paasTemplates, functionPropertyValue, defaultValue));
break;
default:
log.warn("Function [{}] is not yet handled in concat operation.", functionPropertyValue.getFunction());
break;
}
}
}
return evaluatedAttribute.toString();
}
// handle functions. For now, only support Get_OPERATION_OUTPUT on attributes scope
if (attributeValue instanceof FunctionPropertyValue) {
FunctionPropertyValue function = (FunctionPropertyValue) attributeValue;
switch(function.getFunction()) {
case ToscaFunctionConstants.GET_OPERATION_OUTPUT:
List<? extends IPaaSTemplate> paasTemplates = getPaaSTemplatesFromKeyword(basePaaSTemplate, function.getTemplateName(), builtPaaSTemplates);
return extractRuntimeInformationOperationOutput(runtimeInformations, currentInstance, paasTemplates, function, null);
default:
return null;
}
}
return null;
}
Aggregations