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 String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
76 private String acks = DEFAULT_ACKS;
77 private int retries = DEFAULT_RETRIES;
78 private int batchSize = DEFAULT_BATCH_SIZE;
79 private int lingerTime = DEFAULT_LINGER_TIME;
80 private long bufferMemory = DEFAULT_BUFFER_MEMORY;
81 private String groupId = DEFAULT_GROUP_ID;
82 private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
83 private int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
84 private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
85 private String producerTopic = DEFAULT_PRODUCER_TOPIC;
86 private int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
87 private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
88 private String keySerializer = DEFAULT_KEY_SERIALIZER;
89 private String valueSerializer = DEFAULT_VALUE_SERIALIZER;
90 private String keyDeserializer = DEFAULT_KEY_DESERIALIZER;
91 private 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;
302 * Sets the bootstrap servers.
304 * @param bootstrapServers the new bootstrap servers
306 public void setBootstrapServers(String bootstrapServers) {
307 this.bootstrapServers = bootstrapServers;
313 * @param acks the new acks
315 public void setAcks(String acks) {
322 * @param retries the new retries
324 public void setRetries(int retries) {
325 this.retries = retries;
329 * Sets the batch size.
331 * @param batchSize the new batch size
333 public void setBatchSize(int batchSize) {
334 this.batchSize = batchSize;
338 * Sets the linger time.
340 * @param lingerTime the new linger time
342 public void setLingerTime(int lingerTime) {
343 this.lingerTime = lingerTime;
347 * Sets the buffer memory.
349 * @param bufferMemory the new buffer memory
351 public void setBufferMemory(long bufferMemory) {
352 this.bufferMemory = bufferMemory;
358 * @param groupId the new group id
360 public void setGroupId(String groupId) {
361 this.groupId = groupId;
365 * Sets the enable auto commit.
367 * @param enableAutoCommit the new enable auto commit
369 public void setEnableAutoCommit(boolean enableAutoCommit) {
370 this.enableAutoCommit = enableAutoCommit;
374 * Sets the auto commit time.
376 * @param autoCommitTime the new auto commit time
378 public void setAutoCommitTime(int autoCommitTime) {
379 this.autoCommitTime = autoCommitTime;
383 * Sets the session timeout.
385 * @param sessionTimeout the new session timeout
387 public void setSessionTimeout(int sessionTimeout) {
388 this.sessionTimeout = sessionTimeout;
392 * Sets the producer topic.
394 * @param producerTopic the new producer topic
396 public void setProducerTopic(String producerTopic) {
397 this.producerTopic = producerTopic;
401 * Sets the consumer poll time.
403 * @param consumerPollTime the new consumer poll time
405 public void setConsumerPollTime(int consumerPollTime) {
406 this.consumerPollTime = consumerPollTime;
410 * Sets the consumer topic list.
412 * @param consumerTopicList the new consumer topic list
414 public void setConsumerTopicList(String[] consumerTopicList) {
415 this.consumerTopicList = consumerTopicList;
419 * Sets the key serializer.
421 * @param keySerializer the new key serializer
423 public void setKeySerializer(String keySerializer) {
424 this.keySerializer = keySerializer;
428 * Sets the value serializer.
430 * @param valueSerializer the new value serializer
432 public void setValueSerializer(String valueSerializer) {
433 this.valueSerializer = valueSerializer;
437 * Sets the key deserializer.
439 * @param keyDeserializer the new key deserializer
441 public void setKeyDeserializer(String keyDeserializer) {
442 this.keyDeserializer = keyDeserializer;
446 * Sets the value deserializer.
448 * @param valueDeserializer the new value deserializer
450 public void setValueDeserializer(String valueDeserializer) {
451 this.valueDeserializer = valueDeserializer;
457 * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
460 public String validate() {
461 final StringBuilder errorMessageBuilder = new StringBuilder();
463 errorMessageBuilder.append(super.validate());
465 if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
467 .append(" bootstrapServers not specified, must be specified as a string of form host:port\n");
470 if (acks == null || acks.trim().length() == 0) {
471 errorMessageBuilder.append(" acks not specified, must be specified as a string with values [0|1|all]\n");
475 errorMessageBuilder.append(" retries [" + retries + "] invalid, must be specified as retries >= 0\n");
480 .append(" batchSize [" + batchSize + "] invalid, must be specified as batchSize >= 0\n");
483 if (lingerTime < 0) {
485 .append(" lingerTime [" + lingerTime + "] invalid, must be specified as lingerTime >= 0\n");
488 if (bufferMemory < 0) {
490 .append(" bufferMemory [" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0\n");
493 if (groupId == null || groupId.trim().length() == 0) {
494 errorMessageBuilder.append(" groupId not specified, must be specified as a string\n");
497 if (autoCommitTime < 0) {
498 errorMessageBuilder.append(
499 " autoCommitTime [" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0\n");
502 if (sessionTimeout < 0) {
503 errorMessageBuilder.append(
504 " sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0\n");
507 if (producerTopic == null || producerTopic.trim().length() == 0) {
508 errorMessageBuilder.append(" producerTopic not specified, must be specified as a string\n");
511 if (consumerPollTime < 0) {
512 errorMessageBuilder.append(" consumerPollTime [" + consumerPollTime
513 + "] invalid, must be specified as consumerPollTime >= 0\n");
516 if (consumerTopicList == null || consumerTopicList.length == 0) {
517 errorMessageBuilder.append(" consumerTopicList not specified, must be specified as a list of strings\n");
520 for (final String consumerTopic : consumerTopicList) {
521 if (consumerTopic == null || consumerTopic.trim().length() == 0) {
522 errorMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
523 + "\" specified on consumerTopicList, consumer topics must be specified as strings\n");
527 if (keySerializer == null || keySerializer.trim().length() == 0) {
528 errorMessageBuilder.append(" keySerializer not specified, must be specified as a string\n");
531 if (valueSerializer == null || valueSerializer.trim().length() == 0) {
532 errorMessageBuilder.append(" valueSerializer not specified, must be specified as a string\n");
535 if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
536 errorMessageBuilder.append(" keyDeserializer not specified, must be specified as a string\n");
539 if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
540 errorMessageBuilder.append(" valueDeserializer not specified, must be specified as a string\n");
543 return errorMessageBuilder.toString();