op = new ReadAttribute(address, complexRequest.getProp());
} else {
op = new ReadAttribute(address, reqName);
}
Result res = getASConnection().execute(op);
if (!res.isSuccess()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Getting metric [" + req.getName() + "] at [ " + address + "] failed: "
+ res.getFailureDescription());
}
return ReadMetricResult.RequestFailed;
}
Object val = res.getResult();
if (val == null) // One of the AS7 ways of telling "This is not implemented" See also AS7-1454
return ReadMetricResult.Null;
if (req.getDataType() == DataType.MEASUREMENT) {
if (val instanceof String && ((String) val).startsWith("JBAS018003")) // AS7 way of saying "no value available"
return ReadMetricResult.Null;
try {
if (complexRequest != null) {
@SuppressWarnings("unchecked")
Map<String, Number> myValues = (Map<String, Number>) val;
for (String key : myValues.keySet()) {
String sub = complexRequest.getSub();
if (key.equals(sub)) {
addMetric2Report(report, req, myValues.get(key), resolveExpression);
}
}
} else {
addMetric2Report(report, req, val, resolveExpression);
}
} catch (NumberFormatException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Non numeric input for [" + req.getName() + "] : [" + val + "]");
}
return ReadMetricResult.ResolveFailed;
}
} else if (req.getDataType() == DataType.TRAIT) {
if (resolveExpression && val instanceof Map && ((Map) val).containsKey(EXPRESSION_VALUE_KEY)) {
String expression = (String) ((Map) val).get(EXPRESSION_VALUE_KEY);
ResolveExpression resolveExpressionOperation = new ResolveExpression(expression);
Result result = getASConnection().execute(resolveExpressionOperation);
if (!result.isSuccess()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping trait [" + req.getName()
+ "] in measurement report. Could not resolve expression [" + expression
+ "], failureDescription:" + result.getFailureDescription());
return ReadMetricResult.ResolveFailed;
}
}
val = result.getResult();
}
MeasurementDataTrait data = new MeasurementDataTrait(req, getStringValue(val));
report.addData(data);
}