From 3e805e4880fb799a7e1eac6ac3ee14162fa1e9e6 Mon Sep 17 00:00:00 2001 From: talig Date: Wed, 13 Sep 2017 18:16:36 +0300 Subject: Change healing manager logic 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 --- .../sdc/healing/impl/HealingManagerImpl.java | 72 ++++++++++++++-------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core') diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java index 0f2c0e7ee1..16f9c60d7f 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java @@ -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 healParameters) { - String implClassName = healerCodeToImplClass.get(code.name()); - try { - Healer healerImpl = getHealerImplInstance(implClassName); - return healerImpl.heal(healParameters); + ArrayList 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 healAll(Map healParameters) { + ArrayList 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 healParameters, String healerImplClassName, + ArrayList 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 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 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(); } } -- cgit 1.2.3-korg