Make simulator parameters optional
[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 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.models.sim.dmaap.parameters.DmaapSimParameterGroup;
31
32 /**
33  * Simulator parameters.
34  */
35 @Getter
36 public class SimulatorParameters {
37
38     /**
39      * Note: this is only used to capture the provider's parameters; the rest server
40      * parameters that it contains are ignored. Instead, the parameters for the rest
41      * server are contained within the {@link #restServers} entry having the same name as
42      * the provider parameters.
43      */
44     private DmaapSimParameterGroup dmaapProvider;
45
46     private CdsServerParameters grpcServer;
47
48     /**
49      * Parameters for the REST server simulators that are to be started.
50      */
51     private List<ClassRestServerParameters> restServers = new LinkedList<>();
52
53     /**
54      * Topic sinks that are used by {@link #topicServers}.
55      */
56     private List<TopicParameters> topicSinks = new LinkedList<>();
57
58     /**
59      * Topic sources that are used by {@link #topicServers}.
60      */
61     private List<TopicParameters> topicSources = new LinkedList<>();
62
63     /**
64      * Parameters for the TOPIC server simulators that are to be started.
65      */
66     private List<TopicServerParameters> topicServers = new LinkedList<>();
67
68
69     /**
70      * Validates the parameters.
71      *
72      * @param containerName name of the parameter container
73      * @return the validation result
74      */
75     public BeanValidationResult validate(String containerName) {
76         BeanValidationResult result = new BeanValidator().validateTop(containerName, this);
77
78         if (dmaapProvider != null) {
79             result.addResult(dmaapProvider.validate());
80         }
81
82         if (grpcServer != null) {
83             result.addResult(grpcServer.validate());
84         }
85
86         result.validateList("restServers", restServers, params -> params.validate("restServers"));
87         result.validateList("topicServers", topicServers, params -> params.validate("topicServers"));
88
89         return result;
90     }
91 }