This repository was archived by the owner on Jul 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDef.java
More file actions
65 lines (51 loc) · 1.8 KB
/
Def.java
File metadata and controls
65 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.wavefront.labs.convert.converter.rrd.models;
import com.wavefront.labs.convert.ExpressionBuilder;
import com.wavefront.labs.convert.converter.rrd.RRDContext;
import com.wavefront.labs.convert.converter.rrd.RRDExpressionBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.reflect.InvocationTargetException;
public class Def extends Definition {
private static final Logger logger = LogManager.getLogger(Def.class);
private String rrdFile;
private String dsName;
private String CF;
public Def(String line) {
super(line);
}
@Override
public String calculate(RRDContext context) {
String[] parts = expression.split(":");
rrdFile = stripQuotes(parts[0]);
dsName = stripQuotes(parts[1]);
CF = stripQuotes(parts[2]);
for (int i = 3; i < parts.length; i++) {
if (parts[i].startsWith("reduce=")) {
CF = parts[i].split("=")[1];
}
}
ExpressionBuilder expressionBuilder;
String expressionBuilderClass = context.getProperties().getProperty("convert.expressionBuilder", "");
if (!expressionBuilderClass.equals("")) {
try {
expressionBuilder = (ExpressionBuilder) Class.forName(expressionBuilderClass).getDeclaredConstructor().newInstance();
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
logger.error("Could not create instance of: " + expressionBuilderClass, e);
expressionBuilder = new RRDExpressionBuilder();
}
} else {
expressionBuilder = new RRDExpressionBuilder();
}
expressionBuilder.init(context.getProperties());
return expressionBuilder.buildExpression(this);
}
public String getRRDFile() {
return rrdFile;
}
public String getDsName() {
return dsName;
}
public String getCF() {
return CF;
}
}