2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.parameters.dummyclasses;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Properties;
27 import org.onap.policy.apex.model.basicmodel.service.ParameterService;
28 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
31 * Apex parameters for SuperDooper as an event carrier technology.
33 * @author Liam Fallon (liam.fallon@ericsson.com)
35 public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyParameters {
36 // Default parameter values
37 private static final String DEFAULT_ACKS = "all";
38 private static final String DEFAULT_BOOTSTRAP_SERVERS = "localhost:9092";
39 private static final int DEFAULT_RETRIES = 0;
40 private static final int DEFAULT_BATCH_SIZE = 16384;
41 private static final int DEFAULT_LINGER_TIME = 1;
42 private static final long DEFAULT_BUFFER_MEMORY = 33554432;
43 private static final String DEFAULT_GROUP_ID = "default-group-id";
44 private static final boolean DEFAULT_ENABLE_AUTO_COMMIT = true;
45 private static final int DEFAULT_AUTO_COMMIT_TIME = 1000;
46 private static final int DEFAULT_SESSION_TIMEOUT = 30000;
47 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
48 private static final int DEFAULT_CONSUMER_POLL_TIME = 100;
49 private static final String[] DEFAULT_CONSUMER_TOPIC_LIST = {"apex-in"};
50 private static final String DEFAULT_KEY_SERIALIZER = "org.apache.superDooper.common.serialization.StringSerializer";
51 private static final String DEFAULT_VALUE_SERIALIZER =
52 "org.apache.superDooper.common.serialization.StringSerializer";
53 private static final String DEFAULT_KEY_DESERIALIZER =
54 "org.apache.superDooper.common.serialization.StringDeserializer";
55 private static final String DEFAULT_VALUE_DESERIALIZER =
56 "org.apache.superDooper.common.serialization.StringDeserializer";
58 // Parameter property map tokens
59 private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers";
60 private static final String PROPERTY_ACKS = "acks";
61 private static final String PROPERTY_RETRIES = "retries";
62 private static final String PROPERTY_BATCH_SIZE = "batch.size";
63 private static final String PROPERTY_LINGER_TIME = "linger.ms";
64 private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory";
65 private static final String PROPERTY_GROUP_ID = "group.id";
66 private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit";
67 private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms";
68 private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms";
69 private static final String PROPERTY_KEY_SERIALIZER = "key.serializer";
70 private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer";
71 private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer";
72 private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer";
74 // superDooper carrier parameters
75 private final String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
76 private final String acks = DEFAULT_ACKS;
77 private final int retries = DEFAULT_RETRIES;
78 private final int batchSize = DEFAULT_BATCH_SIZE;
79 private final int lingerTime = DEFAULT_LINGER_TIME;
80 private final long bufferMemory = DEFAULT_BUFFER_MEMORY;
81 private final String groupId = DEFAULT_GROUP_ID;
82 private final boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
83 private final int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
84 private final int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
85 private final String producerTopic = DEFAULT_PRODUCER_TOPIC;
86 private final int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
87 private final String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
88 private final String keySerializer = DEFAULT_KEY_SERIALIZER;
89 private final String valueSerializer = DEFAULT_VALUE_SERIALIZER;
90 private final String keyDeserializer = DEFAULT_KEY_DESERIALIZER;
91 private final String valueDeserializer = DEFAULT_VALUE_DESERIALIZER;
94 * Constructor to create a file carrier technology parameters instance and register the instance
95 * with the parameter service.
97 public SuperDooperCarrierTechnologyParameters() {
98 super(SuperDooperCarrierTechnologyParameters.class.getCanonicalName());
99 ParameterService.registerParameters(SuperDooperCarrierTechnologyParameters.class, this);
101 // Set the carrier technology properties for the FILE carrier technology
102 this.setLabel("SUPER_DOOPER");
103 this.setEventProducerPluginClass(
104 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer");
105 this.setEventConsumerPluginClass(
106 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber");
110 * Gets the superDooper producer properties.
112 * @return the superDooper producer properties
114 public Properties getSuperDooperProducerProperties() {
115 final Properties superDooperProperties = new Properties();
117 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
118 superDooperProperties.put(PROPERTY_ACKS, acks);
119 superDooperProperties.put(PROPERTY_RETRIES, retries);
120 superDooperProperties.put(PROPERTY_BATCH_SIZE, batchSize);
121 superDooperProperties.put(PROPERTY_LINGER_TIME, lingerTime);
122 superDooperProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory);
123 superDooperProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer);
124 superDooperProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer);
126 return superDooperProperties;
130 * Gets the superDooper consumer properties.
132 * @return the superDooper consumer properties
134 public Properties getSuperDooperConsumerProperties() {
135 final Properties superDooperProperties = new Properties();
137 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
138 superDooperProperties.put(PROPERTY_GROUP_ID, groupId);
139 superDooperProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit);
140 superDooperProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime);
141 superDooperProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout);
142 superDooperProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer);
143 superDooperProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer);
145 return superDooperProperties;
149 * Gets the bootstrap servers.
151 * @return the bootstrap servers
153 public String getBootstrapServers() {
154 return bootstrapServers;
162 public String getAcks() {
169 * @return the retries
171 public int getRetries() {
176 * Gets the batch size.
178 * @return the batch size
180 public int getBatchSize() {
185 * Gets the linger time.
187 * @return the linger time
189 public int getLingerTime() {
194 * Gets the buffer memory.
196 * @return the buffer memory
198 public long getBufferMemory() {
205 * @return the group id
207 public String getGroupId() {
212 * Checks if is enable auto commit.
214 * @return true, if checks if is enable auto commit
216 public boolean isEnableAutoCommit() {
217 return enableAutoCommit;
221 * Gets the auto commit time.
223 * @return the auto commit time
225 public int getAutoCommitTime() {
226 return autoCommitTime;
230 * Gets the session timeout.
232 * @return the session timeout
234 public int getSessionTimeout() {
235 return sessionTimeout;
239 * Gets the producer topic.
241 * @return the producer topic
243 public String getProducerTopic() {
244 return producerTopic;
248 * Gets the consumer poll time.
250 * @return the consumer poll time
252 public long getConsumerPollTime() {
253 return consumerPollTime;
257 * Gets the consumer topic list.
259 * @return the consumer topic list
261 public Collection<String> getConsumerTopicList() {
262 return Arrays.asList(consumerTopicList);
266 * Gets the key serializer.
268 * @return the key serializer
270 public String getKeySerializer() {
271 return keySerializer;
275 * Gets the value serializer.
277 * @return the value serializer
279 public String getValueSerializer() {
280 return valueSerializer;
284 * Gets the key deserializer.
286 * @return the key deserializer
288 public String getKeyDeserializer() {
289 return keyDeserializer;
293 * Gets the value deserializer.
295 * @return the value deserializer
297 public String getValueDeserializer() {
298 return valueDeserializer;
304 * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
307 public String validate() {
308 final StringBuilder errorMessageBuilder = new StringBuilder();
310 errorMessageBuilder.append(super.validate());
312 if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
314 .append(" bootstrapServers not specified, must be specified as a string of form host:port\n");
317 if (acks == null || acks.trim().length() == 0) {
318 errorMessageBuilder.append(" acks not specified, must be specified as a string with values [0|1|all]\n");
322 errorMessageBuilder.append(" retries [" + retries + "] invalid, must be specified as retries >= 0\n");
327 .append(" batchSize [" + batchSize + "] invalid, must be specified as batchSize >= 0\n");
330 if (lingerTime < 0) {
332 .append(" lingerTime [" + lingerTime + "] invalid, must be specified as lingerTime >= 0\n");
335 if (bufferMemory < 0) {
337 .append(" bufferMemory [" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0\n");
340 if (groupId == null || groupId.trim().length() == 0) {
341 errorMessageBuilder.append(" groupId not specified, must be specified as a string\n");
344 if (autoCommitTime < 0) {
345 errorMessageBuilder.append(
346 " autoCommitTime [" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0\n");
349 if (sessionTimeout < 0) {
350 errorMessageBuilder.append(
351 " sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0\n");
354 if (producerTopic == null || producerTopic.trim().length() == 0) {
355 errorMessageBuilder.append(" producerTopic not specified, must be specified as a string\n");
358 if (consumerPollTime < 0) {
359 errorMessageBuilder.append(" consumerPollTime [" + consumerPollTime
360 + "] invalid, must be specified as consumerPollTime >= 0\n");
363 if (consumerTopicList == null || consumerTopicList.length == 0) {
364 errorMessageBuilder.append(" consumerTopicList not specified, must be specified as a list of strings\n");
367 for (final String consumerTopic : consumerTopicList) {
368 if (consumerTopic == null || consumerTopic.trim().length() == 0) {
369 errorMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
370 + "\" specified on consumerTopicList, consumer topics must be specified as strings\n");
374 if (keySerializer == null || keySerializer.trim().length() == 0) {
375 errorMessageBuilder.append(" keySerializer not specified, must be specified as a string\n");
378 if (valueSerializer == null || valueSerializer.trim().length() == 0) {
379 errorMessageBuilder.append(" valueSerializer not specified, must be specified as a string\n");
382 if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
383 errorMessageBuilder.append(" keyDeserializer not specified, must be specified as a string\n");
386 if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
387 errorMessageBuilder.append(" valueDeserializer not specified, must be specified as a string\n");
390 return errorMessageBuilder.toString();