2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
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;
25 import org.onap.aai.cl.api.Logger;
26 import org.onap.aai.cl.eelf.LoggerFactory;
27 import org.onap.aai.cl.mdc.MdcContext;
28 import org.onap.aai.modelloader.config.ModelLoaderConfig;
29 import org.onap.aai.modelloader.entity.Artifact;
30 import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor;
31 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
32 import org.openecomp.sdc.api.IDistributionClient;
33 import org.openecomp.sdc.api.consumer.INotificationCallback;
34 import org.openecomp.sdc.api.notification.IArtifactInfo;
35 import org.openecomp.sdc.api.notification.INotificationData;
38 public class EventCallback implements INotificationCallback {
39 private static Logger logger = LoggerFactory.getInstance().getLogger(EventCallback.class.getName());
40 private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(EventCallback.class.getName());
42 private ArtifactDeploymentManager artifactDeploymentManager;
43 private ArtifactDownloadManager artifactDownloadManager;
44 private IDistributionClient client;
45 private ModelLoaderConfig config;
47 public EventCallback(IDistributionClient client, ModelLoaderConfig config) {
53 public void activateCallback(INotificationData data) {
54 MdcContext.initialize(data.getDistributionID(), "ModelLoader", "", "Event-Bus", "");
55 logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received distribution " + data.getDistributionID());
57 List<IArtifactInfo> artifacts = new ArtifactInfoExtractor().extract(data);
58 List<Artifact> catalogArtifacts = new ArrayList<>();
59 List<Artifact> modelArtifacts = new ArrayList<>();
61 boolean success = getArtifactDownloadManager()
62 .downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
65 success = getArtifactDeploymentManager().deploy(data, artifacts, modelArtifacts, catalogArtifacts);
68 String statusString = success ? "SUCCESS" : "FAILURE";
69 auditLogger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
70 "Processed distribution " + data.getDistributionID() + " (" + statusString + ")");
74 private ArtifactDeploymentManager getArtifactDeploymentManager() {
75 if (artifactDeploymentManager == null) {
76 artifactDeploymentManager = new ArtifactDeploymentManager(client, config);
79 return artifactDeploymentManager;
82 private ArtifactDownloadManager getArtifactDownloadManager() {
83 if (artifactDownloadManager == null) {
84 artifactDownloadManager = new ArtifactDownloadManager(client, config);
87 return artifactDownloadManager;