2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.service.engine.parameters.dummyclasses;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.Properties;
27 import org.apache.commons.lang3.StringUtils;
28 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
29 import org.onap.policy.common.parameters.BeanValidationResult;
30 import org.onap.policy.common.parameters.ValidationStatus;
31 import org.onap.policy.common.parameters.annotations.Min;
32 import org.onap.policy.common.parameters.annotations.NotBlank;
33 import org.onap.policy.common.parameters.annotations.NotNull;
34 import org.onap.policy.models.base.Validated;
37 * Apex parameters for SuperDooper as an event carrier technology.
39 * @author Liam Fallon (liam.fallon@ericsson.com)
43 public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyParameters {
44 // Default parameter values
45 private static final String DEFAULT_ACKS = "all";
46 private static final String DEFAULT_BOOTSTRAP_SERVERS = "localhost:9092";
47 private static final int DEFAULT_RETRIES = 0;
48 private static final int DEFAULT_BATCH_SIZE = 16384;
49 private static final int DEFAULT_LINGER_TIME = 1;
50 private static final long DEFAULT_BUFFER_MEMORY = 33554432;
51 private static final String DEFAULT_GROUP_ID = "default-group-id";
52 private static final boolean DEFAULT_ENABLE_AUTO_COMMIT = true;
53 private static final int DEFAULT_AUTO_COMMIT_TIME = 1000;
54 private static final int DEFAULT_SESSION_TIMEOUT = 30000;
55 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
56 private static final int DEFAULT_CONSUMER_POLL_TIME = 100;
57 private static final String[] DEFAULT_CONSUMER_TOPIC_LIST = {"apex-in"};
58 private static final String DEFAULT_KEYSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
59 private static final String DEFAULT_VALSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
60 private static final String DEFAULT_KEYDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
61 private static final String DEFAULT_VALDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
63 // Parameter property map tokens
64 private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers";
65 private static final String PROPERTY_ACKS = "acks";
66 private static final String PROPERTY_RETRIES = "retries";
67 private static final String PROPERTY_BATCH_SIZE = "batch.size";
68 private static final String PROPERTY_LINGER_TIME = "linger.ms";
69 private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory";
70 private static final String PROPERTY_GROUP_ID = "group.id";
71 private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit";
72 private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms";
73 private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms";
74 private static final String PROPERTY_KEY_SERIALIZER = "key.serializer";
75 private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer";
76 private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer";
77 private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer";
79 // superDooper carrier parameters
80 private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
81 private String acks = DEFAULT_ACKS;
82 private @Min(0) int retries = DEFAULT_RETRIES;
83 private @Min(0) int batchSize = DEFAULT_BATCH_SIZE;
84 private @Min(0) int lingerTime = DEFAULT_LINGER_TIME;
85 private @Min(0) long bufferMemory = DEFAULT_BUFFER_MEMORY;
86 private String groupId = DEFAULT_GROUP_ID;
87 private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
88 private @Min(0) int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
89 private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
90 private String producerTopic = DEFAULT_PRODUCER_TOPIC;
91 private @Min(0) int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
92 private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
93 private String keySerializer = DEFAULT_KEYSERZER;
94 private String valueSerializer = DEFAULT_VALSERZER;
95 private String keyDeserializer = DEFAULT_KEYDESZER;
96 private String valueDeserializer = DEFAULT_VALDESZER;
99 * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
102 public SuperDooperCarrierTechnologyParameters() {
105 // Set the carrier technology properties for the FILE carrier technology
106 this.setLabel("SUPER_DOOPER");
107 this.setEventProducerPluginClass(
108 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer");
109 this.setEventConsumerPluginClass(
110 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber");
114 * Gets the superDooper producer properties.
116 * @return the superDooper producer properties
118 public Properties getSuperDooperProducerProperties() {
119 final Properties superDooperProperties = new Properties();
121 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
122 superDooperProperties.put(PROPERTY_ACKS, acks);
123 superDooperProperties.put(PROPERTY_RETRIES, retries);
124 superDooperProperties.put(PROPERTY_BATCH_SIZE, batchSize);
125 superDooperProperties.put(PROPERTY_LINGER_TIME, lingerTime);
126 superDooperProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory);
127 superDooperProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer);
128 superDooperProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer);
130 return superDooperProperties;
134 * Gets the superDooper consumer properties.
136 * @return the superDooper consumer properties
138 public Properties getSuperDooperConsumerProperties() {
139 final Properties superDooperProperties = new Properties();
141 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
142 superDooperProperties.put(PROPERTY_GROUP_ID, groupId);
143 superDooperProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit);
144 superDooperProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime);
145 superDooperProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout);
146 superDooperProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer);
147 superDooperProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer);
149 return superDooperProperties;
153 * Gets the bootstrap servers.
155 * @return the bootstrap servers
157 public String getBootstrapServers() {
158 return bootstrapServers;
166 public String getAcks() {
173 * @return the retries
175 public int getRetries() {
180 * Gets the batch size.
182 * @return the batch size
184 public int getBatchSize() {
189 * Gets the linger time.
191 * @return the linger time
193 public int getLingerTime() {
198 * Gets the buffer memory.
200 * @return the buffer memory
202 public long getBufferMemory() {
209 * @return the group id
211 public String getGroupId() {
216 * Checks if is enable auto commit.
218 * @return true, if checks if is enable auto commit
220 public boolean isEnableAutoCommit() {
221 return enableAutoCommit;
225 * Gets the auto commit time.
227 * @return the auto commit time
229 public int getAutoCommitTime() {
230 return autoCommitTime;
234 * Gets the session timeout.
236 * @return the session timeout
238 public int getSessionTimeout() {
239 return sessionTimeout;
243 * Gets the producer topic.
245 * @return the producer topic
247 public String getProducerTopic() {
248 return producerTopic;
252 * Gets the consumer poll time.
254 * @return the consumer poll time
256 public long getConsumerPollTime() {
257 return consumerPollTime;
261 * Gets the consumer topic list.
263 * @return the consumer topic list
265 public Collection<String> getConsumerTopicList() {
266 return Arrays.asList(consumerTopicList);
270 * Gets the key serializer.
272 * @return the key serializer
274 public String getKeySerializer() {
275 return keySerializer;
279 * Gets the value serializer.
281 * @return the value serializer
283 public String getValueSerializer() {
284 return valueSerializer;
288 * Gets the key deserializer.
290 * @return the key deserializer
292 public String getKeyDeserializer() {
293 return keyDeserializer;
297 * Gets the value deserializer.
299 * @return the value deserializer
301 public String getValueDeserializer() {
302 return valueDeserializer;
306 * Sets the bootstrap servers.
308 * @param bootstrapServers the new bootstrap servers
310 public void setBootstrapServers(String bootstrapServers) {
311 this.bootstrapServers = bootstrapServers;
317 * @param acks the new acks
319 public void setAcks(String acks) {
326 * @param retries the new retries
328 public void setRetries(int retries) {
329 this.retries = retries;
333 * Sets the batch size.
335 * @param batchSize the new batch size
337 public void setBatchSize(int batchSize) {
338 this.batchSize = batchSize;
342 * Sets the linger time.
344 * @param lingerTime the new linger time
346 public void setLingerTime(int lingerTime) {
347 this.lingerTime = lingerTime;
351 * Sets the buffer memory.
353 * @param bufferMemory the new buffer memory
355 public void setBufferMemory(long bufferMemory) {
356 this.bufferMemory = bufferMemory;
362 * @param groupId the new group id
364 public void setGroupId(String groupId) {
365 this.groupId = groupId;
369 * Sets the enable auto commit.
371 * @param enableAutoCommit the new enable auto commit
373 public void setEnableAutoCommit(boolean enableAutoCommit) {
374 this.enableAutoCommit = enableAutoCommit;
378 * Sets the auto commit time.
380 * @param autoCommitTime the new auto commit time
382 public void setAutoCommitTime(int autoCommitTime) {
383 this.autoCommitTime = autoCommitTime;
387 * Sets the session timeout.
389 * @param sessionTimeout the new session timeout
391 public void setSessionTimeout(int sessionTimeout) {
392 this.sessionTimeout = sessionTimeout;
396 * Sets the producer topic.
398 * @param producerTopic the new producer topic
400 public void setProducerTopic(String producerTopic) {
401 this.producerTopic = producerTopic;
405 * Sets the consumer poll time.
407 * @param consumerPollTime the new consumer poll time
409 public void setConsumerPollTime(int consumerPollTime) {
410 this.consumerPollTime = consumerPollTime;
414 * Sets the consumer topic list.
416 * @param consumerTopicList the new consumer topic list
418 public void setConsumerTopicList(String[] consumerTopicList) {
419 this.consumerTopicList = consumerTopicList;
423 * Sets the key serializer.
425 * @param keySerializer the new key serializer
427 public void setKeySerializer(String keySerializer) {
428 this.keySerializer = keySerializer;
432 * Sets the value serializer.
434 * @param valueSerializer the new value serializer
436 public void setValueSerializer(String valueSerializer) {
437 this.valueSerializer = valueSerializer;
441 * Sets the key deserializer.
443 * @param keyDeserializer the new key deserializer
445 public void setKeyDeserializer(String keyDeserializer) {
446 this.keyDeserializer = keyDeserializer;
450 * Sets the value deserializer.
452 * @param valueDeserializer the new value deserializer
454 public void setValueDeserializer(String valueDeserializer) {
455 this.valueDeserializer = valueDeserializer;
462 public String getName() {
463 return this.getLabel();
470 public BeanValidationResult validate() {
471 final BeanValidationResult result = super.validate();
473 if (consumerTopicList == null) {
477 if (consumerTopicList.length == 0) {
478 result.addResult("consumerTopicList", consumerTopicList, ValidationStatus.INVALID,
479 "not specified, must be specified as a list of strings");
483 BeanValidationResult result2 = new BeanValidationResult("consumerTopicList", consumerTopicList);
485 for (final String consumerTopic : consumerTopicList) {
486 if (StringUtils.isBlank(consumerTopic)) {
487 result2.addResult("entry " + item, consumerTopic, ValidationStatus.INVALID, Validated.IS_BLANK);
493 result.addResult(result2);