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.service.parameters.carriertechnology.CarrierTechnologyParameters;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ValidationStatus;
32 * Apex parameters for SuperDooper as an event carrier technology.
34 * @author Liam Fallon (liam.fallon@ericsson.com)
36 public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyParameters {
37 // Default parameter values
38 private static final String DEFAULT_ACKS = "all";
39 private static final String DEFAULT_BOOTSTRAP_SERVERS = "localhost:9092";
40 private static final int DEFAULT_RETRIES = 0;
41 private static final int DEFAULT_BATCH_SIZE = 16384;
42 private static final int DEFAULT_LINGER_TIME = 1;
43 private static final long DEFAULT_BUFFER_MEMORY = 33554432;
44 private static final String DEFAULT_GROUP_ID = "default-group-id";
45 private static final boolean DEFAULT_ENABLE_AUTO_COMMIT = true;
46 private static final int DEFAULT_AUTO_COMMIT_TIME = 1000;
47 private static final int DEFAULT_SESSION_TIMEOUT = 30000;
48 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
49 private static final int DEFAULT_CONSUMER_POLL_TIME = 100;
50 private static final String[] DEFAULT_CONSUMER_TOPIC_LIST =
52 private static final String DEFAULT_KEYSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
53 private static final String DEFAULT_VALSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
54 private static final String DEFAULT_KEYDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
55 private static final String DEFAULT_VALDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
57 // Parameter property map tokens
58 private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers";
59 private static final String PROPERTY_ACKS = "acks";
60 private static final String PROPERTY_RETRIES = "retries";
61 private static final String PROPERTY_BATCH_SIZE = "batch.size";
62 private static final String PROPERTY_LINGER_TIME = "linger.ms";
63 private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory";
64 private static final String PROPERTY_GROUP_ID = "group.id";
65 private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit";
66 private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms";
67 private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms";
68 private static final String PROPERTY_KEY_SERIALIZER = "key.serializer";
69 private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer";
70 private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer";
71 private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer";
73 // superDooper carrier parameters
74 private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
75 private String acks = DEFAULT_ACKS;
76 private int retries = DEFAULT_RETRIES;
77 private int batchSize = DEFAULT_BATCH_SIZE;
78 private int lingerTime = DEFAULT_LINGER_TIME;
79 private long bufferMemory = DEFAULT_BUFFER_MEMORY;
80 private String groupId = DEFAULT_GROUP_ID;
81 private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
82 private int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
83 private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
84 private String producerTopic = DEFAULT_PRODUCER_TOPIC;
85 private int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
86 private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
87 private String keySerializer = DEFAULT_KEYSERZER;
88 private String valueSerializer = DEFAULT_VALSERZER;
89 private String keyDeserializer = DEFAULT_KEYDESZER;
90 private String valueDeserializer = DEFAULT_VALDESZER;
93 * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
96 public SuperDooperCarrierTechnologyParameters() {
99 // Set the carrier technology properties for the FILE carrier technology
100 this.setLabel("SUPER_DOOPER");
101 this.setEventProducerPluginClass(
102 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer");
103 this.setEventConsumerPluginClass(
104 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber");
108 * Gets the superDooper producer properties.
110 * @return the superDooper producer properties
112 public Properties getSuperDooperProducerProperties() {
113 final Properties superDooperProperties = new Properties();
115 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
116 superDooperProperties.put(PROPERTY_ACKS, acks);
117 superDooperProperties.put(PROPERTY_RETRIES, retries);
118 superDooperProperties.put(PROPERTY_BATCH_SIZE, batchSize);
119 superDooperProperties.put(PROPERTY_LINGER_TIME, lingerTime);
120 superDooperProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory);
121 superDooperProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer);
122 superDooperProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer);
124 return superDooperProperties;
128 * Gets the superDooper consumer properties.
130 * @return the superDooper consumer properties
132 public Properties getSuperDooperConsumerProperties() {
133 final Properties superDooperProperties = new Properties();
135 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
136 superDooperProperties.put(PROPERTY_GROUP_ID, groupId);
137 superDooperProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit);
138 superDooperProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime);
139 superDooperProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout);
140 superDooperProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer);
141 superDooperProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer);
143 return superDooperProperties;
147 * Gets the bootstrap servers.
149 * @return the bootstrap servers
151 public String getBootstrapServers() {
152 return bootstrapServers;
160 public String getAcks() {
167 * @return the retries
169 public int getRetries() {
174 * Gets the batch size.
176 * @return the batch size
178 public int getBatchSize() {
183 * Gets the linger time.
185 * @return the linger time
187 public int getLingerTime() {
192 * Gets the buffer memory.
194 * @return the buffer memory
196 public long getBufferMemory() {
203 * @return the group id
205 public String getGroupId() {
210 * Checks if is enable auto commit.
212 * @return true, if checks if is enable auto commit
214 public boolean isEnableAutoCommit() {
215 return enableAutoCommit;
219 * Gets the auto commit time.
221 * @return the auto commit time
223 public int getAutoCommitTime() {
224 return autoCommitTime;
228 * Gets the session timeout.
230 * @return the session timeout
232 public int getSessionTimeout() {
233 return sessionTimeout;
237 * Gets the producer topic.
239 * @return the producer topic
241 public String getProducerTopic() {
242 return producerTopic;
246 * Gets the consumer poll time.
248 * @return the consumer poll time
250 public long getConsumerPollTime() {
251 return consumerPollTime;
255 * Gets the consumer topic list.
257 * @return the consumer topic list
259 public Collection<String> getConsumerTopicList() {
260 return Arrays.asList(consumerTopicList);
264 * Gets the key serializer.
266 * @return the key serializer
268 public String getKeySerializer() {
269 return keySerializer;
273 * Gets the value serializer.
275 * @return the value serializer
277 public String getValueSerializer() {
278 return valueSerializer;
282 * Gets the key deserializer.
284 * @return the key deserializer
286 public String getKeyDeserializer() {
287 return keyDeserializer;
291 * Gets the value deserializer.
293 * @return the value deserializer
295 public String getValueDeserializer() {
296 return valueDeserializer;
300 * Sets the bootstrap servers.
302 * @param bootstrapServers the new bootstrap servers
304 public void setBootstrapServers(String bootstrapServers) {
305 this.bootstrapServers = bootstrapServers;
311 * @param acks the new acks
313 public void setAcks(String acks) {
320 * @param retries the new retries
322 public void setRetries(int retries) {
323 this.retries = retries;
327 * Sets the batch size.
329 * @param batchSize the new batch size
331 public void setBatchSize(int batchSize) {
332 this.batchSize = batchSize;
336 * Sets the linger time.
338 * @param lingerTime the new linger time
340 public void setLingerTime(int lingerTime) {
341 this.lingerTime = lingerTime;
345 * Sets the buffer memory.
347 * @param bufferMemory the new buffer memory
349 public void setBufferMemory(long bufferMemory) {
350 this.bufferMemory = bufferMemory;
356 * @param groupId the new group id
358 public void setGroupId(String groupId) {
359 this.groupId = groupId;
363 * Sets the enable auto commit.
365 * @param enableAutoCommit the new enable auto commit
367 public void setEnableAutoCommit(boolean enableAutoCommit) {
368 this.enableAutoCommit = enableAutoCommit;
372 * Sets the auto commit time.
374 * @param autoCommitTime the new auto commit time
376 public void setAutoCommitTime(int autoCommitTime) {
377 this.autoCommitTime = autoCommitTime;
381 * Sets the session timeout.
383 * @param sessionTimeout the new session timeout
385 public void setSessionTimeout(int sessionTimeout) {
386 this.sessionTimeout = sessionTimeout;
390 * Sets the producer topic.
392 * @param producerTopic the new producer topic
394 public void setProducerTopic(String producerTopic) {
395 this.producerTopic = producerTopic;
399 * Sets the consumer poll time.
401 * @param consumerPollTime the new consumer poll time
403 public void setConsumerPollTime(int consumerPollTime) {
404 this.consumerPollTime = consumerPollTime;
408 * Sets the consumer topic list.
410 * @param consumerTopicList the new consumer topic list
412 public void setConsumerTopicList(String[] consumerTopicList) {
413 this.consumerTopicList = consumerTopicList;
417 * Sets the key serializer.
419 * @param keySerializer the new key serializer
421 public void setKeySerializer(String keySerializer) {
422 this.keySerializer = keySerializer;
426 * Sets the value serializer.
428 * @param valueSerializer the new value serializer
430 public void setValueSerializer(String valueSerializer) {
431 this.valueSerializer = valueSerializer;
435 * Sets the key deserializer.
437 * @param keyDeserializer the new key deserializer
439 public void setKeyDeserializer(String keyDeserializer) {
440 this.keyDeserializer = keyDeserializer;
444 * Sets the value deserializer.
446 * @param valueDeserializer the new value deserializer
448 public void setValueDeserializer(String valueDeserializer) {
449 this.valueDeserializer = valueDeserializer;
456 public String getName() {
457 return this.getLabel();
464 public GroupValidationResult validate() {
465 final GroupValidationResult result = super.validate();
467 if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
468 result.setResult("bootstrapServers", ValidationStatus.INVALID,
469 "bootstrapServers not specified, must be specified as a string of form host:port");
472 if (acks == null || acks.trim().length() == 0) {
473 result.setResult("acks", ValidationStatus.INVALID,
474 "acks not specified, must be specified as a string with values [0|1|all]");
478 result.setResult("retries", ValidationStatus.INVALID,
479 "[" + retries + "] invalid, must be specified as retries >= 0");
483 result.setResult("batchSize", ValidationStatus.INVALID,
484 "[" + batchSize + "] invalid, must be specified as batchSize >= 0");
487 if (lingerTime < 0) {
488 result.setResult("lingerTime", ValidationStatus.INVALID,
489 "[" + lingerTime + "] invalid, must be specified as lingerTime >= 0");
492 if (bufferMemory < 0) {
493 result.setResult("bufferMemory", ValidationStatus.INVALID,
494 "[" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0");
497 if (groupId == null || groupId.trim().length() == 0) {
498 result.setResult("groupId", ValidationStatus.INVALID, "not specified, must be specified as a string");
501 if (autoCommitTime < 0) {
502 result.setResult("autoCommitTime", ValidationStatus.INVALID,
503 "[" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0");
506 if (sessionTimeout < 0) {
507 result.setResult("sessionTimeout", ValidationStatus.INVALID, "sessionTimeout [" + sessionTimeout
508 + "] invalid, must be specified as sessionTimeout >= 0");
511 if (producerTopic == null || producerTopic.trim().length() == 0) {
512 result.setResult("producerTopic", ValidationStatus.INVALID,
513 "producerTopic not specified, must be specified as a string");
516 if (consumerPollTime < 0) {
517 result.setResult("consumerPollTime", ValidationStatus.INVALID,
518 "[" + consumerPollTime + "] invalid, must be specified as consumerPollTime >= 0");
521 if (consumerTopicList == null || consumerTopicList.length == 0) {
522 result.setResult("consumerTopicList", ValidationStatus.INVALID,
523 "not specified, must be specified as a list of strings");
526 StringBuilder consumerTopicMessageBuilder = new StringBuilder();
527 for (final String consumerTopic : consumerTopicList) {
528 if (consumerTopic == null || consumerTopic.trim().length() == 0) {
529 consumerTopicMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
530 + "\" specified on consumerTopicList, consumer topics must be specified as strings");
534 if (consumerTopicMessageBuilder.length() > 0) {
535 result.setResult("consumerTopicList", ValidationStatus.INVALID, consumerTopicMessageBuilder.toString());
538 if (keySerializer == null || keySerializer.trim().length() == 0) {
539 result.setResult("keySerializer", ValidationStatus.INVALID, "not specified, must be specified as a string");
542 if (valueSerializer == null || valueSerializer.trim().length() == 0) {
543 result.setResult("valueSerializer", ValidationStatus.INVALID,
544 "not specified, must be specified as a string");
547 if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
548 result.setResult("keyDeserializer", ValidationStatus.INVALID,
549 "not specified, must be specified as a string");
552 if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
553 result.setResult("valueDeserializer", ValidationStatus.INVALID,
554 "not specified, must be specified as a string");