Changes for checkstyle 8.32
[policy/apex-pdp.git] / services / services-engine / src / test / java / org / onap / policy / apex / service / engine / parameters / dummyclasses / SuperDooperCarrierTechnologyParameters.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.service.engine.parameters.dummyclasses;
22
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;
29
30 /**
31  * Apex parameters for SuperDooper as an event carrier technology.
32  *
33  * @author Liam Fallon (liam.fallon@ericsson.com)
34  */
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";
54
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";
70
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;
89
90     /**
91      * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
92      * service.
93      */
94     public SuperDooperCarrierTechnologyParameters() {
95         super();
96
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");
103     }
104
105     /**
106      * Gets the superDooper producer properties.
107      *
108      * @return the superDooper producer properties
109      */
110     public Properties getSuperDooperProducerProperties() {
111         final Properties superDooperProperties = new Properties();
112
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);
121
122         return superDooperProperties;
123     }
124
125     /**
126      * Gets the superDooper consumer properties.
127      *
128      * @return the superDooper consumer properties
129      */
130     public Properties getSuperDooperConsumerProperties() {
131         final Properties superDooperProperties = new Properties();
132
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);
140
141         return superDooperProperties;
142     }
143
144     /**
145      * Gets the bootstrap servers.
146      *
147      * @return the bootstrap servers
148      */
149     public String getBootstrapServers() {
150         return bootstrapServers;
151     }
152
153     /**
154      * Gets the acks.
155      *
156      * @return the acks
157      */
158     public String getAcks() {
159         return acks;
160     }
161
162     /**
163      * Gets the retries.
164      *
165      * @return the retries
166      */
167     public int getRetries() {
168         return retries;
169     }
170
171     /**
172      * Gets the batch size.
173      *
174      * @return the batch size
175      */
176     public int getBatchSize() {
177         return batchSize;
178     }
179
180     /**
181      * Gets the linger time.
182      *
183      * @return the linger time
184      */
185     public int getLingerTime() {
186         return lingerTime;
187     }
188
189     /**
190      * Gets the buffer memory.
191      *
192      * @return the buffer memory
193      */
194     public long getBufferMemory() {
195         return bufferMemory;
196     }
197
198     /**
199      * Gets the group id.
200      *
201      * @return the group id
202      */
203     public String getGroupId() {
204         return groupId;
205     }
206
207     /**
208      * Checks if is enable auto commit.
209      *
210      * @return true, if checks if is enable auto commit
211      */
212     public boolean isEnableAutoCommit() {
213         return enableAutoCommit;
214     }
215
216     /**
217      * Gets the auto commit time.
218      *
219      * @return the auto commit time
220      */
221     public int getAutoCommitTime() {
222         return autoCommitTime;
223     }
224
225     /**
226      * Gets the session timeout.
227      *
228      * @return the session timeout
229      */
230     public int getSessionTimeout() {
231         return sessionTimeout;
232     }
233
234     /**
235      * Gets the producer topic.
236      *
237      * @return the producer topic
238      */
239     public String getProducerTopic() {
240         return producerTopic;
241     }
242
243     /**
244      * Gets the consumer poll time.
245      *
246      * @return the consumer poll time
247      */
248     public long getConsumerPollTime() {
249         return consumerPollTime;
250     }
251
252     /**
253      * Gets the consumer topic list.
254      *
255      * @return the consumer topic list
256      */
257     public Collection<String> getConsumerTopicList() {
258         return Arrays.asList(consumerTopicList);
259     }
260
261     /**
262      * Gets the key serializer.
263      *
264      * @return the key serializer
265      */
266     public String getKeySerializer() {
267         return keySerializer;
268     }
269
270     /**
271      * Gets the value serializer.
272      *
273      * @return the value serializer
274      */
275     public String getValueSerializer() {
276         return valueSerializer;
277     }
278
279     /**
280      * Gets the key deserializer.
281      *
282      * @return the key deserializer
283      */
284     public String getKeyDeserializer() {
285         return keyDeserializer;
286     }
287
288     /**
289      * Gets the value deserializer.
290      *
291      * @return the value deserializer
292      */
293     public String getValueDeserializer() {
294         return valueDeserializer;
295     }
296
297     /**
298      * Sets the bootstrap servers.
299      *
300      * @param bootstrapServers the new bootstrap servers
301      */
302     public void setBootstrapServers(String bootstrapServers) {
303         this.bootstrapServers = bootstrapServers;
304     }
305
306     /**
307      * Sets the acks.
308      *
309      * @param acks the new acks
310      */
311     public void setAcks(String acks) {
312         this.acks = acks;
313     }
314
315     /**
316      * Sets the retries.
317      *
318      * @param retries the new retries
319      */
320     public void setRetries(int retries) {
321         this.retries = retries;
322     }
323
324     /**
325      * Sets the batch size.
326      *
327      * @param batchSize the new batch size
328      */
329     public void setBatchSize(int batchSize) {
330         this.batchSize = batchSize;
331     }
332
333     /**
334      * Sets the linger time.
335      *
336      * @param lingerTime the new linger time
337      */
338     public void setLingerTime(int lingerTime) {
339         this.lingerTime = lingerTime;
340     }
341
342     /**
343      * Sets the buffer memory.
344      *
345      * @param bufferMemory the new buffer memory
346      */
347     public void setBufferMemory(long bufferMemory) {
348         this.bufferMemory = bufferMemory;
349     }
350
351     /**
352      * Sets the group id.
353      *
354      * @param groupId the new group id
355      */
356     public void setGroupId(String groupId) {
357         this.groupId = groupId;
358     }
359
360     /**
361      * Sets the enable auto commit.
362      *
363      * @param enableAutoCommit the new enable auto commit
364      */
365     public void setEnableAutoCommit(boolean enableAutoCommit) {
366         this.enableAutoCommit = enableAutoCommit;
367     }
368
369     /**
370      * Sets the auto commit time.
371      *
372      * @param autoCommitTime the new auto commit time
373      */
374     public void setAutoCommitTime(int autoCommitTime) {
375         this.autoCommitTime = autoCommitTime;
376     }
377
378     /**
379      * Sets the session timeout.
380      *
381      * @param sessionTimeout the new session timeout
382      */
383     public void setSessionTimeout(int sessionTimeout) {
384         this.sessionTimeout = sessionTimeout;
385     }
386
387     /**
388      * Sets the producer topic.
389      *
390      * @param producerTopic the new producer topic
391      */
392     public void setProducerTopic(String producerTopic) {
393         this.producerTopic = producerTopic;
394     }
395
396     /**
397      * Sets the consumer poll time.
398      *
399      * @param consumerPollTime the new consumer poll time
400      */
401     public void setConsumerPollTime(int consumerPollTime) {
402         this.consumerPollTime = consumerPollTime;
403     }
404
405     /**
406      * Sets the consumer topic list.
407      *
408      * @param consumerTopicList the new consumer topic list
409      */
410     public void setConsumerTopicList(String[] consumerTopicList) {
411         this.consumerTopicList = consumerTopicList;
412     }
413
414     /**
415      * Sets the key serializer.
416      *
417      * @param keySerializer the new key serializer
418      */
419     public void setKeySerializer(String keySerializer) {
420         this.keySerializer = keySerializer;
421     }
422
423     /**
424      * Sets the value serializer.
425      *
426      * @param valueSerializer the new value serializer
427      */
428     public void setValueSerializer(String valueSerializer) {
429         this.valueSerializer = valueSerializer;
430     }
431
432     /**
433      * Sets the key deserializer.
434      *
435      * @param keyDeserializer the new key deserializer
436      */
437     public void setKeyDeserializer(String keyDeserializer) {
438         this.keyDeserializer = keyDeserializer;
439     }
440
441     /**
442      * Sets the value deserializer.
443      *
444      * @param valueDeserializer the new value deserializer
445      */
446     public void setValueDeserializer(String valueDeserializer) {
447         this.valueDeserializer = valueDeserializer;
448     }
449
450     /**
451      * {@inheritDoc}.
452      */
453     @Override
454     public String getName() {
455         return this.getLabel();
456     }
457
458     /**
459      * {@inheritDoc}.
460      */
461     @Override
462     public GroupValidationResult validate() {
463         final GroupValidationResult result = super.validate();
464
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");
468         }
469
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]");
473         }
474
475         if (retries < 0) {
476             result.setResult("retries", ValidationStatus.INVALID,
477                     "[" + retries + "] invalid, must be specified as retries >= 0");
478         }
479
480         if (batchSize < 0) {
481             result.setResult("batchSize", ValidationStatus.INVALID,
482                     "[" + batchSize + "] invalid, must be specified as batchSize >= 0");
483         }
484
485         if (lingerTime < 0) {
486             result.setResult("lingerTime", ValidationStatus.INVALID,
487                     "[" + lingerTime + "] invalid, must be specified as lingerTime >= 0");
488         }
489
490         if (bufferMemory < 0) {
491             result.setResult("bufferMemory", ValidationStatus.INVALID,
492                     "[" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0");
493         }
494
495         if (groupId == null || groupId.trim().length() == 0) {
496             result.setResult("groupId", ValidationStatus.INVALID, "not specified, must be specified as a string");
497         }
498
499         if (autoCommitTime < 0) {
500             result.setResult("autoCommitTime", ValidationStatus.INVALID,
501                     "[" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0");
502         }
503
504         if (sessionTimeout < 0) {
505             result.setResult("sessionTimeout", ValidationStatus.INVALID,
506                     "sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0");
507         }
508
509         if (producerTopic == null || producerTopic.trim().length() == 0) {
510             result.setResult("producerTopic", ValidationStatus.INVALID,
511                     "producerTopic not specified, must be specified as a string");
512         }
513
514         if (consumerPollTime < 0) {
515             result.setResult("consumerPollTime", ValidationStatus.INVALID,
516                     "[" + consumerPollTime + "] invalid, must be specified as consumerPollTime >= 0");
517         }
518
519         if (consumerTopicList == null || consumerTopicList.length == 0) {
520             result.setResult("consumerTopicList", ValidationStatus.INVALID,
521                     "not specified, must be specified as a list of strings");
522         }
523
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");
529             }
530         }
531
532         if (consumerTopicMessageBuilder.length() > 0) {
533             result.setResult("consumerTopicList", ValidationStatus.INVALID, consumerTopicMessageBuilder.toString());
534         }
535
536         if (keySerializer == null || keySerializer.trim().length() == 0) {
537             result.setResult("keySerializer", ValidationStatus.INVALID, "not specified, must be specified as a string");
538         }
539
540         if (valueSerializer == null || valueSerializer.trim().length() == 0) {
541             result.setResult("valueSerializer", ValidationStatus.INVALID,
542                     "not specified, must be specified as a string");
543         }
544
545         if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
546             result.setResult("keyDeserializer", ValidationStatus.INVALID,
547                     "not specified, must be specified as a string");
548         }
549
550         if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
551             result.setResult("valueDeserializer", ValidationStatus.INVALID,
552                     "not specified, must be specified as a string");
553         }
554
555         return result;
556     }
557 }