2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * 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=========================================================
21 package org.onap.sdc.generator.impl;
23 import static org.onap.sdc.generator.util.ArtifactGeneratorUtil.logError;
25 import org.onap.sdc.generator.data.GeneratorConstants;
26 import org.onap.sdc.generator.util.ArtifactGeneratorUtil;
27 import org.openecomp.sdc.logging.api.Logger;
28 import org.openecomp.sdc.logging.api.LoggerFactory;
29 import org.onap.sdc.generator.GeneratorManager;
30 import org.onap.sdc.generator.GeneratorTask;
31 import org.onap.sdc.generator.data.Artifact;
32 import org.onap.sdc.generator.data.GenerationData;
33 import org.onap.sdc.generator.intf.ArtifactGenerator;
34 import org.onap.sdc.generator.service.ArtifactGenerationService;
36 import java.util.List;
38 import java.util.concurrent.ForkJoinPool;
41 * Artifact Generation Service implementation class.
43 public class ArtifactGenerationServiceImpl implements ArtifactGenerationService {
45 private static Logger log =
46 LoggerFactory.getLogger(ArtifactGenerationServiceImpl.class.getName());
49 * Artifact generator method.
51 * @param input List of input files as {@link Artifact} models
52 * @param overridingConfiguration Configuration data for invoking generators
53 * @param additionalParams Additional Parameters
54 * @return Generated artifacts/Error data in a {@link GenerationData} object
57 public GenerationData generateArtifact(List<Artifact> input, String overridingConfiguration,
58 Map<String, String> additionalParams) {
60 //Initialize artifact generation logging context
61 ArtifactGeneratorUtil.initializeLoggingContext();
63 List<ArtifactGenerator> generatorsToBeUsed =
64 GeneratorManager.getActiveArtifactGenerators(overridingConfiguration);
65 if (generatorsToBeUsed.size() > 0) {
66 return ForkJoinPool.commonPool().invoke(new GeneratorTask(generatorsToBeUsed, input,
69 return new GenerationData();
71 } catch (IllegalArgumentException iae) {
72 //Invalid client configuration
74 .logError(GeneratorConstants.GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED, iae);
75 GenerationData errorData = new GenerationData();
76 errorData.add(GeneratorConstants.GENERATOR_INVOCATION_ERROR_CODE, iae.getMessage());
78 } catch (Exception ex) {
80 .logError(GeneratorConstants.GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED, ex);
81 GenerationData errorData = new GenerationData();
82 errorData.add(GeneratorConstants.GENERATOR_INVOCATION_ERROR_CODE,
83 GeneratorConstants.GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED);