Upgrade spring-boot to 2.7.X in model-loader
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / entity / model / ModelArtifactHandler.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.modelloader.entity.model;
22
23 import java.util.List;
24 import org.onap.aai.cl.api.Logger;
25 import org.onap.aai.cl.eelf.LoggerFactory;
26 import org.onap.aai.modelloader.config.ModelLoaderConfig;
27 import org.onap.aai.modelloader.entity.Artifact;
28 import org.onap.aai.modelloader.entity.ArtifactHandler;
29 import org.onap.aai.modelloader.restclient.AaiRestClient;
30 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
31 import org.springframework.stereotype.Service;
32
33 @Service
34 public class ModelArtifactHandler extends ArtifactHandler {
35
36     private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifactHandler.class.getName());
37
38     public ModelArtifactHandler(ModelLoaderConfig config) {
39         super(config);
40     }
41
42     @Override
43     public boolean pushArtifacts(List<Artifact> artifacts, String distributionID, List<Artifact> completedArtifacts,
44             AaiRestClient aaiClient) {
45         ModelSorter modelSorter = new ModelSorter();
46         List<Artifact> sortedModelArtifacts;
47         try {
48             sortedModelArtifacts = modelSorter.sort(artifacts);
49         } catch (BabelArtifactParsingException ex) {
50             logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve models: " + ex.getMessage());
51             return false;
52         }
53
54         // Push the ordered list of model artifacts to A&AI. If one fails, we need to roll back the changes.
55         for (Artifact art : sortedModelArtifacts) {
56             AbstractModelArtifact model = (AbstractModelArtifact) art;
57             if (!model.push(aaiClient, config, distributionID, completedArtifacts)) {
58                 return false;
59             }
60         }
61
62         return true;
63     }
64
65     @Override
66     public void rollback(List<Artifact> completedArtifacts, String distributionId, AaiRestClient aaiClient) {
67         for (Artifact artifactToDelete : completedArtifacts) {
68             AbstractModelArtifact model = (AbstractModelArtifact) artifactToDelete;
69             model.rollbackModel(aaiClient, config, distributionId);
70         }
71     }
72 }