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 = {"apex-in"};
51 private static final String DEFAULT_KEYSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
52 private static final String DEFAULT_VALSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
53 private static final String DEFAULT_KEYDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
54 private static final String DEFAULT_VALDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
56 // Parameter property map tokens
57 private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers";
58 private static final String PROPERTY_ACKS = "acks";
59 private static final String PROPERTY_RETRIES = "retries";
60 private static final String PROPERTY_BATCH_SIZE = "batch.size";
61 private static final String PROPERTY_LINGER_TIME = "linger.ms";
62 private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory";
63 private static final String PROPERTY_GROUP_ID = "group.id";
64 private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit";
65 private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms";
66 private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms";
67 private static final String PROPERTY_KEY_SERIALIZER = "key.serializer";
68 private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer";
69 private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer";
70 private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer";
72 // superDooper carrier parameters
73 private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
74 private String acks = DEFAULT_ACKS;
75 private int retries = DEFAULT_RETRIES;
76 private int batchSize = DEFAULT_BATCH_SIZE;
77 private int lingerTime = DEFAULT_LINGER_TIME;
78 private long bufferMemory = DEFAULT_BUFFER_MEMORY;
79 private String groupId = DEFAULT_GROUP_ID;
80 private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
81 private int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
82 private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
83 private String producerTopic = DEFAULT_PRODUCER_TOPIC;
84 private int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
85 private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
86 private String keySerializer = DEFAULT_KEYSERZER;
87 private String valueSerializer = DEFAULT_VALSERZER;
88 private String keyDeserializer = DEFAULT_KEYDESZER;
89 private String valueDeserializer = DEFAULT_VALDESZER;
92 * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
95 public SuperDooperCarrierTechnologyParameters() {
98 // Set the carrier technology properties for the FILE carrier technology
99 this.setLabel("SUPER_DOOPER");
100 this.setEventProducerPluginClass(
101 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer");
102 this.setEventConsumerPluginClass(
103 "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber");
107 * Gets the superDooper producer properties.
109 * @return the superDooper producer properties
111 public Properties getSuperDooperProducerProperties() {
112 final Properties superDooperProperties = new Properties();
114 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
115 superDooperProperties.put(PROPERTY_ACKS, acks);
116 superDooperProperties.put(PROPERTY_RETRIES, retries);
117 superDooperProperties.put(PROPERTY_BATCH_SIZE, batchSize);
118 superDooperProperties.put(PROPERTY_LINGER_TIME, lingerTime);
119 superDooperProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory);
120 superDooperProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer);
121 superDooperProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer);
123 return superDooperProperties;
127 * Gets the superDooper consumer properties.
129 * @return the superDooper consumer properties
131 public Properties getSuperDooperConsumerProperties() {
132 final Properties superDooperProperties = new Properties();
134 superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
135 superDooperProperties.put(PROPERTY_GROUP_ID, groupId);
136 superDooperProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit);
137 superDooperProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime);
138 superDooperProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout);
139 superDooperProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer);
140 superDooperProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer);
142 return superDooperProperties;
146 * Gets the bootstrap servers.
148 * @return the bootstrap servers
150 public String getBootstrapServers() {
151 return bootstrapServers;
159 public String getAcks() {
166 * @return the retries
168 public int getRetries() {
173 * Gets the batch size.
175 * @return the batch size
177 public int getBatchSize() {
182 * Gets the linger time.
184 * @return the linger time
186 public int getLingerTime() {
191 * Gets the buffer memory.
193 * @return the buffer memory
195 public long getBufferMemory() {
202 * @return the group id
204 public String getGroupId() {
209 * Checks if is enable auto commit.
211 * @return true, if checks if is enable auto commit
213 public boolean isEnableAutoCommit() {
214 return enableAutoCommit;
218 * Gets the auto commit time.
220 * @return the auto commit time
222 public int getAutoCommitTime() {
223 return autoCommitTime;
227 * Gets the session timeout.
229 * @return the session timeout
231 public int getSessionTimeout() {
232 return sessionTimeout;
236 * Gets the producer topic.
238 * @return the producer topic
240 public String getProducerTopic() {
241 return producerTopic;
245 * Gets the consumer poll time.
247 * @return the consumer poll time
249 public long getConsumerPollTime() {
250 return consumerPollTime;
254 * Gets the consumer topic list.
256 * @return the consumer topic list
258 public Collection<String> getConsumerTopicList() {
259 return Arrays.asList(consumerTopicList);
263 * Gets the key serializer.
265 * @return the key serializer
267 public String getKeySerializer() {
268 return keySerializer;
272 * Gets the value serializer.
274 * @return the value serializer
276 public String getValueSerializer() {
277 return valueSerializer;
281 * Gets the key deserializer.
283 * @return the key deserializer
285 public String getKeyDeserializer() {
286 return keyDeserializer;
290 * Gets the value deserializer.
292 * @return the value deserializer
294 public String getValueDeserializer() {
295 return valueDeserializer;
299 * Sets the bootstrap servers.
301 * @param bootstrapServers the new bootstrap servers
303 public void setBootstrapServers(String bootstrapServers) {
304 this.bootstrapServers = bootstrapServers;
310 * @param acks the new acks
312 public void setAcks(String acks) {
319 * @param retries the new retries
321 public void setRetries(int retries) {
322 this.retries = retries;
326 * Sets the batch size.
328 * @param batchSize the new batch size
330 public void setBatchSize(int batchSize) {
331 this.batchSize = batchSize;
335 * Sets the linger time.
337 * @param lingerTime the new linger time
339 public void setLingerTime(int lingerTime) {
340 this.lingerTime = lingerTime;
344 * Sets the buffer memory.
346 * @param bufferMemory the new buffer memory
348 public void setBufferMemory(long bufferMemory) {
349 this.bufferMemory = bufferMemory;
355 * @param groupId the new group id
357 public void setGroupId(String groupId) {
358 this.groupId = groupId;
362 * Sets the enable auto commit.
364 * @param enableAutoCommit the new enable auto commit
366 public void setEnableAutoCommit(boolean enableAutoCommit) {
367 this.enableAutoCommit = enableAutoCommit;
371 * Sets the auto commit time.
373 * @param autoCommitTime the new auto commit time
375 public void setAutoCommitTime(int autoCommitTime) {
376 this.autoCommitTime = autoCommitTime;
380 * Sets the session timeout.
382 * @param sessionTimeout the new session timeout
384 public void setSessionTimeout(int sessionTimeout) {
385 this.sessionTimeout = sessionTimeout;
389 * Sets the producer topic.
391 * @param producerTopic the new producer topic
393 public void setProducerTopic(String producerTopic) {
394 this.producerTopic = producerTopic;
398 * Sets the consumer poll time.
400 * @param consumerPollTime the new consumer poll time
402 public void setConsumerPollTime(int consumerPollTime) {
403 this.consumerPollTime = consumerPollTime;
407 * Sets the consumer topic list.
409 * @param consumerTopicList the new consumer topic list
411 public void setConsumerTopicList(String[] consumerTopicList) {
412 this.consumerTopicList = consumerTopicList;
416 * Sets the key serializer.
418 * @param keySerializer the new key serializer
420 public void setKeySerializer(String keySerializer) {
421 this.keySerializer = keySerializer;
425 * Sets the value serializer.
427 * @param valueSerializer the new value serializer
429 public void setValueSerializer(String valueSerializer) {
430 this.valueSerializer = valueSerializer;
434 * Sets the key deserializer.
436 * @param keyDeserializer the new key deserializer
438 public void setKeyDeserializer(String keyDeserializer) {
439 this.keyDeserializer = keyDeserializer;
443 * Sets the value deserializer.
445 * @param valueDeserializer the new value deserializer
447 public void setValueDeserializer(String valueDeserializer) {
448 this.valueDeserializer = valueDeserializer;
455 public String getName() {
456 return this.getLabel();
463 public GroupValidationResult validate() {
464 final GroupValidationResult result = super.validate();
466 if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
467 result.setResult("bootstrapServers", ValidationStatus.INVALID,
468 "bootstrapServers not specified, must be specified as a string of form host:port");
471 if (acks == null || acks.trim().length() == 0) {
472 result.setResult("acks", ValidationStatus.INVALID,
473 "acks not specified, must be specified as a string with values [0|1|all]");
477 result.setResult("retries", ValidationStatus.INVALID,
478 "[" + retries + "] invalid, must be specified as retries >= 0");
482 result.setResult("batchSize", ValidationStatus.INVALID,
483 "[" + batchSize + "] invalid, must be specified as batchSize >= 0");
486 if (lingerTime < 0) {
487 result.setResult("lingerTime", ValidationStatus.INVALID,
488 "[" + lingerTime + "] invalid, must be specified as lingerTime >= 0");
491 if (bufferMemory < 0) {
492 result.setResult("bufferMemory", ValidationStatus.INVALID,
493 "[" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0");
496 if (groupId == null || groupId.trim().length() == 0) {
497 result.setResult("groupId", ValidationStatus.INVALID, "not specified, must be specified as a string");
500 if (autoCommitTime < 0) {
501 result.setResult("autoCommitTime", ValidationStatus.INVALID,
502 "[" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0");
505 if (sessionTimeout < 0) {
506 result.setResult("sessionTimeout", ValidationStatus.INVALID,
507 "sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0");
510 if (producerTopic == null || producerTopic.trim().length() == 0) {
511 result.setResult("producerTopic", ValidationStatus.INVALID,
512 "producerTopic not specified, must be specified as a string");
515 if (consumerPollTime < 0) {
516 result.setResult("consumerPollTime", ValidationStatus.INVALID,
517 "[" + consumerPollTime + "] invalid, must be specified as consumerPollTime >= 0");
520 if (consumerTopicList == null || consumerTopicList.length == 0) {
521 result.setResult("consumerTopicList", ValidationStatus.INVALID,
522 "not specified, must be specified as a list of strings");
525 StringBuilder consumerTopicMessageBuilder = new StringBuilder();
526 for (final String consumerTopic : consumerTopicList) {
527 if (consumerTopic == null || consumerTopic.trim().length() == 0) {
528 consumerTopicMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
529 + "\" specified on consumerTopicList, consumer topics must be specified as strings");
533 if (consumerTopicMessageBuilder.length() > 0) {
534 result.setResult("consumerTopicList", ValidationStatus.INVALID, consumerTopicMessageBuilder.toString());
537 if (keySerializer == null || keySerializer.trim().length() == 0) {
538 result.setResult("keySerializer", ValidationStatus.INVALID, "not specified, must be specified as a string");
541 if (valueSerializer == null || valueSerializer.trim().length() == 0) {
542 result.setResult("valueSerializer", ValidationStatus.INVALID,
543 "not specified, must be specified as a string");
546 if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
547 result.setResult("keyDeserializer", ValidationStatus.INVALID,
548 "not specified, must be specified as a string");
551 if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
552 result.setResult("valueDeserializer", ValidationStatus.INVALID,
553 "not specified, must be specified as a string");