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
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP and OpenECOMP are trademarks
21 * and service marks of AT&T Intellectual Property.
23 package org.openecomp.modelloader.entity.model;
25 import org.openecomp.cl.api.Logger;
26 import org.openecomp.cl.eelf.LoggerFactory;
27 import org.openecomp.modelloader.config.ModelLoaderConfig;
28 import org.openecomp.modelloader.entity.Artifact;
29 import org.openecomp.modelloader.entity.ArtifactHandler;
30 import org.openecomp.modelloader.restclient.AaiRestClient;
31 import org.openecomp.modelloader.service.ModelLoaderMsgs;
33 import java.util.ArrayList;
34 import java.util.List;
37 public class ModelArtifactHandler extends ArtifactHandler {
39 private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifactHandler.class.getName());
41 public ModelArtifactHandler(ModelLoaderConfig config) {
46 public boolean pushArtifacts(List<Artifact> artifacts, String distributionID) {
47 ModelSorter modelSorter = new ModelSorter();
48 List<Artifact> sortedModelArtifacts;
50 sortedModelArtifacts = modelSorter.sort(artifacts);
52 catch (RuntimeException ex) {
53 logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve models: " + ex.getMessage());
57 // Push the ordered list of model artifacts to A&AI. If one fails, we need to roll back
59 List<AbstractModelArtifact> completedModels = new ArrayList<AbstractModelArtifact>();
60 AaiRestClient aaiClient = new AaiRestClient(config);
62 for (Artifact art : sortedModelArtifacts) {
63 AbstractModelArtifact model = (AbstractModelArtifact)art;
64 if (model.push(aaiClient, config, distributionID, completedModels) != true) {
65 for (AbstractModelArtifact modelToDelete : completedModels) {
66 modelToDelete.rollbackModel(aaiClient, config, distributionID);
76 // This method is used for the test REST interface to load models without an ASDC
77 public void loadModelTest(byte[] payload) {
78 List<Artifact> modelArtifacts = new ArrayList<Artifact>();
79 ModelArtifactParser parser = new ModelArtifactParser();
80 modelArtifacts.addAll(parser.parse(payload, "Test-Artifact"));
81 ModelSorter modelSorter = new ModelSorter();
82 List<Artifact> sortedModelArtifacts = modelSorter.sort(modelArtifacts);
83 pushArtifacts(sortedModelArtifacts, "Test-Distribution");