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.openecomp.sdc.generator.impl;
23 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED;
24 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_INVOCATION_ERROR_CODE;
25 import static org.openecomp.sdc.generator.util.ArtifactGeneratorUtil.logError;
27 import org.openecomp.sdc.logging.api.Logger;
28 import org.openecomp.sdc.logging.api.LoggerFactory;
29 import org.openecomp.sdc.generator.GeneratorManager;
30 import org.openecomp.sdc.generator.GeneratorTask;
31 import org.openecomp.sdc.generator.data.Artifact;
32 import org.openecomp.sdc.generator.data.GenerationData;
33 import org.openecomp.sdc.generator.intf.ArtifactGenerator;
34 import org.openecomp.sdc.generator.service.ArtifactGenerationService;
35 import org.openecomp.sdc.generator.util.ArtifactGeneratorUtil;
37 import java.util.List;
39 import java.util.concurrent.ForkJoinPool;
42 * Artifact Generation Service implementation class.
44 public class ArtifactGenerationServiceImpl implements ArtifactGenerationService {
46 private static Logger log =
47 LoggerFactory.getLogger(ArtifactGenerationServiceImpl.class.getName());
50 * Artifact generator method.
52 * @param input List of input files as {@link Artifact} models
53 * @param overridingConfiguration Configuration data for invoking generators
54 * @param additionalParams Additional Parameters
55 * @return Generated artifacts/Error data in a {@link GenerationData} object
58 public GenerationData generateArtifact(List<Artifact> input, String overridingConfiguration,
59 Map<String, String> additionalParams) {
61 //Initialize artifact generation logging context
62 ArtifactGeneratorUtil.initializeLoggingContext();
64 List<ArtifactGenerator> generatorsToBeUsed =
65 GeneratorManager.getActiveArtifactGenerators(overridingConfiguration);
66 if (generatorsToBeUsed.size() > 0) {
67 return ForkJoinPool.commonPool().invoke(new GeneratorTask(generatorsToBeUsed, input,
70 return new GenerationData();
72 } catch (IllegalArgumentException iae) {
73 //Invalid client configuration
74 logError(GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED, iae);
75 GenerationData errorData = new GenerationData();
76 errorData.add(GENERATOR_INVOCATION_ERROR_CODE, iae.getMessage());
78 } catch (Exception ex) {
79 logError(GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED, ex);
80 GenerationData errorData = new GenerationData();
81 errorData.add(GENERATOR_INVOCATION_ERROR_CODE,
82 GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED);