aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-09-07 21:15:51 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-09-09 13:46:03 +0100
commit4d65392df99c1e38792a6842570f2c176680fec5 (patch)
tree5435d499fa6890a698753aaae22f1c0c520d97ab /plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc
parented51ed0f7f1f479e394634de9ffb0778de4ea307 (diff)
Adding code for sending distribution status to sdc
* Adding implementation of IDistributionStatusMessage & IComponentDoneStatusMessage interfaces of SDC. * Adding builder for distribution status classes. * Adding code changes in SdcReceptionHandler to send download/deployment/component status to SDC at various stages of handling notification. * Adding test cases for all new code. Change-Id: I27c9ed373015d728f1ed02528e2ba2a638952bdf Issue-ID: POLICY-956 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc')
-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
5 files changed, 511 insertions, 18 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);
+ }
+ }
}