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.modelloader.config.ModelLoaderConfig;
26 import org.onap.aai.modelloader.entity.Artifact;
27 import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler;
28 import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
29 import org.onap.aai.modelloader.restclient.AaiRestClient;
30 import org.openecomp.sdc.api.IDistributionClient;
31 import org.openecomp.sdc.api.notification.IArtifactInfo;
32 import org.openecomp.sdc.api.notification.INotificationData;
35 * This class is responsible for deploying model and catalog artifacts.
37 public class ArtifactDeploymentManager {
39 private IDistributionClient client;
40 private ModelLoaderConfig config;
41 private ModelArtifactHandler modelArtifactHandler;
42 private VnfCatalogArtifactHandler vnfCatalogArtifactHandler;
43 private NotificationPublisher notificationPublisher;
45 public ArtifactDeploymentManager(IDistributionClient client, ModelLoaderConfig config) {
51 * Deploys model and catalog artifacts to A&AI
53 * @param data data about the notification that is being processed
54 * @param artifacts the specific artifacts found in the data.
55 * @param modelArtifacts collection of artifacts that represent yml files found in a TOSCA_CSAR file that have been
56 * converted to XML and also those for model query specs
57 * @param catalogArtifacts collection of artifacts that represent vnf catalog files
58 * @return boolean <code>true</code> if all deployments were successful otherwise <code>false</code>
60 public boolean deploy(final INotificationData data, final List<IArtifactInfo> artifacts,
61 final List<Artifact> modelArtifacts, final List<Artifact> catalogArtifacts) {
63 AaiRestClient aaiClient = new AaiRestClient(config);
64 String distributionId = data.getDistributionID();
66 List<Artifact> completedArtifacts = new ArrayList<>();
67 boolean deploySuccess =
68 getModelArtifactHandler().pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
71 getModelArtifactHandler().rollback(completedArtifacts, distributionId, aaiClient);
73 List<Artifact> completedImageData = new ArrayList<>();
74 deploySuccess = getVnfCatalogArtifactHandler().pushArtifacts(catalogArtifacts, distributionId,
75 completedImageData, aaiClient);
77 getModelArtifactHandler().rollback(completedArtifacts, distributionId, aaiClient);
78 getVnfCatalogArtifactHandler().rollback(completedImageData, distributionId, aaiClient);
82 publishNotifications(data, "TOSCA_CSAR", artifacts, deploySuccess);
87 private void publishNotifications(INotificationData data, String filterType, List<IArtifactInfo> artifacts,
88 boolean deploymentSuccess) {
89 if (deploymentSuccess) {
90 artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType()))
91 .forEach(a -> getNotificationPublisher().publishDeploySuccess(client, data, a));
92 getNotificationPublisher().publishComponentSuccess(client, data);
94 artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType()))
95 .forEach(a -> getNotificationPublisher().publishDeployFailure(client, data, a));
96 getNotificationPublisher().publishComponentFailure(client, data, "deploy failure");
100 private ModelArtifactHandler getModelArtifactHandler() {
101 if (modelArtifactHandler == null) {
102 modelArtifactHandler = new ModelArtifactHandler(config);
105 return modelArtifactHandler;
108 private NotificationPublisher getNotificationPublisher() {
109 if (notificationPublisher == null) {
110 notificationPublisher = new NotificationPublisher();
113 return notificationPublisher;
116 private VnfCatalogArtifactHandler getVnfCatalogArtifactHandler() {
117 if (vnfCatalogArtifactHandler == null) {
118 this.vnfCatalogArtifactHandler = new VnfCatalogArtifactHandler(config);
121 return vnfCatalogArtifactHandler;