2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.core.converter.impl.pnfd;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.List;
26 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
27 import org.openecomp.core.converter.ServiceTemplateReaderService;
28 import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
29 import org.openecomp.core.converter.pnfd.model.Transformation;
30 import org.openecomp.core.converter.pnfd.model.TransformationBlock;
31 import org.openecomp.core.converter.pnfd.model.TransformationDescription;
32 import org.openecomp.sdc.logging.api.Logger;
33 import org.openecomp.sdc.logging.api.LoggerFactory;
36 * Engine that manages the PNF Descriptor transformation process.
38 public abstract class AbstractPnfdTransformationEngine implements PnfdTransformationEngine {
40 private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPnfdTransformationEngine.class);
42 protected final ServiceTemplate templateTo;
43 protected final ServiceTemplateReaderService templateFrom;
44 private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader =
45 new PnfdTransformationDescriptorReader();
46 protected TransformationDescription transformationDescription;
47 protected Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap;
48 private final String descriptorResourcePath;
50 public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom,
51 final ServiceTemplate templateTo) {
52 this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml");
55 //used for tests purposes
56 AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom,
57 final ServiceTemplate templateTo,
58 final String descriptorResourcePath) {
59 this.templateFrom = templateFrom;
60 this.templateTo = templateTo;
61 this.descriptorResourcePath = descriptorResourcePath;
65 * Gets and Reads the transformation description yaml file.
67 protected void readDefinition() {
68 try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath)) {
69 if (resourceAsStream == null) {
70 if (LOGGER.isErrorEnabled()) {
71 LOGGER.error("Could not find resource '{}'", descriptorResourcePath);
75 transformationDescription = pnfdTransformationDescriptorReader.parse(resourceAsStream);
76 } catch (final IOException e) {
77 LOGGER.error("Could not find resource '{}'", descriptorResourcePath, e);
82 * Executes all transformations specified in the descriptor.
84 protected abstract void executeTransformations();