summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2018-02-28 10:53:11 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-02-28 11:28:17 +0000
commit1b03220adb20c86530e983a6cda78e1732cc05d7 (patch)
tree9eb1192f6baf4f12196a43c2364eb7db09cb7727 /openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main
parent23cc7f5c7d811d7ed1038b354db4c07687e17cc3 (diff)
Healing manager logic enhancements
Check whether healers need to run before running them. Heal private: if there's at least one structure healer - force sync (instead of running data healers). Change-Id: I5cc5ce43d61a59d5cfd6a1db717d6e3e4be1119a Issue-ID: SDC-1066 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main')
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java35
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java22
2 files changed, 30 insertions, 27 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
index 711848c4e1..7a9b6c219f 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
@@ -19,7 +19,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
-import java.util.stream.Stream;
/**
* Created by ayalaben on 8/28/2017
@@ -33,12 +32,16 @@ public class OwnerHealer implements Healer {
private static final SubscribersDao subscribersDao = SubscribersDaoFactory.getInstance()
.createInterface();
- public Object heal(String itemId, Version version) {
- Stream<ItemPermissionsEntity> itemPermissions = permissionsDao.listItemPermissions(itemId)
- .stream();
+ @Override
+ public boolean isHealingNeeded(String itemId, Version version) {
+ return permissionsDao.listItemPermissions(itemId).stream().noneMatch(this::isOwnerPermission) ||
+ isOwnerMissingOnItem(itemId);
+ }
+ public void heal(String itemId, Version version) {
+ Collection<ItemPermissionsEntity> itemPermissions = permissionsDao.listItemPermissions(itemId);
- if (itemPermissions.noneMatch(this::isOwnerPermission)) {
+ if (itemPermissions.stream().noneMatch(this::isOwnerPermission)) {
String currentUserId =
SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId()
.replace(HEALING_USER_SUFFIX, "");
@@ -46,24 +49,22 @@ public class OwnerHealer implements Healer {
permissionsDao.updateItemPermissions(itemId, PermissionTypes.Owner.name(),
Collections.singleton(currentUserId), new HashSet<>());
- updateItemOwner(itemId,currentUserId);
+ updateItemOwner(itemId, currentUserId);
- subscribersDao.subscribe(currentUserId,itemId);
+ subscribersDao.subscribe(currentUserId, itemId);
- return currentUserId;
- } else if (!itemHasOwnerProperty(itemId)){
- Optional<ItemPermissionsEntity> ownerOpt = itemPermissions.filter
- (this::isOwnerPermission).findFirst();
- if(ownerOpt.isPresent()) {
+ } else if (isOwnerMissingOnItem(itemId)) {
+ Optional<ItemPermissionsEntity> ownerOpt =
+ itemPermissions.stream().filter(this::isOwnerPermission).findFirst();
+ if (ownerOpt.isPresent()) {
updateItemOwner(itemId, ownerOpt.get().getUserId());
} else {
throw new SdcRuntimeException("Unexpected error in Owner Healer. Item id: " + itemId);
}
- }
- return itemPermissions.filter(this::isOwnerPermission).findFirst().get().getUserId();
+ }
}
- private void updateItemOwner(String itemId,String userId) {
+ private void updateItemOwner(String itemId, String userId) {
Item item = new Item();
item.setId(itemId);
Item retrievedItem = itemDao.get(item);
@@ -73,11 +74,11 @@ public class OwnerHealer implements Healer {
}
}
- private boolean itemHasOwnerProperty(String itemId){
+ private boolean isOwnerMissingOnItem(String itemId) {
Item item = new Item();
item.setId(itemId);
Item retrievedItem = itemDao.get(item);
- return Objects.nonNull(retrievedItem) && Objects.nonNull(retrievedItem.getOwner());
+ return Objects.nonNull(retrievedItem) && Objects.isNull(retrievedItem.getOwner());
}
private boolean isOwnerPermission(ItemPermissionsEntity permissionsEntity) {
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
index e07faad4fa..4fa5328b6e 100644
--- 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
@@ -43,25 +43,28 @@ public class ToscaServiceModelHealer implements Healer {
}
@Override
- public Object heal(String itemId, Version version) throws Exception {
+ public boolean isHealingNeeded(String itemId, Version version) {
+ OrchestrationTemplateEntity orchestrationTemplate =
+ orchestrationTemplateDao.get(itemId, version);
+ OnboardingTypesEnum onboardingTypes =
+ OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix());
+
+ return Objects.nonNull(onboardingTypes) &&
+ Objects.nonNull(orchestrationTemplate.getContentData());
+ }
+
+ @Override
+ public void 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(
@@ -79,7 +82,6 @@ public class ToscaServiceModelHealer implements Healer {
default:
return Optional.empty();
}
-
}
private FileContentHandler getFileContentHandlerForHealing(