X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FEventCallback.java;h=d7bccbac63720abe479284809b866e8a22a728fd;hb=343089923ca1dafb6a530b77718df5e82926b557;hp=fe6bf7b0400e04b886dea728cd1b7e58737a9e19;hpb=3a1f764b762a91e917e9e14a00c4a7ff3c4e0745;p=aai%2Fmodel-loader.git diff --git a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java index fe6bf7b..d7bccba 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java +++ b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java @@ -1,39 +1,41 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * Copyright © 2017-2018 European Software Marketing Ltd. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; import java.util.ArrayList; import java.util.List; + import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.cl.mdc.MdcContext; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor; -import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; +import org.onap.aai.modelloader.service.ArtifactDeploymentManager; +import org.onap.aai.modelloader.service.BabelServiceClientFactory; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.INotificationCallback; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.INotificationCallback; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; import org.slf4j.MDC; public class EventCallback implements INotificationCallback { @@ -42,12 +44,15 @@ public class EventCallback implements INotificationCallback { private ArtifactDeploymentManager artifactDeploymentManager; private ArtifactDownloadManager artifactDownloadManager; + private NotificationPublisher notificationPublisher; private IDistributionClient client; private ModelLoaderConfig config; + private BabelServiceClientFactory babelServiceClientFactory; - public EventCallback(IDistributionClient client, ModelLoaderConfig config) { + public EventCallback(IDistributionClient client, ModelLoaderConfig config, BabelServiceClientFactory babelServiceClientFactory) { this.client = client; this.config = config; + this.babelServiceClientFactory = babelServiceClientFactory; } @Override @@ -63,27 +68,54 @@ public class EventCallback implements INotificationCallback { getArtifactDownloadManager().downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts); if (success) { - success = getArtifactDeploymentManager().deploy(data, artifacts, modelArtifacts, catalogArtifacts); + success = getArtifactDeploymentManager().deploy(data, modelArtifacts, catalogArtifacts); } String statusString = success ? "SUCCESS" : "FAILURE"; auditLogger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Processed distribution " + data.getDistributionID() + " (" + statusString + ")"); + + publishNotifications(data, "TOSCA_CSAR", artifacts, success); + MDC.clear(); } + + private void publishNotifications(INotificationData data, String filterType, List artifacts, + boolean deploymentSuccess) { + if (deploymentSuccess) { + artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType())) + .forEach(a -> getNotificationPublisher().publishDeploySuccess(client, data, a)); + getNotificationPublisher().publishComponentSuccess(client, data); + } else { + artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType())) + .forEach(a -> getNotificationPublisher().publishDeployFailure(client, data, a)); + getNotificationPublisher().publishComponentFailure(client, data, "deploy failure"); + } + } + private ArtifactDeploymentManager getArtifactDeploymentManager() { if (artifactDeploymentManager == null) { - artifactDeploymentManager = new ArtifactDeploymentManager(client, config); + artifactDeploymentManager = new ArtifactDeploymentManager(config); } + return artifactDeploymentManager; } private ArtifactDownloadManager getArtifactDownloadManager() { if (artifactDownloadManager == null) { - artifactDownloadManager = new ArtifactDownloadManager(client, config, new BabelServiceClientFactory()); + artifactDownloadManager = new ArtifactDownloadManager(client, config, babelServiceClientFactory); } return artifactDownloadManager; } + + + private NotificationPublisher getNotificationPublisher() { + if (notificationPublisher == null) { + notificationPublisher = new NotificationPublisher(); + } + + return notificationPublisher; + } }