* limitations under the License.\r
* ============LICENSE_END============================================\r
* ===================================================================\r
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * \r
*/\r
\r
package org.onap.clamp.clds.sdc.controller;\r
import com.att.eelf.configuration.EELFManager;\r
\r
import java.util.Date;\r
+import java.util.Map.Entry;\r
import java.util.concurrent.ThreadLocalRandom;\r
\r
import org.onap.clamp.clds.config.ClampProperties;\r
import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;\r
import org.onap.clamp.clds.exception.sdc.controller.SdcDownloadException;\r
import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;\r
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;\r
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;\r
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;\r
import org.onap.clamp.clds.util.LoggingUtils;\r
@Override\r
public void activateCallback(INotificationData iNotif) {\r
Date startTime = new Date();\r
- String event = "Receive a callback notification in SDC, nb of resources: " + iNotif.getResources().size();\r
- logger.debug(event);\r
+ logger.info("Receive a callback notification in SDC, nb of resources: " + iNotif.getResources().size());\r
sdcController.treatNotification(iNotif);\r
LoggingUtils.setTimeContext(startTime, new Date());\r
LoggingUtils.setResponseContext("0", "SDC Notification received and processed successfully",\r
* If there is an issue with the parameters provided\r
*/\r
public void initSdc() throws SdcControllerException {\r
- logger.debug("Attempt to initialize the SDC Controller");\r
+ logger.info("Attempt to initialize the SDC Controller: " + sdcConfig.getSdcControllerName());\r
if (this.getControllerStatus() != SdcSingleControllerStatus.STOPPED) {\r
throw new SdcControllerException("The controller is already initialized, call the closeSDC method first");\r
}\r
throw new SdcControllerException("Initialization of the SDC Controller failed with reason: "\r
+ result.getDistributionMessageResult());\r
}\r
+ logger.info("SDC Controller successfully initialized: " + sdcConfig.getSdcControllerName());\r
+ logger.info("Attempt to start the SDC Controller: " + sdcConfig.getSdcControllerName());\r
result = this.distributionClient.start();\r
if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {\r
- logger.debug("SDC distribution client start failed with reason:" + result.getDistributionMessageResult());\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
}\r
+ logger.info("SDC Controller successfully started: " + sdcConfig.getSdcControllerName());\r
this.changeControllerStatus(SdcSingleControllerStatus.IDLE);\r
}\r
\r
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);\r
}\r
\r
+ private void sendAllNotificationForCsarHandler(INotificationData iNotif, CsarHandler csar,\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
+ // 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
+ }\r
+ } else {\r
+ this.sendSdcNotification(notificationType, null, sdcConfig.getConsumerID(), iNotif.getDistributionID(),\r
+ distributionStatus, errorMessage, System.currentTimeMillis());\r
+ }\r
+ }\r
+\r
/**\r
* This method processes the notification received from Sdc.\r
* \r
public void treatNotification(INotificationData iNotif) {\r
CsarHandler csar = null;\r
try {\r
- // wait for a random time, so that 2 running Clamp will not treat the same Notification at the same time \r
- int i = ThreadLocalRandom.current().nextInt(1, 5);\r
- Thread.sleep(i * 1000);\r
-\r
+ // wait for a random time, so that 2 running Clamp will not treat\r
+ // the same Notification at the same time\r
+ Thread.sleep(ThreadLocalRandom.current().nextInt(1, 10) * 1000L);\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
csar.save(downloadTheArtifact(csar.getArtifactElement()));\r
if (csarInstaller.isCsarAlreadyDeployed(csar)) {\r
- this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(),\r
- DistributionStatusEnum.ALREADY_DOWNLOADED, null, System.currentTimeMillis());\r
- this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.ALREADY_DEPLOYED,\r
- null, System.currentTimeMillis());\r
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
+ DistributionStatusEnum.ALREADY_DOWNLOADED, null);\r
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+ DistributionStatusEnum.ALREADY_DEPLOYED, null);\r
} else {\r
- this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_OK, null,\r
- System.currentTimeMillis());\r
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
+ DistributionStatusEnum.DOWNLOAD_OK, null);\r
csarInstaller.installTheCsar(csar);\r
- this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_OK, null,\r
- System.currentTimeMillis());\r
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+ DistributionStatusEnum.DEPLOY_OK, null);\r
}\r
- } catch (SdcArtifactInstallerException e) {\r
+ } catch (SdcArtifactInstallerException | SdcToscaParserException e) {\r
logger.error("SdcArtifactInstallerException exception caught during the notification processing", e);\r
- this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,\r
- e.getMessage(), System.currentTimeMillis());\r
- } catch (SdcDownloadException e) {\r
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+ DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
+ } catch (SdcDownloadException | CsarHandlerException e) {\r
logger.error("SdcDownloadException exception caught during the notification processing", e);\r
- this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR,\r
- e.getMessage(), System.currentTimeMillis());\r
- } catch (CsarHandlerException e) {\r
- logger.error("CsarHandlerException exception caught during the notification processing", e);\r
- this.sendSdcNotification(NotificationType.DOWNLOAD, null, sdcConfig.getConsumerID(),\r
- iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(),\r
- System.currentTimeMillis());\r
- } catch (SdcToscaParserException e) {\r
- logger.error("SdcToscaParserException exception caught during the notification processing", e);\r
- this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
- sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,\r
- e.getMessage(), System.currentTimeMillis());\r
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\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
+ 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
} finally {\r
this.changeControllerStatus(SdcSingleControllerStatus.IDLE);\r
}\r
}\r
\r
private IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact) throws SdcDownloadException {\r
- logger.debug("Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "\r
+ logger.info("Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "\r
+ artifact.getArtifactUUID());\r
IDistributionClientDownloadResult downloadResult;\r
try {\r