Skip to content

Commit

Permalink
cache metric configuration
Browse files Browse the repository at this point in the history
Signed-off-by: hubin6 <[email protected]>
  • Loading branch information
hubin6 committed Nov 17, 2017
1 parent 4b03b68 commit 6d1baa0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ private static void saveContentToCache (String key, String content) {
resourceContent.put(key, content);
}

public static BaseModel getBaseModel(String metricId) {
private static String getContentAndSave(String key, String filePath) {
String content;
String key = "BaseModel" + metricId;
if (getContentFromCache(key) == null){
content = getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + Constants.CONFIG_MODEL_FILE);
content = getStringFromResourcePath(filePath);
saveContentToCache(key, content);
} else {
content = getContentFromCache(key).toString();
}
return content;
}

public static BaseModel getBaseModel(String metricId) {
String key = "BaseModel|" + metricId;
String content = getContentAndSave(key, Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + Constants.CONFIG_MODEL_FILE);
BaseModel bm = JSON.parseObject(content, BaseModel.class);
return bm;
}
Expand Down Expand Up @@ -133,34 +138,48 @@ public static GridModel getGridModelByDateCycle(String metricId, String dateCycl
@NotNull
public static String getMetricChartSql(String metricId, String dateCycle) {
ChartModel model = getChartModelByDateCycle(metricId, dateCycle);
String key = "MetricChartSql" + metricId + dateCycle;
String content;
if (getContentFromCache(key) == null) {
content = getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + model.getSql());
saveContentToCache(key, content);
} else {
content = getContentFromCache(key).toString();
}
String key = "MetricChartSql|" + metricId + '|' + dateCycle;
String content = getContentAndSave(key, Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + model.getSql());
return content;
}

@NotNull
public static String getMetricValueSql(String metricId, String dateCycle) {
ValueModel model = getValueModelByDateCycle(metricId, dateCycle);
return getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
String key = "MetricValueSql|" + metricId + '|' + dateCycle;
String content = getContentAndSave(key, Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + model.getSql());
return content;
}

@NotNull
public static String getMetricGridSql(String metricId, String dateCycle) {
GridModel model = getGridModelByDateCycle(metricId, dateCycle);
return getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
String key = "MetricGridSql|" + metricId + '|' + dateCycle;
String content = getContentAndSave(key, Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + model.getSql());
return content;
}

public static String getMetricChartOption(String metricId, String dateCycle) {
return getStringFromResourcePath(Constants.CONFIG_PARENT_FOLDER + "/" +
String key = "MetricChartOption|" + metricId + '|' + dateCycle;
String content = getContentAndSave(key, Constants.CONFIG_PARENT_FOLDER + "/" +
metricId + "/" + dateCycle + Constants.CHART_OPTION_SUFFIX);
return content;
}

public static String getMetricChartFormat() {
String key = "MetricChartFormat";
String content = getContentAndSave(key, Constants.TEMPLATE_PARENT_FOLDER +
"/" + Constants.CHART_TEMPLATE_FILE);
return content;
}

public static String getMetricValueFormat() {
String key = "MetricValueFormat";
String content = getContentAndSave(key, Constants.TEMPLATE_PARENT_FOLDER +
"/" + Constants.VALUE_TEMPLATE_FILE);
return content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@
*/
@Service
public class ModelServiceImpl implements ModelService {
private static final String chartTemplate = getMetricChartFormat();
private static final String numberTemplate = getMetricValueFormat();

private static String getMetricChartFormat() {
return ModelHelper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER +
"/" + Constants.CHART_TEMPLATE_FILE);
}

private static String getMetricValueFormat() {
return ModelHelper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER +
"/" + Constants.VALUE_TEMPLATE_FILE);
}
private static final String chartTemplate = ModelHelper.getMetricChartFormat();
private static final String numberTemplate = ModelHelper.getMetricValueFormat();

@Override
public Map getModel(String metricId, String metricName) {
Expand Down

0 comments on commit 6d1baa0

Please sign in to comment.