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=========================================================
19 package org.openecomp.core.converter.impl.pnfd;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.List;
25 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
26 import org.openecomp.core.converter.ServiceTemplateReaderService;
27 import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
28 import org.openecomp.core.converter.pnfd.model.Transformation;
29 import org.openecomp.core.converter.pnfd.model.TransformationBlock;
30 import org.openecomp.core.converter.pnfd.model.TransformationDescription;
31 import org.openecomp.sdc.logging.api.Logger;
32 import org.openecomp.sdc.logging.api.LoggerFactory;
35 * Engine that manages the PNF Descriptor transformation process.
37 public abstract class AbstractPnfdTransformationEngine implements PnfdTransformationEngine {
39 private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPnfdTransformationEngine.class);
40 protected final ServiceTemplate templateTo;
41 protected final ServiceTemplateReaderService templateFrom;
42 private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader = new PnfdTransformationDescriptorReader();
43 private final String descriptorResourcePath;
44 protected TransformationDescription transformationDescription;
45 protected Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap;
47 public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) {
48 this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml");
51 //used for tests purposes
52 AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo,
53 final String descriptorResourcePath) {
54 this.templateFrom = templateFrom;
55 this.templateTo = templateTo;
56 this.descriptorResourcePath = descriptorResourcePath;
60 * Gets and Reads the transformation description yaml file.
62 protected void readDefinition() {
63 try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath)) {
64 if (resourceAsStream == null) {
65 if (LOGGER.isErrorEnabled()) {
66 LOGGER.error("Could not find resource '{}'", descriptorResourcePath);
70 transformationDescription = pnfdTransformationDescriptorReader.parse(resourceAsStream);
71 } catch (final IOException e) {
72 LOGGER.error("Could not find resource '{}'", descriptorResourcePath, e);
77 * Executes all transformations specified in the descriptor.
79 protected abstract void executeTransformations();