Change healing manager logic 29/12229/1
authortalig <talig@amdocs.com>
Wed, 13 Sep 2017 15:16:36 +0000 (18:16 +0300)
committertalig <talig@amdocs.com>
Wed, 13 Sep 2017 15:25:16 +0000 (18:25 +0300)
Execute all healers even if one/more have failed.
Turn off vsp old version indication and log healers errors.
This is a temporary solution that would fix non-heat issues only.

Change-Id: I1fbcd3cc33a0520034b3dd373e2cfbe7339c06bd
Issue-ID: SDC-332
Signed-off-by: talig <talig@amdocs.com>
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-api/src/main/java/org/openecomp/sdc/healing/api/HealingManager.java
openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java
openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java

index 78c4cbf..c9f4159 100644 (file)
@@ -38,6 +38,7 @@ import org.openecomp.core.validation.util.MessageContainerUtil;
 import org.openecomp.sdc.activityLog.ActivityLogManager;
 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
 import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
 import org.openecomp.sdc.common.errors.ErrorCode;
 import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
 import org.openecomp.sdc.common.utils.CommonUtil;
@@ -136,6 +137,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
@@ -850,7 +852,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
             : checkout(vspId, user);
     version.setStatus(VersionStatus.Locked);
 
-    healingManager.healAll(getHealingParamsAsMap(vspId, version, user));
+    Optional<String> errorMessages =
+        healingManager.healAll(getHealingParamsAsMap(vspId, version, user));
 
     VspDetails vspDetails = new VspDetails(vspId, version);
     vspDetails.setOldVersion(null);
@@ -858,6 +861,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
 
     logger.audit("Healed VSP " + vspDetails.getId());
     mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+
