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;
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.restclient.BabelServiceClientFactory;
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;
39 public class EventCallback implements INotificationCallback {
40 private static Logger logger = LoggerFactory.getInstance().getLogger(EventCallback.class.getName());
41 private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(EventCallback.class.getName());
43 private ArtifactDeploymentManager artifactDeploymentManager;
44 private ArtifactDownloadManager artifactDownloadManager;
45 private IDistributionClient client;
46 private ModelLoaderConfig config;
48 public EventCallback(IDistributionClient client, ModelLoaderConfig config) {
54 public void activateCallback(INotificationData data) {
55 MdcContext.initialize(data.getDistributionID(), "ModelLoader", "", "Event-Bus", "");
56 logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received distribution " + data.getDistributionID());
58 List<IArtifactInfo> artifacts = new ArtifactInfoExtractor().extract(data);
59 List<Artifact> catalogArtifacts = new ArrayList<>();
60 List<Artifact> modelArtifacts = new ArrayList<>();
63 getArtifactDownloadManager().downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
66 success = getArtifactDeploymentManager().deploy(data, artifacts, modelArtifacts, catalogArtifacts);
69 String statusString = success ? "SUCCESS" : "FAILURE";
70 auditLogger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
71 "Processed distribution " + data.getDistributionID() + " (" + statusString + ")");
75 private ArtifactDeploymentManager getArtifactDeploymentManager() {
76 if (artifactDeploymentManager == null) {
77 artifactDeploymentManager = new ArtifactDeploymentManager(client, config);
80 return artifactDeploymentManager;
83 private ArtifactDownloadManager getArtifactDownloadManager() {
84 if (artifactDownloadManager == null) {
85 artifactDownloadManager = new ArtifactDownloadManager(client, config, new BabelServiceClientFactory());
88 return artifactDownloadManager;