From 8561671bacac36db04b34351df9ddb9d3f5e79cc Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 23 Mar 2018 11:12:50 +0100 Subject: Sonar fixes Rework the class due to sonar report Issue-ID: CLAMP-81 Change-Id: I5f99728b3aa1c194d0bf7b2cf727e8dbdf99684f Signed-off-by: Determe, Sebastien (sd378r) --- .../clds/sdc/controller/SdcSingleController.java | 68 ++++++++++++---------- 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'src') 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 f8fef3943..d09362669 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 @@ -56,10 +56,14 @@ import org.openecomp.sdc.utils.DistributionStatusEnum; public class SdcSingleController { private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSingleController.class); - protected boolean isAsdcClientAutoManaged = false; - protected CsarInstaller csarInstaller; - protected ClampProperties refProp; + private boolean isAsdcClientAutoManaged = false; + private CsarInstaller csarInstaller; + private ClampProperties refProp; public static final String CONFIG_SDC_FOLDER = "sdc.csarFolder"; + private int nbOfNotificationsOngoing = 0; + private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED; + private SdcSingleControllerConfiguration sdcConfig; + private IDistributionClient distributionClient; /** * Inner class for Notification callback @@ -88,14 +92,18 @@ public class SdcSingleController { } } - // ***** Controller STATUS code - protected int nbOfNotificationsOngoing = 0; - public int getNbOfNotificationsOngoing() { return nbOfNotificationsOngoing; } - private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED; + private void changeControllerStatusIdle() { + if (this.nbOfNotificationsOngoing > 1) { + --this.nbOfNotificationsOngoing; + } else { + this.nbOfNotificationsOngoing = 0; + this.controllerStatus = SdcSingleControllerStatus.IDLE; + } + } protected final synchronized void changeControllerStatus(SdcSingleControllerStatus newControllerStatus) { switch (newControllerStatus) { @@ -104,12 +112,7 @@ public class SdcSingleController { this.controllerStatus = newControllerStatus; break; case IDLE: - if (this.nbOfNotificationsOngoing > 1) { - --this.nbOfNotificationsOngoing; - } else { - this.nbOfNotificationsOngoing = 0; - this.controllerStatus = newControllerStatus; - } + this.changeControllerStatusIdle(); break; default: this.controllerStatus = newControllerStatus; @@ -121,10 +124,6 @@ public class SdcSingleController { return this.controllerStatus; } - // ***** END of Controller STATUS code - protected SdcSingleControllerConfiguration sdcConfig; - private IDistributionClient distributionClient; - public SdcSingleController(ClampProperties clampProp, CsarInstaller csarInstaller, SdcSingleControllerConfiguration sdcSingleConfig, boolean isClientAutoManaged) { this.isAsdcClientAutoManaged = isClientAutoManaged; @@ -234,10 +233,11 @@ public class SdcSingleController { e.getMessage(), System.currentTimeMillis()); } catch (CsarHandlerException e) { logger.error("CsarHandlerException exception caught during the notification processing", e); - this.sendASDCNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(), - sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, - e.getMessage(), System.currentTimeMillis()); + this.sendASDCNotification(NotificationType.DOWNLOAD, null, sdcConfig.getConsumerID(), + iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(), + System.currentTimeMillis()); } catch (SdcToscaParserException e) { + logger.error("SdcToscaParserException exception caught during the notification processing", e); this.sendASDCNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(), sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR, e.getMessage(), System.currentTimeMillis()); @@ -291,19 +291,11 @@ public class SdcSingleController { status, timestamp); switch (notificationType) { case DOWNLOAD: - if (errorReason != null) { - this.distributionClient.sendDownloadStatus(message, errorReason); - } else { - this.distributionClient.sendDownloadStatus(message); - } + this.sendDownloadStatus(message, errorReason); action = "sendDownloadStatus"; break; case DEPLOY: - if (errorReason != null) { - this.distributionClient.sendDeploymentStatus(message, errorReason); - } else { - this.distributionClient.sendDeploymentStatus(message); - } + this.sendDeploymentStatus(message, errorReason); action = "sendDeploymentdStatus"; break; default: @@ -314,4 +306,20 @@ public class SdcSingleController { } logger.info("Sdc Notification sent successfully(" + action + ")"); } + + private void sendDownloadStatus(IDistributionStatusMessage message, String errorReason) { + if (errorReason != null) { + this.distributionClient.sendDownloadStatus(message, errorReason); + } else { + this.distributionClient.sendDownloadStatus(message); + } + } + + private void sendDeploymentStatus(IDistributionStatusMessage message, String errorReason) { + if (errorReason != null) { + this.distributionClient.sendDeploymentStatus(message, errorReason); + } else { + this.distributionClient.sendDeploymentStatus(message); + } + } } -- cgit 1.2.3-korg