aaab8d81fb4c83c9ee16fddeee30fafb3588281f
[ccsdk/cds.git] /
1 /*
2  * Copyright (C) 2019 Bell Canada. All rights reserved.
3  *
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.
7  */
8
9 package org.onap.ccsdk.cds.cdssdclistener;
10
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;
23
24 @Component
25 public class CdsSdcListenerNotificationCallback implements INotificationCallback {
26
27     @Autowired
28     private CdsSdcListenerDto cdsSdcListenerDto;
29
30     @Autowired
31     private ListenerServiceImpl listenerService;
32
33     private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerNotificationCallback.class);
34
35     @Override
36     public void activateCallback(INotificationData notificationData) {
37         LOGGER.info(notificationData.getDistributionID(), "The UUID generated by SDC {}");
38         processNotification(notificationData);
39     }
40
41     private void processNotification(INotificationData notificationData) {
42         final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient();
43         notificationData.getServiceArtifacts()
44             .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient));
45     }
46
47     /**
48      * Download the TOSCA CSAR artifact.
49      *
50      * @param info - Artifact information
51      * @param distributionClient - SDC distribution client
52      */
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);
58
59             // Download the artifact
60             IDistributionClientDownloadResult result = distributionClient.download(info);
61
62             if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
63                 LOGGER.error("Failed to download the artifact from : {} due to {} ", url,
64                     result.getDistributionActionResult());
65             } else {
66                 // TODO Store the CSAR into CSARArchive path and extract the Blueprint using ListenerServiceImpl.extractBluePrint
67             }
68         }
69     }
70 }