Fix: invoke the publish method only if the service is enabled
Change-Id: Ie127458d6c8c6689d81b37436d200580ef7133a7
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryManager.java
index 0ea76dc..3fcf013 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryManager.java
@@ -99,7 +99,7 @@
// TODO: need to find a way to invoke gRPC endpoint using channel
if (channel == null) {
- log.warn("gRPC telemetry service has not been enabled!");
+ log.debug("gRPC telemetry service has not been enabled!");
}
return null;
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryManager.java
index 19acaaa..99a64564 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryManager.java
@@ -142,12 +142,12 @@
@Override
public void publish(InfluxRecord<String, Set<FlowInfo>> record) {
if (producer == null) {
- log.warn("InfluxDB telemetry service has not been enabled!");
+ log.debug("InfluxDB telemetry service has not been enabled!");
return;
}
if (record.flowInfos().size() == 0) {
- log.warn("No record to publish");
+ log.debug("No record to publish");
return;
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/OpenstackTelemetryManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/OpenstackTelemetryManager.java
index 7d8a233..761e01b 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/OpenstackTelemetryManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/OpenstackTelemetryManager.java
@@ -20,8 +20,11 @@
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.apache.kafka.clients.producer.ProducerRecord;
+import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.openstacktelemetry.api.FlowInfo;
import org.onosproject.openstacktelemetry.api.GrpcTelemetryService;
import org.onosproject.openstacktelemetry.api.InfluxDbTelemetryService;
@@ -40,6 +43,7 @@
import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_MEASUREMENT;
import static org.onosproject.openstacktelemetry.codec.TinaMessageByteBufferCodec.KAFKA_KEY;
import static org.onosproject.openstacktelemetry.codec.TinaMessageByteBufferCodec.KAFKA_TOPIC;
+import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getPropertyValueAsBoolean;
/**
* Openstack telemetry manager.
@@ -50,6 +54,11 @@
private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final String ENABLE_SERVICE = "enableService";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
private List<TelemetryService> telemetryServices = Lists.newArrayList();
@Activate
@@ -75,19 +84,27 @@
@Override
public void publish(Set<FlowInfo> flowInfos) {
telemetryServices.forEach(service -> {
- if (service instanceof GrpcTelemetryManager) {
+ if (service instanceof GrpcTelemetryManager &&
+ getPropertyValueAsBoolean(componentConfigService.getProperties(
+ GrpcTelemetryConfigManager.class.getName()), ENABLE_SERVICE)) {
invokeGrpcPublisher((GrpcTelemetryService) service, flowInfos);
}
- if (service instanceof InfluxDbTelemetryManager) {
+ if (service instanceof InfluxDbTelemetryManager &&
+ getPropertyValueAsBoolean(componentConfigService.getProperties(
+ InfluxDbTelemetryConfigManager.class.getName()), ENABLE_SERVICE)) {
invokeInfluxDbPublisher((InfluxDbTelemetryService) service, flowInfos);
}
- if (service instanceof KafkaTelemetryManager) {
+ if (service instanceof KafkaTelemetryManager &&
+ getPropertyValueAsBoolean(componentConfigService.getProperties(
+ KafkaTelemetryConfigManager.class.getName()), ENABLE_SERVICE)) {
invokeKafkaPublisher((KafkaTelemetryService) service, flowInfos);
}
- if (service instanceof RestTelemetryManager) {
+ if (service instanceof RestTelemetryManager &&
+ getPropertyValueAsBoolean(componentConfigService.getProperties(
+ RestTelemetryConfigManager.class.getName()), ENABLE_SERVICE)) {
invokeRestPublisher((RestTelemetryService) service, flowInfos);
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryManager.java
index 78dd101..f94748c 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryManager.java
@@ -133,7 +133,7 @@
public Response publish(String record) {
if (target == null) {
- log.warn("REST telemetry service has not been enabled!");
+ log.debug("REST telemetry service has not been enabled!");
return null;
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/OpenstackTelemetryUtil.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/OpenstackTelemetryUtil.java
index 86f3772..abc4e97 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/OpenstackTelemetryUtil.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/OpenstackTelemetryUtil.java
@@ -16,8 +16,11 @@
package org.onosproject.openstacktelemetry.util;
import com.google.common.base.Strings;
+import org.onosproject.cfg.ConfigProperty;
import java.util.Dictionary;
+import java.util.Optional;
+import java.util.Set;
import static org.onlab.util.Tools.get;
@@ -51,4 +54,18 @@
}
return value;
}
+
+ /**
+ * Obtains the property value with specified property key name.
+ *
+ * @param properties a collection of properties
+ * @param name key name
+ * @return mapping value
+ */
+ public static boolean getPropertyValueAsBoolean(Set<ConfigProperty> properties, String name) {
+ Optional<ConfigProperty> property =
+ properties.stream().filter(p -> p.name().equals(name)).findFirst();
+
+ return property.map(ConfigProperty::asBoolean).orElse(false);
+ }
}