diff options
author | Avi Gaffa <avi.gaffa@amdocs.com> | 2017-09-14 05:32:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-14 05:32:11 +0000 |
commit | de8841c36349510e1b4c773753afad0eb8061f8c (patch) | |
tree | 82cab3d0dedc997a06bcc9132386e40d00e9b2a9 /openecomp-be/lib/openecomp-healing-lib | |
parent | 67b4ec2d8d3c3db4758a73e81378d01787eb94a1 (diff) | |
parent | 3e805e4880fb799a7e1eac6ac3ee14162fa1e9e6 (diff) |
Merge "Change healing manager logic"
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib')
3 files changed, 52 insertions, 30 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-api/src/main/java/org/openecomp/sdc/healing/api/HealingManager.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-api/src/main/java/org/openecomp/sdc/healing/api/HealingManager.java index a2ce153a82..211d9a21b2 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-api/src/main/java/org/openecomp/sdc/healing/api/HealingManager.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-api/src/main/java/org/openecomp/sdc/healing/api/HealingManager.java @@ -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); } 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<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(); } } diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java index 4e8de71ea3..130405be1d 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java @@ -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); } |