28c4f42d2c3eaeafe68a12aeca4c697612361158
[policy/models.git] / models-sim / policy-models-simulators / src / main / java / org / onap / policy / models / simulators / SimulatorParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.simulators;
23
24 import java.util.LinkedList;
25 import java.util.List;
26 import lombok.Getter;
27 import org.onap.policy.common.endpoints.parameters.TopicParameters;
28 import org.onap.policy.common.parameters.BeanValidationResult;
29 import org.onap.policy.common.parameters.BeanValidator;
30 import org.onap.policy.common.parameters.ValidationStatus;
31 import org.onap.policy.common.parameters.annotations.Valid;
32 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
33
34 /**
35  * Simulator parameters.
36  */
37 @Getter
38 public class SimulatorParameters {
39
40     /**
41      * Note: this is only used to capture the provider's parameters; the rest server
42      * parameters that it contains are ignored. Instead, the parameters for the rest
43      * server are contained within the {@link #restServers} entry having the same name as
44      * the provider parameters.
45      */
46     private DmaapSimParameterGroup dmaapProvider;
47
48     private @Valid CdsServerParameters grpcServer;
49
50     /**
51      * Parameters for the REST server simulators that are to be started.
52      */
53     private List<@Valid ClassRestServerParameters> restServers = new LinkedList<>();
54
55     /**
56      * Topic sinks that are used by {@link #topicServers}.
57      */
58     private List<@Valid TopicParameters> topicSinks = new LinkedList<>();
59
60     /**
61      * Topic sources that are used by {@link #topicServers}.
62      */
63     private List<@Valid TopicParameters> topicSources = new LinkedList<>();
64
65     /**
66      * Parameters for the TOPIC server simulators that are to be started.
67      */
68     private List<@Valid TopicServerParameters> topicServers = new LinkedList<>();
69
70
71     /**
72      * Validates the parameters.
73      *
74      * @param containerName name of the parameter container
75      * @return the validation result
76      */
77     public BeanValidationResult validate(String containerName) {
78         BeanValidationResult result = new BeanValidator().validateTop(containerName, this);
79
80         if (dmaapProvider != null) {
81             // do not want full validation of the provider, so validate the relevant
82             // fields ourselves
83             var subResult = new BeanValidationResult("dmaapProvider", dmaapProvider);
84             subResult.validateNotNull("name", dmaapProvider.getName());
85             if (dmaapProvider.getTopicSweepSec() < 1) {
86                 subResult.addResult("topicSweepSec", dmaapProvider.getTopicSweepSec(),
87                                 ValidationStatus.INVALID, "is below the minimum value: 1");
88             }
89             result.addResult(subResult);
90         }
91
92         return result;
93     }
94 }