* ============LICENSE_END============================================\r
* Modifications copyright (c) 2018 Nokia\r
* ===================================================================\r
- * \r
+ *\r
*/\r
\r
package org.onap.clamp.clds.sdc.controller;\r
}\r
\r
/**\r
- * This method can be called multiple times at the same moment. The\r
- * controller must be thread safe !\r
+ * This method can be called multiple times at the same moment. The controller\r
+ * must be thread safe !\r
*/\r
@Override\r
public void activateCallback(INotificationData iNotif) {\r
sdcController.treatNotification(iNotif);\r
LoggingUtils.setTimeContext(startTime, new Date());\r
LoggingUtils.setResponseContext("0", "SDC Notification received and processed successfully",\r
- this.getClass().getName());\r
+ this.getClass().getName());\r
}\r
}\r
\r
\r
protected final synchronized void changeControllerStatus(SdcSingleControllerStatus newControllerStatus) {\r
switch (newControllerStatus) {\r
- case BUSY:\r
- ++this.nbOfNotificationsOngoing;\r
- this.controllerStatus = newControllerStatus;\r
- break;\r
- case IDLE:\r
- this.changeControllerStatusIdle();\r
- break;\r
- default:\r
- this.controllerStatus = newControllerStatus;\r
- break;\r
+ case BUSY:\r
+ ++this.nbOfNotificationsOngoing;\r
+ this.controllerStatus = newControllerStatus;\r
+ break;\r
+ case IDLE:\r
+ this.changeControllerStatusIdle();\r
+ break;\r
+ default:\r
+ this.controllerStatus = newControllerStatus;\r
+ break;\r
}\r
}\r
\r
}\r
\r
public SdcSingleController(ClampProperties clampProp, CsarInstaller csarInstaller,\r
- SdcSingleControllerConfiguration sdcSingleConfig, boolean isClientAutoManaged) {\r
- this.isSdcClientAutoManaged = isClientAutoManaged;\r
+ SdcSingleControllerConfiguration sdcSingleConfig, IDistributionClient distributionClient) {\r
+ this.distributionClient = distributionClient;\r
+ isSdcClientAutoManaged = (distributionClient == null);\r
this.sdcConfig = sdcSingleConfig;\r
this.refProp = clampProp;\r
this.csarInstaller = csarInstaller;\r
* This method initializes the SDC Controller and the SDC Client.\r
*\r
* @throws SdcControllerException\r
- * It throws an exception if the SDC Client cannot be\r
- * instantiated or if an init attempt is done when already\r
- * initialized\r
+ * It throws an exception if the SDC Client cannot be instantiated or if\r
+ * an init attempt is done when already initialized\r
* @throws SdcParametersException\r
- * If there is an issue with the parameters provided\r
+ * If there is an issue with the parameters provided\r
*/\r
public void initSdc() throws SdcControllerException {\r
logger.info("Attempt to initialize the SDC Controller: " + sdcConfig.getSdcControllerName());\r
if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {\r
logger.error("SDC distribution client init failed with reason:" + result.getDistributionMessageResult());\r
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);\r
- throw new SdcControllerException("Initialization of the SDC Controller failed with reason: "\r
- + result.getDistributionMessageResult());\r
+ throw new SdcControllerException(\r
+ "Initialization of the SDC Controller failed with reason: " + result.getDistributionMessageResult());\r
}\r
logger.info("SDC Controller successfully initialized: " + sdcConfig.getSdcControllerName());\r
logger.info("Attempt to start the SDC Controller: " + sdcConfig.getSdcControllerName());\r
logger.error("SDC distribution client start failed with reason:" + result.getDistributionMessageResult());\r
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);\r
throw new SdcControllerException(\r
- "Startup of the SDC Controller failed with reason: " + result.getDistributionMessageResult());\r
+ "Startup of the SDC Controller failed with reason: " + result.getDistributionMessageResult());\r
}\r
logger.info("SDC Controller successfully started: " + sdcConfig.getSdcControllerName());\r
this.changeControllerStatus(SdcSingleControllerStatus.IDLE);\r
* This method closes the SDC Controller and the SDC Client.\r
*\r
* @throws SdcControllerException\r
- * It throws an exception if the SDC Client cannot be closed\r
- * because it's currently BUSY in processing notifications.\r
+ * It throws an exception if the SDC Client cannot be closed because\r
+ * it's currently BUSY in processing notifications.\r
*/\r
public void closeSdc() throws SdcControllerException {\r
if (this.getControllerStatus() == SdcSingleControllerStatus.BUSY) {\r
}\r
\r
private void sendAllNotificationForCsarHandler(INotificationData iNotif, CsarHandler csar,\r
- NotificationType notificationType, DistributionStatusEnum distributionStatus, String errorMessage) {\r
+ NotificationType notificationType, DistributionStatusEnum distributionStatus, String errorMessage) {\r
if (csar != null) {\r
// Notify for the CSAR\r
this.sendSdcNotification(notificationType, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), distributionStatus, errorMessage,\r
- System.currentTimeMillis());\r
+ sdcConfig.getConsumerID(), iNotif.getDistributionID(), distributionStatus, errorMessage,\r
+ System.currentTimeMillis());\r
// Notify for all VF resources found\r
for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {\r
// Normally always 1 artifact in resource for Clamp as we\r
// specified\r
// only VF_METADATA type\r
this.sendSdcNotification(notificationType,\r
- blueprint.getValue().getResourceAttached().getArtifacts().get(0).getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), distributionStatus, errorMessage,\r
- System.currentTimeMillis());\r
+ blueprint.getValue().getResourceAttached().getArtifacts().get(0).getArtifactURL(),\r
+ sdcConfig.getConsumerID(), iNotif.getDistributionID(), distributionStatus, errorMessage,\r
+ System.currentTimeMillis());\r
}\r
} else {\r
this.sendSdcNotification(notificationType, null, sdcConfig.getConsumerID(), iNotif.getDistributionID(),\r
- distributionStatus, errorMessage, System.currentTimeMillis());\r
+ distributionStatus, errorMessage, System.currentTimeMillis());\r
}\r
}\r
\r
/**\r
* This method processes the notification received from Sdc.\r
- * \r
+ *\r
* @param iNotif\r
- * The INotificationData\r
+ * The INotificationData\r
*/\r
public void treatNotification(INotificationData iNotif) {\r
CsarHandler csar = null;\r
logger.info("Notification received for service UUID:" + iNotif.getServiceUUID());\r
this.changeControllerStatus(SdcSingleControllerStatus.BUSY);\r
csar = new CsarHandler(iNotif, this.sdcConfig.getSdcControllerName(),\r
- refProp.getStringValue(CONFIG_SDC_FOLDER));\r
+ refProp.getStringValue(CONFIG_SDC_FOLDER));\r
csar.save(downloadTheArtifact(csar.getArtifactElement()));\r
if (csarInstaller.isCsarAlreadyDeployed(csar)) {\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
- DistributionStatusEnum.ALREADY_DOWNLOADED, null);\r
+ DistributionStatusEnum.ALREADY_DOWNLOADED, null);\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
- DistributionStatusEnum.ALREADY_DEPLOYED, null);\r
+ DistributionStatusEnum.ALREADY_DEPLOYED, null);\r
} else {\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
- DistributionStatusEnum.DOWNLOAD_OK, null);\r
+ DistributionStatusEnum.DOWNLOAD_OK, null);\r
csarInstaller.installTheCsar(csar);\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
- DistributionStatusEnum.DEPLOY_OK, null);\r
+ DistributionStatusEnum.DEPLOY_OK, null);\r
}\r
} catch (SdcArtifactInstallerException | SdcToscaParserException e) {\r
logger.error("SdcArtifactInstallerException exception caught during the notification processing", e);\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
- DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
+ DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
} catch (SdcDownloadException | CsarHandlerException e) {\r
logger.error("SdcDownloadException exception caught during the notification processing", e);\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
- DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage());\r
+ DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage());\r
} catch (InterruptedException e) {\r
logger.error("Interrupt exception caught during the notification processing", e);\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
- DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
+ DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
Thread.currentThread().interrupt();\r
} catch (RuntimeException e) {\r
logger.error("Unexpected exception caught during the notification processing", e);\r
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
- DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
+ DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
} finally {\r
this.changeControllerStatus(SdcSingleControllerStatus.IDLE);\r
}\r
}\r
\r
private IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact) throws SdcDownloadException {\r
- logger.info("Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "\r
- + artifact.getArtifactUUID());\r
+ logger.info(\r
+ "Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: " + artifact.getArtifactUUID());\r
IDistributionClientDownloadResult downloadResult;\r
try {\r
downloadResult = distributionClient.download(artifact);\r
}\r
if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult())) {\r
logger.info("Successfully downloaded the artifact " + artifact.getArtifactURL() + " UUID "\r
- + artifact.getArtifactUUID() + "Size of payload " + downloadResult.getArtifactPayload().length);\r
+ + artifact.getArtifactUUID() + "Size of payload " + downloadResult.getArtifactPayload().length);\r
} else {\r
- throw new SdcDownloadException("Artifact " + artifact.getArtifactName()\r
- + " could not be downloaded from SDC URL " + artifact.getArtifactURL() + " UUID "\r
- + artifact.getArtifactUUID() + ")" + System.lineSeparator() + "Error message is "\r
- + downloadResult.getDistributionMessageResult() + System.lineSeparator());\r
+ throw new SdcDownloadException(\r
+ "Artifact " + artifact.getArtifactName() + " could not be downloaded from SDC URL "\r
+ + artifact.getArtifactURL() + " UUID " + artifact.getArtifactUUID() + ")" + System.lineSeparator()\r
+ + "Error message is " + downloadResult.getDistributionMessageResult() + System.lineSeparator());\r
}\r
return downloadResult;\r
}\r
\r
private void sendSdcNotification(NotificationType notificationType, String artifactURL, String consumerID,\r
- String distributionID, DistributionStatusEnum status, String errorReason, long timestamp) {\r
+ String distributionID, DistributionStatusEnum status, String errorReason, long timestamp) {\r
String event = "Sending " + notificationType.name() + "(" + status.name() + ")"\r
- + " notification to SDC for artifact:" + artifactURL;\r
+ + " notification to SDC for artifact:" + artifactURL;\r
if (errorReason != null) {\r
event = event + "(" + errorReason + ")";\r
}\r
String action = "";\r
try {\r
IDistributionStatusMessage message = new DistributionStatusMessage(artifactURL, consumerID, distributionID,\r
- status, timestamp);\r
+ status, timestamp);\r
switch (notificationType) {\r
- case DOWNLOAD:\r
- this.sendDownloadStatus(message, errorReason);\r
- action = "sendDownloadStatus";\r
- break;\r
- case DEPLOY:\r
- this.sendDeploymentStatus(message, errorReason);\r
- action = "sendDeploymentdStatus";\r
- break;\r
- default:\r
- break;\r
+ case DOWNLOAD:\r
+ this.sendDownloadStatus(message, errorReason);\r
+ action = "sendDownloadStatus";\r
+ break;\r
+ case DEPLOY:\r
+ this.sendDeploymentStatus(message, errorReason);\r
+ action = "sendDeploymentdStatus";\r
+ break;\r
+ default:\r
+ break;\r
}\r
} catch (RuntimeException e) {\r
logger.warn("Unable to send the SDC Notification (" + action + ") due to an exception", e);\r