if (containGetSecretFunction(evaluatedProperty)) { return evaluatedProperty; case ToscaFunctionConstants.GET_PROPERTY: return getProperty(evaluatorContext, template, properties, evaluatedFunction); default: throw new IllegalArgumentException("GET_ATTRIBUTE or GET_OPERATION_OUTPUT cannot be defined on a property."); return concat(evaluatorContext, template, properties, (ConcatPropertyValue) evaluatedProperty);
private void processGetInput(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate template, Map<String, AbstractPropertyValue> properties) { for (Map.Entry<String, AbstractPropertyValue> propEntry : safe(properties).entrySet()) { try { AbstractPropertyValue value = FunctionEvaluator.tryResolveValue(evaluatorContext, template, properties, propEntry.getValue()); if (propEntry.getValue() != value) { propEntry.setValue(value); } } catch (IllegalArgumentException e) { // FIXME we should add an error log rather than throwing the exception here. See internal of FunctionEvaluator.resolveValue and especially // concat processing. throw e; } } } }
case ToscaFunctionConstants.SELF: if (properties != null) { AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, template, properties, function.getElementNameToFetch()); if (propertyValue != null) { return tryResolveValue(evaluatorContext, template, properties, propertyValue); return doGetProperty(evaluatorContext, template, function); case ToscaFunctionConstants.HOST: if (template instanceof NodeTemplate) { return doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) template), function); } else { params.addAll(function.getParameters().subList(2, function.getParameters().size())); FunctionPropertyValue newFunc = new FunctionPropertyValue(function.getFunction(), params); return tryResolveValue(evaluatorContext, firstNode, firstNode.getProperties(), newFunc); return doGetProperty(evaluatorContext, evaluatorContext.getTopology().getNodeTemplates().get(function.getTemplateName()), function);
if (requestInputParameter != null) { if (!(requestInputParameter instanceof Map) || !FunctionEvaluator.containGetSecretFunction(PropertyService.asFunctionPropertyValue(requestInputParameter))) {
Capability targetCapability = safe(((NodeTemplate) targetTemplate).getCapabilities()).get(function.getCapabilityOrRequirementName()); if (targetCapability != null) { propertyValue = getFromPath(evaluatorContext, targetTemplate, targetCapability.getProperties(), function.getElementNameToFetch()); Requirement requirement = safe(((NodeTemplate) targetTemplate).getRequirements()).get(function.getCapabilityOrRequirementName()); if (requirement != null) { propertyValue = getFromPath(evaluatorContext, targetTemplate, requirement.getProperties(), function.getElementNameToFetch()); propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function); return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue); 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); return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
addRequiredPropertyError(task, propertyErrorKey); } else if (FunctionEvaluator.containGetSecretFunction(value)) {
private static AbstractPropertyValue concat(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate template, Map<String, AbstractPropertyValue> properties, ConcatPropertyValue concatPropertyValue) { StringBuilder sb = new StringBuilder(); for (AbstractPropertyValue abstractPropertyValue : concatPropertyValue.getParameters()) { AbstractPropertyValue propertyValue = tryResolveValue(evaluatorContext, template, properties, abstractPropertyValue); if (propertyValue == null) { // Ignore this as it may be a null default value } else if (propertyValue instanceof ScalarPropertyValue) { sb.append(((ScalarPropertyValue) propertyValue).getValue()); } else if (propertyValue instanceof ListPropertyValue) { for (Object listValue : ((ListPropertyValue) propertyValue).getValue()) { if (listValue instanceof String) { sb.append(listValue); } else { throw new IllegalArgumentException("Concat can only be resolved for strings or list of strings."); } } } else if (propertyValue instanceof FunctionPropertyValue && ToscaFunctionConstants.GET_INPUT.equals(((FunctionPropertyValue) propertyValue).getFunction())) { // just ignore that as unprocessed inputs are from voluntary callback in the evaluator context for later processing. log.debug("Ignoring contact of an unresolved get_input function."); } else { throw new IllegalArgumentException("Concat can only be resolved for strings or list of strings."); } } return new ScalarPropertyValue(sb.toString()); }
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); }