aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperDooperCarrierTechnologyParameters.java
blob: d7a502c7f3945911d07fb0f4d9fad4dc9f6f6f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.service.engine.parameters.dummyclasses;

import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.base.Validated;

/**
 * Apex parameters for SuperDooper as an event carrier technology.
 *
 * @author Liam Fallon (liam.fallon@ericsson.com)
 */
@NotNull
@NotBlank
public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyParameters {
    // Default parameter values
    private static final String DEFAULT_ACKS = "all";
    private static final String DEFAULT_BOOTSTRAP_SERVERS = "localhost:9092";
    private static final int DEFAULT_RETRIES = 0;
    private static final int DEFAULT_BATCH_SIZE = 16384;
    private static final int DEFAULT_LINGER_TIME = 1;
    private static final long DEFAULT_BUFFER_MEMORY = 33554432;
    private static final String DEFAULT_GROUP_ID = "default-group-id";
    private static final boolean DEFAULT_ENABLE_AUTO_COMMIT = true;
    private static final int DEFAULT_AUTO_COMMIT_TIME = 1000;
    private static final int DEFAULT_SESSION_TIMEOUT = 30000;
    private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
    private static final int DEFAULT_CONSUMER_POLL_TIME = 100;
    private static final String[] DEFAULT_CONSUMER_TOPIC_LIST = {"apex-in"};
    private static final String DEFAULT_KEYSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
    private static final String DEFAULT_VALSERZER = "org.apache.superDooper.common.serialization.StringSerializer";
    private static final String DEFAULT_KEYDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";
    private static final String DEFAULT_VALDESZER = "org.apache.superDooper.common.serialization.StringDeserializer";

    // Parameter property map tokens
    private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers";
    private static final String PROPERTY_ACKS = "acks";
    private static final String PROPERTY_RETRIES = "retries";
    private static final String PROPERTY_BATCH_SIZE = "batch.size";
    private static final String PROPERTY_LINGER_TIME = "linger.ms";
    private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory";
    private static final String PROPERTY_GROUP_ID = "group.id";
    private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit";
    private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms";
    private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms";
    private static final String PROPERTY_KEY_SERIALIZER = "key.serializer";
    private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer";
    private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer";
    private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer";

    // superDooper carrier parameters
    private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
    private String acks = DEFAULT_ACKS;
    private @Min(0) int retries = DEFAULT_RETRIES;
    private @Min(0) int batchSize = DEFAULT_BATCH_SIZE;
    private @Min(0) int lingerTime = DEFAULT_LINGER_TIME;
    private @Min(0) long bufferMemory = DEFAULT_BUFFER_MEMORY;
    private String groupId = DEFAULT_GROUP_ID;
    private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
    private @Min(0) int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
    private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
    private String producerTopic = DEFAULT_PRODUCER_TOPIC;
    private @Min(0) int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
    private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
    private String keySerializer = DEFAULT_KEYSERZER;
    private String valueSerializer = DEFAULT_VALSERZER;
    private String keyDeserializer = DEFAULT_KEYDESZER;
    private String valueDeserializer = DEFAULT_VALDESZER;

    /**
     * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
     * service.
     */
    public SuperDooperCarrierTechnologyParameters() {
        super();

        // Set the carrier technology properties for the FILE carrier technology
        this.setLabel("SUPER_DOOPER");
        this.setEventProducerPluginClass(
                "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventProducer");
        this.setEventConsumerPluginClass(
                "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperEventSubscriber");
    }

    /**
     * Gets the superDooper producer properties.
     *
     * @return the superDooper producer properties
     */
    public Properties getSuperDooperProducerProperties() {
        final Properties superDooperProperties = new Properties();

        superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
        superDooperProperties.put(PROPERTY_ACKS, acks);
        superDooperProperties.put(PROPERTY_RETRIES, retries);
        superDooperProperties.put(PROPERTY_BATCH_SIZE, batchSize);
        superDooperProperties.put(PROPERTY_LINGER_TIME, lingerTime);
        superDooperProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory);
        superDooperProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer);
        superDooperProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer);

        return superDooperProperties;
    }

    /**
     * Gets the superDooper consumer properties.
     *
     * @return the superDooper consumer properties
     */
    public Properties getSuperDooperConsumerProperties() {
        final Properties superDooperProperties = new Properties();

        superDooperProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers);
        superDooperProperties.put(PROPERTY_GROUP_ID, groupId);
        superDooperProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit);
        superDooperProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime);
        superDooperProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout);
        superDooperProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer);
        superDooperProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer);

        return superDooperProperties;
    }

    /**
     * Gets the bootstrap servers.
     *
     * @return the bootstrap servers
     */
    public String getBootstrapServers() {
        return bootstrapServers;
    }

    /**
     * Gets the acks.
     *
     * @return the acks
     */
    public String getAcks() {
        return acks;
    }

    /**
     * Gets the retries.
     *
     * @return the retries
     */
    public int getRetries() {
        return retries;
    }

    /**
     * Gets the batch size.
     *
     * @return the batch size
     */
    public int getBatchSize() {
        return batchSize;
    }

    /**
     * Gets the linger time.
     *
     * @return the linger time
     */
    public int getLingerTime() {
        return lingerTime;
    }

    /**
     * Gets the buffer memory.
     *
     * @return the buffer memory
     */
    public long getBufferMemory() {
        return bufferMemory;
    }

    /**
     * Gets the group id.
     *
     * @return the group id
     */
    public String getGroupId() {
        return groupId;
    }

    /**
     * Checks if is enable auto commit.
     *
     * @return true, if checks if is enable auto commit
     */
    public boolean isEnableAutoCommit() {
        return enableAutoCommit;
    }

    /**
     * Gets the auto commit time.
     *
     * @return the auto commit time
     */
    public int getAutoCommitTime() {
        return autoCommitTime;
    }

    /**
     * Gets the session timeout.
     *
     * @return the session timeout
     */
    public int getSessionTimeout() {
        return sessionTimeout;
    }

    /**
     * Gets the producer topic.
     *
     * @return the producer topic
     */
    public String getProducerTopic() {
        return producerTopic;
    }

    /**
     * Gets the consumer poll time.
     *
     * @return the consumer poll time
     */
    public long getConsumerPollTime() {
        return consumerPollTime;
    }

    /**
     * Gets the consumer topic list.
     *
     * @return the consumer topic list
     */
    public Collection<String> getConsumerTopicList() {
        return Arrays.asList(consumerTopicList);
    }

    /**
     * Gets the key serializer.
     *
     * @return the key serializer
     */
    public String getKeySerializer() {
        return keySerializer;
    }

    /**
     * Gets the value serializer.
     *
     * @return the value serializer
     */
    public String getValueSerializer() {
        return valueSerializer;
    }

    /**
     * Gets the key deserializer.
     *
     * @return the key deserializer
     */
    public String getKeyDeserializer() {
        return keyDeserializer;
    }

    /**
     * Gets the value deserializer.
     *
     * @return the value deserializer
     */
    public String getValueDeserializer() {
        return valueDeserializer;
    }

    /**
     * Sets the bootstrap servers.
     *
     * @param bootstrapServers the new bootstrap servers
     */
    public void setBootstrapServers(String bootstrapServers) {
        this.bootstrapServers = bootstrapServers;
    }

    /**
     * Sets the acks.
     *
     * @param acks the new acks
     */
    public void setAcks(String acks) {
        this.acks = acks;
    }

    /**
     * Sets the retries.
     *
     * @param retries the new retries
     */
    public void setRetries(int retries) {
        this.retries = retries;
    }

    /**
     * Sets the batch size.
     *
     * @param batchSize the new batch size
     */
    public void setBatchSize(int batchSize) {
        this.batchSize = batchSize;
    }

    /**
     * Sets the linger time.
     *
     * @param lingerTime the new linger time
     */
    public void setLingerTime(int lingerTime) {
        this.lingerTime = lingerTime;
    }

    /**
     * Sets the buffer memory.
     *
     * @param bufferMemory the new buffer memory
     */
    public void setBufferMemory(long bufferMemory) {
        this.bufferMemory = bufferMemory;
    }

    /**
     * Sets the group id.
     *
     * @param groupId the new group id
     */
    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    /**
     * Sets the enable auto commit.
     *
     * @param enableAutoCommit the new enable auto commit
     */
    public void setEnableAutoCommit(boolean enableAutoCommit) {
        this.enableAutoCommit = enableAutoCommit;
    }

    /**
     * Sets the auto commit time.
     *
     * @param autoCommitTime the new auto commit time
     */
    public void setAutoCommitTime(int autoCommitTime) {
        this.autoCommitTime = autoCommitTime;
    }

    /**
     * Sets the session timeout.
     *
     * @param sessionTimeout the new session timeout
     */
    public void setSessionTimeout(int sessionTimeout) {
        this.sessionTimeout = sessionTimeout;
    }

    /**
     * Sets the producer topic.
     *
     * @param producerTopic the new producer topic
     */
    public void setProducerTopic(String producerTopic) {
        this.producerTopic = producerTopic;
    }

    /**
     * Sets the consumer poll time.
     *
     * @param consumerPollTime the new consumer poll time
     */
    public void setConsumerPollTime(int consumerPollTime) {
        this.consumerPollTime = consumerPollTime;
    }

    /**
     * Sets the consumer topic list.
     *
     * @param consumerTopicList the new consumer topic list
     */
    public void setConsumerTopicList(String[] consumerTopicList) {
        this.consumerTopicList = consumerTopicList;
    }

    /**
     * Sets the key serializer.
     *
     * @param keySerializer the new key serializer
     */
    public void setKeySerializer(String keySerializer) {
        this.keySerializer = keySerializer;
    }

    /**
     * Sets the value serializer.
     *
     * @param valueSerializer the new value serializer
     */
    public void setValueSerializer(String valueSerializer) {
        this.valueSerializer = valueSerializer;
    }

    /**
     * Sets the key deserializer.
     *
     * @param keyDeserializer the new key deserializer
     */
    public void setKeyDeserializer(String keyDeserializer) {
        this.keyDeserializer = keyDeserializer;
    }

    /**
     * Sets the value deserializer.
     *
     * @param valueDeserializer the new value deserializer
     */
    public void setValueDeserializer(String valueDeserializer) {
        this.valueDeserializer = valueDeserializer;
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public String getName() {
        return this.getLabel();
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public BeanValidationResult validate() {
        final BeanValidationResult result = super.validate();

        if (consumerTopicList == null) {
            return result;
        }

        if (consumerTopicList.length == 0) {
            result.addResult("consumerTopicList", consumerTopicList, ValidationStatus.INVALID,
                    "not specified, must be specified as a list of strings");
            return result;
        }

        BeanValidationResult result2 = new BeanValidationResult("consumerTopicList", consumerTopicList);
        int item = 0;
        for (final String consumerTopic : consumerTopicList) {
            if (StringUtils.isBlank(consumerTopic)) {
                result2.addResult("entry " + item, consumerTopic, ValidationStatus.INVALID, Validated.IS_BLANK);
            }

            ++item;
        }

        result.addResult(result2);

        return result;
    }
}