2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.openecomp.modelloader.entity.model;
26 import org.openecomp.cl.api.Logger;
27 import org.openecomp.cl.eelf.LoggerFactory;
28 import org.openecomp.modelloader.config.ModelLoaderConfig;
29 import org.openecomp.modelloader.entity.Artifact;
30 import org.openecomp.modelloader.entity.ArtifactHandler;
31 import org.openecomp.modelloader.restclient.AaiRestClient;
32 import org.openecomp.modelloader.service.ModelLoaderMsgs;
34 import java.util.ArrayList;
35 import java.util.List;
38 public class ModelArtifactHandler extends ArtifactHandler {
40 private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifactHandler.class.getName());
42 public ModelArtifactHandler(ModelLoaderConfig config) {
47 public boolean pushArtifacts(List<Artifact> artifacts, String distributionID) {
48 ModelSorter modelSorter = new ModelSorter();
49 List<Artifact> sortedModelArtifacts;
51 sortedModelArtifacts = modelSorter.sort(artifacts);
53 catch (RuntimeException ex) {
54 logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve models: " + ex.getMessage());
58 // Push the ordered list of model artifacts to A&AI. If one fails, we need to roll back
60 List<AbstractModelArtifact> completedModels = new ArrayList<AbstractModelArtifact>();
61 AaiRestClient aaiClient = new AaiRestClient(config);
63 for (Artifact art : sortedModelArtifacts) {
64 AbstractModelArtifact model = (AbstractModelArtifact)art;
65 if (model.push(aaiClient, config, distributionID, completedModels) != true) {
66 for (AbstractModelArtifact modelToDelete : completedModels) {
67 modelToDelete.rollbackModel(aaiClient, config, distributionID);
77 // This method is used for the test REST interface to load models without an ASDC
78 public void loadModelTest(byte[] payload) {
79 List<Artifact> modelArtifacts = new ArrayList<Artifact>();
80 ModelArtifactParser parser = new ModelArtifactParser();
81 modelArtifacts.addAll(parser.parse(payload, "Test-Artifact"));
82 ModelSorter modelSorter = new ModelSorter();
83 List<Artifact> sortedModelArtifacts = modelSorter.sort(modelArtifacts);
84 pushArtifacts(sortedModelArtifacts, "Test-Distribution");