2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.modelloader.notification;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.cl.mdc.MdcContext;
29 import org.onap.aai.modelloader.entity.Artifact;
30 import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor;
31 import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
32 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
33 import org.onap.sdc.api.IDistributionClient;
34 import org.onap.sdc.api.consumer.INotificationCallback;
35 import org.onap.sdc.api.notification.IArtifactInfo;
36 import org.onap.sdc.api.notification.INotificationData;
38 import org.springframework.stereotype.Component;
41 public class EventCallback implements INotificationCallback {
42 private static Logger logger = LoggerFactory.getInstance().getLogger(EventCallback.class.getName());
43 private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(EventCallback.class.getName());
45 private final ArtifactDeploymentManager artifactDeploymentManager;
46 private final ArtifactDownloadManager artifactDownloadManager;
47 private final NotificationPublisher notificationPublisher;
48 private final IDistributionClient client;
50 public EventCallback(IDistributionClient client, ArtifactDeploymentManager artifactDeploymentManager, ArtifactDownloadManager artifactDownloadManager, NotificationPublisher notificationPublisher) {
51 this.artifactDeploymentManager = artifactDeploymentManager;
52 this.artifactDownloadManager = artifactDownloadManager;
53 this.notificationPublisher = notificationPublisher;
58 public void activateCallback(INotificationData data) {
59 MdcContext.initialize(data.getDistributionID(), "ModelLoader", "", "Event-Bus", "");
60 logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received distribution " + data.getDistributionID());
62 List<IArtifactInfo> artifacts = new ArtifactInfoExtractor().extract(data);
63 List<Artifact> catalogArtifacts = new ArrayList<>();
64 List<Artifact> modelArtifacts = new ArrayList<>();
67 artifactDownloadManager.downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
70 success = artifactDeploymentManager.deploy(data, modelArtifacts, catalogArtifacts);
73 String statusString = success ? "SUCCESS" : "FAILURE";
74 auditLogger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
75 "Processed distribution " + data.getDistributionID() + " (" + statusString + ")");
77 publishNotifications(data, "TOSCA_CSAR", artifacts, success);
83 private void publishNotifications(INotificationData data, String filterType, List<IArtifactInfo> artifacts,
84 boolean deploymentSuccess) {
85 if (deploymentSuccess) {
86 artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType()))
87 .forEach(a -> notificationPublisher.publishDeploySuccess(client, data, a));
88 notificationPublisher.publishComponentSuccess(client, data);
90 artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType()))
91 .forEach(a -> notificationPublisher.publishDeployFailure(client, data, a));
92 notificationPublisher.publishComponentFailure(client, data, "deploy failure");