Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
if metrics plugin exists
Browse files Browse the repository at this point in the history
  • Loading branch information
childe committed Jul 5, 2017
1 parent d45805e commit 58ba1a6
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions hangout-core/src/main/java/com/ctrip/ops/sysdev/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,43 @@ public static void main(String[] args) {
final List<HashMap<String, Map>> outputConfigs = (ArrayList<HashMap<String, Map>>) configs.get("outputs");
final List<HashMap<String, Map>> metricsConfigs = (ArrayList<HashMap<String, Map>>) configs.get("metrics");

metricsConfigs.forEach(metric -> {
metric.forEach((metricType, metricConfig) -> {
logger.info("begin to build metric " + metricType);

Class<?> metricClass = null;

List<String> classNames = Arrays.asList("com.ctrip.ops.sysdev.metrics." + metricType, metricType);
boolean tryCtrip = true;
for (String className : classNames) {
try {
metricClass = Class.forName(className);
Constructor<?> ctor = metricClass.getConstructor(Map.class);
BaseMetric metricInstance = (BaseMetric) ctor.newInstance(metricConfig);
logger.info("build metric " + metricType + " done");

metricInstance.register();
logger.info("metric" + metricType + " started");

break;
} catch (ClassNotFoundException e) {
if (tryCtrip == true) {
logger.info("maybe a third party metric plugin. try to build " + metricType);
tryCtrip = false;
continue;
} else {
if (metricsConfigs != null) {
metricsConfigs.forEach(metric -> {
metric.forEach((metricType, metricConfig) -> {
logger.info("begin to build metric " + metricType);

Class<?> metricClass = null;

List<String> classNames = Arrays.asList("com.ctrip.ops.sysdev.metrics." + metricType, metricType);
boolean tryCtrip = true;
for (String className : classNames) {
try {
metricClass = Class.forName(className);
Constructor<?> ctor = metricClass.getConstructor(Map.class);
BaseMetric metricInstance = (BaseMetric) ctor.newInstance(metricConfig);
logger.info("build metric " + metricType + " done");

metricInstance.register();
logger.info("metric" + metricType + " started");

break;
} catch (ClassNotFoundException e) {
if (tryCtrip == true) {
logger.info("maybe a third party metric plugin. try to build " + metricType);
tryCtrip = false;
continue;
} else {
logger.error(e);
System.exit(-1);
}
} catch (Exception e) {
logger.error(e);
System.exit(-1);
}
} catch (Exception e) {
logger.error(e);
System.exit(-1);
}
}
});
});
});
}

// for input in all_inputs, Go through every input and emit immediately
inputConfigs.forEach(
Expand Down

0 comments on commit 58ba1a6

Please sign in to comment.