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
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.testsuites.performance.benchmark.eventgenerator;
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterGroup;
25 import org.onap.policy.common.parameters.ValidationStatus;
28 * This class defines the parameters for event generation.
30 public class EventGeneratorParameters implements ParameterGroup {
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;
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;
49 * Create default parameters.
51 public EventGeneratorParameters() {
52 // Default parameters are generated
56 public String getName() {
61 public void setName(String name) {
65 public String getHost() {
69 public void setHost(String host) {
73 public int getPort() {
77 public void setPort(int port) {
81 public int getBatchCount() {
85 public void setBatchCount(int batchCount) {
86 this.batchCount = batchCount;
89 public int getBatchSize() {
93 public void setBatchSize(int batchSize) {
94 this.batchSize = batchSize;
97 public long getDelayBetweenBatches() {
98 return delayBetweenBatches;
101 public void setDelayBetweenBatches(long delayBetweenBatches) {
102 this.delayBetweenBatches = delayBetweenBatches;
105 public String getOutFile() {
109 public void setOutFile(String outFile) {
110 this.outFile = outFile;
117 public GroupValidationResult validate() {
118 GroupValidationResult validationResult = new GroupValidationResult(this);
120 if (isNullOrBlank(name)) {
121 validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
124 if (isNullOrBlank(host)) {
125 validationResult.setResult("host", ValidationStatus.INVALID, "host must be a non-blank string");
128 if (port < 1024 || port > 65535) {
129 validationResult.setResult("port", ValidationStatus.INVALID,
130 "port must be an integer between 1024 and 65535 inclusive");
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");
140 validationResult.setResult("batchSize", ValidationStatus.INVALID,
141 "batchSize must be an integer greater than zero");
144 if (delayBetweenBatches < 0) {
145 validationResult.setResult("batchSize", ValidationStatus.INVALID,
146 "batchSize must be an integer with a value of zero or more");
149 return validationResult;
152 private boolean isNullOrBlank(final String stringValue) {
153 return stringValue == null || stringValue.trim().length() == 0;