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.
}
}
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);
}
}
}
}
}
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);
}
}
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);
}
}
}
}
}
}
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;
}
Aggregations