diff options
Diffstat (limited to 'plugins/reception-plugins/src/main')
3 files changed, 337 insertions, 7 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java index 945670b9..99529759 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java @@ -21,8 +21,6 @@ package org.onap.policy.distribution.reception.handling.sdc; import java.util.List; - -import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup; import org.onap.sdc.api.consumer.IConfiguration; /** @@ -31,14 +29,14 @@ import org.onap.sdc.api.consumer.IConfiguration; */ public class SdcConfiguration implements IConfiguration { - private PssdConfigurationParametersGroup configParameters = null; + private SdcReceptionHandlerConfigurationParameterGroup configParameters = null; /** * Constructor for instantiating {@link SdcConfiguration}. * * @param configParameters the SDC Client configuration parameters */ - public SdcConfiguration(final PssdConfigurationParametersGroup configParameters) { + public SdcConfiguration(final SdcReceptionHandlerConfigurationParameterGroup configParameters) { this.configParameters = configParameters; } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java index 60c94e2b..f0f9e20d 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java @@ -26,7 +26,6 @@ import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.reception.decoding.PluginInitializationException; import org.onap.policy.distribution.reception.decoding.PluginTerminationException; import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; -import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup; import org.onap.sdc.api.IDistributionClient; import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.impl.DistributionClientFactory; @@ -39,13 +38,13 @@ public class SdcReceptionHandler extends AbstractReceptionHandler { private static final Logger LOGGER = FlexLogger.getLogger(SdcReceptionHandler.class); private SdcReceptionHandlerStatus sdcReceptionHandlerStatus = SdcReceptionHandlerStatus.STOPPED; - private PssdConfigurationParametersGroup handlerParameters; + private SdcReceptionHandlerConfigurationParameterGroup handlerParameters; private IDistributionClient distributionClient; private volatile int nbOfNotificationsOngoing = 0; @Override protected void initializeReception(final String parameterGroupName) throws PluginInitializationException { - handlerParameters = (PssdConfigurationParametersGroup) ParameterService.get(parameterGroupName); + handlerParameters = (SdcReceptionHandlerConfigurationParameterGroup) ParameterService.get(parameterGroupName); initializeSdcClient(); startSdcClient(); } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java new file mode 100644 index 00000000..5c46049f --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java @@ -0,0 +1,333 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import java.util.List; +import java.util.UUID; +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.common.utils.validation.ParameterValidationUtils; +import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; + +/** + * This class handles reading, parsing and validating of the Policy SDC Service Distribution + * parameters from Json format, which strictly adheres to the interface:IConfiguration, defined by + * SDC SDK. + */ +public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup { + + // Interface of IConfiguration item + private String asdcAddress; + private List<String> messageBusAddress; + private String user; + private String password; + private int pollingInterval; + private int pollingTimeout; + private String consumerId; + private List<String> artifactTypes; + private String consumerGroup; + private String environmentName; + private String keystorePath; + private String keystorePassword; + private boolean activeserverTlsAuth; + private boolean isFilterinEmptyResources; + private Boolean isUseHttpsWithDmaap; + + /** + * Inner static class is to used as a Builder. + * + */ + public static class PssdConfigurationBuilder { + private String asdcAddress; + private List<String> messageBusAddress; + private String user; + private String password; + private int pollingInterval; + private int pollingTimeout; + private String consumerId; + private List<String> artifactTypes; + private String consumerGroup; + private String environmentName; + private String keystorePath; + private String keystorePassword; + private boolean activeserverTlsAuth; + private boolean isFilterinEmptyResources; + private Boolean isUseHttpsWithDmaap; + + public PssdConfigurationBuilder setAsdcAddress(final String val) { + asdcAddress = val; + return this; + } + + public PssdConfigurationBuilder setMessageBusAddress(final List<String> val) { + messageBusAddress = val; + return this; + } + + public PssdConfigurationBuilder setUser(final String val) { + user = val; + return this; + } + + public PssdConfigurationBuilder setPassword(final String val) { + password = val; + return this; + } + + public PssdConfigurationBuilder setPollingInterval(final int val) { + pollingInterval = val; + return this; + } + + public PssdConfigurationBuilder setPollingTimeout(final int val) { + pollingTimeout = val; + return this; + } + + public PssdConfigurationBuilder setConsumerId(final String val) { + consumerId = val; + return this; + } + + public PssdConfigurationBuilder setArtifactTypes(final List<String> val) { + artifactTypes = val; + return this; + } + + public PssdConfigurationBuilder setConsumerGroup(final String val) { + consumerGroup = val; + return this; + } + + public PssdConfigurationBuilder setEnvironmentName(final String val) { + environmentName = val; + return this; + } + + public PssdConfigurationBuilder setKeystorePath(final String val) { + keystorePath = val; + return this; + } + + public PssdConfigurationBuilder setKeystorePassword(final String val) { + keystorePassword = val; + return this; + } + + public PssdConfigurationBuilder setActiveserverTlsAuth(final boolean val) { + activeserverTlsAuth = val; + return this; + } + + public PssdConfigurationBuilder setIsFilterinEmptyResources(final boolean val) { + isFilterinEmptyResources = val; + return this; + } + + public PssdConfigurationBuilder setIsUseHttpsWithDmaap(final Boolean val) { + isUseHttpsWithDmaap = val; + return this; + } + + /** + * Creates a new PssdConfigurationParametersGroup instance. + */ + public SdcReceptionHandlerConfigurationParameterGroup build() { + return new SdcReceptionHandlerConfigurationParameterGroup(this); + } + } + + /** + * The constructor for instantiating PssdConfigurationParametersGroup. It is kept private so + * that it could only be called by PssdConfigurationBuilder. + * + * @param builder stores all the values used by PssdConfigurationParametersGroup + */ + private SdcReceptionHandlerConfigurationParameterGroup(final PssdConfigurationBuilder builder) { + asdcAddress = builder.asdcAddress; + messageBusAddress = builder.messageBusAddress; + user = builder.user; + password = builder.password; + pollingInterval = builder.pollingInterval; + pollingTimeout = builder.pollingTimeout; + consumerId = builder.consumerId; + artifactTypes = builder.artifactTypes; + consumerGroup = builder.consumerGroup; + environmentName = builder.environmentName; + keystorePath = builder.keystorePath; + keystorePassword = builder.keystorePassword; + activeserverTlsAuth = builder.activeserverTlsAuth; + isFilterinEmptyResources = builder.isFilterinEmptyResources; + isUseHttpsWithDmaap = builder.isUseHttpsWithDmaap; + + } + + public String getAsdcAddress() { + return asdcAddress; + } + + public List<String> getMsgBusAddress() { + return messageBusAddress; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + + public int getPollingInterval() { + return pollingInterval; + } + + public int getPollingTimeout() { + return pollingTimeout; + } + + public String getConsumerID() { + return consumerId; + } + + public List<String> getArtifactTypes() { + return artifactTypes; + } + + public String getConsumerGroup() { + return consumerGroup; + } + + public String getEnvironmentName() { + return environmentName; + } + + public String getKeyStorePassword() { + return keystorePassword; + } + + public String getKeyStorePath() { + return keystorePath; + } + + public boolean activateServerTLSAuth() { + return activeserverTlsAuth; + } + + public boolean isFilterInEmptyResources() { + return isFilterinEmptyResources; + } + + public Boolean isUseHttpsWithDmaap() { + return isUseHttpsWithDmaap; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "name =" + getName() + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = " + + messageBusAddress + ", user = " + user + "]"; + } + + /** + * Set the name of this group. + * + * @param name the name to set. + */ + @Override + public void setName(final String name) { + super.setName(name + "_" + UUID.randomUUID().toString()); + } + + /** + * {@inheritDoc} + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + validateStringElement(validationResult, asdcAddress, "asdcAddress"); + validateStringElement(validationResult, user, "user"); + validateStringElement(validationResult, consumerId, "consumerId"); + validateStringElement(validationResult, consumerGroup, "consumerGroup"); + validateStringElement(validationResult, keystorePath, "keystorePath"); + validateStringElement(validationResult, keystorePassword, "keystorePassword"); + validateIntElement(validationResult, pollingInterval, "pollingInterval"); + validateIntElement(validationResult, pollingTimeout, "pollingTimeout"); + validateStringListElement(validationResult, messageBusAddress, "messageBusAddress"); + validateStringListElement(validationResult, artifactTypes, "artifactTypes"); + return validationResult; + } + + /** + * Validate the integer Element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validateIntElement(final GroupValidationResult validationResult, final int element, + final String elementName) { + if (!ParameterValidationUtils.validateIntParameter(element)) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + elementName + " must be a positive integer"); + } + } + + /** + * Validate the String List Element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element, + final String elementName) { + if (element == null) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + elementName + " must be a list of non-blank string"); + } else { + for (final String temp : element) { + if (!ParameterValidationUtils.validateStringParameter(temp)) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + "the string of " + elementName + "must be a non-blank string"); + } + } + } + } + + /** + * Validate the string element. + * + * @param validationResult the result object + * @param element the element to validate + * @param elementName the element name for error message + */ + private void validateStringElement(final GroupValidationResult validationResult, final String element, + final String elementName) { + if (!ParameterValidationUtils.validateStringParameter(asdcAddress)) { + validationResult.setResult(elementName, ValidationStatus.INVALID, + elementName + " must be a non-blank string"); + } + } +} + |