OSGi property annotations for ganglia metrics app
Change-Id: If326fce501bb701e8dc34dcbb2ad1a17c7fc8978
diff --git a/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/DefaultGangliaMetricsReporter.java b/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/DefaultGangliaMetricsReporter.java
index 742564a..f74133e 100644
--- a/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/DefaultGangliaMetricsReporter.java
+++ b/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/DefaultGangliaMetricsReporter.java
@@ -36,12 +36,31 @@
import java.util.Dictionary;
import java.util.concurrent.TimeUnit;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.ADDRESS;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.ADDRESS_DEFAULT;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.METRIC_NAMES;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.METRIC_NAMES_DEFAULT;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.MONITOR_ALL;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.MONITOR_ALL_DEFAULT;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.PORT;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.PORT_DEFAULT;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.TTL;
+import static org.onosproject.gangliametrics.OsgiPropertyConstants.TTL_DEFAULT;
import static org.slf4j.LoggerFactory.getLogger;
/**
* A metric report that reports all metrics value to ganglia monitoring server.
*/
-@Component(immediate = true)
+@Component(
+ immediate = true,
+ property = {
+ MONITOR_ALL + ":Boolean=" + MONITOR_ALL_DEFAULT,
+ METRIC_NAMES + "=" + METRIC_NAMES_DEFAULT,
+ ADDRESS + "=" + ADDRESS_DEFAULT,
+ PORT + ":Integer=" + PORT_DEFAULT,
+ TTL + ":Integer=" + TTL_DEFAULT
+ }
+)
public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter {
private final Logger log = getLogger(getClass());
@@ -51,11 +70,6 @@
private static final int REPORT_PERIOD = 1;
private static final TimeUnit REPORT_TIME_UNIT = TimeUnit.MINUTES;
- private static final String DEFAULT_ADDRESS = "localhost";
- private static final int DEFAULT_PORT = 8649;
- private static final int DEFAULT_TTL = 1;
- private static final String DEFAULT_METRIC_NAMES = "default";
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected CoreService coreService;
@@ -65,25 +79,20 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected ComponentConfigService cfgService;
- //@Property(name = "monitorAll", boolValue = true,
- // label = "Enable to monitor all of metrics stored in metric registry default is true")
- protected boolean monitorAll = true;
+ /** Enable to monitor all of metrics stored in metric registry default is true. */
+ protected boolean monitorAll = MONITOR_ALL_DEFAULT;
- //@Property(name = "metricNames", value = DEFAULT_METRIC_NAMES,
- // label = "Names of metric to be monitored; default metric names are 'default'")
- protected String metricNames = DEFAULT_METRIC_NAMES;
+ /** Names of metric to be monitored; default metric names are 'default'. */
+ protected String metricNames = METRIC_NAMES_DEFAULT;
- //@Property(name = "address", value = DEFAULT_ADDRESS,
- // label = "IP address of ganglia monitoring server; default is localhost")
- protected String address = DEFAULT_ADDRESS;
+ /** IP address of ganglia monitoring server; default is localhost. */
+ protected String address = ADDRESS_DEFAULT;
- //@Property(name = "port", intValue = DEFAULT_PORT,
- // label = "Port number of ganglia monitoring server; default is 8649")
- protected int port = DEFAULT_PORT;
+ /** Port number of ganglia monitoring server; default is 8649. */
+ protected int port = PORT_DEFAULT;
- //@Property(name = "ttl", intValue = DEFAULT_TTL,
- // label = "TTL value of ganglia monitoring server; default is 1")
- protected int ttl = DEFAULT_TTL;
+ /** TTL value of ganglia monitoring server; default is 1. */
+ protected int ttl = TTL_DEFAULT;
private GMetric ganglia;
private GangliaReporter gangliaReporter;
@@ -201,33 +210,33 @@
private void readComponentConfiguration(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
- String addressStr = Tools.get(properties, "address");
- address = addressStr != null ? addressStr : DEFAULT_ADDRESS;
+ String addressStr = Tools.get(properties, ADDRESS);
+ address = addressStr != null ? addressStr : ADDRESS_DEFAULT;
log.info("Configured. Ganglia server address is {}", address);
- String metricNameStr = Tools.get(properties, "metricNames");
- metricNames = metricNameStr != null ? metricNameStr : DEFAULT_METRIC_NAMES;
+ String metricNameStr = Tools.get(properties, METRIC_NAMES);
+ metricNames = metricNameStr != null ? metricNameStr : METRIC_NAMES_DEFAULT;
log.info("Configured. Metric name is {}", metricNames);
- Integer portConfigured = Tools.getIntegerProperty(properties, "port");
+ Integer portConfigured = Tools.getIntegerProperty(properties, PORT);
if (portConfigured == null) {
- port = DEFAULT_PORT;
+ port = PORT_DEFAULT;
log.info("Ganglia port is not configured, default value is {}", port);
} else {
port = portConfigured;
log.info("Configured. Ganglia port is configured to {}", port);
}
- Integer ttlConfigured = Tools.getIntegerProperty(properties, "ttl");
+ Integer ttlConfigured = Tools.getIntegerProperty(properties, TTL);
if (ttlConfigured == null) {
- ttl = DEFAULT_TTL;
+ ttl = TTL_DEFAULT;
log.info("Ganglia TTL is not configured, default value is {}", ttl);
} else {
ttl = ttlConfigured;
log.info("Configured. Ganglia TTL is configured to {}", ttl);
}
- Boolean monitorAllEnabled = Tools.isPropertyEnabled(properties, "monitorAll");
+ Boolean monitorAllEnabled = Tools.isPropertyEnabled(properties, MONITOR_ALL);
if (monitorAllEnabled == null) {
log.info("Monitor all metrics is not configured, " +
"using current value of {}", monitorAll);
diff --git a/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/OsgiPropertyConstants.java b/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/OsgiPropertyConstants.java
new file mode 100644
index 0000000..0a349ab
--- /dev/null
+++ b/apps/gangliametrics/src/main/java/org/onosproject/gangliametrics/OsgiPropertyConstants.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gangliametrics;
+
+public final class OsgiPropertyConstants {
+ private OsgiPropertyConstants() {
+ }
+
+ static final String MONITOR_ALL = "monitorAll";
+ static final boolean MONITOR_ALL_DEFAULT = true;
+
+ static final String METRIC_NAMES = "metricNames";
+ static final String METRIC_NAMES_DEFAULT = "default";
+
+ static final String ADDRESS = "address";
+ static final String ADDRESS_DEFAULT = "localhost";
+
+ static final String PORT = "port";
+ static final int PORT_DEFAULT = 8649;
+
+ static final String TTL = "ttl";
+ static final int TTL_DEFAULT = 1;
+}