[ONOS-7683] Implement various default telemetry configs
Change-Id: Ibfd222be32e9fb7cb29833f9b0d369abaa6e814d
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultGrpcTelemetryConfig.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultGrpcTelemetryConfig.java
new file mode 100644
index 0000000..7b0433e
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultGrpcTelemetryConfig.java
@@ -0,0 +1,148 @@
+/*
+ * 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.config;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.onosproject.openstacktelemetry.api.config.GrpcTelemetryConfig;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A configuration file contains gRPC telemetry parameters.
+ */
+public final class DefaultGrpcTelemetryConfig implements GrpcTelemetryConfig {
+
+ private final String address;
+ private final int port;
+ private final boolean usePlaintext;
+ private final int maxInboundMsgSize;
+ private final Map<String, Object> configMap;
+
+ private DefaultGrpcTelemetryConfig(String address, int port,
+ boolean usePlaintext, int maxInboundMsgSize,
+ Map<String, Object> configMap) {
+ this.address = address;
+ this.port = port;
+ this.usePlaintext = usePlaintext;
+ this.maxInboundMsgSize = maxInboundMsgSize;
+ this.configMap = configMap;
+ }
+
+ @Override
+ public String address() {
+ return address;
+ }
+
+ @Override
+ public int port() {
+ return port;
+ }
+
+ @Override
+ public boolean usePlaintext() {
+ return usePlaintext;
+ }
+
+ @Override
+ public int maxInboundMsgSize() {
+ return maxInboundMsgSize;
+ }
+
+ @Override
+ public Map<String, Object> configMap() {
+ if (configMap != null) {
+ return ImmutableMap.copyOf(configMap);
+ } else {
+ return Maps.newConcurrentMap();
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof DefaultGrpcTelemetryConfig) {
+ final DefaultGrpcTelemetryConfig other = (DefaultGrpcTelemetryConfig) obj;
+ return Objects.equals(this.address, other.address) &&
+ Objects.equals(this.port, other.port) &&
+ Objects.equals(this.usePlaintext, other.usePlaintext) &&
+ Objects.equals(this.maxInboundMsgSize, other.maxInboundMsgSize) &&
+ Objects.equals(this.configMap, other.configMap);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address, port, usePlaintext, maxInboundMsgSize, configMap);
+ }
+
+ /**
+ * Builder class of DefaultKafkaTelemetryConfig.
+ */
+ public final class DefaultBuilder implements Builder {
+
+ private String address;
+ private int port;
+ private boolean usePlaintext;
+ private int maxInboundMsgSize;
+ private Map<String, Object> configMap;
+
+ @Override
+ public Builder withAddress(String address) {
+ this.address = address;
+ return this;
+ }
+
+ @Override
+ public Builder withPort(int port) {
+ this.port = port;
+ return this;
+ }
+
+ @Override
+ public Builder withUsePlaintext(boolean usePlaintext) {
+ this.usePlaintext = usePlaintext;
+ return this;
+ }
+
+ @Override
+ public Builder withMaxInboundMsgSize(int maxInboundMsgSize) {
+ this.maxInboundMsgSize = maxInboundMsgSize;
+ return this;
+ }
+
+ @Override
+ public Builder withConfigMap(Map<String, Object> configMap) {
+ this.configMap = configMap;
+ return this;
+ }
+
+ @Override
+ public GrpcTelemetryConfig build() {
+ checkNotNull(address, "gRPC server address cannot be null");
+
+ return new DefaultGrpcTelemetryConfig(address, port, usePlaintext,
+ maxInboundMsgSize, configMap);
+ }
+ }
+}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultInfluxDbTelemetryConfig.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultInfluxDbTelemetryConfig.java
new file mode 100644
index 0000000..a95517b
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultInfluxDbTelemetryConfig.java
@@ -0,0 +1,182 @@
+/*
+ * 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.config;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.onosproject.openstacktelemetry.api.config.InfluxDbTelemetryConfig;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A configuration file contains InfluxDB telemetry parameters.
+ */
+public final class DefaultInfluxDbTelemetryConfig implements InfluxDbTelemetryConfig {
+
+ private final String address;
+ private final int port;
+ private final String username;
+ private final String password;
+ private final String database;
+ private final boolean enableBatch;
+ private final Map<String, Object> configMap;
+
+ private DefaultInfluxDbTelemetryConfig(String address, int port,
+ String username, String password,
+ String database, boolean enableBatch,
+ Map<String, Object> configMap) {
+ this.address = address;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.database = database;
+ this.enableBatch = enableBatch;
+ this.configMap = configMap;
+ }
+
+ @Override
+ public String address() {
+ return address;
+ }
+
+ @Override
+ public int port() {
+ return port;
+ }
+
+ @Override
+ public String username() {
+ return username;
+ }
+
+ @Override
+ public String password() {
+ return password;
+ }
+
+ @Override
+ public String database() {
+ return database;
+ }
+
+ @Override
+ public boolean enableBatch() {
+ return enableBatch;
+ }
+
+ @Override
+ public Map<String, Object> configMap() {
+ if (configMap != null) {
+ return ImmutableMap.copyOf(configMap);
+ } else {
+ return Maps.newConcurrentMap();
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof DefaultInfluxDbTelemetryConfig) {
+ final DefaultInfluxDbTelemetryConfig other = (DefaultInfluxDbTelemetryConfig) obj;
+ return Objects.equals(this.address, other.address) &&
+ Objects.equals(this.port, other.port) &&
+ Objects.equals(this.username, other.username) &&
+ Objects.equals(this.password, other.password) &&
+ Objects.equals(this.database, other.database) &&
+ Objects.equals(this.enableBatch, other.enableBatch) &&
+ Objects.equals(this.configMap, other.configMap);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address, port, username, password, database, enableBatch, configMap);
+ }
+
+ /**
+ * Builder class of DefaultInfluxDbTelemetryConfig.
+ */
+ public final class DefaultBuilder implements Builder {
+
+ private String address;
+ private int port;
+ private String username;
+ private String password;
+ private String database;
+ private boolean enableBatch;
+ private Map<String, Object> configMap;
+
+ @Override
+ public Builder withAddress(String address) {
+ this.address = address;
+ return this;
+ }
+
+ @Override
+ public Builder withPort(int port) {
+ this.port = port;
+ return this;
+ }
+
+ @Override
+ public Builder withUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+ @Override
+ public Builder withPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+ @Override
+ public Builder withDatabase(String database) {
+ this.database = database;
+ return this;
+ }
+
+ @Override
+ public Builder withEnableBatch(boolean enableBatch) {
+ this.enableBatch = enableBatch;
+ return this;
+ }
+
+ @Override
+ public Builder withConfigMap(Map<String, Object> configMap) {
+ this.configMap = configMap;
+ return this;
+ }
+
+ @Override
+ public InfluxDbTelemetryConfig build() {
+ checkNotNull(address, "InfluxDB server address cannot be null");
+ checkNotNull(username, "InfluxDB server username cannot be null");
+ checkNotNull(password, "InfluxDB server password cannot be null");
+ checkNotNull(database, "InfluxDB server database cannot be null");
+
+ return new DefaultInfluxDbTelemetryConfig(address, port, username,
+ password, database, enableBatch, configMap);
+ }
+ }
+}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultKafkaTelemetryConfig.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultKafkaTelemetryConfig.java
new file mode 100644
index 0000000..9dc460a
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultKafkaTelemetryConfig.java
@@ -0,0 +1,229 @@
+/*
+ * 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.config;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.onosproject.openstacktelemetry.api.config.KafkaTelemetryConfig;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A configuration file contains Kafka telemetry parameters.
+ */
+public final class DefaultKafkaTelemetryConfig implements KafkaTelemetryConfig {
+
+ private final String address;
+ private final int port;
+ private final int retries;
+ private final String requiredAcks;
+ private final int batchSize;
+ private final int lingerMs;
+ private final int memoryBuffer;
+ private final String keySerializer;
+ private final String valueSerializer;
+ private final Map<String, Object> configMap;
+
+ private DefaultKafkaTelemetryConfig(String address, int port, int retries,
+ String requiredAcks, int batchSize,
+ int lingerMs, int memoryBuffer,
+ String keySerializer,
+ String valueSerializer,
+ Map<String, Object> configMap) {
+ this.address = address;
+ this.port = port;
+ this.retries = retries;
+ this.requiredAcks = requiredAcks;
+ this.batchSize = batchSize;
+ this.lingerMs = lingerMs;
+ this.memoryBuffer = memoryBuffer;
+ this.keySerializer = keySerializer;
+ this.valueSerializer = valueSerializer;
+ this.configMap = configMap;
+ }
+
+ @Override
+ public String address() {
+ return address;
+ }
+
+ @Override
+ public int port() {
+ return port;
+ }
+
+ @Override
+ public int retries() {
+ return retries;
+ }
+
+ @Override
+ public String requiredAcks() {
+ return requiredAcks;
+ }
+
+ @Override
+ public int batchSize() {
+ return batchSize;
+ }
+
+ @Override
+ public int lingerMs() {
+ return lingerMs;
+ }
+
+ @Override
+ public int memoryBuffer() {
+ return memoryBuffer;
+ }
+
+ @Override
+ public String keySerializer() {
+ return keySerializer;
+ }
+
+ @Override
+ public String valueSerializer() {
+ return valueSerializer;
+ }
+
+ @Override
+ public Map<String, Object> configMap() {
+ if (configMap != null) {
+ return ImmutableMap.copyOf(configMap);
+ } else {
+ return Maps.newConcurrentMap();
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof DefaultKafkaTelemetryConfig) {
+ final DefaultKafkaTelemetryConfig other = (DefaultKafkaTelemetryConfig) obj;
+ return Objects.equals(this.address, other.address) &&
+ Objects.equals(this.port, other.port) &&
+ Objects.equals(this.retries, other.retries) &&
+ Objects.equals(this.requiredAcks, other.requiredAcks) &&
+ Objects.equals(this.batchSize, other.batchSize) &&
+ Objects.equals(this.lingerMs, other.lingerMs) &&
+ Objects.equals(this.memoryBuffer, other.memoryBuffer) &&
+ Objects.equals(this.keySerializer, other.keySerializer) &&
+ Objects.equals(this.valueSerializer, other.valueSerializer) &&
+ Objects.equals(this.configMap, other.configMap);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address, port, retries, requiredAcks, batchSize,
+ lingerMs, memoryBuffer, keySerializer, valueSerializer, configMap);
+ }
+
+ /**
+ * Builder class of DefaultKafkaTelemetryConfig.
+ */
+ public final class DefaultBuilder implements Builder {
+ private String address;
+ private int port;
+ private int retries;
+ private String requiredAcks;
+ private int batchSize;
+ private int lingerMs;
+ private int memoryBuffer;
+ private String keySerializer;
+ private String valueSerializer;
+ private Map<String, Object> configMap;
+
+ @Override
+ public Builder withAddress(String address) {
+ this.address = address;
+ return this;
+ }
+
+ @Override
+ public Builder withPort(int port) {
+ this.port = port;
+ return this;
+ }
+
+ @Override
+ public Builder withRetries(int retries) {
+ this.retries = retries;
+ return this;
+ }
+
+ @Override
+ public Builder withRequiredAcks(String requiredAcks) {
+ this.requiredAcks = requiredAcks;
+ return this;
+ }
+
+ @Override
+ public Builder withBatchSize(int batchSize) {
+ this.batchSize = batchSize;
+ return this;
+ }
+
+ @Override
+ public Builder withLingerMs(int lingerMs) {
+ this.lingerMs = lingerMs;
+ return this;
+ }
+
+ @Override
+ public Builder withMemoryBuffer(int memoryBuffer) {
+ this.memoryBuffer = memoryBuffer;
+ return this;
+ }
+
+ @Override
+ public Builder withKeySerializer(String keySerializer) {
+ this.keySerializer = keySerializer;
+ return this;
+ }
+
+ @Override
+ public Builder withValueSerializer(String valueSerializer) {
+ this.valueSerializer = valueSerializer;
+ return this;
+ }
+
+ @Override
+ public Builder withConfigMap(Map<String, Object> configMap) {
+ this.configMap = configMap;
+ return this;
+ }
+
+ @Override
+ public KafkaTelemetryConfig build() {
+ checkNotNull(address, "Kafka server address cannot be null");
+ checkNotNull(keySerializer, "Kafka key serializer cannot be null");
+ checkNotNull(valueSerializer, "Kafka value serializer cannot be null");
+
+ return new DefaultKafkaTelemetryConfig(address, port, retries,
+ requiredAcks, batchSize, lingerMs, memoryBuffer,
+ keySerializer, valueSerializer, configMap);
+ }
+ }
+}
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultRestTelemetryConfig.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultRestTelemetryConfig.java
new file mode 100644
index 0000000..b11b14e
--- /dev/null
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/config/DefaultRestTelemetryConfig.java
@@ -0,0 +1,181 @@
+/*
+ * 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.config;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.onosproject.openstacktelemetry.api.config.RestTelemetryConfig;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A configuration file contains REST telemetry parameters.
+ */
+public final class DefaultRestTelemetryConfig implements RestTelemetryConfig {
+
+ private final String address;
+ private final int port;
+ private final String endpoint;
+ private final String method;
+ private final String requestMediaType;
+ private final String responseMediaType;
+ private final Map<String, Object> configMap;
+
+ private DefaultRestTelemetryConfig(String address, int port, String endpoint,
+ String method, String requestMediaType,
+ String responseMediaType,
+ Map<String, Object> configMap) {
+ this.address = address;
+ this.port = port;
+ this.endpoint = endpoint;
+ this.method = method;
+ this.requestMediaType = requestMediaType;
+ this.responseMediaType = responseMediaType;
+ this.configMap = configMap;
+ }
+
+ @Override
+ public String address() {
+ return address;
+ }
+
+ @Override
+ public int port() {
+ return port;
+ }
+
+ @Override
+ public String endpoint() {
+ return endpoint;
+ }
+
+ @Override
+ public String method() {
+ return method;
+ }
+
+ @Override
+ public String requestMediaType() {
+ return requestMediaType;
+ }
+
+ @Override
+ public String responseMediaType() {
+ return responseMediaType;
+ }
+
+ @Override
+ public Map<String, Object> configMap() {
+ if (configMap != null) {
+ return ImmutableMap.copyOf(configMap);
+ } else {
+ return Maps.newConcurrentMap();
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof DefaultRestTelemetryConfig) {
+ final DefaultRestTelemetryConfig other = (DefaultRestTelemetryConfig) obj;
+ return Objects.equals(this.address, other.address) &&
+ Objects.equals(this.port, other.port) &&
+ Objects.equals(this.endpoint, other.endpoint) &&
+ Objects.equals(this.method, other.method) &&
+ Objects.equals(this.requestMediaType, other.requestMediaType) &&
+ Objects.equals(this.responseMediaType, other.responseMediaType) &&
+ Objects.equals(this.configMap, other.configMap);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address, port, endpoint, method, requestMediaType,
+ responseMediaType, configMap);
+ }
+
+ /**
+ * Builder class of DefaultRestTelemetryConfig.
+ */
+ public final class DefaultBuilder implements Builder {
+
+ private String address;
+ private int port;
+ private String endpoint;
+ private String method;
+ private String requestMediaType;
+ private String responseMediaType;
+ private Map<String, Object> configMap;
+
+ @Override
+ public Builder withAddress(String address) {
+ this.address = address;
+ return this;
+ }
+
+ @Override
+ public Builder withPort(int port) {
+ this.port = port;
+ return this;
+ }
+
+ @Override
+ public Builder withEndpoint(String endpoint) {
+ this.endpoint = endpoint;
+ return this;
+ }
+
+ @Override
+ public Builder withMethod(String method) {
+ this.method = method;
+ return this;
+ }
+
+ @Override
+ public Builder withRequestMediaType(String mediaType) {
+ this.requestMediaType = mediaType;
+ return this;
+ }
+
+ @Override
+ public Builder withResponseMediaType(String mediaType) {
+ this.responseMediaType = mediaType;
+ return this;
+ }
+
+ @Override
+ public Builder withConfigMap(Map<String, Object> configMap) {
+ this.configMap = configMap;
+ return this;
+ }
+
+ @Override
+ public RestTelemetryConfig build() {
+ checkNotNull(address, "REST server address cannot be null");
+ checkNotNull(endpoint, "REST server endpoint cannot be null");
+
+ return new DefaultRestTelemetryConfig(address, port, endpoint,
+ method, requestMediaType, responseMediaType, configMap);
+ }
+ }
+}