use of alien4cloud.paas.IPaaSTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluator method extractRuntimeInformationProperty.
/**
* Extract property value from runtime informations
*
* @param topology
* @param propertyOrAttributeName
* @param nodes
* @return
*/
private static String extractRuntimeInformationProperty(Topology topology, String propertyOrAttributeName, List<? extends IPaaSTemplate> nodes) {
AbstractPropertyValue propertyOrAttributeValue;
NodeTemplate template = null;
for (IPaaSTemplate node : nodes) {
String nodeName = node.getId();
template = topology.getNodeTemplates().get(nodeName);
if (template != null && template.getProperties() != null) {
propertyOrAttributeValue = template.getProperties().get(propertyOrAttributeName);
if (propertyOrAttributeValue != null) {
return PropertyUtil.getScalarValue(propertyOrAttributeValue);
}
}
}
log.warn("Couldn't find property [ {} ] of node [ {} ]", propertyOrAttributeName, nodes);
return "[" + nodes + "." + propertyOrAttributeName + "=Error!]";
}
use of alien4cloud.paas.IPaaSTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluator method extractRuntimeInformationAttribute.
/**
* Return the first matching value in parent nodes hierarchy
*
* @param runtimeInformations
* @param currentInstance
* @param nodes
* @param propertyOrAttributeName
* @return runtime value
*/
private static String extractRuntimeInformationAttribute(Map<String, Map<String, InstanceInformation>> runtimeInformations, String currentInstance, List<? extends IPaaSTemplate> nodes, String propertyOrAttributeName) {
Map<String, String> attributes = null;
// return the first found
for (IPaaSTemplate node : nodes) {
String nodeName = node.getId();
// get the current attribute value
if (runtimeInformations.get(nodeName) != null) {
// get value for an instance if instance number found
if (runtimeInformations.get(nodeName).containsKey(currentInstance)) {
attributes = runtimeInformations.get(nodeName).get(currentInstance).getAttributes();
} else {
attributes = runtimeInformations.get(nodeName).entrySet().iterator().next().getValue().getAttributes();
}
if (attributes.containsKey(propertyOrAttributeName)) {
return attributes.get(propertyOrAttributeName);
}
}
}
log.warn("Couldn't find attribute [ {} ] in nodes [ {} ]", propertyOrAttributeName, nodes.toString());
// value not yet computed (or won't be computes)
return "<" + propertyOrAttributeName + ">";
}
use of alien4cloud.paas.IPaaSTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluator method extractRuntimeInformationOperationOutput.
private static String extractRuntimeInformationOperationOutput(Map<String, Map<String, InstanceInformation>> runtimeInformations, String instanceId, List<? extends IPaaSTemplate> nodes, FunctionPropertyValue function, String defaultValue) {
String outputRQN = AlienUtils.prefixWith(AlienConstants.OPERATION_NAME_SEPARATOR, function.getElementNameToFetch(), function.getInterfaceName(), function.getOperationName());
// return the first found
for (IPaaSTemplate node : nodes) {
String nodeName = node.getId();
if (runtimeInformations.get(nodeName) != null) {
Map<String, String> outputs;
// get value for an instance if instance number found
if (runtimeInformations.get(nodeName).containsKey(instanceId)) {
outputs = runtimeInformations.get(nodeName).get(instanceId).getOperationsOutputs();
} else {
outputs = runtimeInformations.get(nodeName).entrySet().iterator().next().getValue().getAttributes();
}
String formatedOutputName = ToscaNormativeUtil.formatedOperationOutputName(nodeName, function.getInterfaceName(), function.getOperationName(), function.getElementNameToFetch());
if (outputs.containsKey(formatedOutputName)) {
return outputs.get(formatedOutputName);
}
}
}
log.warn("Couldn't find output [ {} ] in nodes [ {} ]", outputRQN, nodes.toString());
return defaultValue;
}
Aggregations