8eb41b4e31846286807d335718624dd1184da9e9
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 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.testsuites.performance.benchmark.eventgenerator;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterGroup;
25 import org.onap.policy.common.parameters.ValidationStatus;
26
27 /**
28  * This class defines the parameters for event generation.
29  */
30 public class EventGeneratorParameters implements ParameterGroup {
31     // @formatter:off
32     private static final String DEFAULT_NAME                  = EventGeneratorParameters.class.getSimpleName();
33     private static final String DEFAULT_HOST                  = "localhost";
34     private static final int    DEFAULT_PORT                  = 32801;
35     private static final int    DEFAULT_BATCH_COUNT           = 1;
36     private static final int    DEFAULT_BATCH_SIZE            = 1;
37     private static final long   DEFAULT_DELAY_BETWEEN_BATCHES = 2000;
38
39     private String name                = DEFAULT_NAME;
40     private String host                = DEFAULT_HOST;
41     private int    port                = DEFAULT_PORT;
42     private int    batchCount          = DEFAULT_BATCH_COUNT;
43     private int    batchSize           = DEFAULT_BATCH_SIZE;
44     private long   delayBetweenBatches = DEFAULT_DELAY_BETWEEN_BATCHES;
45     private String outFile             = null;
46     // @formatter:on
47
48     /**
49      * Create default parameters.
50      */
51     public EventGeneratorParameters() {
52         // Default parameters are generated
53     }
54
55     @Override
56     public String getName() {
57         return name;
58     }
59
60     @Override
61     public void setName(String name) {
62         this.name = name;
63     }
64
65     public String getHost() {
66         return host;
67     }
68
69     public void setHost(String host) {
70         this.host = host;
71     }
72
73     public int getPort() {
74         return port;
75     }
76
77     public void setPort(int port) {
78         this.port = port;
79     }
80
81     public int getBatchCount() {
82         return batchCount;
83     }
84
85     public void setBatchCount(int batchCount) {
86         this.batchCount = batchCount;
87     }
88
89     public int getBatchSize() {
90         return batchSize;
91     }
92
93     public void setBatchSize(int batchSize) {
94         this.batchSize = batchSize;
95     }
96
97     public long getDelayBetweenBatches() {
98         return delayBetweenBatches;
99     }
100
101     public void setDelayBetweenBatches(long delayBetweenBatches) {
102         this.delayBetweenBatches = delayBetweenBatches;
103     }
104
105     public String getOutFile() {
106         return outFile;
107     }
108
109     public void setOutFile(String outFile) {
110         this.outFile = outFile;
111     }
112
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public GroupValidationResult validate() {
118         GroupValidationResult validationResult = new GroupValidationResult(this);
119
120         if (isNullOrBlank(name)) {
121             validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
122         }
123
124         if (isNullOrBlank(host)) {
125             validationResult.setResult("host", ValidationStatus.INVALID, "host must be a non-blank string");
126         }
127
128         if (port < 1024 || port > 65535) {
129             validationResult.setResult("port", ValidationStatus.INVALID,
130                             "port must be an integer between 1024 and 65535 inclusive");
131         }
132
133         if (batchCount < 0) {
134             validationResult.setResult("batchCount", ValidationStatus.INVALID,
135                             "batchCount must be an integer with a value of zero or more, "
136                                             + "zero means generate batches forever");
137         }
138
139         if (batchSize < 1) {
140             validationResult.setResult("batchSize", ValidationStatus.INVALID,
141                             "batchSize must be an integer greater than zero");
142         }
143
144         if (delayBetweenBatches < 0) {
145             validationResult.setResult("batchSize", ValidationStatus.INVALID,
146                             "batchSize must be an integer with a value of zero or more");
147         }
148
149         return validationResult;
150     }
151
152     private boolean isNullOrBlank(final String stringValue) {
153         return stringValue == null || stringValue.trim().length() == 0;
154     }
155
156 }