+    if (errorMessages.isPresent()) {
+      throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
+          .withCategory(ErrorCategory.APPLICATION).withMessage(errorMessages.get()).build());
+    }
   }
 
   private void autoHeal(String vspId, Version checkoutVersion, VspDetails vspDetails, String user) {
@@ -865,14 +873,20 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
 
     checkoutVersion.setStatus(VersionStatus.Locked);
     Map<String, Object> healingParams = getHealingParamsAsMap(vspId, checkoutVersion, user);
-    healingManager.healAll(healingParams);
+
+    Optional<String> errorMessages = healingManager.healAll(healingParams);
+
     vspDetails.setVersion(checkoutVersion);
     vspDetails.setOldVersion(null);
     vspInfoDao.updateOldVersionIndication(vspDetails);
 
     logger.audit("Healed VSP " + vspDetails.getName());
-
     mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+
+    if (errorMessages.isPresent()) {
+      throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
+          .withCategory(ErrorCategory.APPLICATION).withMessage(errorMessages.get()).build());
+    }
   }
 
   private Map<String, Object> getHealingParamsAsMap(String vspId, Version version, String user) {
index 8bcb0a5..72ad333 100644 (file)
@@ -22,7 +22,7 @@ package org.openecomp.sdc.common.errors;
 
 
 public enum Messages {
-  CANT_LOAD_CLASS("Can't load class %s. Error: %s"),
+  CANT_LOAD_HEALING_CLASS("Can't load healing class %s."),
 
   VERSION_UPGRADE("Item %s is of old version. A check out was made in order to get new " +
       "functionalities"),
index a2ce153..211d9a2 100644 (file)
@@ -23,6 +23,7 @@ package org.openecomp.sdc.healing.api;
 import org.openecomp.sdc.healing.types.HealCode;
 
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * Created by Talio on 11/29/2016.
@@ -30,5 +31,5 @@ import java.util.Map;
 public interface HealingManager {
     Object heal(HealCode code, Map<String, Object> healParameters);
 
-    void healAll(Map<String, Object> healParameters);
+    Optional<String> healAll(Map<String, Object> healParameters);
 }
index 0f2c0e7..16f9c60 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdc.healing.impl;
 
+import org.openecomp.core.utilities.CommonMethods;
 import org.openecomp.core.utilities.file.FileUtils;
 import org.openecomp.core.utilities.json.JsonUtil;
 import org.openecomp.sdc.common.errors.Messages;
@@ -33,8 +34,10 @@ import org.openecomp.sdc.logging.types.LoggerErrorCode;
 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
 
-import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * Created by Talio on 11/29/2016.
@@ -45,34 +48,53 @@ public class HealingManagerImpl implements HealingManager {
 
   @Override
   public Object heal(HealCode code, Map<String, Object> healParameters) {
-    String implClassName = healerCodeToImplClass.get(code.name());
-    try {
-      Healer healerImpl = getHealerImplInstance(implClassName);
-      return healerImpl.heal(healParameters);
+    ArrayList<String> healingFailureMessages = new ArrayList<>();
+
+    Object result =
+        heal(healParameters, healerCodeToImplClass.get(code.name()), healingFailureMessages);
+
+    if (!healingFailureMessages.isEmpty()) {
+      throw new RuntimeException(CommonMethods.listToSeparatedString(healingFailureMessages, '\n'));
+    }
+    return result;
+  }
 
+  @Override
+  public Optional<String> healAll(Map<String, Object> healParameters) {
+    ArrayList<String> healingFailureMessages = new ArrayList<>();
+
+    for (String implClassName : healerCodeToImplClass.values()) {
+      heal(healParameters, implClassName, healingFailureMessages);
+    }
+
+    return healingFailureMessages.isEmpty() ? Optional.empty()
+        : Optional.of(CommonMethods.listToSeparatedString(healingFailureMessages, '\n'));
+  }
+
+  private Object heal(Map<String, Object> healParameters, String healerImplClassName,
+                      ArrayList<String> healingFailureMessages) {
+    Healer healerImpl;
+    try {
+      healerImpl = getHealerImplInstance(healerImplClassName);
     } catch (Exception e) {
       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
           LoggerTragetServiceName.SELF_HEALING, ErrorLevel.ERROR.name(), LoggerErrorCode
               .DATA_ERROR.getErrorCode(), LoggerErrorDescription.CANT_HEAL);
-      throw new RuntimeException(String.format(Messages.CANT_LOAD_CLASS.getErrorMessage(),
-          implClassName, e.getMessage()));
+      healingFailureMessages
+          .add(String.format(Messages.CANT_LOAD_HEALING_CLASS.getErrorMessage(),
+              healerImplClassName));
+      return null;
     }
-  }
 
-  @Override
-  public void healAll(Map<String, Object> healParameters) {
-    for (String implClassName : healerCodeToImplClass.values()) {
-      try {
-        Healer healerImpl = getHealerImplInstance(implClassName);
-        healerImpl.heal(healParameters);
-      } catch (Exception e) {
-        MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
-            LoggerTragetServiceName.SELF_HEALING, ErrorLevel.ERROR.name(), LoggerErrorCode
-                .DATA_ERROR.getErrorCode(), LoggerErrorDescription.CANT_HEAL);
-        throw new RuntimeException(String.format(Messages.CANT_LOAD_CLASS.getErrorMessage(),
-            implClassName, e.getMessage()));
-      }
+    try {
+      return healerImpl.heal(healParameters);
+    } catch (Exception e) {
+      MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+          LoggerTragetServiceName.SELF_HEALING, ErrorLevel.ERROR.name(), LoggerErrorCode
+              .DATA_ERROR.getErrorCode(), LoggerErrorDescription.CANT_HEAL);
+      healingFailureMessages.add(e.getMessage());
     }
+    return null;
   }
 
   private static Map<String, String> initHealers() {
@@ -80,10 +102,8 @@ public class HealingManagerImpl implements HealingManager {
   }
 
   private Healer getHealerImplInstance(String implClassName)
-      throws ClassNotFoundException, NoSuchMethodException, InstantiationException,
-      IllegalAccessException, java.lang.reflect.InvocationTargetException {
-    Class<?> clazz = Class.forName(implClassName);
-    Constructor<?> constructor = clazz.getConstructor();
-    return (Healer) constructor.newInstance();
+      throws InstantiationException, IllegalAccessException, InvocationTargetException,
+      NoSuchMethodException, ClassNotFoundException {
+    return (Healer) Class.forName(implClassName).getConstructor().newInstance();
   }
 }
index 4e8de71..130405b 100644 (file)
@@ -67,9 +67,9 @@ public class SubEntitiesQuestionnaireHealer implements Healer {
         : (Version) healingParams.get(SdcCommon.VERSION);
 
     Collection<ComponentEntity> componentEntities =
-
         componentDao.listCompositionAndQuestionnaire(vspId, version);
-    networkDao.list(new NetworkEntity(vspId, version,null));
+
+    networkDao.list(new NetworkEntity(vspId, version, null));
 
     Collection<NicEntity> nicEntities = vendorSoftwareProductDao.listNicsByVsp(vspId, version);
 
@@ -90,7 +90,8 @@ public class SubEntitiesQuestionnaireHealer implements Healer {
 
     for (Object entity : compositionEntities) {
       CompositionEntity compositionEntity = (CompositionEntity) entity;
-      if (Objects.isNull(compositionEntity.getQuestionnaireData())) {
+      if (Objects.isNull(compositionEntity.getQuestionnaireData()) ||
+          "".equals(compositionEntity.getQuestionnaireData())) {
         compositionEntity.setVersion(newVersion);
         updateNullQuestionnaire(compositionEntity, type);
       }
index c76b15d..fffcc47 100644 (file)
@@ -51,14 +51,12 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType;
@@ -69,6 +67,7 @@ import org.openecomp.sdc.versioning.dao.types.Version;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -82,6 +81,8 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa
           "COMPOSITION_ENTITY_DATA_MANAGER_ERR";
   private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG =
           "Invalid input: %s may not be null";
+  private static final String MISSING_OR_INVALID_QUESTIONNAIRE_MSG =
+      "Data is missing/invalid for this %s. Please refill and resubmit.";
 
   private static final Logger logger =
           LoggerFactory.getLogger(CompositionEntityDataManagerImpl.class);
@@ -105,7 +106,7 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa
                                           NicDao nicDao, NetworkDao networkDao,
                                           ImageDao imageDao, ComputeDao computeDao,
                                           DeploymentFlavorDao deploymentFlavorDao,
-                                          VendorSoftwareProductDao vendorSoftwareProductDao ) {
+                                          VendorSoftwareProductDao vendorSoftwareProductDao) {
     this.vspInfoDao = vspInfoDao;
     this.componentDao = componentDao;
     this.nicDao = nicDao;
@@ -588,12 +589,10 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa
             compositionEntityData.entity.getCompositionEntityId().toString(),
             compositionEntityData.entity.getQuestionnaireData()));
 
-    if(Objects.isNull(compositionEntityData.entity.getQuestionnaireData()) || !JsonUtil.isValidJson
-            (compositionEntityData.entity.getQuestionnaireData())){
-      List<String> errors = new ArrayList<>();
-      errors.add("Data is missing for the above " + compositionEntityData.entity.getType() +
-              ". Complete the mandatory fields and resubmit.");
-      return errors;
+    if (Objects.isNull(compositionEntityData.entity.getQuestionnaireData()) ||
+        !JsonUtil.isValidJson(compositionEntityData.entity.getQuestionnaireData())) {
+      return Collections.singletonList(String
+          .format(MISSING_OR_INVALID_QUESTIONNAIRE_MSG, compositionEntityData.entity.getType()));
     }
 
     return JsonUtil.validate(
@@ -677,8 +676,8 @@ public class CompositionEntityDataManagerImpl implements CompositionEntityDataMa
     return compute;
   }
 
-  public void saveComputesFlavorByComponent(String vspId, Version version, Component component, String
-          componentId) {
+  public void saveComputesFlavorByComponent(String vspId, Version version, Component component,
+                                            String componentId) {
     if (CollectionUtils.isNotEmpty(component.getCompute())) {
       for (ComputeData flavor : component.getCompute()) {
         ComputeEntity computeEntity = new ComputeEntity(vspId, version, componentId, null);