From 58ba1a66b0d4ec30a948cd5f5184796f02cdf86f Mon Sep 17 00:00:00 2001 From: childe Date: Wed, 5 Jul 2017 15:41:04 +0800 Subject: [PATCH] if metrics plugin exists --- .../java/com/ctrip/ops/sysdev/core/Main.java | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/hangout-core/src/main/java/com/ctrip/ops/sysdev/core/Main.java b/hangout-core/src/main/java/com/ctrip/ops/sysdev/core/Main.java index d9a42453..fafe4efc 100644 --- a/hangout-core/src/main/java/com/ctrip/ops/sysdev/core/Main.java +++ b/hangout-core/src/main/java/com/ctrip/ops/sysdev/core/Main.java @@ -41,41 +41,43 @@ public static void main(String[] args) { final List> outputConfigs = (ArrayList>) configs.get("outputs"); final List> metricsConfigs = (ArrayList>) configs.get("metrics"); - metricsConfigs.forEach(metric -> { - metric.forEach((metricType, metricConfig) -> { - logger.info("begin to build metric " + metricType); - - Class metricClass = null; - - List 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 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(