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;
26 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
27 import org.onap.policy.common.parameters.GroupValidationResult;
28 import org.onap.policy.common.parameters.ValidationStatus;
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_KEYSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
51 private static final String DEFAULT_VALSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
52 private static final String DEFAULT_KEYDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
53 private static final String DEFAULT_VALDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
55 // Parameter property map tokens
56 private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers";
57 private static final String PROPERTY_ACKS = "acks";
58 private static final String PROPERTY_RETRIES = "retries";
59 private static final String PROPERTY_BATCH_SIZE = "batch.size";
60 private static final String PROPERTY_LINGER_TIME = "linger.ms";
61 private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory";
62 private static final String PROPERTY_GROUP_ID = "group.id";
63 private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit";
64 private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms";
65 private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms";
66 private static final String PROPERTY_KEY_SERIALIZER = "key.serializer";
67 private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer";
68 private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer";
69 private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer";
71 // superDooper carrier parameters
72 private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
73 private String acks = DEFAULT_ACKS;
74 private int retries = DEFAULT_RETRIES;
75 private int batchSize = DEFAULT_BATCH_SIZE;
76 private int lingerTime = DEFAULT_LINGER_TIME;
77 private long bufferMemory = DEFAULT_BUFFER_MEMORY;
78 private String groupId = DEFAULT_GROUP_ID;
79 private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
80 private int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
81 private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
82 private String producerTopic = DEFAULT_PRODUCER_TOPIC;
83 private int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
84 private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
85 private String keySerializer = DEFAULT_KEYSERZER;
86 private String valueSerializer = DEFAULT_VALSERZER;
87 private String keyDeserializer = DEFAULT_KEYDESZER;
88 private String valueDeserializer = DEFAULT_VALDESZER;
91 * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
94 public SuperDooperCarrierTechnologyParameters() {
97 // Set the carrier technology properties for the FILE carrier technology
98 this.setLabel("SUPER_DOOPER");
99 this.setEventProducerPluginClass(
100 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer");
101 this.setEventConsumerPluginClass(
102 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber");
106 * Gets the superDooper producer properties.
108 * @return the superDooper producer properties
110 public Properties getSuperDooperProducerProperties() {
111 final Properties superDooperProperties = new Properties();
113 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
114 superDooperProperties.put(PROPERTY_ACKS, acks);
115 superDooperProperties.put(PROPERTY_RETRIES, retries);
116 superDooperProperties.put(PROPERTY_BATCH_SIZE, batchSize);
117 superDooperProperties.put(PROPERTY_LINGER_TIME, lingerTime);
118 superDooperProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory);
119 superDooperProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer);
120 superDooperProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer);
122 return superDooperProperties;
126 * Gets the superDooper consumer properties.
128 * @return the superDooper consumer properties
130 public Properties getSuperDooperConsumerProperties() {
131 final Properties superDooperProperties = new Properties();
133 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
134 superDooperProperties.put(PROPERTY_GROUP_ID, groupId);
135 superDooperProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit);
136 superDooperProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime);
137 superDooperProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout);
138 superDooperProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer);
139 superDooperProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer);
141 return superDooperProperties;
145 * Gets the bootstrap servers.
147 * @return the bootstrap servers
149 public String getBootstrapServers() {
150 return bootstrapServers;
158 public String getAcks() {
165 * @return the retries
167 public int getRetries() {
172 * Gets the batch size.
174 * @return the batch size
176 public int getBatchSize() {
181 * Gets the linger time.
183 * @return the linger time
185 public int getLingerTime() {
190 * Gets the buffer memory.
192 * @return the buffer memory
194 public long getBufferMemory() {
201 * @return the group id
203 public String getGroupId() {
208 * Checks if is enable auto commit.
210 * @return true, if checks if is enable auto commit
212 public boolean isEnableAutoCommit() {
213 return enableAutoCommit;
217 * Gets the auto commit time.
219 * @return the auto commit time
221 public int getAutoCommitTime() {
222 return autoCommitTime;
226 * Gets the session timeout.
228 * @return the session timeout
230 public int getSessionTimeout() {
231 return sessionTimeout;
235 * Gets the producer topic.
237 * @return the producer topic
239 public String getProducerTopic() {
240 return producerTopic;
244 * Gets the consumer poll time.
246 * @return the consumer poll time
248 public long getConsumerPollTime() {
249 return consumerPollTime;
253 * Gets the consumer topic list.
255 * @return the consumer topic list
257 public Collection<String> getConsumerTopicList() {
258 return Arrays.asList(consumerTopicList);
262 * Gets the key serializer.
264 * @return the key serializer
266 public String getKeySerializer() {
267 return keySerializer;
271 * Gets the value serializer.
273 * @return the value serializer
275 public String getValueSerializer() {
276 return valueSerializer;
280 * Gets the key deserializer.
282 * @return the key deserializer
284 public String getKeyDeserializer() {
285 return keyDeserializer;
289 * Gets the value deserializer.
291 * @return the value deserializer
293 public String getValueDeserializer() {
294 return valueDeserializer;
298 * Sets the bootstrap servers.
300 * @param bootstrapServers the new bootstrap servers
302 public void setBootstrapServers(String bootstrapServers) {
303 this.bootstrapServers = bootstrapServers;
309 * @param acks the new acks
311 public void setAcks(String acks) {
318 * @param retries the new retries
320 public void setRetries(int retries) {
321 this.retries = retries;
325 * Sets the batch size.
327 * @param batchSize the new batch size
329 public void setBatchSize(int batchSize) {
330 this.batchSize = batchSize;
334 * Sets the linger time.
336 * @param lingerTime the new linger time
338 public void setLingerTime(int lingerTime) {
339 this.lingerTime = lingerTime;
343 * Sets the buffer memory.
345 * @param bufferMemory the new buffer memory
347 public void setBufferMemory(long bufferMemory) {
348 this.bufferMemory = bufferMemory;
354 * @param groupId the new group id
356 public void setGroupId(String groupId) {
357 this.groupId = groupId;
361 * Sets the enable auto commit.
363 * @param enableAutoCommit the new enable auto commit
365 public void setEnableAutoCommit(boolean enableAutoCommit) {
366 this.enableAutoCommit = enableAutoCommit;
370 * Sets the auto commit time.
372 * @param autoCommitTime the new auto commit time
374 public void setAutoCommitTime(int autoCommitTime) {
375 this.autoCommitTime = autoCommitTime;
379 * Sets the session timeout.
381 * @param sessionTimeout the new session timeout
383 public void setSessionTimeout(int sessionTimeout) {
384 this.sessionTimeout = sessionTimeout;
388 * Sets the producer topic.
390 * @param producerTopic the new producer topic
392 public void setProducerTopic(String producerTopic) {
393 this.producerTopic = producerTopic;
397 * Sets the consumer poll time.
399 * @param consumerPollTime the new consumer poll time
401 public void setConsumerPollTime(int consumerPollTime) {
402 this.consumerPollTime = consumerPollTime;
406 * Sets the consumer topic list.
408 * @param consumerTopicList the new consumer topic list
410 public void setConsumerTopicList(String[] consumerTopicList) {
411 this.consumerTopicList = consumerTopicList;
415 * Sets the key serializer.
417 * @param keySerializer the new key serializer
419 public void setKeySerializer(String keySerializer) {
420 this.keySerializer = keySerializer;
424 * Sets the value serializer.
426 * @param valueSerializer the new value serializer
428 public void setValueSerializer(String valueSerializer) {
429 this.valueSerializer = valueSerializer;
433 * Sets the key deserializer.
435 * @param keyDeserializer the new key deserializer
437 public void setKeyDeserializer(String keyDeserializer) {
438 this.keyDeserializer = keyDeserializer;
442 * Sets the value deserializer.
444 * @param valueDeserializer the new value deserializer
446 public void setValueDeserializer(String valueDeserializer) {
447 this.valueDeserializer = valueDeserializer;
454 public String getName() {
455 return this.getLabel();
462 public GroupValidationResult validate() {
463 final GroupValidationResult result = super.validate();
465 if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
466 result.setResult("bootstrapServers", ValidationStatus.INVALID,
467 "bootstrapServers not specified, must be specified as a string of form host:port");
470 if (acks == null || acks.trim().length() == 0) {
471 result.setResult("acks", ValidationStatus.INVALID,
472 "acks not specified, must be specified as a string with values [0|1|all]");
476 result.setResult("retries", ValidationStatus.INVALID,
477 "[" + retries + "] invalid, must be specified as retries >= 0");
481 result.setResult("batchSize", ValidationStatus.INVALID,
482 "[" + batchSize + "] invalid, must be specified as batchSize >= 0");
485 if (lingerTime < 0) {
486 result.setResult("lingerTime", ValidationStatus.INVALID,
487 "[" + lingerTime + "] invalid, must be specified as lingerTime >= 0");
490 if (bufferMemory < 0) {
491 result.setResult("bufferMemory", ValidationStatus.INVALID,
492 "[" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0");
495 if (groupId == null || groupId.trim().length() == 0) {
496 result.setResult("groupId", ValidationStatus.INVALID, "not specified, must be specified as a string");
499 if (autoCommitTime < 0) {
500 result.setResult("autoCommitTime", ValidationStatus.INVALID,
501 "[" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0");
504 if (sessionTimeout < 0) {
505 result.setResult("sessionTimeout", ValidationStatus.INVALID,
506 "sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0");
509 if (producerTopic == null || producerTopic.trim().length() == 0) {
510 result.setResult("producerTopic", ValidationStatus.INVALID,
511 "producerTopic not specified, must be specified as a string");
514 if (consumerPollTime < 0) {
515 result.setResult("consumerPollTime", ValidationStatus.INVALID,
516 "[" + consumerPollTime + "] invalid, must be specified as consumerPollTime >= 0");
519 if (consumerTopicList == null || consumerTopicList.length == 0) {
520 result.setResult("consumerTopicList", ValidationStatus.INVALID,
521 "not specified, must be specified as a list of strings");
524 StringBuilder consumerTopicMessageBuilder = new StringBuilder();
525 for (final String consumerTopic : consumerTopicList) {
526 if (consumerTopic == null || consumerTopic.trim().length() == 0) {
527 consumerTopicMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
528 + "\" specified on consumerTopicList, consumer topics must be specified as strings");
532 if (consumerTopicMessageBuilder.length() > 0) {
533 result.setResult("consumerTopicList", ValidationStatus.INVALID, consumerTopicMessageBuilder.toString());
536 if (keySerializer == null || keySerializer.trim().length() == 0) {
537 result.setResult("keySerializer", ValidationStatus.INVALID, "not specified, must be specified as a string");
540 if (valueSerializer == null || valueSerializer.trim().length() == 0) {
541 result.setResult("valueSerializer", ValidationStatus.INVALID,
542 "not specified, must be specified as a string");
545 if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
546 result.setResult("keyDeserializer", ValidationStatus.INVALID,
547 "not specified, must be specified as a string");
550 if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
551 result.setResult("valueDeserializer", ValidationStatus.INVALID,
552 "not specified, must be specified as a string");