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.service;
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.onap.sdc.api.notification.INotificationData;
31 import org.springframework.stereotype.Component;
34 * This class is responsible for deploying model and catalog artifacts.
37 public class ArtifactDeploymentManager {
39 private final ModelLoaderConfig config;
40 private final ModelArtifactHandler modelArtifactHandler;
41 private final VnfCatalogArtifactHandler vnfCatalogArtifactHandler;
43 public ArtifactDeploymentManager(ModelLoaderConfig config, ModelArtifactHandler modelArtifactHandler, VnfCatalogArtifactHandler vnfCatalogArtifactHandler) {
45 this.modelArtifactHandler = modelArtifactHandler;
46 this.vnfCatalogArtifactHandler = vnfCatalogArtifactHandler;
50 * Deploys model and catalog artifacts to A&AI.
52 * @param data data about the notification that is being processed
53 * @param modelArtifacts collection of artifacts that represent yml files found in a TOSCA_CSAR file that have been
54 * converted to XML and also those for model query specs
55 * @param catalogArtifacts collection of artifacts that represent vnf catalog files
56 * @return boolean <code>true</code> if all deployments were successful otherwise <code>false</code>
58 public boolean deploy(final INotificationData data, final List<Artifact> modelArtifacts,
59 final List<Artifact> catalogArtifacts) {
61 AaiRestClient aaiClient = new AaiRestClient(config);
62 String distributionId = data.getDistributionID();
64 List<Artifact> completedArtifacts = new ArrayList<>();
65 boolean deploySuccess =
66 modelArtifactHandler.pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
69 modelArtifactHandler.rollback(completedArtifacts, distributionId, aaiClient);
71 List<Artifact> completedImageData = new ArrayList<>();
72 deploySuccess = vnfCatalogArtifactHandler.pushArtifacts(catalogArtifacts, distributionId,
73 completedImageData, aaiClient);
75 modelArtifactHandler.rollback(completedArtifacts, distributionId, aaiClient);
76 vnfCatalogArtifactHandler.rollback(completedImageData, distributionId, aaiClient);