import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
-import org.onap.clamp.clds.exception.policy.PolicyModelException;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;
* @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;
/**
* This method initializes the SDC Controller and the SDC Client.
*
- * @throws SdcControllerException It throws an exception if the SDC Client cannot be instantiated or if
- * an init attempt is done when already initialized
+ * @throws SdcControllerException It throws an exception if the SDC Client
+ * cannot be instantiated or if an init attempt
+ * is done when already initialized
*/
public void initSdc() throws SdcControllerException {
logger.info("Attempt to initialize the SDC Controller: " + sdcConfig.getSdcControllerName());
if (distributionClient == null) {
distributionClient = DistributionClientFactory.createDistributionClient();
}
- IDistributionClientResult result = distributionClient.init(sdcConfig,
- new SdcNotificationCallBack(this));
+ IDistributionClientResult result = distributionClient.init(sdcConfig, new SdcNotificationCallBack(this));
if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
logger.error("SDC distribution client init failed with reason:" + result.getDistributionMessageResult());
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);
- throw new SdcControllerException(
- "Initialization of the SDC Controller failed with reason: "
- + result.getDistributionMessageResult());
+ throw new SdcControllerException("Initialization of the SDC Controller failed with reason: "
+ + result.getDistributionMessageResult());
}
logger.info("SDC Controller successfully initialized: " + sdcConfig.getSdcControllerName());
logger.info("Attempt to start the SDC Controller: " + sdcConfig.getSdcControllerName());
}
/**
- * This method closes the SDC Controller and the SDC Client.
- *
- * @throws SdcControllerException It throws an exception if the SDC Client cannot be closed because
- * it's currently BUSY in processing notifications.
- */
+ * This method closes the SDC Controller and the SDC Client.
+ *
+ * @throws SdcControllerException It throws an exception if the SDC Client
+ * cannot be closed because it's currently BUSY
+ * in processing notifications.
+ */
public void closeSdc() throws SdcControllerException {
if (this.getControllerStatus() == SdcSingleControllerStatus.BUSY) {
throw new SdcControllerException("Cannot close the SDC controller as it's currently in BUSY state");
}
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(),
this.sendSdcNotification(notificationType,
blueprint.getValue().getResourceAttached().getArtifacts().get(0).getArtifactURL(),
sdcConfig.getConsumerID(), notificationData.getDistributionID(), distributionStatus,
- errorMessage,
- System.currentTimeMillis());
+ errorMessage, System.currentTimeMillis());
}
} else {
this.sendSdcNotification(notificationType, null, sdcConfig.getConsumerID(),
- notificationData.getDistributionID(),
- distributionStatus, errorMessage, System.currentTimeMillis());
+ notificationData.getDistributionID(), distributionStatus, errorMessage, System.currentTimeMillis());
}
}
logger.error("SdcDownloadException exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DOWNLOAD,
DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage());
- } catch (PolicyModelException e) {
- logger.error("PolicyModelException exception caught during the notification processing", e);
- sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY,
- DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
} catch (InterruptedException e) {
logger.error("Interrupt exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY,
logger.error("Unexpected exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(notificationData, csar, NotificationType.DEPLOY,
DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
- } finally {
+ } finally {
this.changeControllerStatus(SdcSingleControllerStatus.IDLE);
}
}
}
private IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact) throws SdcDownloadException {
- logger.info(
- "Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "
- + artifact.getArtifactUUID());
+ logger.info("Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "
+ + artifact.getArtifactUUID());
IDistributionClientDownloadResult downloadResult;
try {
downloadResult = distributionClient.download(artifact);
logger.info("Successfully downloaded the artifact " + artifact.getArtifactURL() + " UUID "
+ artifact.getArtifactUUID() + "Size of payload " + downloadResult.getArtifactPayload().length);
} else {
- throw new SdcDownloadException(
- "Artifact " + artifact.getArtifactName() + " could not be downloaded from SDC URL "
- + artifact.getArtifactURL() + " UUID " + artifact.getArtifactUUID() + ")"
- + System.lineSeparator()
- + "Error message is " + downloadResult.getDistributionMessageResult()
- + System.lineSeparator());
+ throw new SdcDownloadException("Artifact " + artifact.getArtifactName()
+ + " could not be downloaded from SDC URL " + artifact.getArtifactURL() + " UUID "
+ + artifact.getArtifactUUID() + ")" + System.lineSeparator() + "Error message is "
+ + downloadResult.getDistributionMessageResult() + System.lineSeparator());
}
return downloadResult;
}
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) {