aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java74
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java112
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java77
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java132
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java134
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java61
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java65
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java36
8 files changed, 671 insertions, 20 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java
new file mode 100644
index 00000000..581681b7
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessage.java
@@ -0,0 +1,74 @@
+/*-
+ * ============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 org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.utils.DistributionStatusEnum;
+
+/**
+ * This class represents the component done status of the distribution service.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class ComponentDoneStatusMessage implements IComponentDoneStatusMessage {
+
+ private String consumerId;
+ private String distributionId;
+ private DistributionStatusEnum distributionStatus;
+ private long timestamp;
+
+ /**
+ * Constructor for instantiating {@link ComponentDoneStatusMessage} class.
+ *
+ * @param messageBuilder the message builder
+ */
+ public ComponentDoneStatusMessage(final ComponentDoneStatusMessageBuilder messageBuilder) {
+ this.consumerId = messageBuilder.getConsumerId();
+ this.distributionId = messageBuilder.getDistributionId();
+ this.distributionStatus = messageBuilder.getDistributionStatus();
+ this.timestamp = messageBuilder.getTimestamp();
+ }
+
+ @Override
+ public DistributionStatusEnum getStatus() {
+ return distributionStatus;
+ }
+
+ @Override
+ public String getDistributionID() {
+ return distributionId;
+ }
+
+ @Override
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String getConsumerID() {
+ return consumerId;
+ }
+
+ @Override
+ public String getComponentName() {
+ return "POLICY";
+ }
+}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java
new file mode 100644
index 00000000..567ae8d6
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/ComponentDoneStatusMessageBuilder.java
@@ -0,0 +1,112 @@
+/*-
+ * ============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 org.onap.sdc.utils.DistributionStatusEnum;
+
+/**
+ * This class builds an instance of {@link ComponentDoneStatusMessage} class.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class ComponentDoneStatusMessageBuilder {
+
+ private String consumerId;
+ private String distributionId;
+ private DistributionStatusEnum distributionStatus;
+ private long timestamp;
+
+ /**
+ * Returns consumer id of this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @return the consumerId
+ */
+ public String getConsumerId() {
+ return consumerId;
+ }
+
+ /**
+ * Returns distribution id of this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @return the distributionId
+ */
+ public String getDistributionId() {
+ return distributionId;
+ }
+
+ /**
+ * Returns distribution status of this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @return the distributionStatus
+ */
+ public DistributionStatusEnum getDistributionStatus() {
+ return distributionStatus;
+ }
+
+ /**
+ * Returns time of this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @return the timestamp
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Set consumer id url to this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @param consumerId the consumerId to set
+ */
+ public ComponentDoneStatusMessageBuilder setConsumerId(final String consumerId) {
+ this.consumerId = consumerId;
+ return this;
+ }
+
+ /**
+ * Set distribution id to this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @param distributionId the distributionId to set
+ */
+ public ComponentDoneStatusMessageBuilder setDistributionId(final String distributionId) {
+ this.distributionId = distributionId;
+ return this;
+ }
+
+ /**
+ * Set distribution status to this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @param distributionStatus the distributionStatus to set
+ */
+ public ComponentDoneStatusMessageBuilder setDistributionStatus(final DistributionStatusEnum distributionStatus) {
+ this.distributionStatus = distributionStatus;
+ return this;
+ }
+
+ /**
+ * Set time to this {@link ComponentDoneStatusMessageBuilder} instance.
+ *
+ * @param timestamp the timestamp to set
+ */
+ public ComponentDoneStatusMessageBuilder setTimestamp(final long timestamp) {
+ this.timestamp = timestamp;
+ return this;
+ }
+}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java
new file mode 100644
index 00000000..436c061e
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessage.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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 org.onap.sdc.api.consumer.IDistributionStatusMessage;
+import org.onap.sdc.utils.DistributionStatusEnum;
+
+/**
+ * This class represents the distribution status of the distribution service.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DistributionStatusMessage implements IDistributionStatusMessage {
+
+ private String artifactUrl;
+ private String consumerId;
+ private String distributionId;
+ private DistributionStatusEnum distributionStatus;
+ private long timestamp;
+
+ /**
+ * Constructor for instantiating {@link DistributionStatusMessage} class.
+ *
+ * @param messageBuilder the message builder
+ */
+ public DistributionStatusMessage(final DistributionStatusMessageBuilder messageBuilder) {
+ this.artifactUrl = messageBuilder.getArtifactUrl();
+ this.consumerId = messageBuilder.getConsumerId();
+ this.distributionId = messageBuilder.getDistributionId();
+ this.distributionStatus = messageBuilder.getDistributionStatus();
+ this.timestamp = messageBuilder.getTimestamp();
+ }
+
+ @Override
+ public String getArtifactURL() {
+ return artifactUrl;
+ }
+
+ @Override
+ public String getConsumerID() {
+ return consumerId;
+ }
+
+ @Override
+ public String getDistributionID() {
+ return distributionId;
+ }
+
+ @Override
+ public DistributionStatusEnum getStatus() {
+ return distributionStatus;
+ }
+
+ @Override
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java
new file mode 100644
index 00000000..b83a7686
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/DistributionStatusMessageBuilder.java
@@ -0,0 +1,132 @@
+/*-
+ * ============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 org.onap.sdc.utils.DistributionStatusEnum;
+
+/**
+ * This class builds an instance of {@link DistributionStatusMessage} class.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DistributionStatusMessageBuilder {
+
+ private String artifactUrl;
+ private String consumerId;
+ private String distributionId;
+ private DistributionStatusEnum distributionStatus;
+ private long timestamp;
+
+ /**
+ * Returns artifact url of this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @return the artifactUrl
+ */
+ public String getArtifactUrl() {
+ return artifactUrl;
+ }
+
+ /**
+ * Returns consumer id of this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @return the consumerId
+ */
+ public String getConsumerId() {
+ return consumerId;
+ }
+
+ /**
+ * Returns distribution id of this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @return the distributionId
+ */
+ public String getDistributionId() {
+ return distributionId;
+ }
+
+ /**
+ * Returns distribution status of this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @return the distributionStatus
+ */
+ public DistributionStatusEnum getDistributionStatus() {
+ return distributionStatus;
+ }
+
+ /**
+ * Returns time of this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @return the timestamp
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Set artifact url to this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @param artifactUrl the artifactUrl to set
+ */
+ public DistributionStatusMessageBuilder setArtifactUrl(final String artifactUrl) {
+ this.artifactUrl = artifactUrl;
+ return this;
+ }
+
+ /**
+ * Set consumer id url to this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @param consumerId the consumerId to set
+ */
+ public DistributionStatusMessageBuilder setConsumerId(final String consumerId) {
+ this.consumerId = consumerId;
+ return this;
+ }
+
+ /**
+ * Set distribution id to this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @param distributionId the distributionId to set
+ */
+ public DistributionStatusMessageBuilder setDistributionId(final String distributionId) {
+ this.distributionId = distributionId;
+ return this;
+ }
+
+ /**
+ * Set distribution status to this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @param distributionStatus the distributionStatus to set
+ */
+ public DistributionStatusMessageBuilder setDistributionStatus(final DistributionStatusEnum distributionStatus) {
+ this.distributionStatus = distributionStatus;
+ return this;
+ }
+
+ /**
+ * Set time to this {@link DistributionStatusMessageBuilder} instance.
+ *
+ * @param timestamp the timestamp to set
+ */
+ public DistributionStatusMessageBuilder setTimestamp(final long timestamp) {
+ this.timestamp = timestamp;
+ return this;
+ }
+}
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 f2d8aa4d..0601f4b2 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
@@ -36,6 +36,8 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
import org.onap.policy.distribution.reception.handling.sdc.exceptions.ArtifactDownloadException;
import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.api.consumer.INotificationCallback;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
@@ -43,6 +45,7 @@ import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.impl.DistributionClientFactory;
import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.onap.sdc.utils.DistributionStatusEnum;
/**
* Handles reception of inputs from ONAP Service Design and Creation (SDC) from which policies may be decoded.
@@ -54,8 +57,13 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
private SdcReceptionHandlerStatus sdcReceptionHandlerStatus = SdcReceptionHandlerStatus.STOPPED;
private SdcReceptionHandlerConfigurationParameterGroup handlerParameters;
private IDistributionClient distributionClient;
+ private SdcConfiguration sdcConfig;
private volatile int nbOfNotificationsOngoing = 0;
+ private enum DistributionStatusType {
+ DOWNLOAD, DEPLOY
+ }
+
@Override
protected void initializeReception(final String parameterGroupName) throws PluginInitializationException {
handlerParameters = (SdcReceptionHandlerConfigurationParameterGroup) ParameterService.get(parameterGroupName);
@@ -63,9 +71,6 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
startSdcClient();
}
- // Add functionality for receiving SDC distibutions and invoking AbstractReceptionHandler
- // inputReceived()
-
@Override
public void destroy() throws PluginTerminationException {
LOGGER.debug("Going to stop the SDC Client...");
@@ -96,7 +101,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
*
* @param newStatus the new status
*/
- private synchronized final void changeSdcReceptionHandlerStatus(final SdcReceptionHandlerStatus newStatus) {
+ private final synchronized void changeSdcReceptionHandlerStatus(final SdcReceptionHandlerStatus newStatus) {
switch (newStatus) {
case INIT:
case STOPPED:
@@ -139,7 +144,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
LOGGER.error(message);
throw new PluginInitializationException(message);
}
- final SdcConfiguration sdcConfig = new SdcConfiguration(handlerParameters);
+ sdcConfig = new SdcConfiguration(handlerParameters);
distributionClient = createSdcDistributionClient();
final IDistributionClientResult clientResult = distributionClient.init(sdcConfig, this);
if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
@@ -176,29 +181,35 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
/**
* Method to process csar service artifacts from incoming SDC notification.
*
- * @param iNotif the notification from SDC
+ * @param notificationData the notification from SDC
*/
- public void processCsarServiceArtifacts(final INotificationData iNotif) {
+ public void processCsarServiceArtifacts(final INotificationData notificationData) {
boolean artifactsProcessedSuccessfully = true;
- for (final IArtifactInfo artifact : iNotif.getServiceArtifacts()) {
+ for (final IArtifactInfo artifact : notificationData.getServiceArtifacts()) {
try {
- final IDistributionClientDownloadResult resultArtifact = downloadTheArtifact(artifact);
+ final IDistributionClientDownloadResult resultArtifact =
+ downloadTheArtifact(artifact, notificationData);
final Path filePath = writeArtifactToFile(artifact, resultArtifact);
final Csar csarObject = new Csar(filePath.toString());
inputReceived(csarObject);
- // send deploy success status to sdc
+ sendDistributionStatus(DistributionStatusType.DEPLOY, artifact.getArtifactURL(),
+ notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_OK, null);
deleteArtifactFile(filePath);
} catch (final ArtifactDownloadException | PolicyDecodingException exp) {
LOGGER.error("Failed to process csar service artifacts ", exp);
artifactsProcessedSuccessfully = false;
- // send deploy failed status to sdc
+ sendDistributionStatus(DistributionStatusType.DEPLOY, artifact.getArtifactURL(),
+ notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,
+ "Failed to deploy the artifact due to: " + exp.getMessage());
}
}
if (artifactsProcessedSuccessfully) {
- // send final distribution success status to sdc
+ sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_OK,
+ null);
} else {
- // send final distribution failed status to sdc
+ sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_ERROR,
+ "Failed to process the artifact");
}
}
@@ -209,17 +220,20 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
* @return the download result
* @throws ArtifactDownloadException if download fails
*/
- private IDistributionClientDownloadResult downloadTheArtifact(final IArtifactInfo artifact)
- throws ArtifactDownloadException {
+ private IDistributionClientDownloadResult downloadTheArtifact(final IArtifactInfo artifact,
+ final INotificationData notificationData) throws ArtifactDownloadException {
final IDistributionClientDownloadResult downloadResult = distributionClient.download(artifact);
if (!downloadResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
- final String message = "Failed to download artifact with name: " + artifact.getArtifactName();
+ final String message = "Failed to download artifact with name: " + artifact.getArtifactName() + " due to: "
+ + downloadResult.getDistributionMessageResult();
LOGGER.error(message);
- // send failure download status to sdc
+ sendDistributionStatus(DistributionStatusType.DOWNLOAD, artifact.getArtifactURL(),
+ notificationData.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, message);
throw new ArtifactDownloadException(message);
}
- // send success download status to sdc
+ sendDistributionStatus(DistributionStatusType.DOWNLOAD, artifact.getArtifactURL(),
+ notificationData.getDistributionID(), DistributionStatusEnum.DOWNLOAD_OK, null);
return downloadResult;
}
@@ -259,4 +273,88 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
LOGGER.error("Failed to delete the downloaded artifact file", exp);
}
}
+
+ /**
+ * Sends the distribution status to SDC using the input values.
+ *
+ * @param statusType the status type
+ * @param artifactUrl the artifact url
+ * @param distributionId the distribution id
+ * @param status the status
+ * @param errorReason the error reason
+ */
+ private void sendDistributionStatus(final DistributionStatusType statusType, final String artifactUrl,
+ final String distributionId, final DistributionStatusEnum status, final String errorReason) {
+
+ IDistributionClientResult clientResult = null;
+ 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);
+ }
+ }
+
+ final StringBuilder loggerMessage = new StringBuilder();
+ loggerMessage.append("distribution status to SDC with values - ").append("DistributionId")
+ .append(distributionId).append(" Artifact: ").append(artifactUrl).append(" StatusType: ")
+ .append(statusType.name()).append(" Status: ").append(status.name());
+ if (errorReason != null) {
+ loggerMessage.append(" ErrorReason: ").append(errorReason);
+ }
+ if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+ loggerMessage.insert(0, "Failed sending ");
+ LOGGER.debug(loggerMessage);
+ } else {
+ loggerMessage.insert(0, "Successfully Sent ");
+ LOGGER.debug(loggerMessage);
+ }
+ }
+
+ /**
+ * Sends the component done status to SDC using the input values.
+ *
+ * @param distributionId the distribution Id
+ * @param status the distribution status
+ * @param errorReason the error reason
+ */
+ private void sendComponentDoneStatus(final String distributionId, final DistributionStatusEnum status,
+ final String errorReason) {
+ IDistributionClientResult clientResult = null;
+ final ComponentDoneStatusMessageBuilder messageBuilder = new ComponentDoneStatusMessageBuilder()
+ .setConsumerId(sdcConfig.getConsumerID()).setDistributionId(distributionId)
+ .setDistributionStatus(status).setTimestamp(System.currentTimeMillis());
+ final IComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder);
+ if (errorReason == null) {
+ clientResult = distributionClient.sendComponentDoneStatus(message);
+ } else {
+ clientResult = distributionClient.sendComponentDoneStatus(message, errorReason);
+ }
+
+ final StringBuilder loggerMessage = new StringBuilder();
+ loggerMessage.append("component done status to SDC with values - ").append("DistributionId")
+ .append(distributionId).append(" Status: ").append(status.name());
+ if (errorReason != null) {
+ loggerMessage.append(" ErrorReason: ").append(errorReason);
+ }
+ if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+ loggerMessage.insert(0, "Failed sending ");
+ LOGGER.debug(loggerMessage);
+ } else {
+ loggerMessage.insert(0, "Successfully Sent ");
+ LOGGER.debug(loggerMessage);
+ }
+ }
}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java
new file mode 100644
index 00000000..75e32243
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java
@@ -0,0 +1,61 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.sdc.utils.DistributionStatusEnum;
+
+public class TestComponentDoneStatusMessage {
+
+ @Test
+ public void testComponentDoneStatusMessage_Success() {
+ final String consumerId = "dummyId";
+ final String distributionId = "dummyDistribution";
+ final long timestamp = System.currentTimeMillis();
+ final ComponentDoneStatusMessageBuilder messageBuilder =
+ new ComponentDoneStatusMessageBuilder().setConsumerId(consumerId).setDistributionId(distributionId)
+ .setDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK).setTimestamp(timestamp);
+ final ComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder);
+ assertEquals("POLICY", message.getComponentName());
+ assertEquals(consumerId, message.getConsumerID());
+ assertEquals(distributionId, message.getDistributionID());
+ assertEquals(DistributionStatusEnum.COMPONENT_DONE_OK, message.getStatus());
+ assertEquals(timestamp, message.getTimestamp());
+ }
+
+ @Test
+ public void testComponentDoneStatusMessage_Failure() {
+ final String consumerId = "dummyId";
+ final String distributionId = "dummyDistribution";
+ final long timestamp = System.currentTimeMillis();
+ final ComponentDoneStatusMessageBuilder messageBuilder =
+ new ComponentDoneStatusMessageBuilder().setConsumerId(consumerId).setDistributionId(distributionId)
+ .setDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR).setTimestamp(timestamp);
+ final ComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder);
+ assertEquals("POLICY", message.getComponentName());
+ assertEquals(consumerId, message.getConsumerID());
+ assertEquals(distributionId, message.getDistributionID());
+ assertEquals(DistributionStatusEnum.COMPONENT_DONE_ERROR, message.getStatus());
+ assertEquals(timestamp, message.getTimestamp());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java
new file mode 100644
index 00000000..be127776
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java
@@ -0,0 +1,65 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.sdc.utils.DistributionStatusEnum;
+
+public class TestDistributionStatusMessage {
+
+ @Test
+ public void testDistributionStatusMessage_Download() {
+ final String artifactUrl = "http://dummyurl";
+ final String consumerId = "dummyId";
+ final String distributionId = "dummyDistribution";
+ final long timestamp = System.currentTimeMillis();
+
+ final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder()
+ .setArtifactUrl(artifactUrl).setConsumerId(consumerId).setDistributionId(distributionId)
+ .setDistributionStatus(DistributionStatusEnum.DOWNLOAD_OK).setTimestamp(timestamp);
+ final DistributionStatusMessage message = new DistributionStatusMessage(messageBuilder);
+ assertEquals(artifactUrl, message.getArtifactURL());
+ assertEquals(consumerId, message.getConsumerID());
+ assertEquals(distributionId, message.getDistributionID());
+ assertEquals(DistributionStatusEnum.DOWNLOAD_OK, message.getStatus());
+ assertEquals(timestamp, message.getTimestamp());
+ }
+
+ @Test
+ public void testDistributionStatusMessage_Deploy() {
+ final String artifactUrl = "http://dummyurl";
+ final String consumerId = "dummyId";
+ final String distributionId = "dummyDistribution";
+ final long timestamp = System.currentTimeMillis();
+
+ final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder()
+ .setArtifactUrl(artifactUrl).setConsumerId(consumerId).setDistributionId(distributionId)
+ .setDistributionStatus(DistributionStatusEnum.DEPLOY_OK).setTimestamp(timestamp);
+ final DistributionStatusMessage message = new DistributionStatusMessage(messageBuilder);
+ assertEquals(artifactUrl, message.getArtifactURL());
+ assertEquals(consumerId, message.getConsumerID());
+ assertEquals(distributionId, message.getDistributionID());
+ assertEquals(DistributionStatusEnum.DEPLOY_OK, message.getStatus());
+ assertEquals(timestamp, message.getTimestamp());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
index a648f807..c4020a41 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
@@ -110,6 +110,12 @@ public class TestSdcReceptionHandler {
Mockito.when(distributionClient.init(any(), any())).thenReturn(successfulClientInitResult);
Mockito.when(distributionClient.start()).thenReturn(successfulClientInitResult);
Mockito.when(distributionClient.stop()).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.sendComponentDoneStatus(any())).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.sendDownloadStatus(any())).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.sendDeploymentStatus(any())).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(successfulClientInitResult);
Mockito.when(distributionClient.download(any())).thenReturn(successfulClientDownloadResult);
Mockito.when(notificationData.getServiceArtifacts()).thenReturn(Arrays.asList(artifactInfo));
Mockito.when(artifactInfo.getArtifactName()).thenReturn(DUMMY_SERVICE_CSAR);
@@ -118,6 +124,8 @@ public class TestSdcReceptionHandler {
.thenReturn(DistributionActionResultEnum.SUCCESS);
Mockito.when(successfulClientDownloadResult.getDistributionActionResult())
.thenReturn(DistributionActionResultEnum.SUCCESS);
+ Mockito.when(failureClientInitResult.getDistributionActionResult())
+ .thenReturn(DistributionActionResultEnum.FAIL);
}
@@ -164,8 +172,6 @@ public class TestSdcReceptionHandler {
public final void testStartSdcClient_Failure() throws PluginInitializationException {
try {
Mockito.when(distributionClient.start()).thenReturn(failureClientInitResult);
- Mockito.when(failureClientInitResult.getDistributionActionResult())
- .thenReturn(DistributionActionResultEnum.FAIL);
sypHandler.initializeReception(pssdConfigParameters.getName());
fail("Test must throw an exception here");
@@ -256,6 +262,32 @@ public class TestSdcReceptionHandler {
assertEquals(0, policyForwarder.getNumberOfPoliciesReceived());
}
+ @Test
+ public void testSendDistributionStatusFailure() throws NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException, PluginInitializationException {
+
+ Mockito.when(successfulClientDownloadResult.getDistributionActionResult())
+ .thenReturn(DistributionActionResultEnum.FAIL);
+ Mockito.when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(failureClientInitResult);
+ Mockito.when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(failureClientInitResult);
+ Mockito.when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(failureClientInitResult);
+
+ final DummyDecoder policyDecoder = new DummyDecoder();
+ final Collection<PolicyDecoder<Csar, DummyPolicy>> policyDecoders = new ArrayList<>();
+ policyDecoders.add(policyDecoder);
+
+ final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder();
+ final Collection<PolicyForwarder> policyForwarders = new ArrayList<>();
+ policyForwarders.add(policyForwarder);
+
+ setUpPlugins(sypHandler, policyDecoders, policyForwarders);
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ sypHandler.activateCallback(notificationData);
+
+ assertEquals(null, policyDecoder.getDecodedPolicy());
+ assertEquals(0, policyForwarder.getNumberOfPoliciesReceived());
+ }
+
private void setUpPlugins(final AbstractReceptionHandler receptionHandler,
final Collection<PolicyDecoder<Csar, DummyPolicy>> decoders, final Collection<PolicyForwarder> forwarders)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException,