summaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/main/java/org
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-09-11 12:38:03 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-09-11 12:38:24 +0100
commit5e4eb38ae737abd2054108b99bbd7b3649ec77d1 (patch)
treed4ad73ac67c675905f99574ac2a1b6b8c86fb2a2 /plugins/reception-plugins/src/main/java/org
parent1662df01bb8e54f17048b8a86f0c5560ae79fe83 (diff)
Fix all sonar issues in distribution
* Fixing all sonar issues in distribution * Adding more test cases to improve code coverage Change-Id: I296f96b66046e25c3c462632091f40565ff75478 Issue-ID: POLICY-1035 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'plugins/reception-plugins/src/main/java/org')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java54
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java337
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java160
3 files changed, 388 insertions, 163 deletions
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 0601f4b2..14b0f1ec 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
@@ -66,7 +66,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
@Override
protected void initializeReception(final String parameterGroupName) throws PluginInitializationException {
- handlerParameters = (SdcReceptionHandlerConfigurationParameterGroup) ParameterService.get(parameterGroupName);
+ handlerParameters = ParameterService.get(parameterGroupName);
initializeSdcClient();
startSdcClient();
}
@@ -108,12 +108,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
sdcReceptionHandlerStatus = newStatus;
break;
case IDLE:
- if (nbOfNotificationsOngoing > 1) {
- --nbOfNotificationsOngoing;
- } else {
- nbOfNotificationsOngoing = 0;
- sdcReceptionHandlerStatus = newStatus;
- }
+ handleIdleStatusChange(newStatus);
break;
case BUSY:
++nbOfNotificationsOngoing;
@@ -286,27 +281,24 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
private void sendDistributionStatus(final DistributionStatusType statusType, final String artifactUrl,
final String distributionId, final DistributionStatusEnum status, final String errorReason) {
- IDistributionClientResult clientResult = null;
+ IDistributionClientResult clientResult;
final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder()
.setArtifactUrl(artifactUrl).setConsumerId(sdcConfig.getConsumerID()).setDistributionId(distributionId)
.setDistributionStatus(status).setTimestamp(System.currentTimeMillis());
final IDistributionStatusMessage message = new DistributionStatusMessage(messageBuilder);
- switch (statusType) {
- case DOWNLOAD:
- if (errorReason != null) {
- clientResult = distributionClient.sendDownloadStatus(message, errorReason);
- } else {
- clientResult = distributionClient.sendDownloadStatus(message);
- }
- break;
- case DEPLOY:
- if (errorReason != null) {
- clientResult = distributionClient.sendDeploymentStatus(message, errorReason);
- } else {
- clientResult = distributionClient.sendDeploymentStatus(message);
- }
+ if (DistributionStatusType.DOWNLOAD.equals(statusType)) {
+ if (errorReason != null) {
+ clientResult = distributionClient.sendDownloadStatus(message, errorReason);
+ } else {
+ clientResult = distributionClient.sendDownloadStatus(message);
+ }
+ } else {
+ if (errorReason != null) {
+ clientResult = distributionClient.sendDeploymentStatus(message, errorReason);
+ } else {
+ clientResult = distributionClient.sendDeploymentStatus(message);
+ }
}
-
final StringBuilder loggerMessage = new StringBuilder();
loggerMessage.append("distribution status to SDC with values - ").append("DistributionId")
.append(distributionId).append(" Artifact: ").append(artifactUrl).append(" StatusType: ")
@@ -332,7 +324,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
*/
private void sendComponentDoneStatus(final String distributionId, final DistributionStatusEnum status,
final String errorReason) {
- IDistributionClientResult clientResult = null;
+ IDistributionClientResult clientResult;
final ComponentDoneStatusMessageBuilder messageBuilder = new ComponentDoneStatusMessageBuilder()
.setConsumerId(sdcConfig.getConsumerID()).setDistributionId(distributionId)
.setDistributionStatus(status).setTimestamp(System.currentTimeMillis());
@@ -357,4 +349,18 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
LOGGER.debug(loggerMessage);
}
}
+
+ /**
+ * Handle the status change of {@link SdcReceptionHandler} to Idle.
+ *
+ * @param newStatus the new status
+ */
+ private void handleIdleStatusChange(final SdcReceptionHandlerStatus newStatus) {
+ if (nbOfNotificationsOngoing > 1) {
+ --nbOfNotificationsOngoing;
+ } else {
+ nbOfNotificationsOngoing = 0;
+ sdcReceptionHandlerStatus = newStatus;
+ }
+ }
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java
new file mode 100644
index 00000000..34eaf33e
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterBuilder.java
@@ -0,0 +1,337 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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;
+
+/**
+ * This class builds an instance of {@link SdcReceptionHandlerConfigurationParameterGroup} class.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class SdcReceptionHandlerConfigurationParameterBuilder {
+
+ private boolean activeserverTlsAuth;
+ private boolean filterinEmptyResources;
+ private boolean useHttpsWithDmaap;
+ private int pollingTimeout;
+ private int pollingInterval;
+ private String user;
+ private String password;
+ private String consumerId;
+ private String consumerGroup;
+ private String asdcAddress;
+ private String environmentName;
+ private String keystorePath;
+ private String keystorePassword;
+ private List<String> messageBusAddress;
+ private List<String> artifactTypes;
+
+ /**
+ * Set activeserverTlsAuth to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param activeserverTlsAuth the activeserverTlsAuth
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setActiveserverTlsAuth(final boolean activeserverTlsAuth) {
+ this.activeserverTlsAuth = activeserverTlsAuth;
+ return this;
+ }
+
+ /**
+ * Set filterinEmptyResources to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param filterinEmptyResources the filterinEmptyResources
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setFilterinEmptyResources(
+ final boolean filterinEmptyResources) {
+ this.filterinEmptyResources = filterinEmptyResources;
+ return this;
+ }
+
+ /**
+ * Set useHttpsWithDmaap to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param useHttpsWithDmaap the useHttpsWithDmaap
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setUseHttpsWithDmaap(final Boolean useHttpsWithDmaap) {
+ this.useHttpsWithDmaap = useHttpsWithDmaap;
+ return this;
+ }
+
+ /**
+ * Set pollingInterval to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param pollingInterval the pollingInterval
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setPollingInterval(final int pollingInterval) {
+ this.pollingInterval = pollingInterval;
+ return this;
+ }
+
+ /**
+ * Set pollingTimeout to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param pollingTimeout the pollingTimeout
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setPollingTimeout(final int pollingTimeout) {
+ this.pollingTimeout = pollingTimeout;
+ return this;
+ }
+
+ /**
+ * Set asdcAddress to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param asdcAddress the asdcAddress
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setAsdcAddress(final String asdcAddress) {
+ this.asdcAddress = asdcAddress;
+ return this;
+ }
+
+ /**
+ * Set user to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param user the user
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setUser(final String user) {
+ this.user = user;
+ return this;
+ }
+
+ /**
+ * Set password to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param password the password
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ /**
+ * Set consumerId to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param consumerId the consumerId
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setConsumerId(final String consumerId) {
+ this.consumerId = consumerId;
+ return this;
+ }
+
+ /**
+ * Set consumerGroup to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param consumerGroup the consumerGroup
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setConsumerGroup(final String consumerGroup) {
+ this.consumerGroup = consumerGroup;
+ return this;
+ }
+
+ /**
+ * Set environmentName to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param environmentName the environmentName
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setEnvironmentName(final String environmentName) {
+ this.environmentName = environmentName;
+ return this;
+ }
+
+ /**
+ * Set keystorePath to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param keystorePath the keystorePath
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setKeystorePath(final String keystorePath) {
+ this.keystorePath = keystorePath;
+ return this;
+ }
+
+ /**
+ * Set keystorePassword to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param keystorePassword the keystorePassword
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setKeystorePassword(final String keystorePassword) {
+ this.keystorePassword = keystorePassword;
+ return this;
+ }
+
+ /**
+ * Set messageBusAddress to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param messageBusAddress the messageBusAddress
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setMessageBusAddress(final List<String> messageBusAddress) {
+ this.messageBusAddress = messageBusAddress;
+ return this;
+ }
+
+ /**
+ * Set artifactTypes to this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @param artifactTypes the artifactTypes
+ */
+ public SdcReceptionHandlerConfigurationParameterBuilder setArtifactTypes(final List<String> artifactTypes) {
+ this.artifactTypes = artifactTypes;
+ return this;
+ }
+
+ /**
+ * Returns the active server TlsAuth of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the activeserverTlsAuth
+ */
+ public boolean isActiveserverTlsAuth() {
+ return activeserverTlsAuth;
+ }
+
+ /**
+ * Returns the isFilterinEmptyResources flag of this {@link SdcReceptionHandlerConfigurationParameterBuilder}
+ * instance.
+ *
+ * @return the isFilterinEmptyResources
+ */
+ public boolean isFilterinEmptyResources() {
+ return filterinEmptyResources;
+ }
+
+ /**
+ * Returns the isUseHttpsWithDmaap flag of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the isUseHttpsWithDmaap
+ */
+ public Boolean getIsUseHttpsWithDmaap() {
+ return useHttpsWithDmaap;
+ }
+
+ /**
+ * Returns the polling interval of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the pollingInterval
+ */
+ public int getPollingInterval() {
+ return pollingInterval;
+ }
+
+ /**
+ * Returns the polling timeout of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the pollingTimeout
+ */
+ public int getPollingTimeout() {
+ return pollingTimeout;
+ }
+
+ /**
+ * Returns the asdc address of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the asdcAddress
+ */
+ public String getAsdcAddress() {
+ return asdcAddress;
+ }
+
+ /**
+ * Returns the user of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the user
+ */
+ public String getUser() {
+ return user;
+ }
+
+ /**
+ * Returns the password of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the password
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Returns the consumer id of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the consumerId
+ */
+ public String getConsumerId() {
+ return consumerId;
+ }
+
+ /**
+ * Returns the consumer group of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the consumerGroup
+ */
+ public String getConsumerGroup() {
+ return consumerGroup;
+ }
+
+ /**
+ * Returns the environment name of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the environmentName
+ */
+ public String getEnvironmentName() {
+ return environmentName;
+ }
+
+ /**
+ * Returns the keystore path of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the keystorePath
+ */
+ public String getKeystorePath() {
+ return keystorePath;
+ }
+
+ /**
+ * Returns the keystore password of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the keystorePassword
+ */
+ public String getKeystorePassword() {
+ return keystorePassword;
+ }
+
+ /**
+ * Returns the message bus address of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the messageBusAddress
+ */
+ public List<String> getMessageBusAddress() {
+ return messageBusAddress;
+ }
+
+ /**
+ * Returns the artifact types of this {@link SdcReceptionHandlerConfigurationParameterBuilder} instance.
+ *
+ * @return the artifactTypes
+ */
+ public List<String> getArtifactTypes() {
+ return artifactTypes;
+ }
+
+}
+
+
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
index 08fd707c..bbee652a 100644
--- 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
@@ -34,7 +34,6 @@ import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigu
*/
public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
- // Interface of IConfiguration item
private String asdcAddress;
private List<String> messageBusAddress;
private String user;
@@ -56,22 +55,23 @@ public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHan
*
* @param builder the SDC configuration builder
*/
- private SdcReceptionHandlerConfigurationParameterGroup(final SdcConfigurationBuilder 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 SdcReceptionHandlerConfigurationParameterGroup(
+ final SdcReceptionHandlerConfigurationParameterBuilder builder) {
+ asdcAddress = builder.getAsdcAddress();
+ messageBusAddress = builder.getMessageBusAddress();
+ user = builder.getUser();
+ password = builder.getPassword();
+ pollingInterval = builder.getPollingInterval();
+ pollingTimeout = builder.getPollingTimeout();
+ consumerId = builder.getConsumerId();
+ artifactTypes = builder.getArtifactTypes();
+ consumerGroup = builder.getConsumerGroup();
+ environmentName = builder.getEnvironmentName();
+ keyStorePath = builder.getKeystorePath();
+ keyStorePassword = builder.getKeystorePassword();
+ activeServerTlsAuth = builder.isActiveserverTlsAuth();
+ isFilterInEmptyResources = builder.isFilterinEmptyResources();
+ isUseHttpsWithDmaap = builder.getIsUseHttpsWithDmaap();
}
@@ -146,119 +146,6 @@ public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHan
}
/**
- * Inner static class is to used as a Builder.
- *
- */
- public static class SdcConfigurationBuilder {
- 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 SdcConfigurationBuilder setAsdcAddress(final String val) {
- asdcAddress = val;
- return this;
- }
-
- public SdcConfigurationBuilder setMessageBusAddress(final List<String> val) {
- messageBusAddress = val;
- return this;
- }
-
- public SdcConfigurationBuilder setUser(final String val) {
- user = val;
- return this;
- }
-
- public SdcConfigurationBuilder setPassword(final String val) {
- password = val;
- return this;
- }
-
- public SdcConfigurationBuilder setPollingInterval(final int val) {
- pollingInterval = val;
- return this;
- }
-
- public SdcConfigurationBuilder setPollingTimeout(final int val) {
- pollingTimeout = val;
- return this;
- }
-
- public SdcConfigurationBuilder setConsumerId(final String val) {
- consumerId = val;
- return this;
- }
-
- public SdcConfigurationBuilder setArtifactTypes(final List<String> val) {
- artifactTypes = val;
- return this;
- }
-
- public SdcConfigurationBuilder setConsumerGroup(final String val) {
- consumerGroup = val;
- return this;
- }
-
- public SdcConfigurationBuilder setEnvironmentName(final String val) {
- environmentName = val;
- return this;
- }
-
- public SdcConfigurationBuilder setKeystorePath(final String val) {
- keystorePath = val;
- return this;
- }
-
- public SdcConfigurationBuilder setKeystorePassword(final String val) {
- keystorePassword = val;
- return this;
- }
-
- public SdcConfigurationBuilder setActiveserverTlsAuth(final boolean val) {
- activeserverTlsAuth = val;
- return this;
- }
-
- public SdcConfigurationBuilder setIsFilterinEmptyResources(final boolean val) {
- isFilterinEmptyResources = val;
- return this;
- }
-
- public SdcConfigurationBuilder setIsUseHttpsWithDmaap(final Boolean val) {
- isUseHttpsWithDmaap = val;
- return this;
- }
-
- /**
- * Creates an instance of {@link SdcReceptionHandlerConfigurationParameterGroup}.
- */
- public SdcReceptionHandlerConfigurationParameterGroup build() {
- return new SdcReceptionHandlerConfigurationParameterGroup(this);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "name =" + getName() + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
- + messageBusAddress + ", user = " + user + "]";
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -301,15 +188,10 @@ public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHan
*/
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");
- }
+ for (final String temp : element) {
+ if (!ParameterValidationUtils.validateStringParameter(temp)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ "the string of " + elementName + "must be a non-blank string");
}
}
}