diff options
author | sebdet <sebastien.determe@intl.att.com> | 2020-10-12 12:12:03 +0200 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2020-10-12 11:44:54 +0000 |
commit | dbf8757410e7bc8b1db6bd8890144ec822ce810e (patch) | |
tree | aa2e0e6de6e1675575e5e6189b6534594312ce25 /src/main/java/org | |
parent | 88fd35f7b46041f723cff0eaaf4ea4ed46e9530f (diff) |
Send sdc notifs
Send the right COMPONENT_DONE_OK/COMPONENT_DONE_ERROR to SDC when transaction is complete, so that user can see that in the sdc UI.
Issue-ID: CLAMP-955
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: I2632f721819cf612a6816bd6caf5d961df6b3106
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java index fbb37d52..1885cc49 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java @@ -43,6 +43,7 @@ import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.clamp.loop.CsarInstaller; 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; @@ -160,7 +161,8 @@ public class SdcSingleController { * @param distributionClient the distribution client */ public SdcSingleController(ClampProperties clampProp, CsarInstaller csarInstaller, - SdcSingleControllerConfiguration sdcSingleConfig, IDistributionClient distributionClient) { + SdcSingleControllerConfiguration sdcSingleConfig, + IDistributionClient distributionClient) { this.distributionClient = distributionClient; isSdcClientAutoManaged = (distributionClient == null); this.sdcConfig = sdcSingleConfig; @@ -228,7 +230,8 @@ public class SdcSingleController { } private void sendAllNotificationForCsarHandler(INotificationData notificationData, CsarHandler csar, - NotificationType notificationType, DistributionStatusEnum distributionStatus, String errorMessage) { + NotificationType notificationType, + DistributionStatusEnum distributionStatus, String errorMessage) { if (csar != null) { // Notify for the CSAR this.sendSdcNotification(notificationType, csar.getArtifactElement().getArtifactURL(), @@ -277,28 +280,34 @@ public class SdcSingleController { csarInstaller.installTheCsar(csar); sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY, DistributionStatusEnum.DEPLOY_OK, null); + this.sendComponentStatus(notificationData, DistributionStatusEnum.COMPONENT_DONE_OK, null); } } catch (SdcArtifactInstallerException | SdcToscaParserException e) { logger.error("SdcArtifactInstallerException exception caught during the notification processing", e); sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY, DistributionStatusEnum.DEPLOY_ERROR, e.getMessage()); + this.sendComponentStatus(notificationData, DistributionStatusEnum.COMPONENT_DONE_ERROR, e.getMessage()); } catch (SdcDownloadException | CsarHandlerException e) { logger.error("SdcDownloadException exception caught during the notification processing", e); sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DOWNLOAD, DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage()); + this.sendComponentStatus(notificationData, DistributionStatusEnum.COMPONENT_DONE_ERROR, e.getMessage()); } catch (InterruptedException e) { logger.error("Interrupt exception caught during the notification processing", e); sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY, DistributionStatusEnum.DEPLOY_ERROR, e.getMessage()); + this.sendComponentStatus(notificationData, DistributionStatusEnum.COMPONENT_DONE_ERROR, e.getMessage()); Thread.currentThread().interrupt(); } catch (BlueprintParserException e) { logger.error("BlueprintParser exception caught during the notification processing", e); sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY, DistributionStatusEnum.DEPLOY_ERROR, e.getMessage()); + this.sendComponentStatus(notificationData, DistributionStatusEnum.COMPONENT_DONE_ERROR, e.getMessage()); } catch (RuntimeException e) { logger.error("Unexpected exception caught during the notification processing", e); sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY, DistributionStatusEnum.DEPLOY_ERROR, e.getMessage()); + this.sendComponentStatus(notificationData, DistributionStatusEnum.COMPONENT_DONE_ERROR, e.getMessage()); } finally { this.changeControllerStatus(SdcSingleControllerStatus.IDLE); } @@ -341,7 +350,8 @@ public class SdcSingleController { } private void sendSdcNotification(NotificationType notificationType, String artifactUrl, String consumerId, - String distributionId, DistributionStatusEnum status, String errorReason, long timestamp) { + String distributionId, DistributionStatusEnum status, String errorReason, + long timestamp) { String event = "Sending " + notificationType.name() + "(" + status.name() + ")" + " notification to SDC for artifact:" + artifactUrl; if (errorReason != null) { @@ -370,6 +380,43 @@ public class SdcSingleController { logger.info("SDC Notification sent successfully(" + action + ")"); } + private void sendComponentStatus(INotificationData notificationData, DistributionStatusEnum status, + String errorReason) { + try { + IComponentDoneStatusMessage message = new IComponentDoneStatusMessage() { + + @Override public String getDistributionID() { + return notificationData.getDistributionID(); + } + + @Override public String getConsumerID() { + return sdcConfig.getConsumerID(); + } + + @Override public long getTimestamp() { + return System.currentTimeMillis(); + } + + @Override public DistributionStatusEnum getStatus() { + return status; + } + + @Override public String getComponentName() { + return sdcConfig.getUser(); + } + }; + + if (errorReason != null) { + this.distributionClient.sendComponentDoneStatus(message, errorReason); + } else { + this.distributionClient.sendComponentDoneStatus(message); + } + } catch (RuntimeException e) { + logger.warn("Unable to send the SDC Notification (" + status.name() + ") due to an exception", e); + } + logger.info("SDC Notification sent successfully(" + status.name() + ")"); + } + private void sendDownloadStatus(IDistributionStatusMessage message, String errorReason) { if (errorReason != null) { this.distributionClient.sendDownloadStatus(message, errorReason); |