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.entity.model;
23 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.ArtifactHandler;
28 import org.onap.aai.modelloader.restclient.AaiRestClient;
29 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
33 public class ModelArtifactHandler extends ArtifactHandler {
35 private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifactHandler.class.getName());
37 public ModelArtifactHandler(ModelLoaderConfig config) {
42 public boolean pushArtifacts(List<Artifact> artifacts, String distributionID, List<Artifact> completedArtifacts,
43 AaiRestClient aaiClient) {
44 ModelSorter modelSorter = new ModelSorter();
45 List<Artifact> sortedModelArtifacts;
47 sortedModelArtifacts = modelSorter.sort(artifacts);
48 } catch (RuntimeException ex) {
49 logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve models: " + ex.getMessage());
53 // Push the ordered list of model artifacts to A&AI. If one fails, we need to roll back the changes.
54 for (Artifact art : sortedModelArtifacts) {
55 AbstractModelArtifact model = (AbstractModelArtifact) art;
56 if (!model.push(aaiClient, config, distributionID, completedArtifacts)) {
65 public void rollback(List<Artifact> completedArtifacts, String distributionId, AaiRestClient aaiClient) {
66 for (Artifact artifactToDelete : completedArtifacts) {
67 AbstractModelArtifact model = (AbstractModelArtifact) artifactToDelete;
68 model.rollbackModel(aaiClient, config, distributionId);