aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java97
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java19
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java53
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/InvalidToscaDefinitionImportException.java7
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java77
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java79
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaDefinitionImportHandler.java94
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java2
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java16
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java87
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java9
12 files changed, 209 insertions, 345 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
index 7168192526..1be85a5759 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
@@ -19,20 +19,20 @@
* * ============LICENSE_END=========================================================
*
*/
-
package org.openecomp.core.impl;
-import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
import static org.openecomp.core.converter.datatypes.Constants.DEFINITIONS_DIR;
import static org.openecomp.core.converter.datatypes.Constants.GLOBAL_ST_NAME;
import static org.openecomp.core.converter.datatypes.Constants.GLOBAL_SUBSTITUTION;
import static org.openecomp.core.converter.datatypes.Constants.MAIN_ST_NAME;
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
import static org.openecomp.core.converter.datatypes.Constants.OPENECOMP_HEAT_INDEX;
import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
@@ -66,10 +66,10 @@ import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.error.YAMLException;
public abstract class AbstractToscaConverter implements ToscaConverter {
+
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractToscaConverter.class);
- public abstract void convertTopologyTemplate(@NotNull ServiceTemplate serviceTemplate,
- ServiceTemplateReaderService readerService);
+ public abstract void convertTopologyTemplate(@NotNull ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService);
protected void handleMetadataFile(Map<String, byte[]> csarFiles) {
byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME);
@@ -78,8 +78,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
}
}
- protected void handleDefinitionTemplate(String key, Map<String, byte[]> csarFiles,
- GlobalSubstitutionServiceTemplate gsst) {
+ protected void handleDefinitionTemplate(String key, Map<String, byte[]> csarFiles, GlobalSubstitutionServiceTemplate gsst) {
try {
ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(csarFiles.get(key));
Object nodeTypes = readerService.getNodeTypes();
@@ -89,9 +88,9 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
}
gsst.appendDataTypes((Map) readerService.getDataTypes());
} catch (YAMLException ye) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage("Invalid YAML content in file " + key)
- .withCategory(ErrorCategory.APPLICATION).build(), ye);
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withMessage("Invalid YAML content in file " + key).withCategory(ErrorCategory.APPLICATION).build(),
+ ye);
}
}
@@ -100,52 +99,39 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
if (artifactIndex < 0) {
return fileName;
}
-
- int artifactDirectoryIndex =
- artifactIndex + CsarFileTypes.Artifacts.name().length() + 1;
+ int artifactDirectoryIndex = artifactIndex + CsarFileTypes.Artifacts.name().length() + 1;
return fileName.substring(artifactDirectoryIndex);
}
- protected void updateToscaServiceModel(ToscaServiceModel toscaServiceModel,
- Map<String, ServiceTemplate> serviceTemplates,
+ protected void updateToscaServiceModel(ToscaServiceModel toscaServiceModel, Map<String, ServiceTemplate> serviceTemplates,
FileContentHandler externalFilesHandler,
- GlobalSubstitutionServiceTemplate globalSubstitutionServiceTemplate,
- Map<String, byte[]> csarFiles, String entryDefinitionServiceTemplateName) {
- Collection<ServiceTemplate> globalServiceTemplates =
- GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR).values();
+ GlobalSubstitutionServiceTemplate globalSubstitutionServiceTemplate, Map<String, byte[]> csarFiles,
+ String entryDefinitionServiceTemplateName) {
+ Collection<ServiceTemplate> globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR).values();
addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates);
toscaServiceModel.setServiceTemplates(serviceTemplates);
toscaServiceModel.setEntryDefinitionServiceTemplate(entryDefinitionServiceTemplateName);
- externalFilesHandler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME,
- csarFiles.get(TOSCA_META_ORIG_PATH_FILE_NAME));
+ externalFilesHandler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, csarFiles.get(TOSCA_META_ORIG_PATH_FILE_NAME));
toscaServiceModel.setArtifactFiles(externalFilesHandler);
-
if (MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) {
- serviceTemplates
- .put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate);
+ serviceTemplates.put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate);
}
}
- private void addGlobalServiceTemplates(Collection<ServiceTemplate> globalServiceTemplates,
- Map<String, ServiceTemplate> serviceTemplates) {
+ private void addGlobalServiceTemplates(Collection<ServiceTemplate> globalServiceTemplates, Map<String, ServiceTemplate> serviceTemplates) {
for (ServiceTemplate serviceTemplate : globalServiceTemplates) {
serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate);
}
}
- protected void handleServiceTemplate(String serviceTemplateName,
- String fileName, Map<String, byte[]> csarFiles,
+ protected void handleServiceTemplate(String serviceTemplateName, String fileName, Map<String, byte[]> csarFiles,
Map<String, ServiceTemplate> serviceTemplates) {
final byte[] inputServiceTemplate = getServiceTemplateFromCsar(fileName, csarFiles);
Optional<ServiceTemplate> serviceTemplate = convertServiceTemplate(fileName, inputServiceTemplate);
- serviceTemplate.ifPresent(
- serviceTemplateValue -> addServiceTemplate(serviceTemplateName, serviceTemplateValue,
- serviceTemplates));
+ serviceTemplate.ifPresent(serviceTemplateValue -> addServiceTemplate(serviceTemplateName, serviceTemplateValue, serviceTemplates));
}
- private void addServiceTemplate(String serviceTemplateName,
- ServiceTemplate serviceTemplate,
- Map<String, ServiceTemplate> serviceTemplates) {
+ private void addServiceTemplate(String serviceTemplateName, ServiceTemplate serviceTemplate, Map<String, ServiceTemplate> serviceTemplates) {
serviceTemplates.put(serviceTemplateName, serviceTemplate);
}
@@ -153,12 +139,10 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
return csarFiles.get(fileName);
}
- private Optional<ServiceTemplate> convertServiceTemplate(String serviceTemplateName,
- byte[] fileContent) {
+ private Optional<ServiceTemplate> convertServiceTemplate(String serviceTemplateName, byte[] fileContent) {
ServiceTemplate serviceTemplate = new ServiceTemplate();
try {
- ServiceTemplateReaderService readerService =
- new ServiceTemplateReaderServiceImpl(fileContent);
+ ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(fileContent);
convertMetadata(serviceTemplateName, serviceTemplate, readerService);
convertToscaVersion(serviceTemplate, readerService);
convertImports(serviceTemplate);
@@ -166,17 +150,13 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
convertDataTypes(serviceTemplate, readerService);
convertTopologyTemplate(serviceTemplate, readerService);
} catch (YAMLException ye) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage("Invalid YAML content in file" + serviceTemplateName)
- .withCategory(ErrorCategory.APPLICATION).build(), ye);
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("Invalid YAML content in file" + serviceTemplateName)
+ .withCategory(ErrorCategory.APPLICATION).build(), ye);
}
-
-
return Optional.of(serviceTemplate);
}
- private void convertToscaVersion(ServiceTemplate serviceTemplate,
- ServiceTemplateReaderService readerService) {
+ private void convertToscaVersion(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
Object toscaVersion = readerService.getToscaVersion();
serviceTemplate.setTosca_definitions_version((String) toscaVersion);
}
@@ -194,26 +174,20 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
Import anImport = new Import();
anImport.setFile(fileName);
importMap.put(key, anImport);
-
return importMap;
}
- private void convertMetadata(String serviceTemplateName,
- ServiceTemplate serviceTemplate,
- ServiceTemplateReaderService readerService) {
+ private void convertMetadata(String serviceTemplateName, ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
Map<String, Object> metadataToConvert = (Map<String, Object>) readerService.getMetadata();
Map<String, String> finalMetadata = new HashMap<>();
-
if (MapUtils.isNotEmpty(metadataToConvert)) {
for (Map.Entry<String, Object> metadataEntry : metadataToConvert.entrySet()) {
- if (Objects.isNull(metadataEntry.getValue()) ||
- !(metadataEntry.getValue() instanceof String)) {
+ if (Objects.isNull(metadataEntry.getValue()) || !(metadataEntry.getValue() instanceof String)) {
continue;
}
finalMetadata.put(metadataEntry.getKey(), (String) metadataEntry.getValue());
}
}
-
finalMetadata.put("template_name", getTemplateNameFromStName(serviceTemplateName));
serviceTemplate.setMetadata(finalMetadata);
}
@@ -223,27 +197,18 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
if (MapUtils.isEmpty(nodeTypes)) {
return;
}
-
for (Map.Entry<String, Object> nodeTypeEntry : nodeTypes.entrySet()) {
- Optional<NodeType> nodeType = ToscaConverterUtil
- .createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(),
- NodeType.class);
-
- nodeType.ifPresent(nodeTypeValue -> DataModelUtil
- .addNodeType(serviceTemplate, nodeTypeEntry.getKey(), nodeTypeValue));
+ Optional<NodeType> nodeType = ToscaConverterUtil.createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), NodeType.class);
+ nodeType.ifPresent(nodeTypeValue -> DataModelUtil.addNodeType(serviceTemplate, nodeTypeEntry.getKey(), nodeTypeValue));
}
}
- protected void convertDataTypes(final ServiceTemplate serviceTemplate,
- final ServiceTemplateReaderService readerService) {
+ protected void convertDataTypes(final ServiceTemplate serviceTemplate, final ServiceTemplateReaderService readerService) {
try {
final Map<String, Object> dataTypes = readerService.getDataTypes();
for (final Map.Entry<String, Object> entry : dataTypes.entrySet()) {
- final Optional<DataType> dataType =
- ToscaConverterUtil.createObjectFromClass(entry.getKey(), entry.getValue(), DataType.class);
-
- dataType.ifPresent(
- nodeTypeValue -> DataModelUtil.addDataType(serviceTemplate, entry.getKey(), nodeTypeValue));
+ final Optional<DataType> dataType = ToscaConverterUtil.createObjectFromClass(entry.getKey(), entry.getValue(), DataType.class);
+ dataType.ifPresent(nodeTypeValue -> DataModelUtil.addDataType(serviceTemplate, entry.getKey(), nodeTypeValue));
}
} catch (final Exception ex) {
LOGGER.error("Unable to process data types: ", ex);
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
index ee669244ce..fb170e3ece 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
@@ -19,7 +19,6 @@
* * ============LICENSE_END=========================================================
*
*/
-
package org.openecomp.core.impl;
import static org.openecomp.core.converter.datatypes.Constants.GLOBAL_ST_NAME;
@@ -40,7 +39,6 @@ import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-
public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractToscaSolConverter.class);
@@ -75,21 +73,19 @@ public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
if (isGlobalServiceTemplate(fileEntry.getKey())) {
handleServiceTemplate(GLOBAL_ST_NAME, fileEntry.getKey(), csarFiles, serviceTemplates);
} else {
- artifacts.addFile(
- getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue());
+ artifacts.addFile(getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue());
}
}
}
}
- private void handleImportDefinitions(final String fileName, final Map<String, byte[]> csarFiles
- , final GlobalSubstitutionServiceTemplate gsst) {
+ private void handleImportDefinitions(final String fileName, final Map<String, byte[]> csarFiles, final GlobalSubstitutionServiceTemplate gsst) {
final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler(csarFiles, fileName);
if (toscaDefinitionImportHandler.hasError()) {
throw new InvalidToscaDefinitionImportException(toscaDefinitionImportHandler.getErrors());
}
- final Map<String, ServiceTemplateReaderService> handledImportDefinitionFileMap =
- toscaDefinitionImportHandler.getHandledImportDefinitionFileMap();
+ final Map<String, ServiceTemplateReaderService> handledImportDefinitionFileMap = toscaDefinitionImportHandler
+ .getHandledImportDefinitionFileMap();
handledDefinitionFilesList.addAll(handledImportDefinitionFileMap.keySet());
for (final String file : handledDefinitionFilesList) {
handleDefinitionTemplate(file, csarFiles, gsst);
@@ -98,8 +94,8 @@ public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
private String getMainServiceDefinitionFileName(FileContentHandler contentHandler) throws IOException {
try {
- ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(
- contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
+ ToscaMetadata toscaMetadata = OnboardingToscaMetadata
+ .parseToscaMetadataFile(contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
return toscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName());
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
@@ -113,5 +109,4 @@ public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
}
return path;
}
-
-} \ No newline at end of file
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java
index 98d8d23751..4907451a06 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.impl;
import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
@@ -35,15 +34,14 @@ import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypes
public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
- public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME =
- "GlobalSubstitutionTypesServiceTemplate.yaml";
+ public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME = "GlobalSubstitutionTypesServiceTemplate.yaml";
public static final String TEMPLATE_NAME_PROPERTY = "template_name";
public static final String DEFINITION_VERSION = "tosca_simple_yaml_1_0_0";
public static final String HEAT_INDEX = "openecomp_heat_index";
public static final String HEAT_INDEX_IMPORT_FILE = "openecomp-heat/_index.yml";
public static final String ONAP_INDEX_IMPORT_FILE = "onap/_index.yml";
-
// transient needed to avoid being parsed as a YAML String. Used parser is reading fields instead of getters,
+
// although it ignores static or transient fields.
private final transient Map<String, ServiceTemplate> globalServiceTemplates;
private final transient Map<String, DataType> globalDataTypeMap;
@@ -51,12 +49,11 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
public GlobalSubstitutionServiceTemplate() {
super();
init();
- globalServiceTemplates =
- GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR);
+ globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR);
globalDataTypeMap = loadGlobalDataTypes();
}
- public void init() {
+ public void init() {
writeDefinitionSection();
writeMetadataSection();
writeImportsSection();
@@ -73,12 +70,10 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
if (MapUtils.isEmpty(dataTypeMap)) {
return;
}
- dataTypeMap.entrySet().stream()
- .filter(dataTypeEntry -> !isGlobalDataType(dataTypeEntry.getKey()))
- .forEach(dataTypeEntry -> {
- final Optional<DataType> dataType = parseDataTypeToYamlObject(dataTypeEntry);
- dataType.ifPresent(dataType1 -> getData_types().put(dataTypeEntry.getKey(), dataType1));
- });
+ dataTypeMap.entrySet().stream().filter(dataTypeEntry -> !isGlobalDataType(dataTypeEntry.getKey())).forEach(dataTypeEntry -> {
+ final Optional<DataType> dataType = parseDataTypeToYamlObject(dataTypeEntry);
+ dataType.ifPresent(dataType1 -> getData_types().put(dataTypeEntry.getKey(), dataType1));
+ });
}
private void writeImportsSection() {
@@ -94,7 +89,6 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
stringImportMap.put(ONAP_INDEX, onapDefinitionsImport);
}
-
private void writeMetadataSection() {
Map<String, String> metadata = new HashMap<>();
metadata.put(TEMPLATE_NAME_PROPERTY, "GlobalSubstitutionTypes");
@@ -105,22 +99,18 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
setTosca_definitions_version(DEFINITION_VERSION);
}
- private Optional<Map<String, NodeType>> findNonGlobalTypesNodes(final Map<String, NodeType> nodes){
+ private Optional<Map<String, NodeType>> findNonGlobalTypesNodes(final Map<String, NodeType> nodes) {
final Map<String, NodeType> globalNodeTypes = getAllGlobalNodeTypes();
if (MapUtils.isEmpty(globalNodeTypes)) {
return Optional.of(nodes);
}
-
final Map<String, NodeType> nodeTypesToAdd = new HashMap<>();
-
- for(Map.Entry<String, NodeType> nodeTypeEntry : nodes.entrySet()){
- if(!globalNodeTypes.containsKey(nodeTypeEntry.getKey())){
+ for (Map.Entry<String, NodeType> nodeTypeEntry : nodes.entrySet()) {
+ if (!globalNodeTypes.containsKey(nodeTypeEntry.getKey())) {
Optional<NodeType> nodeType = parseNodeTypeToYamlObject(nodeTypeEntry);
- nodeType
- .ifPresent(nodeTypeValue -> nodeTypesToAdd.put(nodeTypeEntry.getKey(), nodeTypeValue));
+ nodeType.ifPresent(nodeTypeValue -> nodeTypesToAdd.put(nodeTypeEntry.getKey(), nodeTypeValue));
}
}
-
return Optional.of(nodeTypesToAdd);
}
@@ -128,37 +118,30 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
if (MapUtils.isEmpty(globalDataTypeMap)) {
return false;
}
-
return globalDataTypeMap.containsKey(dataType);
}
private Optional<NodeType> parseNodeTypeToYamlObject(final Entry<String, NodeType> nodeTypeEntry) {
- return ToscaConverterUtil
- .createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), NodeType.class);
+ return ToscaConverterUtil.createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), NodeType.class);
}
private Optional<DataType> parseDataTypeToYamlObject(final Entry<String, DataType> dataTypeEntry) {
- return ToscaConverterUtil
- .createObjectFromClass(dataTypeEntry.getKey(), dataTypeEntry.getValue(), DataType.class);
+ return ToscaConverterUtil.createObjectFromClass(dataTypeEntry.getKey(), dataTypeEntry.getValue(), DataType.class);
}
private Map<String, DataType> loadGlobalDataTypes() {
- return globalServiceTemplates.values().stream()
- .map(ServiceTemplate::getData_types)
- .filter(MapUtils::isNotEmpty)
+ return globalServiceTemplates.values().stream().map(ServiceTemplate::getData_types).filter(MapUtils::isNotEmpty)
.flatMap(stringDataTypeMap -> stringDataTypeMap.entrySet().stream())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (dataType, dataType2) -> dataType));
}
- private Map<String, NodeType> getAllGlobalNodeTypes(){
+ private Map<String, NodeType> getAllGlobalNodeTypes() {
Map<String, NodeType> globalNodeTypes = new HashMap<>();
-
- for(Map.Entry<String, ServiceTemplate> serviceTemplateEntry : globalServiceTemplates.entrySet()){
- if(isNodesServiceTemplate(serviceTemplateEntry.getKey())){
+ for (Map.Entry<String, ServiceTemplate> serviceTemplateEntry : globalServiceTemplates.entrySet()) {
+ if (isNodesServiceTemplate(serviceTemplateEntry.getKey())) {
globalNodeTypes.putAll(serviceTemplateEntry.getValue().getNode_types());
}
}
-
return globalNodeTypes;
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/InvalidToscaDefinitionImportException.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/InvalidToscaDefinitionImportException.java
index ac2e5eccc2..0c683fbf85 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/InvalidToscaDefinitionImportException.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/InvalidToscaDefinitionImportException.java
@@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.impl;
import java.util.List;
@@ -33,15 +32,15 @@ public class InvalidToscaDefinitionImportException extends RuntimeException {
/**
* Builds the exception message based on the provided validation error list.
- * @param validationErrorList The error list
+ *
+ * @param validationErrorList The error list
*/
public InvalidToscaDefinitionImportException(final List<ErrorMessage> validationErrorList) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("The provided package is invalid as it contains descriptors import errors:\n");
if (CollectionUtils.isNotEmpty(validationErrorList)) {
final StringJoiner joiner = new StringJoiner(";\n");
- validationErrorList.forEach(
- errorMessage -> joiner.add(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage())));
+ validationErrorList.forEach(errorMessage -> joiner.add(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage())));
message = stringBuilder.append(joiner.toString()).toString();
} else {
message = stringBuilder.toString();
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
index 6f50205f44..1d109bb457 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
@@ -13,58 +13,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.impl;
+import static org.openecomp.core.converter.datatypes.Constants.GLOBAL_ST_NAME;
+import static org.openecomp.core.converter.datatypes.Constants.MAIN_ST_NAME;
+
+import java.util.HashMap;
+import java.util.Map;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.converter.ServiceTemplateReaderService;
import org.openecomp.core.converter.datatypes.CsarFileTypes;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.openecomp.core.converter.datatypes.Constants.GLOBAL_ST_NAME;
-import static org.openecomp.core.converter.datatypes.Constants.MAIN_ST_NAME;
-
public class ToscaConverterImpl extends AbstractToscaConverter {
- @Override
- public ToscaServiceModel convert(FileContentHandler fileContentHandler) {
- Map<String, byte[]> csarFiles = new HashMap<>(fileContentHandler.getFiles());
- ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
- Map<String, ServiceTemplate> serviceTemplates = new HashMap<>();
- FileContentHandler artifacts = new FileContentHandler();
- GlobalSubstitutionServiceTemplate gsst = new GlobalSubstitutionServiceTemplate();
- csarFiles.putAll(fileContentHandler.getFiles());
- for (Map.Entry<String, byte[]> fileEntry : csarFiles.entrySet()) {
- CsarFileTypes fileType = getFileType(fileEntry.getKey());
- switch (fileType) {
- case mainServiceTemplate:
- handleServiceTemplate(MAIN_ST_NAME, fileEntry.getKey(), csarFiles, serviceTemplates);
- break;
-
- case globalServiceTemplate:
- handleServiceTemplate(GLOBAL_ST_NAME, fileEntry.getKey(), csarFiles, serviceTemplates);
- break;
-
- case externalFile:
- artifacts.addFile(
- getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue());
- break;
-
- case definitionsFile:
- handleDefinitionTemplate(fileEntry.getKey(), csarFiles, gsst);
- break;
-
- default:
- break;
- }
- }
- handleMetadataFile(csarFiles);
- updateToscaServiceModel(toscaServiceModel, serviceTemplates, artifacts, gsst, csarFiles, MAIN_ST_NAME);
- return toscaServiceModel;
+ @Override
+ public ToscaServiceModel convert(FileContentHandler fileContentHandler) {
+ Map<String, byte[]> csarFiles = new HashMap<>(fileContentHandler.getFiles());
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ Map<String, ServiceTemplate> serviceTemplates = new HashMap<>();
+ FileContentHandler artifacts = new FileContentHandler();
+ GlobalSubstitutionServiceTemplate gsst = new GlobalSubstitutionServiceTemplate();
+ csarFiles.putAll(fileContentHandler.getFiles());
+ for (Map.Entry<String, byte[]> fileEntry : csarFiles.entrySet()) {
+ CsarFileTypes fileType = getFileType(fileEntry.getKey());
+ switch (fileType) {
+ case mainServiceTemplate:
+ handleServiceTemplate(MAIN_ST_NAME, fileEntry.getKey(), csarFiles, serviceTemplates);
+ break;
+ case globalServiceTemplate:
+ handleServiceTemplate(GLOBAL_ST_NAME, fileEntry.getKey(), csarFiles, serviceTemplates);
+ break;
+ case externalFile:
+ artifacts.addFile(getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue());
+ break;
+ case definitionsFile:
+ handleDefinitionTemplate(fileEntry.getKey(), csarFiles, gsst);
+ break;
+ default:
+ break;
+ }
+ }
+ handleMetadataFile(csarFiles);
+ updateToscaServiceModel(toscaServiceModel, serviceTemplates, artifacts, gsst, csarFiles, MAIN_ST_NAME);
+ return toscaServiceModel;
}
@Override
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
index a77c150a91..ffb953c89e 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
@@ -13,65 +13,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.impl;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.converter.errors.CreateToscaObjectErrorBuilder;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.utils.CommonUtil;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
public class ToscaConverterUtil {
- private static final String DEFAULT = "default";
- private static final String DEFAULT_CAPITAL = "Default";
- private static final Set<String> DEFAULT_VALUE_KEYS;
+ private static final String DEFAULT = "default";
+ private static final String DEFAULT_CAPITAL = "Default";
+ private static final Set<String> DEFAULT_VALUE_KEYS;
- static {
- DEFAULT_VALUE_KEYS =
- Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet());
- }
-
- private ToscaConverterUtil() {
- // static utility methods only, prevent instantiation
- }
-
- static <T> Optional<T> createObjectFromClass(String objectId,
- Object objectCandidate,
- Class<T> classToCreate) {
- try {
- return CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate);
- } catch (Exception ex) {
- throw new CoreException(
- new CreateToscaObjectErrorBuilder(classToCreate.getSimpleName(), objectId)
- .build(), ex);
+ static {
+ DEFAULT_VALUE_KEYS = Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet());
}
- }
-
- static Optional<Object> getDefaultValue(Object entryValue,
- Object objectToAssignDefaultValue) {
- if (!(entryValue instanceof Map)
- || Objects.isNull(objectToAssignDefaultValue)) {
- return Optional.empty();
+ private ToscaConverterUtil() {
+ // static utility methods only, prevent instantiation
}
- return Optional.ofNullable(getDefaultParameterValue((Map<String, Object>) entryValue));
- }
-
- private static Object getDefaultParameterValue(Map<String, Object> entryValue) {
- Object defaultValue = null;
- Set<String> keys = new HashSet<>(entryValue.keySet());
- keys.retainAll(DEFAULT_VALUE_KEYS);
+ static <T> Optional<T> createObjectFromClass(String objectId, Object objectCandidate, Class<T> classToCreate) {
+ try {
+ return CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate);
+ } catch (Exception ex) {
+ throw new CoreException(new CreateToscaObjectErrorBuilder(classToCreate.getSimpleName(), objectId).build(), ex);
+ }
+ }
- if (CollectionUtils.isNotEmpty(keys)) {
- defaultValue = entryValue.get(keys.iterator().next());
+ static Optional<Object> getDefaultValue(Object entryValue, Object objectToAssignDefaultValue) {
+ if (!(entryValue instanceof Map) || Objects.isNull(objectToAssignDefaultValue)) {
+ return Optional.empty();
+ }
+ return Optional.ofNullable(getDefaultParameterValue((Map<String, Object>) entryValue));
}
- return defaultValue;
- }
+ private static Object getDefaultParameterValue(Map<String, Object> entryValue) {
+ Object defaultValue = null;
+ Set<String> keys = new HashSet<>(entryValue.keySet());
+ keys.retainAll(DEFAULT_VALUE_KEYS);
+ if (CollectionUtils.isNotEmpty(keys)) {
+ defaultValue = entryValue.get(keys.iterator().next());
+ }
+ return defaultValue;
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaDefinitionImportHandler.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaDefinitionImportHandler.java
index 661cadc738..a48fb36374 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaDefinitionImportHandler.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaDefinitionImportHandler.java
@@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.impl;
import static org.openecomp.sdc.tosca.csar.CSARConstants.NON_FILE_IMPORT_ATTRIBUTES;
@@ -46,9 +45,7 @@ import org.slf4j.LoggerFactory;
public class ToscaDefinitionImportHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaDefinitionImportHandler.class);
-
private final Map<String, byte[]> fileMap;
-
/**
* Stores all processed files during the import handling
*/
@@ -59,17 +56,17 @@ public class ToscaDefinitionImportHandler {
/**
* Reads the provided package structure starting from a main definition yaml file.
- * @param fileStructureMap The package structure with file path and respective file byte
- * @param mainDefinitionFilePath The main descriptor yaml file to start the reading
+ *
+ * @param fileStructureMap The package structure with file path and respective file byte
+ * @param mainDefinitionFilePath The main descriptor yaml file to start the reading
*/
- public ToscaDefinitionImportHandler(final Map<String, byte[]> fileStructureMap,
- final String mainDefinitionFilePath) {
+ public ToscaDefinitionImportHandler(final Map<String, byte[]> fileStructureMap, final String mainDefinitionFilePath) {
this.fileMap = fileStructureMap;
readImportsFromMainDefinition(mainDefinitionFilePath);
}
private void readImportsFromMainDefinition(final String mainDefinitionFilePath) {
- if(!checkMainDefinitionExists(mainDefinitionFilePath)) {
+ if (!checkMainDefinitionExists(mainDefinitionFilePath)) {
return;
}
final ServiceTemplateReaderService readerService = parseToServiceTemplate(mainDefinitionFilePath).orElse(null);
@@ -90,19 +87,16 @@ public class ToscaDefinitionImportHandler {
return Optional.of(new ServiceTemplateReaderServiceImpl(fileMap.get(definitionFile)));
} catch (final Exception ex) {
LOGGER.debug("Could not parse '{}' to a ServiceTemplateReader", definitionFile, ex);
- reportError(ErrorLevel.ERROR,
- String.format(Messages.INVALID_YAML_FORMAT.getErrorMessage(), ex.getMessage()));
+ reportError(ErrorLevel.ERROR, String.format(Messages.INVALID_YAML_FORMAT.getErrorMessage(), ex.getMessage()));
}
-
return Optional.empty();
}
/**
- * Reads and validates the descriptor imports recursively.
- * Starts from the provided descriptor and goes until the end of the import tree.
+ * Reads and validates the descriptor imports recursively. Starts from the provided descriptor and goes until the end of the import tree.
* Processes each file just once.
*
- * @param fileName the descriptor file path
+ * @param fileName the descriptor file path
*/
private void handleImports(final String fileName) {
currentFile = fileName;
@@ -113,14 +107,11 @@ public class ToscaDefinitionImportHandler {
if (readerService == null) {
return;
}
-
handledImportDefinitionFileMap.put(fileName, readerService);
final List<Object> imports = readerService.getImports();
final List<String> extractImportFiles = extractFileImports(imports);
- extractImportFiles.stream()
- .map(importedFile -> resolveImportPath(FilenameUtils.getPath(fileName), importedFile))
- .filter(resolvedPath -> !handledImportDefinitionFileMap.containsKey(resolvedPath))
- .forEach(this::handleImports);
+ extractImportFiles.stream().map(importedFile -> resolveImportPath(FilenameUtils.getPath(fileName), importedFile))
+ .filter(resolvedPath -> !handledImportDefinitionFileMap.containsKey(resolvedPath)).forEach(this::handleImports);
}
/**
@@ -133,22 +124,19 @@ public class ToscaDefinitionImportHandler {
* - yetAnotherDescriptor:
* yetAnotherDescriptor: ../Definitions/yetAnotherDescriptor.yaml
* </pre>
- * @param imports the import statements
- * @return
- * The list of import file paths found
+ *
+ * @param imports the import statements
+ * @return The list of import file paths found
*/
private List<String> extractFileImports(final List<Object> imports) {
final List<String> importedFileList = new ArrayList<>();
imports.forEach(importObject -> importedFileList.addAll(readImportStatement(importObject)));
-
return importedFileList;
}
/**
- * Reads an import statement which can be a value, a [key:value] or a [key:[key:value]].
- * Ignores entries which contains the same keys as
- * {@link org.openecomp.sdc.tosca.csar.CSARConstants#NON_FILE_IMPORT_ATTRIBUTES}.
- * Reports invalid import statements.
+ * Reads an import statement which can be a value, a [key:value] or a [key:[key:value]]. Ignores entries which contains the same keys as {@link
+ * org.openecomp.sdc.tosca.csar.CSARConstants#NON_FILE_IMPORT_ATTRIBUTES}. Reports invalid import statements.
* <pre>
* example of yaml imports statements:
* - /Artifacts/anImportedDescriptor.yaml
@@ -156,9 +144,9 @@ public class ToscaDefinitionImportHandler {
* - yetAnotherDescriptor:
* yetAnotherDescriptor: ../Definitions/yetAnotherDescriptor.yaml
* </pre>
- * @param importObject the object representing the yaml import statement
- * @return
- * The list of import file paths found
+ *
+ * @param importObject the object representing the yaml import statement
+ * @return The list of import file paths found
*/
private List<String> readImportStatement(final Object importObject) {
final List<String> importedFileList = new ArrayList<>();
@@ -172,43 +160,34 @@ public class ToscaDefinitionImportHandler {
}
}
} else {
- reportError(ErrorLevel.ERROR,
- String.format(Messages.INVALID_IMPORT_STATEMENT.getErrorMessage(), currentFile, importObject));
+ reportError(ErrorLevel.ERROR, String.format(Messages.INVALID_IMPORT_STATEMENT.getErrorMessage(), currentFile, importObject));
}
-
return importedFileList;
}
/**
* Given a directory path, resolves the import path.
- * @param directoryPath A directory path to resolve the import path
- * @param importPath An import statement path
- * @return
- * The resolved path of the import, using as base the directory path
+ *
+ * @param directoryPath A directory path to resolve the import path
+ * @param importPath An import statement path
+ * @return The resolved path of the import, using as base the directory path
*/
private String resolveImportPath(final String directoryPath, final String importPath) {
final String fixedParentDir;
if (StringUtils.isEmpty(directoryPath)) {
fixedParentDir = "/";
} else {
- fixedParentDir = String.format("%s%s%s",
- directoryPath.startsWith("/") ? "" : "/"
- , directoryPath
- , directoryPath.endsWith("/") ? "" : "/");
+ fixedParentDir = String.format("%s%s%s", directoryPath.startsWith("/") ? "" : "/", directoryPath, directoryPath.endsWith("/") ? "" : "/");
}
-
final URI parentDirUri = URI.create(fixedParentDir);
-
String resolvedImportPath = parentDirUri.resolve(importPath).toString();
if (resolvedImportPath.contains("../")) {
- reportError(ErrorLevel.ERROR,
- Messages.INVALID_IMPORT_STATEMENT.formatMessage(currentFile, importPath));
+ reportError(ErrorLevel.ERROR, Messages.INVALID_IMPORT_STATEMENT.formatMessage(currentFile, importPath));
return null;
}
if (resolvedImportPath.startsWith("/")) {
resolvedImportPath = resolvedImportPath.substring(1);
}
-
return resolvedImportPath;
}
@@ -221,28 +200,25 @@ public class ToscaDefinitionImportHandler {
}
/**
- * Checks if the given file path exists inside the file structure.
- * Reports an error if the file was not found.
+ * Checks if the given file path exists inside the file structure. Reports an error if the file was not found.
*
- * @param filePath file path to check inside the file structure
- * @param errorMsg the error message to report
- * @return
- * {@code true} if the file exists, {@code false} otherwise
+ * @param filePath file path to check inside the file structure
+ * @param errorMsg the error message to report
+ * @return {@code true} if the file exists, {@code false} otherwise
*/
private boolean checkFileExists(final String filePath, final String errorMsg) {
if (!fileMap.containsKey(filePath)) {
reportError(ErrorLevel.ERROR, errorMsg);
return false;
}
-
return true;
}
/**
* Adds an error to the validation error list.
*
- * @param errorLevel the error level
- * @param errorMessage the error message
+ * @param errorLevel the error level
+ * @param errorMessage the error message
*/
private void reportError(final ErrorLevel errorLevel, final String errorMessage) {
validationErrorList.add(new ErrorMessage(errorLevel, errorMessage));
@@ -250,8 +226,8 @@ public class ToscaDefinitionImportHandler {
/**
* Gets the list of errors.
- * @return
- * The import validation errors detected
+ *
+ * @return The import validation errors detected
*/
public List<ErrorMessage> getErrors() {
return validationErrorList;
@@ -259,8 +235,8 @@ public class ToscaDefinitionImportHandler {
/**
* Checks if the handler detected a import error.
- * @return
- * {@code true} if the handler detected any error, {@code false} otherwise.
+ *
+ * @return {@code true} if the handler detected any error, {@code false} otherwise.
*/
public boolean hasError() {
return !validationErrorList.isEmpty();
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java
index 7d2a38f4f0..e43ed5383a 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java
@@ -19,7 +19,6 @@
* * ============LICENSE_END=========================================================
*
*/
-
package org.openecomp.core.impl;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
@@ -31,5 +30,4 @@ public class ToscaSolConverterVnf extends AbstractToscaSolConverter {
public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
new VnfTopologyTemplateConverter().convertTopologyTemplate(serviceTemplate, readerService);
}
-
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java
index b861980f24..425c57aeb9 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolModelDrivenConverterPnf.java
@@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.impl;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
@@ -29,22 +28,19 @@ public class ToscaSolModelDrivenConverterPnf extends AbstractToscaSolConverter {
/**
* Calls the model driven engine to parse the onboarding PNF descriptor
+ *
* @param serviceTemplate
* @param readerService
*/
@Override
- public void convertTopologyTemplate(final ServiceTemplate serviceTemplate,
- final ServiceTemplateReaderService readerService) {
- final PnfdTransformationEngine pnfdTransformationEngine =
- new PnfdNodeTemplateTransformationEngine(readerService, serviceTemplate);
+ public void convertTopologyTemplate(final ServiceTemplate serviceTemplate, final ServiceTemplateReaderService readerService) {
+ final PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(readerService, serviceTemplate);
pnfdTransformationEngine.transform();
}
@Override
- protected void convertNodeTypes(final ServiceTemplate serviceTemplate,
- final ServiceTemplateReaderService readerService) {
- final PnfdTransformationEngine pnfdTransformationEngine =
- new PnfdNodeTypeTransformationEngine(readerService, serviceTemplate);
+ protected void convertNodeTypes(final ServiceTemplate serviceTemplate, final ServiceTemplateReaderService readerService) {
+ final PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTypeTransformationEngine(readerService, serviceTemplate);
pnfdTransformationEngine.transform();
}
-} \ No newline at end of file
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java
index dd7e11ab2b..ec7e493464 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java
@@ -19,9 +19,20 @@
* * ============LICENSE_END=========================================================
*
*/
-
package org.openecomp.core.impl;
+import static org.openecomp.core.converter.datatypes.Constants.CAPABILITIES;
+import static org.openecomp.core.converter.datatypes.Constants.INPUTS;
+import static org.openecomp.core.converter.datatypes.Constants.NODE_FILTER;
+import static org.openecomp.core.converter.datatypes.Constants.NODE_TYPE;
+import static org.openecomp.core.converter.datatypes.Constants.OUTPUTS;
+import static org.openecomp.core.converter.datatypes.Constants.REQUIREMENTS;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.commons.collections.MapUtils;
import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition;
import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
@@ -39,19 +50,6 @@ import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBui
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.tosca.services.DataModelUtil;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
-import static org.openecomp.core.converter.datatypes.Constants.CAPABILITIES;
-import static org.openecomp.core.converter.datatypes.Constants.INPUTS;
-import static org.openecomp.core.converter.datatypes.Constants.NODE_FILTER;
-import static org.openecomp.core.converter.datatypes.Constants.NODE_TYPE;
-import static org.openecomp.core.converter.datatypes.Constants.OUTPUTS;
-import static org.openecomp.core.converter.datatypes.Constants.REQUIREMENTS;
-
public class VnfTopologyTemplateConverter {
public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
@@ -72,28 +70,23 @@ public class VnfTopologyTemplateConverter {
addInputsOrOutputsToServiceTemplate(serviceTemplate, outputs, Constants.OUTPUTS);
}
- private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, Map<String, Object> mapToConvert,
- String inputsOrOutputs) {
+ private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, Map<String, Object> mapToConvert, String inputsOrOutputs) {
if (MapUtils.isEmpty(mapToConvert)) {
return;
}
-
for (Map.Entry<String, Object> entry : mapToConvert.entrySet()) {
- Optional<ParameterDefinition> parameterDefinition = ToscaConverterUtil.createObjectFromClass(entry.getKey(),
- entry.getValue(), ParameterDefinition.class);
-
+ Optional<ParameterDefinition> parameterDefinition = ToscaConverterUtil
+ .createObjectFromClass(entry.getKey(), entry.getValue(), ParameterDefinition.class);
parameterDefinition.ifPresent(parameterDefinitionValue -> {
- Optional<Object> defaultValue =
- ToscaConverterUtil.getDefaultValue(entry.getValue(), parameterDefinition.get());
+ Optional<Object> defaultValue = ToscaConverterUtil.getDefaultValue(entry.getValue(), parameterDefinition.get());
defaultValue.ifPresent(parameterDefinitionValue::set_default);
- addToServiceTemplateAccordingToSection(serviceTemplate, inputsOrOutputs, entry.getKey(),
- parameterDefinition.get());
+ addToServiceTemplateAccordingToSection(serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition.get());
});
}
}
- private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, String inputsOrOutputs,
- String parameterId, ParameterDefinition parameterDefinition) {
+ private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, String inputsOrOutputs, String parameterId,
+ ParameterDefinition parameterDefinition) {
if (inputsOrOutputs.equals(INPUTS)) {
DataModelUtil.addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition);
} else if (inputsOrOutputs.equals(OUTPUTS)) {
@@ -106,7 +99,6 @@ public class VnfTopologyTemplateConverter {
if (MapUtils.isEmpty(nodeTemplates)) {
return;
}
-
for (Map.Entry<String, Object> nodeTemplateEntry : nodeTemplates.entrySet()) {
NodeTemplate nodeTemplate = convertNodeTemplate(nodeTemplateEntry.getValue());
DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate);
@@ -115,7 +107,6 @@ public class VnfTopologyTemplateConverter {
private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) {
NodeTemplate nodeTemplate = new NodeTemplate();
-
Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate;
nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts"));
nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes"));
@@ -128,7 +119,6 @@ public class VnfTopologyTemplateConverter {
nodeTemplate.setRequirements((List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
nodeTemplate.setCapabilities(convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
-
return nodeTemplate;
}
@@ -136,23 +126,17 @@ public class VnfTopologyTemplateConverter {
if (MapUtils.isEmpty(capabilities)) {
return null;
}
-
Map<String, CapabilityAssignment> convertedCapabilities = new HashMap<>();
for (Map.Entry<String, Object> capabilityAssignmentEntry : capabilities.entrySet()) {
- Optional<CapabilityAssignment> capabilityAssignment = ToscaConverterUtil.createObjectFromClass(
- capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(),
- CapabilityAssignment.class);
-
- capabilityAssignment.ifPresent(capabilityAssignmentValue -> convertedCapabilities
- .put(capabilityAssignmentEntry.getKey(),
- capabilityAssignmentValue));
-
+ Optional<CapabilityAssignment> capabilityAssignment = ToscaConverterUtil
+ .createObjectFromClass(capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), CapabilityAssignment.class);
+ capabilityAssignment
+ .ifPresent(capabilityAssignmentValue -> convertedCapabilities.put(capabilityAssignmentEntry.getKey(), capabilityAssignmentValue));
}
return convertedCapabilities;
}
- private void convertSubstitutionMappings(ServiceTemplate serviceTemplate,
- ServiceTemplateReaderService readerService) {
+ private void convertSubstitutionMappings(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
Map<String, Object> substitutionMappings = readerService.getSubstitutionMappings();
if (MapUtils.isEmpty(substitutionMappings)) {
return;
@@ -163,53 +147,41 @@ public class VnfTopologyTemplateConverter {
private SubstitutionMapping convertSubstitutionMappings(Map<String, Object> substitutionMappings) {
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
-
substitutionMapping.setNode_type((String) substitutionMappings.get(NODE_TYPE));
- substitutionMapping.setCapabilities(
- convertSubstitutionMappingsSections(CAPABILITIES, substitutionMappings.get(CAPABILITIES)));
- substitutionMapping.setRequirements(
- convertSubstitutionMappingsSections(REQUIREMENTS, substitutionMappings.get(REQUIREMENTS)));
+ substitutionMapping.setCapabilities(convertSubstitutionMappingsSections(CAPABILITIES, substitutionMappings.get(CAPABILITIES)));
+ substitutionMapping.setRequirements(convertSubstitutionMappingsSections(REQUIREMENTS, substitutionMappings.get(REQUIREMENTS)));
substitutionMapping.setSubstitution_filter((NodeFilter) substitutionMappings.get(NODE_FILTER));
-
return substitutionMapping;
}
private Map<String, List<String>> convertSubstitutionMappingsSections(String sectionName, Object sectionToConvert) {
-
if (Objects.isNull(sectionToConvert)) {
return null;
}
-
if (!(sectionToConvert instanceof Map)) {
- throw new CoreException(new SubstitutionMappingsConverterErrorBuilder(sectionName,
- sectionToConvert.getClass().getSimpleName()).build());
+ throw new CoreException(new SubstitutionMappingsConverterErrorBuilder(sectionName, sectionToConvert.getClass().getSimpleName()).build());
}
-
return convertSection(sectionToConvert);
}
private Map<String, List<String>> convertSection(Object sectionToConvert) {
-
Map<String, Object> sectionAsMap = (Map<String, Object>) sectionToConvert;
Map<String, List<String>> convertedSection = new HashMap<>();
-
if (MapUtils.isEmpty(sectionAsMap)) {
return null;
}
-
for (Map.Entry<String, Object> entry : sectionAsMap.entrySet()) {
if (entry.getValue() instanceof List) {
convertedSection.put(entry.getKey(), (List<String>) entry.getValue());
}
}
-
return convertedSection;
}
private void convertPolicies(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) {
List<Object> policiesList = readerService.getPolicies();
- policiesList.forEach(policiesListItem -> ((Map<String, Object>) policiesListItem).forEach((key, value) ->
- DataModelUtil.addPolicyDefinition(serviceTemplate, key, convertPolicy(value))));
+ policiesList.forEach(policiesListItem -> ((Map<String, Object>) policiesListItem)
+ .forEach((key, value) -> DataModelUtil.addPolicyDefinition(serviceTemplate, key, convertPolicy(value))));
}
private PolicyDefinition convertPolicy(Object policyCandidate) {
@@ -221,7 +193,6 @@ public class VnfTopologyTemplateConverter {
policyDefinition.setProperties((Map<String, Object>) policy.get("properties"));
policyDefinition.setTargets((List<String>) policy.get("targets"));
policyDefinition.setTriggers((Map<String, Trigger>) policy.get("triggers"));
-
return policyDefinition;
}
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java
index d585868365..1e8a83e172 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/factory/ToscaConverterFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.impl.factory;
import org.openecomp.core.converter.ToscaConverter;
@@ -25,8 +24,9 @@ import org.openecomp.core.converter.factory.ToscaConverterFactory;
import org.openecomp.core.impl.ToscaConverterImpl;
public class ToscaConverterFactoryImpl extends ToscaConverterFactory {
- @Override
- public ToscaConverter createInterface() {
- return new ToscaConverterImpl();
- }
+
+ @Override
+ public ToscaConverter createInterface() {
+ return new ToscaConverterImpl();
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
index 9cd2d7ea07..421aeb60d2 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
@@ -17,15 +17,14 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.impl.services;
-import static org.openecomp.core.converter.datatypes.Constants.POLICIES;
import static org.openecomp.core.converter.datatypes.Constants.INPUTS;
import static org.openecomp.core.converter.datatypes.Constants.METADATA;
import static org.openecomp.core.converter.datatypes.Constants.NODE_TEMPLATES;
import static org.openecomp.core.converter.datatypes.Constants.NODE_TYPES;
import static org.openecomp.core.converter.datatypes.Constants.OUTPUTS;
+import static org.openecomp.core.converter.datatypes.Constants.POLICIES;
import static org.openecomp.core.converter.datatypes.Constants.SUBSTITUTION_MAPPINGS;
import static org.openecomp.core.converter.datatypes.Constants.TOPOLOGY_TEMPLATE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DATA_TYPES;
@@ -63,8 +62,7 @@ public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderSe
@Override
public List<Object> getPolicies() {
List<Object> policiesList = new ArrayList<>();
- if (Objects.nonNull(this.getTopologyTemplate()) && Objects.nonNull(
- ((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES))) {
+ if (Objects.nonNull(this.getTopologyTemplate()) && Objects.nonNull(((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES))) {
policiesList = (List<Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES);
}
return policiesList;
@@ -112,8 +110,7 @@ public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderSe
@Override
public Map<String, Object> getSubstitutionMappings() {
return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
- : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate())
- .get(SUBSTITUTION_MAPPINGS);
+ : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(SUBSTITUTION_MAPPINGS);
}
@Override