2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Intel. 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=========================================================
20 package org.onap.policy.distribution.reception.parameters;
22 import java.io.FileReader;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.UUID;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ParameterGroup;
30 import org.onap.policy.common.parameters.ValidationStatus;
33 * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
34 * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
36 public class PSSDConfigurationParametersGroup implements ParameterGroup {
38 // Policy SDC Service Distribution specified field.
41 // Interface of IConfiguration item
42 private String asdcAddress;
43 private List<String> messageBusAddress;
45 private String password;
46 private int pollingInterval;
47 private int pollingTimeout;
48 private String consumerId;
49 private List<String> artifactTypes;
50 private String consumerGroup;
51 private String environmentName;
52 private String keystorePath;
53 private String keystorePassword;
54 private boolean activeserverTlsAuth;
55 private boolean isFilterinEmptyResources;
56 private Boolean isUseHttpsWithDmaap;
59 *Inner static class is to used as a Builder
62 public static class PSSDConfigurationBuilder {
63 private String asdcAddress;
64 private List<String> messageBusAddress;
66 private String password;
67 private int pollingInterval;
68 private int pollingTimeout;
69 private String consumerId;
70 private List<String> artifactTypes;
71 private String consumerGroup;
72 private String environmentName;
73 private String keystorePath;
74 private String keystorePassword;
75 private boolean activeserverTlsAuth;
76 private boolean isFilterinEmptyResources;
77 private Boolean isUseHttpsWithDmaap;
79 public PSSDConfigurationBuilder setAsdcAddress(String val)
80 { asdcAddress = val; return this; }
81 public PSSDConfigurationBuilder setMessageBusAddress(List<String> val)
82 { messageBusAddress = val; return this; }
83 public PSSDConfigurationBuilder setUser(String val)
84 { user = val; return this; }
85 public PSSDConfigurationBuilder setPassword(String val)
86 { password = val; return this; }
87 public PSSDConfigurationBuilder setPollingInterval(int val)
88 { pollingInterval = val; return this; }
89 public PSSDConfigurationBuilder setPollingTimeout(int val)
90 { pollingTimeout = val; return this; }
91 public PSSDConfigurationBuilder setConsumerId(String val)
92 { consumerId = val; return this; }
93 public PSSDConfigurationBuilder setArtifactTypes(List<String> val)
94 { artifactTypes = val; return this; }
95 public PSSDConfigurationBuilder setConsumerGroup(String val)
96 { consumerGroup = val; return this; }
97 public PSSDConfigurationBuilder setEnvironmentName(String val)
98 { environmentName = val; return this; }
99 public PSSDConfigurationBuilder setKeystorePath(String val)
100 { keystorePath = val; return this; }
101 public PSSDConfigurationBuilder setKeystorePassword(String val)
102 { keystorePassword = val; return this; }
103 public PSSDConfigurationBuilder setActiveserverTlsAuth(boolean val)
104 { activeserverTlsAuth = val; return this; }
105 public PSSDConfigurationBuilder setIsFilterinEmptyResources(boolean val)
106 { isFilterinEmptyResources = val; return this; }
107 public PSSDConfigurationBuilder setIsUseHttpsWithDmaap(Boolean val)
108 { isUseHttpsWithDmaap = val; return this; }
112 * it is to create a new PSSDConfigurationParametersGroup instance.
114 public PSSDConfigurationParametersGroup build() {
115 return new PSSDConfigurationParametersGroup(this);
120 * The constructor for instantiating PSSDConfigurationParametersGroup it is a private
121 * so that it could ONLY be instantiated by PSSDConfigurationBuilder
123 * @param builder stores all the values used by PSSDConfigurationParametersGroup
125 private PSSDConfigurationParametersGroup(PSSDConfigurationBuilder builder) {
126 asdcAddress = builder.asdcAddress;
127 messageBusAddress = builder.messageBusAddress;
129 password = builder.password;
130 pollingInterval = builder.pollingInterval;
131 pollingTimeout = builder.pollingTimeout;
132 consumerId = builder.consumerId;
133 artifactTypes = builder.artifactTypes;
134 consumerGroup = builder.consumerGroup;
135 environmentName = builder.environmentName;
136 keystorePath = builder.keystorePath;
137 keystorePassword = builder.keystorePassword;
138 activeserverTlsAuth = builder.activeserverTlsAuth;
139 isFilterinEmptyResources = builder.isFilterinEmptyResources;
140 isUseHttpsWithDmaap = builder.isUseHttpsWithDmaap;
144 public String getAsdcAddress() {
148 public List<String> getMsgBusAddress() {
149 return messageBusAddress;
152 public String getUser() {
156 public String getPassword() {
160 public int getPollingInterval() {
161 return pollingInterval;
164 public int getPollingTimeout() {
165 return pollingTimeout;
168 public String getConsumerID() {
172 public List<String> getArtifactTypes() {
173 return artifactTypes;
176 public String getConsumerGroup() {
177 return consumerGroup;
180 public String getEnvironmentName() {
181 return environmentName;
184 public String getKeyStorePassword() {
185 return keystorePassword;
188 public String getKeyStorePath() {
192 public boolean activateServerTLSAuth() {
193 return activeserverTlsAuth;
196 public boolean isFilterInEmptyResources() {
197 return isFilterinEmptyResources;
200 public Boolean isUseHttpsWithDmaap() {
201 return isUseHttpsWithDmaap;
205 public String toString() {
206 return "name =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
207 + messageBusAddress + ", user = " + user + "]";
211 public String getName() {
216 public GroupValidationResult validate() {
217 final GroupValidationResult validationResult = new GroupValidationResult(this);
219 if (asdcAddress == null || asdcAddress.trim().length() == 0) {
220 validationResult.setResult("asdcAddress", ValidationStatus.INVALID,
221 "asdcAddress must be a non-blank string");
224 if (user == null || user.trim().length() == 0) {
225 validationResult.setResult("user", ValidationStatus.INVALID, "user must be a non-blank string");
228 if (consumerId == null || consumerId.trim().length() == 0) {
229 validationResult.setResult("consumerId", ValidationStatus.INVALID, "consumerId must be a non-blank string");
232 if (consumerGroup == null || consumerGroup.trim().length() == 0) {
233 validationResult.setResult("consumerGroup", ValidationStatus.INVALID,
234 "consumerGroup must be a non-blank string");
237 if (keystorePath == null || keystorePath.trim().length() == 0) {
238 validationResult.setResult("keystorePath", ValidationStatus.INVALID,
239 "keystorePath must be a non-blank string");
242 if (keystorePassword == null || keystorePassword.trim().length() == 0) {
243 validationResult.setResult("keystorePassword", ValidationStatus.INVALID,
244 "keystorePassword must be a non-blank string");
247 if (messageBusAddress == null) {
248 validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
249 "messageBusAddress must be a list of non-blank string");
251 for (final String temp : messageBusAddress) {
252 if (temp.trim().length() == 0) {
253 validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
254 "the string of messageBusAddress must be a non-blank string");
259 if (artifactTypes == null) {
260 validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
261 "artifactTypes must be a list of non-blank string");
263 for (final String temp : artifactTypes) {
264 if (temp.trim().length() == 0) {
265 validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
266 "the string of artifactTypes must be a non-blank string");
271 if (pollingInterval <= 0) {
272 validationResult.setResult("pollingInterval", ValidationStatus.INVALID,
273 "pollingInterval must be a positive integer");
276 if (pollingTimeout <= 0) {
277 validationResult.setResult("pollingTimeout", ValidationStatus.INVALID,
278 "pollingTimeout must be a positive integer");
281 return validationResult;
285 * Set the name of this group.
287 * @param name the name to set.
289 public void setName(final String name) {
290 this.name = name + "_" + UUID.randomUUID().toString();