summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2018-01-29 11:23:39 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-02-15 14:23:32 +0000
commit924ba9adf027dd4969896cd905a8a41ba4c30655 (patch)
tree035e2ba4ef7100bca4f097d6ca10dbf40cf11aa9 /openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl
parentb4c4dbc6bbcd9995387c0716ee57f620c7a701df (diff)
Add Tosca model healer
create a Tosca model healer for future changes in Tosca structure Change-Id: I3843e4727b6bbb383576ae6a4fb055c5b6fa001f Issue-ID: SDC-973 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl')
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml11
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java116
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/resources/mock/healers/capability/capabilityAsList/in/MainServiceTemplate.yaml76
3 files changed, 203 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml
index 1359e6921d..5b0558c5f6 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml
@@ -44,6 +44,17 @@
<artifactId>openecomp-item-permissions-impl</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-tosca-converter-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-tosca-converter-core</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java
new file mode 100644
index 0000000000..e07faad4fa
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java
@@ -0,0 +1,116 @@
+package org.openecomp.sdc.healing.healers;
+
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.converter.ToscaConverter;
+import org.openecomp.core.converter.factory.ToscaConverterFactory;
+import org.openecomp.core.model.dao.ServiceModelDao;
+import org.openecomp.core.model.dao.ServiceModelDaoFactory;
+import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.translator.datatypes.TranslatorOutput;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
+import org.openecomp.core.validation.util.MessageContainerUtil;
+import org.openecomp.sdc.common.utils.CommonUtil;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.io.IOException;
+import java.util.Objects;
+import java.util.Optional;
+
+public class ToscaServiceModelHealer implements Healer {
+ private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+ private OrchestrationTemplateDao orchestrationTemplateDao;
+ private static final String VALIDATION_FAILURE_MESSAGE = "Product was updated. Please " +
+ "update the uploaded Heat file according to these validation errors: \n";
+
+ public ToscaServiceModelHealer() {
+ this.serviceModelDao = ServiceModelDaoFactory.getInstance().createInterface();
+ this.orchestrationTemplateDao = OrchestrationTemplateDaoFactory.getInstance().createInterface();
+ }
+
+ public ToscaServiceModelHealer(
+ ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao,
+ OrchestrationTemplateDao orchestrationTemplateDao) {
+ this.serviceModelDao = serviceModelDao;
+ this.orchestrationTemplateDao = orchestrationTemplateDao;
+ }
+
+ @Override
+ public Object heal(String itemId, Version version) throws Exception {
+ OrchestrationTemplateEntity orchestrationTemplateEntity =
+ orchestrationTemplateDao.get(itemId, version);
+ OnboardingTypesEnum type =
+ OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplateEntity.getFileSuffix());
+
+ if (Objects.isNull(type)
+ || Objects.isNull(orchestrationTemplateEntity.getContentData())) {
+ return null;
+ }
+
+ Optional<ToscaServiceModel> healedServiceModel =
+ healServiceModel(orchestrationTemplateEntity, type);
+
+ healedServiceModel.ifPresent(serviceModel -> serviceModelDao
+ .overrideServiceModel(itemId, version, serviceModel));
+
+ return healedServiceModel;
+
+ }
+
+ private Optional<ToscaServiceModel> healServiceModel(
+ OrchestrationTemplateEntity orchestrationTemplateEntity,
+ OnboardingTypesEnum type) throws IOException {
+ switch (type) {
+ case ZIP:
+ return Optional.of(healServiceModelFromZip(
+ getFileContentHandlerForHealing(orchestrationTemplateEntity, type)));
+
+ case CSAR:
+ return Optional.of(healServiceModelFromCsar(
+ getFileContentHandlerForHealing(orchestrationTemplateEntity, type)));
+
+ default:
+ return Optional.empty();
+ }
+
+ }
+
+ private FileContentHandler getFileContentHandlerForHealing(
+ OrchestrationTemplateEntity orchestrationTemplateEntity, OnboardingTypesEnum type)
+ throws IOException {
+ byte[] uploadedFileContent = orchestrationTemplateEntity.getContentData().array();
+ return CommonUtil.validateAndUploadFileContent(type, uploadedFileContent);
+ }
+
+ private ToscaServiceModel healServiceModelFromZip(FileContentHandler contentMap) {
+ TranslatorOutput translatorOutput =
+ HeatToToscaUtil.loadAndTranslateTemplateData(contentMap);
+
+ if (areThereValidationErrors(translatorOutput)) {
+ String validationErrorsAsString = MessageContainerUtil.getErrorMessagesListAsString
+ (MessageContainerUtil
+ .getMessageByLevel(ErrorLevel.ERROR, translatorOutput.getErrorMessages()));
+ throw new RuntimeException(VALIDATION_FAILURE_MESSAGE + validationErrorsAsString);
+ }
+
+ return translatorOutput.getToscaServiceModel();
+ }
+
+ private boolean areThereValidationErrors(TranslatorOutput translatorOutput) {
+ return MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR,
+ translatorOutput.getErrorMessages()));
+ }
+
+ private ToscaServiceModel healServiceModelFromCsar(FileContentHandler contentMap)
+ throws IOException {
+ ToscaConverter toscaConverter = ToscaConverterFactory.getInstance().createInterface();
+ return toscaConverter.convert(contentMap);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/resources/mock/healers/capability/capabilityAsList/in/MainServiceTemplate.yaml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/resources/mock/healers/capability/capabilityAsList/in/MainServiceTemplate.yaml
new file mode 100644
index 0000000000..faa15f37c2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/resources/mock/healers/capability/capabilityAsList/in/MainServiceTemplate.yaml
@@ -0,0 +1,76 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Main
+imports:
+- openecomp_heat_index:
+ file: openecomp-heat/_index.yml
+node_types:
+ org.openecomp.resource.vfc.nodes.heat.pcrf_psm:
+ derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server
+ org.openecomp.resource.vfc.nodes.heat.pcm:
+ derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server
+topology_template:
+ inputs:
+ Internal2_name:
+ label: Internal2_name
+ hidden: false
+ immutable: false
+ type: string
+ description: Internal2_name
+ node_templates:
+ pd_server:
+ type: org.openecomp.resource.vfc.nodes.heat.pd_server
+ properties:
+ availability_zone:
+ get_input:
+ - compute_pd_server_availability_zone
+ - index_value
+ flavor:
+ get_input: vm_flavor_name
+ image:
+ get_input: vm_image_name
+ name:
+ get_input:
+ - compute_pd_server_name
+ - index_value
+ user_data_format:
+ get_input:
+ - compute_pd_server_user_data_format
+ - index_value
+ pd_server_pd01_port:
+ type: org.openecomp.resource.cp.v2.extNeutronCP
+ properties:
+ ip_requirements:
+ get_input: port_pd01_port_ip_requirements
+ requirements:
+ - binding:
+ capability: tosca.capabilities.network.Bindable
+ node: pd_server
+ relationship: tosca.relationships.network.BindsTo
+ capabilities:
+ - port_mirroring:
+ properties:
+ connection_point:
+ nf_type: ''
+ nfc_type: pd_server
+ network_role:
+ get_input: port_pd01_port_network_role
+ pps_capacity: ''
+ groups:
+ ep-jsa_net:
+ type: org.openecomp.groups.heat.HeatStack
+ properties:
+ heat_file: ../Artifacts/ep-jsa_net.yaml
+ description: |
+ Version 2.0 02-09-2016 (Authors: John Doe, user PROD)
+ members:
+ - pcm_port_1
+ - FSB1_Internal2
+ - FSB1_Internal1
+ - FSB1_OAM
+ - psm01_port_0
+ - pcm_port_0
+ - server_pcm
+ - pcrf_server_psm
+ - FSB2
+ - FSB1 \ No newline at end of file