[ONOS-7683] Add default implementation of telemetry config managers
Change-Id: Iac3681ceff2b343746d2d0b1043300044043b63a
diff --git a/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java b/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java
index 0419529..98253cf 100644
--- a/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java
+++ b/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java
@@ -27,6 +27,21 @@
private static final String DEFAULT_SERVER_IP = "localhost";
+ // default configuration variables for gRPC
+ public static final String DEFAULT_GRPC_SERVER_IP = DEFAULT_SERVER_IP;
+ public static final int DEFAULT_GRPC_SERVER_PORT = 50051;
+ public static final boolean DEFAULT_GRPC_USE_PLAINTEXT = true;
+ public static final int DEFAULT_GRPC_MAX_INBOUND_MSG_SIZE = 4 * 1024 * 1024;
+
+ // default configuration variables for InfluxDB
+ public static final String DEFAULT_INFLUXDB_SERVER_IP = DEFAULT_SERVER_IP;
+ public static final int DEFAULT_INFLUXDB_SERVER_PORT = 8086;
+ public static final String DEFAULT_INFLUXDB_USERNAME = "onos";
+ public static final String DEFAULT_INFLUXDB_PASSWORD = "onos";
+ public static final String DEFAULT_INFLUXDB_DATABASE = "onos";
+ public static final boolean DEFAULT_INFLUXDB_ENABLE_BATCH = true;
+
+ // default configuration variables for Kafka
public static final String DEFAULT_KAFKA_SERVER_IP = DEFAULT_SERVER_IP;
public static final int DEFAULT_KAFKA_SERVER_PORT = 9092;
public static final int DEFAULT_KAFKA_RETRIES = 0;
@@ -39,6 +54,12 @@
public static final String DEFAULT_KAFKA_VALUE_SERIALIZER =
"org.apache.kafka.common.serialization.ByteArraySerializer";
+ // default configuration variables for REST API
public static final String DEFAULT_REST_SERVER_IP = DEFAULT_SERVER_IP;
public static final int DEFAULT_REST_SERVER_PORT = 80;
+ public static final String DEFAULT_REST_ENDPOINT = "telemetry";
+ public static final String DEFAULT_REST_METHOD = "POST";
+ public static final String DEFAULT_REST_REQUEST_MEDIA_TYPE = "application/json";
+ public static final String DEFAULT_REST_RESPONSE_MEDIA_TYPE = "application/json";
+
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryConfigManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryConfigManager.java
index 03baace..308ee49 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryConfigManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/GrpcTelemetryConfigManager.java
@@ -15,16 +15,139 @@
*/
package org.onosproject.openstacktelemetry.impl;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.util.Tools;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.openstacktelemetry.api.GrpcTelemetryAdminService;
import org.onosproject.openstacktelemetry.api.GrpcTelemetryConfigService;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
+import org.onosproject.openstacktelemetry.config.DefaultGrpcTelemetryConfig;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Dictionary;
+
+import static org.onlab.util.Tools.get;
+import static org.onlab.util.Tools.getIntegerProperty;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_GRPC_MAX_INBOUND_MSG_SIZE;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_GRPC_SERVER_IP;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_GRPC_SERVER_PORT;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_GRPC_USE_PLAINTEXT;
+import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getBooleanProperty;
/**
* gRPC server configuration manager for publishing openstack telemetry.
*/
public class GrpcTelemetryConfigManager implements GrpcTelemetryConfigService {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final String ADDRESS = "address";
+ private static final String PORT = "port";
+ private static final String USE_PLAINTEXT = "usePlaintext";
+ private static final String MAX_INBOUND_MSG_SIZE = "maxInboundMsgSize";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected GrpcTelemetryAdminService grpcTelemetryAdminService;
+
+ @Property(name = ADDRESS, value = DEFAULT_GRPC_SERVER_IP,
+ label = "Default IP address to establish initial connection to gRPC server")
+ protected String address = DEFAULT_GRPC_SERVER_IP;
+
+ @Property(name = PORT, intValue = DEFAULT_GRPC_SERVER_PORT,
+ label = "Default port number to establish initial connection to gRPC server")
+ protected Integer port = DEFAULT_GRPC_SERVER_PORT;
+
+ @Property(name = USE_PLAINTEXT, boolValue = DEFAULT_GRPC_USE_PLAINTEXT,
+ label = "UsePlaintext flag value used for connecting to gRPC server")
+ protected Boolean usePlaintext = DEFAULT_GRPC_USE_PLAINTEXT;
+
+ @Property(name = MAX_INBOUND_MSG_SIZE, intValue = DEFAULT_GRPC_MAX_INBOUND_MSG_SIZE,
+ label = "Maximum inbound message size used for communicating with gRPC server")
+ protected Integer maxInboundMsgSize = DEFAULT_GRPC_MAX_INBOUND_MSG_SIZE;
+
+ @Activate
+ protected void activate(ComponentContext context) {
+ componentConfigService.registerProperties(getClass());
+ grpcTelemetryAdminService.start(getConfig());
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ componentConfigService.unregisterProperties(getClass(), false);
+ grpcTelemetryAdminService.stop();
+ log.info("Stopped");
+ }
+
+ @Modified
+ private void modified(ComponentContext context) {
+ readComponentConfiguration(context);
+ grpcTelemetryAdminService.restart(getConfig());
+ log.info("Modified");
+ }
+
@Override
public TelemetryConfig getConfig() {
- return null;
+ return new DefaultGrpcTelemetryConfig.DefaultBuilder()
+ .withAddress(address)
+ .withPort(port)
+ .withUsePlaintext(usePlaintext)
+ .withMaxInboundMsgSize(maxInboundMsgSize)
+ .build();
}
+
+ /**
+ * Extracts properties from the component configuration context.
+ *
+ * @param context the component context
+ */
+ private void readComponentConfiguration(ComponentContext context) {
+ Dictionary<?, ?> properties = context.getProperties();
+
+ String addressStr = get(properties, ADDRESS);
+ address = addressStr != null ? addressStr : DEFAULT_GRPC_SERVER_IP;
+ log.info("Configured. gRPC server address is {}", address);
+
+ Integer portConfigured = Tools.getIntegerProperty(properties, PORT);
+ if (portConfigured == null) {
+ port = DEFAULT_GRPC_SERVER_PORT;
+ log.info("gRPC server port is NOT configured, default value is {}", port);
+ } else {
+ port = portConfigured;
+ log.info("Configured. gRPC server port is {}", port);
+ }
+
+ Boolean usePlaintextConfigured =
+ getBooleanProperty(properties, USE_PLAINTEXT);
+ if (usePlaintextConfigured == null) {
+ usePlaintext = DEFAULT_GRPC_USE_PLAINTEXT;
+ log.info("gRPC server use plaintext flag is NOT " +
+ "configured, default value is {}", usePlaintext);
+ } else {
+ usePlaintext = usePlaintextConfigured;
+ log.info("Configured. gRPC server use plaintext flag is {}", usePlaintext);
+ }
+
+ Integer maxInboundMsgSizeConfigured =
+ getIntegerProperty(properties, MAX_INBOUND_MSG_SIZE);
+ if (maxInboundMsgSizeConfigured == null) {
+ maxInboundMsgSize = DEFAULT_GRPC_MAX_INBOUND_MSG_SIZE;
+ log.info("gRPC server max inbound message size is NOT " +
+ "configured, default value is {}", maxInboundMsgSize);
+ } else {
+ maxInboundMsgSize = maxInboundMsgSizeConfigured;
+ log.info("Configured. gRPC server max inbound message size is {}", maxInboundMsgSize);
+ }
+ }
+
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryConfigManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryConfigManager.java
index 3aba590..77c3d63 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryConfigManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/InfluxDbTelemetryConfigManager.java
@@ -15,16 +15,150 @@
*/
package org.onosproject.openstacktelemetry.impl;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.util.Tools;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.openstacktelemetry.api.InfluxDbTelemetryAdminService;
import org.onosproject.openstacktelemetry.api.InfluxDbTelemetryConfigService;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
+import org.onosproject.openstacktelemetry.config.DefaultInfluxDbTelemetryConfig;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Dictionary;
+
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_DATABASE;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_ENABLE_BATCH;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_PASSWORD;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_SERVER_IP;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_SERVER_PORT;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_USERNAME;
+import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getBooleanProperty;
/**
* InfluxDB server configuration manager for publishing openstack telemetry.
*/
public class InfluxDbTelemetryConfigManager implements InfluxDbTelemetryConfigService {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final String ADDRESS = "address";
+ private static final String PORT = "port";
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String DATABASE = "database";
+ private static final String ENABLE_BATCH = "enableBatch";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected InfluxDbTelemetryAdminService influxDbTelemetryAdminService;
+
+ @Property(name = ADDRESS, value = DEFAULT_INFLUXDB_SERVER_IP,
+ label = "Default IP address to establish initial connection to InfluxDB server")
+ protected String address = DEFAULT_INFLUXDB_SERVER_IP;
+
+ @Property(name = PORT, intValue = DEFAULT_INFLUXDB_SERVER_PORT,
+ label = "Default port number to establish initial connection to InfluxDB server")
+ protected Integer port = DEFAULT_INFLUXDB_SERVER_PORT;
+
+ @Property(name = USERNAME, value = DEFAULT_INFLUXDB_USERNAME,
+ label = "Username used for authenticating against InfluxDB server")
+ protected String username = DEFAULT_INFLUXDB_USERNAME;
+
+ @Property(name = PASSWORD, value = DEFAULT_INFLUXDB_PASSWORD,
+ label = "Password used for authenticating against InfluxDB server")
+ protected String password = DEFAULT_INFLUXDB_PASSWORD;
+
+ @Property(name = DATABASE, value = DEFAULT_INFLUXDB_DATABASE,
+ label = "Database of InfluxDB server")
+ protected String database = DEFAULT_INFLUXDB_DATABASE;
+
+ @Property(name = ENABLE_BATCH, boolValue = DEFAULT_INFLUXDB_ENABLE_BATCH,
+ label = "Flag value of enabling batch mode of InfluxDB server")
+ protected Boolean enableBatch = DEFAULT_INFLUXDB_ENABLE_BATCH;
+
+ @Activate
+ protected void activate(ComponentContext context) {
+ componentConfigService.registerProperties(getClass());
+ influxDbTelemetryAdminService.start(getConfig());
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ componentConfigService.unregisterProperties(getClass(), false);
+ influxDbTelemetryAdminService.stop();
+ log.info("Stopped");
+ }
+
+ @Modified
+ private void modified(ComponentContext context) {
+ readComponentConfiguration(context);
+ influxDbTelemetryAdminService.restart(getConfig());
+ log.info("Modified");
+ }
+
@Override
public TelemetryConfig getConfig() {
- return null;
+ return new DefaultInfluxDbTelemetryConfig.DefaultBuilder()
+ .withAddress(address)
+ .withPort(port)
+ .withUsername(username)
+ .withPassword(password)
+ .withDatabase(database)
+ .withEnableBatch(enableBatch)
+ .build();
+ }
+
+ /**
+ * Extracts properties from the component configuration context.
+ *
+ * @param context the component context
+ */
+ private void readComponentConfiguration(ComponentContext context) {
+ Dictionary<?, ?> properties = context.getProperties();
+
+ String addressStr = Tools.get(properties, ADDRESS);
+ address = addressStr != null ? addressStr : DEFAULT_INFLUXDB_SERVER_IP;
+ log.info("Configured. InfluxDB server address is {}", address);
+
+ Integer portConfigured = Tools.getIntegerProperty(properties, PORT);
+ if (portConfigured == null) {
+ port = DEFAULT_INFLUXDB_SERVER_PORT;
+ log.info("InfluxDB server port is NOT configured, default value is {}", port);
+ } else {
+ port = portConfigured;
+ log.info("Configured. InfluxDB server port is {}", port);
+ }
+
+ String usernameStr = Tools.get(properties, USERNAME);
+ username = usernameStr != null ? usernameStr : DEFAULT_INFLUXDB_USERNAME;
+ log.info("Configured. InfluxDB server username is {}", username);
+
+ String passwordStr = Tools.get(properties, PASSWORD);
+ password = passwordStr != null ? passwordStr : DEFAULT_INFLUXDB_PASSWORD;
+ log.info("Configured. InfluxDB server password is {}", password);
+
+ String databaseStr = Tools.get(properties, DATABASE);
+ database = databaseStr != null ? databaseStr : DEFAULT_INFLUXDB_DATABASE;
+ log.info("Configured. InfluxDB server database is {}", database);
+
+ Boolean enableBatchConfigured = getBooleanProperty(properties, ENABLE_BATCH);
+ if (enableBatchConfigured == null) {
+ enableBatch = DEFAULT_INFLUXDB_ENABLE_BATCH;
+ log.info("InfluxDB server enable batch flag is " +
+ "NOT configured, default value is {}", enableBatch);
+ } else {
+ enableBatch = enableBatchConfigured;
+ log.info("Configured. InfluxDB server enable batch is {}", enableBatch);
+ }
}
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/KafkaTelemetryConfigManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/KafkaTelemetryConfigManager.java
index db319a3..242709d 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/KafkaTelemetryConfigManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/KafkaTelemetryConfigManager.java
@@ -15,16 +15,197 @@
*/
package org.onosproject.openstacktelemetry.impl;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.util.Tools;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.openstacktelemetry.api.KafkaTelemetryAdminService;
import org.onosproject.openstacktelemetry.api.KafkaTelemetryConfigService;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
+import org.onosproject.openstacktelemetry.config.DefaultKafkaTelemetryConfig;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Dictionary;
+
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_BATCH_SIZE;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_KEY_SERIALIZER;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_LINGER_MS;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_MEMORY_BUFFER;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_REQUIRED_ACKS;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_RETRIES;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_SERVER_IP;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_SERVER_PORT;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_KAFKA_VALUE_SERIALIZER;
/**
* Kafka server configuration manager for publishing openstack telemetry.
*/
public class KafkaTelemetryConfigManager implements KafkaTelemetryConfigService {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final String ADDRESS = "address";
+ private static final String PORT = "port";
+ private static final String RETRIES = "retries";
+ private static final String REQUIRED_ACKS = "requiredAcks";
+ private static final String BATCH_SIZE = "batchSize";
+ private static final String LINGER_MS = "lingerMs";
+ private static final String MEMORY_BUFFER = "memoryBuffer";
+ private static final String KEY_SERIALIZER = "keySerializer";
+ private static final String VALUE_SERIALIZER = "valueSerializer";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected KafkaTelemetryAdminService kafkaTelemetryAdminService;
+
+ @Property(name = ADDRESS, value = DEFAULT_KAFKA_SERVER_IP,
+ label = "Default IP address to establish initial connection to Kafka server")
+ protected String address = DEFAULT_KAFKA_SERVER_IP;
+
+ @Property(name = PORT, intValue = DEFAULT_KAFKA_SERVER_PORT,
+ label = "Default port number to establish initial connection to Kafka server")
+ protected Integer port = DEFAULT_KAFKA_SERVER_PORT;
+
+ @Property(name = RETRIES, intValue = DEFAULT_KAFKA_RETRIES,
+ label = "Number of times the producer can retry to send after first failure")
+ protected int retries = DEFAULT_KAFKA_RETRIES;
+
+ @Property(name = REQUIRED_ACKS, value = DEFAULT_KAFKA_REQUIRED_ACKS,
+ label = "Producer will get an acknowledgement after the leader has replicated the data")
+ protected String requiredAcks = DEFAULT_KAFKA_REQUIRED_ACKS;
+
+ @Property(name = BATCH_SIZE, intValue = DEFAULT_KAFKA_BATCH_SIZE,
+ label = "The largest record batch size allowed by Kafka")
+ protected Integer batchSize = DEFAULT_KAFKA_BATCH_SIZE;
+
+ @Property(name = LINGER_MS, intValue = DEFAULT_KAFKA_LINGER_MS,
+ label = "The producer groups together any records that arrive in " +
+ "between request transmissions into a single batched request")
+ protected Integer lingerMs = DEFAULT_KAFKA_LINGER_MS;
+
+ @Property(name = MEMORY_BUFFER, intValue = DEFAULT_KAFKA_MEMORY_BUFFER,
+ label = "The total memory used for log cleaner I/O buffers across all cleaner threads")
+ protected Integer memoryBuffer = DEFAULT_KAFKA_MEMORY_BUFFER;
+
+ @Property(name = KEY_SERIALIZER, value = DEFAULT_KAFKA_KEY_SERIALIZER,
+ label = "Serializer class for key that implements the Serializer interface")
+ protected String keySerializer = DEFAULT_KAFKA_KEY_SERIALIZER;
+
+ @Property(name = VALUE_SERIALIZER, value = DEFAULT_KAFKA_VALUE_SERIALIZER,
+ label = "Serializer class for value that implements the Serializer interface")
+ protected String valueSerializer = DEFAULT_KAFKA_VALUE_SERIALIZER;
+
+ @Activate
+ protected void activate(ComponentContext context) {
+ componentConfigService.registerProperties(getClass());
+ kafkaTelemetryAdminService.start(getConfig());
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ componentConfigService.unregisterProperties(getClass(), false);
+ kafkaTelemetryAdminService.stop();
+ log.info("Stopped");
+ }
+
+ @Modified
+ private void modified(ComponentContext context) {
+ readComponentConfiguration(context);
+ kafkaTelemetryAdminService.restart(getConfig());
+ log.info("Modified");
+ }
+
@Override
public TelemetryConfig getConfig() {
- return null;
+ return new DefaultKafkaTelemetryConfig.DefaultBuilder()
+ .withAddress(address)
+ .withPort(port)
+ .withRetries(retries)
+ .withRequiredAcks(requiredAcks)
+ .withBatchSize(batchSize)
+ .withLingerMs(lingerMs)
+ .withMemoryBuffer(memoryBuffer)
+ .withKeySerializer(keySerializer)
+ .withValueSerializer(valueSerializer)
+ .build();
+ }
+
+ /**
+ * Extracts properties from the component configuration context.
+ *
+ * @param context the component context
+ */
+ private void readComponentConfiguration(ComponentContext context) {
+ Dictionary<?, ?> properties = context.getProperties();
+
+ String addressStr = Tools.get(properties, ADDRESS);
+ address = addressStr != null ? addressStr : DEFAULT_KAFKA_SERVER_IP;
+ log.info("Configured. Kafka server address is {}", address);
+
+ Integer portConfigured = Tools.getIntegerProperty(properties, PORT);
+ if (portConfigured == null) {
+ port = DEFAULT_KAFKA_SERVER_PORT;
+ log.info("Kafka server port is NOT configured, default value is {}", port);
+ } else {
+ port = portConfigured;
+ log.info("Configured. Kafka server port is {}", port);
+ }
+
+ Integer retriesConfigured = Tools.getIntegerProperty(properties, RETRIES);
+ if (retriesConfigured == null) {
+ retries = DEFAULT_KAFKA_RETRIES;
+ log.info("Kafka number of retries property is NOT configured, default value is {}", retries);
+ } else {
+ retries = retriesConfigured;
+ log.info("Configured. Kafka number of retries is {}", retries);
+ }
+
+ String requiredAcksStr = Tools.get(properties, REQUIRED_ACKS);
+ requiredAcks = requiredAcksStr != null ? requiredAcksStr : DEFAULT_KAFKA_REQUIRED_ACKS;
+ log.info("Configured, Kafka required acknowledgement is {}", requiredAcks);
+
+ Integer batchSizeConfigured = Tools.getIntegerProperty(properties, BATCH_SIZE);
+ if (batchSizeConfigured == null) {
+ batchSize = DEFAULT_KAFKA_BATCH_SIZE;
+ log.info("Kafka batch size property is NOT configured, default value is {}", batchSize);
+ } else {
+ batchSize = batchSizeConfigured;
+ log.info("Configured. Kafka batch size is {}", batchSize);
+ }
+
+ Integer lingerMsConfigured = Tools.getIntegerProperty(properties, LINGER_MS);
+ if (lingerMsConfigured == null) {
+ lingerMs = DEFAULT_KAFKA_LINGER_MS;
+ log.info("Kafka lingerMs property is NOT configured, default value is {}", lingerMs);
+ } else {
+ lingerMs = lingerMsConfigured;
+ log.info("Configured. Kafka lingerMs is {}", lingerMs);
+ }
+
+ Integer memoryBufferConfigured = Tools.getIntegerProperty(properties, MEMORY_BUFFER);
+ if (memoryBufferConfigured == null) {
+ memoryBuffer = DEFAULT_KAFKA_MEMORY_BUFFER;
+ log.info("Kafka memory buffer property is NOT configured, default value is {}", memoryBuffer);
+ } else {
+ memoryBuffer = memoryBufferConfigured;
+ log.info("Configured. Kafka memory buffer is {}", memoryBuffer);
+ }
+
+ String keySerializerStr = Tools.get(properties, KEY_SERIALIZER);
+ keySerializer = keySerializerStr != null ? keySerializerStr : DEFAULT_KAFKA_KEY_SERIALIZER;
+ log.info("Configured, Kafka key serializer is {}", keySerializer);
+
+ String valueSerializerStr = Tools.get(properties, VALUE_SERIALIZER);
+ valueSerializer = valueSerializerStr != null ? valueSerializerStr : DEFAULT_KAFKA_VALUE_SERIALIZER;
+ log.info("Configured, Kafka value serializer is {}", valueSerializer);
}
}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryConfigManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryConfigManager.java
index 66add3c..832c60b 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryConfigManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/RestTelemetryConfigManager.java
@@ -15,16 +15,145 @@
*/
package org.onosproject.openstacktelemetry.impl;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.util.Tools;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.openstacktelemetry.api.RestTelemetryAdminService;
import org.onosproject.openstacktelemetry.api.RestTelemetryConfigService;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
+import org.onosproject.openstacktelemetry.config.DefaultRestTelemetryConfig;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Dictionary;
+
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_REST_ENDPOINT;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_REST_METHOD;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_REST_REQUEST_MEDIA_TYPE;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_REST_RESPONSE_MEDIA_TYPE;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_REST_SERVER_IP;
+import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_REST_SERVER_PORT;
/**
* REST server configuration manager for publishing openstack telemetry.
*/
public class RestTelemetryConfigManager implements RestTelemetryConfigService {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final String ADDRESS = "address";
+ private static final String PORT = "port";
+ private static final String ENDPOINT = "endpoint";
+ private static final String METHOD = "method";
+ private static final String REQUEST_MEDIA_TYPE = "requestMediaType";
+ private static final String RESPONSE_MEDIA_TYPE = "responseMediaType";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RestTelemetryAdminService restTelemetryAdminService;
+
+ @Property(name = ADDRESS, value = DEFAULT_REST_SERVER_IP,
+ label = "Default IP address to establish initial connection to REST server")
+ protected String address = DEFAULT_REST_SERVER_IP;
+
+ @Property(name = PORT, intValue = DEFAULT_REST_SERVER_PORT,
+ label = "Default port number to establish initial connection to REST server")
+ protected Integer port = DEFAULT_REST_SERVER_PORT;
+
+ @Property(name = ENDPOINT, value = DEFAULT_REST_ENDPOINT,
+ label = "Endpoint of REST server")
+ protected String endpoint = DEFAULT_REST_ENDPOINT;
+
+ @Property(name = METHOD, value = DEFAULT_REST_METHOD,
+ label = "HTTP method of REST server")
+ protected String method = DEFAULT_REST_METHOD;
+
+ @Property(name = REQUEST_MEDIA_TYPE, value = DEFAULT_REST_REQUEST_MEDIA_TYPE,
+ label = "Request media type of REST server")
+ protected String requestMediaType = DEFAULT_REST_REQUEST_MEDIA_TYPE;
+
+ @Property(name = RESPONSE_MEDIA_TYPE, value = DEFAULT_REST_RESPONSE_MEDIA_TYPE,
+ label = "Response media type of REST server")
+ protected String responseMediaType = DEFAULT_REST_RESPONSE_MEDIA_TYPE;
+
+ @Activate
+ protected void activate(ComponentContext context) {
+ componentConfigService.registerProperties(getClass());
+ restTelemetryAdminService.start(getConfig());
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ componentConfigService.unregisterProperties(getClass(), false);
+ restTelemetryAdminService.stop();
+ log.info("Stopped");
+ }
+
+ @Modified
+ private void modified(ComponentContext context) {
+ readComponentConfiguration(context);
+ restTelemetryAdminService.restart(getConfig());
+ log.info("Modified");
+ }
+
@Override
public TelemetryConfig getConfig() {
- return null;
+ return new DefaultRestTelemetryConfig.DefaultBuilder()
+ .withAddress(address)
+ .withPort(port)
+ .withEndpoint(endpoint)
+ .withMethod(method)
+ .withRequestMediaType(requestMediaType)
+ .withResponseMediaType(responseMediaType)
+ .build();
+ }
+
+ /**
+ * Extracts properties from the component configuration context.
+ *
+ * @param context the component context
+ */
+ private void readComponentConfiguration(ComponentContext context) {
+ Dictionary<?, ?> properties = context.getProperties();
+
+ String addressStr = Tools.get(properties, ADDRESS);
+ address = addressStr != null ? addressStr : DEFAULT_REST_SERVER_IP;
+ log.info("Configured. REST server address is {}", address);
+
+ Integer portConfigured = Tools.getIntegerProperty(properties, PORT);
+ if (portConfigured == null) {
+ port = DEFAULT_REST_SERVER_PORT;
+ log.info("REST server port is NOT configured, default value is {}", port);
+ } else {
+ port = portConfigured;
+ log.info("Configured. REST server port is {}", port);
+ }
+
+ String endpointStr = Tools.get(properties, ENDPOINT);
+ endpoint = endpointStr != null ? endpointStr : DEFAULT_REST_ENDPOINT;
+ log.info("Configured. REST server endpoint is {}", endpoint);
+
+ String methodStr = Tools.get(properties, METHOD);
+ method = methodStr != null ? methodStr : DEFAULT_REST_METHOD;
+ log.info("Configured. REST server default HTTP method is {}", method);
+
+ String requestMediaTypeStr = Tools.get(properties, REQUEST_MEDIA_TYPE);
+ requestMediaType = requestMediaTypeStr != null ?
+ requestMediaTypeStr : DEFAULT_REST_REQUEST_MEDIA_TYPE;
+ log.info("Configured. REST server request media type is {}", requestMediaType);
+
+ String responseMediaTypeStr = Tools.get(properties, RESPONSE_MEDIA_TYPE);
+ responseMediaType = responseMediaTypeStr != null ?
+ responseMediaTypeStr : DEFAULT_REST_RESPONSE_MEDIA_TYPE;
+ log.info("Configured. REST server response media type is {}", responseMediaType);
}
}
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
new file mode 100644
index 0000000..86f3772
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/OpenstackTelemetryUtil.java
@@ -0,0 +1,54 @@
+/*
+ * 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.openstacktelemetry.util;
+
+import com.google.common.base.Strings;
+
+import java.util.Dictionary;
+
+import static org.onlab.util.Tools.get;
+
+/**
+ * An utility that used in openstack telemetry app.
+ */
+public final class OpenstackTelemetryUtil {
+
+ /**
+ * Prevents object instantiation from external.
+ */
+ private OpenstackTelemetryUtil() {
+ }
+
+ /**
+ * Gets Boolean property from the propertyName
+ * Return null if propertyName is not found.
+ *
+ * @param properties properties to be looked up
+ * @param propertyName the name of the property to look up
+ * @return value when the propertyName is defined or return null
+ */
+ public static Boolean getBooleanProperty(Dictionary<?, ?> properties,
+ String propertyName) {
+ Boolean value;
+ try {
+ String s = get(properties, propertyName);
+ value = Strings.isNullOrEmpty(s) ? null : Boolean.valueOf(s);
+ } catch (ClassCastException e) {
+ value = null;
+ }
+ return value;
+ }
+}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/package-info.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/package-info.java
new file mode 100644
index 0000000..e1ba071
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/util/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Openstack telemetry utility package.
+ */
+package org.onosproject.openstacktelemetry.util;
\ No newline at end of file