提交 1bfc68c8 编写于 作者: G Gao Hongtao 提交者: wu-sheng

Fix thermodynamic query error (#1716)

* Avoid query error by adding initial instance to AlarmTrend

* Fix thermodynamic query
上级 813ea1ed
......@@ -26,6 +26,7 @@ public class Const {
public static final String ID_SPLIT = "_";
public static final String KEY_VALUE_SPLIT = ",";
public static final String ARRAY_SPLIT = "|";
public static final String ARRAY_PARSER_SPLIT = "\\|";
public static final int USER_SERVICE_ID = 1;
public static final int USER_INSTANCE_ID = 1;
public static final int USER_ENDPOINT_ID = 1;
......
......@@ -49,11 +49,11 @@ public class IntKeyLongValueArray extends ArrayList<IntKeyLongValue> implements
}
@Override public void toObject(String data) {
String[] keyValues = data.split(Const.ARRAY_SPLIT);
String[] keyValues = data.split(Const.ARRAY_PARSER_SPLIT);
for (int i = 0; i < keyValues.length; i++) {
IntKeyLongValue value = new IntKeyLongValue();
value.toObject(keyValues[i]);
this.set(i, value);
this.add(value);
}
}
}
......@@ -41,7 +41,7 @@ public abstract class ThermodynamicIndicator extends Indicator {
@Getter @Setter @Column(columnName = STEP) private int step = 0;
@Getter @Setter @Column(columnName = NUM_OF_STEPS) private int numOfSteps = 0;
@Getter @Setter @Column(columnName = DETAIL_GROUP) private IntKeyLongValueArray detailGroup = new IntKeyLongValueArray(30);
@Getter @Setter @Column(columnName = DETAIL_GROUP, isValue = true) private IntKeyLongValueArray detailGroup = new IntKeyLongValueArray(30);
private Map<Integer, IntKeyLongValue> detailIndex;
......
......@@ -77,7 +77,13 @@ public class MetricQueryService implements Service {
final long endTB) throws IOException, ParseException {
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, startTB, endTB);
List<String> ids = new ArrayList<>();
durationPoints.forEach(durationPoint -> ids.add(durationPoint.getPoint() + Const.ID_SPLIT + id));
durationPoints.forEach(durationPoint -> {
if (id == null) {
ids.add(durationPoint.getPoint() + "");
} else {
ids.add(durationPoint.getPoint() + Const.ID_SPLIT + id);
}
});
return getMetricQueryDAO().getThermodynamic(indName, step, ids, ValueColumnIds.INSTANCE.getValueCName(indName));
}
......
......@@ -26,4 +26,13 @@ import lombok.*;
public class Thermodynamic {
private List<List<Long>> nodes = new ArrayList<>();
private int axisYStep;
public void setNodeValue(int columnNum, int rowNum, Long value) {
List<Long> element = new ArrayList<>(3);
element.add((long)columnNum);
element.add((long)rowNum);
element.add(value);
nodes.add(element);
}
}
\ No newline at end of file
......@@ -106,12 +106,20 @@ public class MetricQueryEsDAO extends EsDAO implements IMetricQueryDAO {
MultiGetResponse response = getClient().multiGet(indexName, ids);
Thermodynamic thermodynamic = new Thermodynamic();
List<List<Long>> thermodynamicValueMatrix = new ArrayList<>();
int numOfSteps = 0;
for (MultiGetItemResponse itemResponse : response.getResponses()) {
int axisYStep = ((Number)itemResponse.getResponse().getSource().get(ThermodynamicIndicator.STEP)).intValue();
Map<String, Object> source = itemResponse.getResponse().getSource();
if (source == null) {
// add empty list to represent no data exist for this time bucket
thermodynamicValueMatrix.add(new ArrayList<>());
} else {
int axisYStep = ((Number)source.get(ThermodynamicIndicator.STEP)).intValue();
thermodynamic.setAxisYStep(axisYStep);
int numOfSteps = ((Number)itemResponse.getResponse().getSource().get(ThermodynamicIndicator.NUM_OF_STEPS)).intValue();
numOfSteps = ((Number)source.get(ThermodynamicIndicator.NUM_OF_STEPS)).intValue();
String value = (String)itemResponse.getResponse().getSource().get(ThermodynamicIndicator.DETAIL_GROUP);
String value = (String)source.get(ThermodynamicIndicator.DETAIL_GROUP);
IntKeyLongValueArray intKeyLongValues = new IntKeyLongValueArray(5);
intKeyLongValues.toObject(value);
......@@ -124,8 +132,31 @@ public class MetricQueryEsDAO extends EsDAO implements IMetricQueryDAO {
axisYValues.set(intKeyLongValue.getKey(), intKeyLongValue.getValue());
}
thermodynamic.getNodes().add(axisYValues);
thermodynamicValueMatrix.add(axisYValues);
}
}
int defaultNumOfSteps = numOfSteps;
thermodynamicValueMatrix.forEach(columnOfThermodynamic -> {
if (columnOfThermodynamic.size() == 0) {
if (defaultNumOfSteps > 0) {
for (int i = 0; i < defaultNumOfSteps; i++) {
columnOfThermodynamic.add(0L);
}
}
}
}
);
for (int colNum = 0; colNum < thermodynamicValueMatrix.size(); colNum++) {
List<Long> column = thermodynamicValueMatrix.get(colNum);
for (int rowNum = 0; rowNum < column.size(); rowNum++) {
Long value = column.get(rowNum);
thermodynamic.setNodeValue(colNum, rowNum, value);
}
}
return thermodynamic;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册