d7a502c7f3945911d07fb0f4d9fad4dc9f6f6f79
[policy/apex-pdp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.service.engine.parameters.dummyclasses;
23
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;
35
36 /**
37  * Apex parameters for SuperDooper as an event carrier technology.
38  *
39  * @author Liam Fallon (liam.fallon@ericsson.com)
40  */
41 @NotNull
42 @NotBlank
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";
62
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";
78
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;
97
98     /**
99      * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
100      * service.
101      */
102     public SuperDooperCarrierTechnologyParameters() {
103         super();
104
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");
111     }
112
113     /**
114      * Gets the superDooper producer properties.
115      *
116      * @return the superDooper producer properties
117      */
118     public Properties getSuperDooperProducerProperties() {
119         final Properties superDooperProperties = new Properties();
120
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);
129
130         return superDooperProperties;
131     }
132
133     /**
134      * Gets the superDooper consumer properties.
135      *
136      * @return the superDooper consumer properties
137      */
138     public Properties getSuperDooperConsumerProperties() {
139         final Properties superDooperProperties = new Properties();
140
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);
148
149         return superDooperProperties;
150     }
151
152     /**
153      * Gets the bootstrap servers.
154      *
155      * @return the bootstrap servers
156      */
157     public String getBootstrapServers() {
158         return bootstrapServers;
159     }
160
161     /**
162      * Gets the acks.
163      *
164      * @return the acks
165      */
166     public String getAcks() {
167         return acks;
168     }
169
170     /**
171      * Gets the retries.
172      *
173      * @return the retries
174      */
175     public int getRetries() {
176         return retries;
177     }
178
179     /**
180      * Gets the batch size.
181      *
182      * @return the batch size
183      */
184     public int getBatchSize() {
185         return batchSize;
186     }
187
188     /**
189      * Gets the linger time.
190      *
191      * @return the linger time
192      */
193     public int getLingerTime() {
194         return lingerTime;
195     }
196
197     /**
198      * Gets the buffer memory.
199      *
200      * @return the buffer memory
201      */
202     public long getBufferMemory() {
203         return bufferMemory;
204     }
205
206     /**
207      * Gets the group id.
208      *
209      * @return the group id
210      */
211     public String getGroupId() {
212         return groupId;
213     }
214
215     /**
216      * Checks if is enable auto commit.
217      *
218      * @return true, if checks if is enable auto commit
219      */
220     public boolean isEnableAutoCommit() {
221         return enableAutoCommit;
222     }
223
224     /**
225      * Gets the auto commit time.
226      *
227      * @return the auto commit time
228      */
229     public int getAutoCommitTime() {
230         return autoCommitTime;
231     }
232
233     /**
234      * Gets the session timeout.
235      *
236      * @return the session timeout
237      */
238     public int getSessionTimeout() {
239         return sessionTimeout;
240     }
241
242     /**
243      * Gets the producer topic.
244      *
245      * @return the producer topic
246      */
247     public String getProducerTopic() {
248         return producerTopic;
249     }
250
251     /**
252      * Gets the consumer poll time.
253      *
254      * @return the consumer poll time
255      */
256     public long getConsumerPollTime() {
257         return consumerPollTime;
258     }
259
260     /**
261      * Gets the consumer topic list.
262      *
263      * @return the consumer topic list
264      */
265     public Collection<String> getConsumerTopicList() {
266         return Arrays.asList(consumerTopicList);
267     }
268
269     /**
270      * Gets the key serializer.
271      *
272      * @return the key serializer
273      */
274     public String getKeySerializer() {
275         return keySerializer;
276     }
277
278     /**
279      * Gets the value serializer.
280      *
281      * @return the value serializer
282      */
283     public String getValueSerializer() {
284         return valueSerializer;
285     }
286
287     /**
288      * Gets the key deserializer.
289      *
290      * @return the key deserializer
291      */
292     public String getKeyDeserializer() {
293         return keyDeserializer;
294     }
295
296     /**
297      * Gets the value deserializer.
298      *
299      * @return the value deserializer
300      */
301     public String getValueDeserializer() {
302         return valueDeserializer;
303     }
304
305     /**
306      * Sets the bootstrap servers.
307      *
308      * @param bootstrapServers the new bootstrap servers
309      */
310     public void setBootstrapServers(String bootstrapServers) {
311         this.bootstrapServers = bootstrapServers;
312     }
313
314     /**
315      * Sets the acks.
316      *
317      * @param acks the new acks
318      */
319     public void setAcks(String acks) {
320         this.acks = acks;
321     }
322
323     /**
324      * Sets the retries.
325      *
326      * @param retries the new retries
327      */
328     public void setRetries(int retries) {
329         this.retries = retries;
330     }
331
332     /**
333      * Sets the batch size.
334      *
335      * @param batchSize the new batch size
336      */
337     public void setBatchSize(int batchSize) {
338         this.batchSize = batchSize;
339     }
340
341     /**
342      * Sets the linger time.
343      *
344      * @param lingerTime the new linger time
345      */
346     public void setLingerTime(int lingerTime) {
347         this.lingerTime = lingerTime;
348     }
349
350     /**
351      * Sets the buffer memory.
352      *
353      * @param bufferMemory the new buffer memory
354      */
355     public void setBufferMemory(long bufferMemory) {
356         this.bufferMemory = bufferMemory;
357     }
358
359     /**
360      * Sets the group id.
361      *
362      * @param groupId the new group id
363      */
364     public void setGroupId(String groupId) {
365         this.groupId = groupId;
366     }
367
368     /**
369      * Sets the enable auto commit.
370      *
371      * @param enableAutoCommit the new enable auto commit
372      */
373     public void setEnableAutoCommit(boolean enableAutoCommit) {
374         this.enableAutoCommit = enableAutoCommit;
375     }
376
377     /**
378      * Sets the auto commit time.
379      *
380      * @param autoCommitTime the new auto commit time
381      */
382     public void setAutoCommitTime(int autoCommitTime) {
383         this.autoCommitTime = autoCommitTime;
384     }
385
386     /**
387      * Sets the session timeout.
388      *
389      * @param sessionTimeout the new session timeout
390      */
391     public void setSessionTimeout(int sessionTimeout) {
392         this.sessionTimeout = sessionTimeout;
393     }
394
395     /**
396      * Sets the producer topic.
397      *
398      * @param producerTopic the new producer topic
399      */
400     public void setProducerTopic(String producerTopic) {
401         this.producerTopic = producerTopic;
402     }
403
404     /**
405      * Sets the consumer poll time.
406      *
407      * @param consumerPollTime the new consumer poll time
408      */
409     public void setConsumerPollTime(int consumerPollTime) {
410         this.consumerPollTime = consumerPollTime;
411     }
412
413     /**
414      * Sets the consumer topic list.
415      *
416      * @param consumerTopicList the new consumer topic list
417      */
418     public void setConsumerTopicList(String[] consumerTopicList) {
419         this.consumerTopicList = consumerTopicList;
420     }
421
422     /**
423      * Sets the key serializer.
424      *
425      * @param keySerializer the new key serializer
426      */
427     public void setKeySerializer(String keySerializer) {
428         this.keySerializer = keySerializer;
429     }
430
431     /**
432      * Sets the value serializer.
433      *
434      * @param valueSerializer the new value serializer
435      */
436     public void setValueSerializer(String valueSerializer) {
437         this.valueSerializer = valueSerializer;
438     }
439
440     /**
441      * Sets the key deserializer.
442      *
443      * @param keyDeserializer the new key deserializer
444      */
445     public void setKeyDeserializer(String keyDeserializer) {
446         this.keyDeserializer = keyDeserializer;
447     }
448
449     /**
450      * Sets the value deserializer.
451      *
452      * @param valueDeserializer the new value deserializer
453      */
454     public void setValueDeserializer(String valueDeserializer) {
455         this.valueDeserializer = valueDeserializer;
456     }
457
458     /**
459      * {@inheritDoc}.
460      */
461     @Override
462     public String getName() {
463         return this.getLabel();
464     }
465
466     /**
467      * {@inheritDoc}.
468      */
469     @Override
470     public BeanValidationResult validate() {
471         final BeanValidationResult result = super.validate();
472
473         if (consumerTopicList == null) {
474             return result;
475         }
476
477         if (consumerTopicList.length == 0) {
478             result.addResult("consumerTopicList", consumerTopicList, ValidationStatus.INVALID,
479                     "not specified, must be specified as a list of strings");
480             return result;
481         }
482
483         BeanValidationResult result2 = new BeanValidationResult("consumerTopicList", consumerTopicList);
484         int item = 0;
485         for (final String consumerTopic : consumerTopicList) {
486             if (StringUtils.isBlank(consumerTopic)) {
487                 result2.addResult("entry " + item, consumerTopic, ValidationStatus.INVALID, Validated.IS_BLANK);
488             }
489
490             ++item;
491         }
492
493         result.addResult(result2);
494
495         return result;
496     }
497 }