Fix thermodynamic query error (#1716)
* Avoid query error by adding initial instance to AlarmTrend * Fix thermodynamic query
This commit is contained in:
parent
813ea1ed39
commit
1bfc68c8ab
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -106,26 +106,57 @@ 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();
|
||||
thermodynamic.setAxisYStep(axisYStep);
|
||||
int numOfSteps = ((Number)itemResponse.getResponse().getSource().get(ThermodynamicIndicator.NUM_OF_STEPS)).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);
|
||||
numOfSteps = ((Number)source.get(ThermodynamicIndicator.NUM_OF_STEPS)).intValue();
|
||||
|
||||
String value = (String)itemResponse.getResponse().getSource().get(ThermodynamicIndicator.DETAIL_GROUP);
|
||||
IntKeyLongValueArray intKeyLongValues = new IntKeyLongValueArray(5);
|
||||
intKeyLongValues.toObject(value);
|
||||
String value = (String)source.get(ThermodynamicIndicator.DETAIL_GROUP);
|
||||
IntKeyLongValueArray intKeyLongValues = new IntKeyLongValueArray(5);
|
||||
intKeyLongValues.toObject(value);
|
||||
|
||||
List<Long> axisYValues = new ArrayList<>();
|
||||
for (int i = 0; i < numOfSteps; i++) {
|
||||
axisYValues.add(0L);
|
||||
List<Long> axisYValues = new ArrayList<>();
|
||||
for (int i = 0; i < numOfSteps; i++) {
|
||||
axisYValues.add(0L);
|
||||
}
|
||||
|
||||
for (IntKeyLongValue intKeyLongValue : intKeyLongValues) {
|
||||
axisYValues.set(intKeyLongValue.getKey(), intKeyLongValue.getValue());
|
||||
}
|
||||
|
||||
thermodynamicValueMatrix.add(axisYValues);
|
||||
}
|
||||
|
||||
for (IntKeyLongValue intKeyLongValue : intKeyLongValues) {
|
||||
axisYValues.set(intKeyLongValue.getKey(), intKeyLongValue.getValue());
|
||||
}
|
||||
|
||||
thermodynamic.getNodes().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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue