2 * Copyright (C) 2019 Bell Canada. All rights reserved.
4 * NOTICE: All the intellectual and technical concepts contained herein are
5 * proprietary to Bell Canada and are protected by trade secret or copyright law.
6 * Unauthorized copying of this file, via any medium is strictly prohibited.
9 package org.onap.ccsdk.cds.cdssdclistener;
11 import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
12 import java.util.Objects;
13 import org.onap.ccsdk.cds.cdssdclistener.service.ListenerServiceImpl;
14 import org.onap.sdc.api.IDistributionClient;
15 import org.onap.sdc.api.consumer.INotificationCallback;
16 import org.onap.sdc.api.notification.IArtifactInfo;
17 import org.onap.sdc.api.notification.INotificationData;
18 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Component;
25 public class CdsSdcListenerNotificationCallback implements INotificationCallback {
28 private CdsSdcListenerDto cdsSdcListenerDto;
31 private ListenerServiceImpl listenerService;
33 private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerNotificationCallback.class);
36 public void activateCallback(INotificationData notificationData) {
37 LOGGER.info(notificationData.getDistributionID(), "The UUID generated by SDC {}");
38 processNotification(notificationData);
41 private void processNotification(INotificationData notificationData) {
42 final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient();
43 notificationData.getServiceArtifacts()
44 .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient));
48 * Download the TOSCA CSAR artifact.
50 * @param info - Artifact information
51 * @param distributionClient - SDC distribution client
53 private void downloadCsarArtifacts(IArtifactInfo info, IDistributionClient distributionClient) {
54 final String url = info.getArtifactURL();
55 final String id = info.getArtifactUUID();
56 if (Objects.equals(info.getArtifactType(), CdsSdcListenerConfiguration.TOSCA_CSAR)) {
57 LOGGER.info("Trying to download the artifact from : {} and UUID is {} ", url, id);
59 // Download the artifact
60 IDistributionClientDownloadResult result = distributionClient.download(info);
62 if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
63 LOGGER.error("Failed to download the artifact from : {} due to {} ", url,
64 result.getDistributionActionResult());
66 // TODO Store the CSAR into CSARArchive path and extract the Blueprint using ListenerServiceImpl.extractBluePrint