Search in sources :

Example 1 with IValue

use of org.alien4cloud.tosca.model.definitions.IValue in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method addAttributeFromPropertyDefinition.

private void addAttributeFromPropertyDefinition(PropertyDefinition pd, String propertyName, NodeType substituteNodeType) {
    // FIXME we have an issue here : if several nodes have the same attribute name, or if an attribute and a property have the same name,
    Map<String, IValue> attributes = substituteNodeType.getAttributes();
    if (pd != null && !attributes.containsKey(propertyName)) {
        if (ToscaTypes.isSimple(pd.getType())) {
            AttributeDefinition attributeDefinition = new AttributeDefinition();
            attributeDefinition.setType(pd.getType());
            attributeDefinition.setDescription(pd.getDescription());
            // FIXME known issue we don't support complex attributes right now.
            if (pd.getDefault() != null && pd.getDefault() instanceof ScalarPropertyValue) {
                attributeDefinition.setDefault(((ScalarPropertyValue) pd.getDefault()).getValue());
            }
            attributes.put(propertyName, attributeDefinition);
        }
    // FIXME else: known issue we don't support complex attributes right now.
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)

Example 2 with IValue

use of org.alien4cloud.tosca.model.definitions.IValue in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillSubstituteAttributesFromTypeAtttributes.

private void fillSubstituteAttributesFromTypeAtttributes(Topology topology, NodeType substituteNodeType) {
    Map<String, IValue> attributes = substituteNodeType.getAttributes();
    Map<String, Set<String>> outputAttributes = topology.getOutputAttributes();
    if (outputAttributes != null) {
        for (Map.Entry<String, Set<String>> oae : outputAttributes.entrySet()) {
            String nodeName = oae.getKey();
            NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            for (String attributeName : oae.getValue()) {
                IValue ivalue = nodeTemplateType.getAttributes().get(attributeName);
                // is a conflict
                if (ivalue != null && !attributes.containsKey(attributeName)) {
                    attributes.put(attributeName, ivalue);
                }
            }
        }
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) Set(java.util.Set) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 3 with IValue

use of org.alien4cloud.tosca.model.definitions.IValue in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processAttributesForOperationOutputs.

/**
 * Check attributes of a paaSNodeTemplate for get_operation_output usage, and register in the related operation the output name
 *
 * @param paaSNodeTemplate
 * @param paaSNodeTemplates
 */
private void processAttributesForOperationOutputs(final IPaaSTemplate<? extends AbstractInstantiableToscaType> paaSNodeTemplate, final Map<String, PaaSNodeTemplate> paaSNodeTemplates) {
    Map<String, IValue> attributes = paaSNodeTemplate.getIndexedToscaElement().getAttributes();
    if (MapUtils.isEmpty(attributes)) {
        return;
    }
    for (Entry<String, IValue> attribute : attributes.entrySet()) {
        String name = attribute.getKey();
        IValue value = attribute.getValue();
        processIValueForOperationOutput(name, value, paaSNodeTemplate, paaSNodeTemplates, true);
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue)

Example 4 with IValue

use of org.alien4cloud.tosca.model.definitions.IValue in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processOperationsInputsForOperationOutputs.

/**
 * Check operations input of every operations of all interfaces of a IPaaSTemplate for get_operation_output usage, and register in the related operation
 * the output name
 *
 * @param paaSTemplate
 * @param paaSNodeTemplates
 */
private <V extends AbstractInstantiableToscaType> void processOperationsInputsForOperationOutputs(final IPaaSTemplate<V> paaSTemplate, final Map<String, PaaSNodeTemplate> paaSNodeTemplates) {
    Map<String, Interface> interfaces = ((AbstractInstantiableToscaType) paaSTemplate.getIndexedToscaElement()).getInterfaces();
    if (interfaces != null) {
        for (Interface interfass : interfaces.values()) {
            for (Operation operation : interfass.getOperations().values()) {
                Map<String, IValue> inputsParams = operation.getInputParameters();
                if (inputsParams != null) {
                    for (Entry<String, IValue> input : inputsParams.entrySet()) {
                        String name = input.getKey();
                        IValue value = input.getValue();
                        processIValueForOperationOutput(name, value, paaSTemplate, paaSNodeTemplates, false);
                    }
                }
            }
        }
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 5 with IValue

use of org.alien4cloud.tosca.model.definitions.IValue 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;
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)

Aggregations

IValue (org.alien4cloud.tosca.model.definitions.IValue)10 Set (java.util.Set)3 AttributeDefinition (org.alien4cloud.tosca.model.definitions.AttributeDefinition)3 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 Interface (org.alien4cloud.tosca.model.definitions.Interface)3 Operation (org.alien4cloud.tosca.model.definitions.Operation)3 NodeType (org.alien4cloud.tosca.model.types.NodeType)3 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)2 Map (java.util.Map)2 Csar (org.alien4cloud.tosca.model.Csar)2 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)2 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)2 Test (org.junit.Test)2 ConstraintInformation (alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ConstraintRequiredParameterException (org.alien4cloud.tosca.exceptions.ConstraintRequiredParameterException)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 AbstractInstantiableToscaType (org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType)1 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)1