summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-healing-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib')
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-api/src/main/java/org/openecomp/sdc/healing/interfaces/Healer.java6
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java248
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json18<
<!--
  ~ Copyright © 2016-2018 European Support Limited
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <name>openecomp-sdc-validation-impl</name>
    <artifactId>openecomp-sdc-validation-impl</artifactId>


    <parent>
        <groupId>org.openecomp.sdc</groupId>
        <artifactId>openecomp-sdc-lib</artifactId>
        <version>1.6.3-SNAPSHOT</version>
        <relativePath>../..</relativePath>
    </parent>

    <dependencies>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc</groupId>
            <artifactId>openecomp-sdc-logging-core</artifactId>
            <version>${project.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc</groupId>
            <artifactId>openecomp-sdc-logging-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc.core</groupId>
            <artifactId>openecomp-utilities-lib</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc</groupId>
            <artifactId>openecomp-sdc-validation-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc.core</groupId>
            <artifactId>openecomp-common-lib</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc.core</groupId>
            <artifactId>openecomp-heat-lib</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons.io.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openecomp.sdc</groupId>
            <artifactId>openecomp-sdc-validation-core</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

</project>
rivate Optional<String> healPublic(String itemId, Version version,
- Map<String, Map<String, String>> itemHealers, String user) {
- SessionContext context =
- SessionContextProviderFactory.getInstance().createInterface().get();
- SessionContextProviderFactory.getInstance().createInterface().create(user
- + HEALING_USER_SUFFIX,context.getTenant());
+ private List<String> healPublic(String itemId, Version version, List<Healer> healers,
+ String user) {
+ String tenant = SessionContextProviderFactory.getInstance().createInterface().get().getTenant();
+ SessionContextProviderFactory.getInstance().createInterface()
+ .create(user + HEALING_USER_SUFFIX, tenant);
- versioningManager.sync(itemId, version);
+ versioningManager.forceSync(itemId, version);
- Optional<String> healingFailureMessages = executeHealers(itemId, version, itemHealers);
+ List<String> failureMessages = executeHealers(itemId, version, healers);
Version publicVersion = versioningManager.get(itemId, version);
if (Objects.nonNull(publicVersion.getState()) && publicVersion.getState().isDirty()) {
versioningManager.publish(itemId, version, "Healing vsp");
}
- SessionContextProviderFactory.getInstance().createInterface().create(user, context.getTenant());
- return healingFailureMessages;
+ SessionContextProviderFactory.getInstance().createInterface().create(user, tenant);
+ return failureMessages;
}
- private Optional<Version> createNewVersion(String itemId, Version version) {
- Version newVersion = new Version();
- newVersion.setBaseId(version.getId());
- try {
- return Optional.of(versioningManager.create(itemId, newVersion, VersionCreationMethod.major));
- } catch (Exception e) {
- return Optional.empty();
- }
- }
-
- private Optional<String> executeHealers(String itemId, Version version,
- Map<String, Map<String, String>> itemHealers) {
- List<String> healers = itemHealers.values().stream()
- .map(Map::values)
- .flatMap(Collection::stream)
- .collect(Collectors.toList());
-
- List<String> healingFailureMessages = new ArrayList<>();
- for (String implClassName : healers) {
- executeHealer(itemId, version, implClassName, healingFailureMessages);
- }
-
- return healingFailureMessages.isEmpty()
- ? Optional.empty()
- : Optional.of(CommonMethods.listToSeparatedString(healingFailureMessages, '\n'));
- }
-
-
- private Object executeHealer(String itemId, Version version, String healerClassName,
- List<String> healingFailureMessages) {
- Healer healer;
- try {
- healer = getHealerImplInstance(healerClassName);
- } catch (Exception e) {
- healingFailureMessages
- .add(String.format(Messages.CANT_LOAD_HEALING_CLASS.getErrorMessage(),
- healerClassName));
- return null;
+ private List<String> executeHealers(String itemId, Version version, List<Healer> healers) {
+ List<String> failureMessages = new LinkedList<>();
+ for (Healer healer : healers) {
+ try {
+ healer.heal(itemId, version);
+ } catch (Exception e) {
+ failureMessages.add(
+ String.format("Failure in healer %s: %s", healer.getClass().getName(), e.getMessage()));
+ }
}
- try {
- return healer.heal(itemId, version);
- } catch (Exception e) {
- healingFailureMessages.add(e.getMessage() + " ,healer name :" + healerClassName);
- }
- return null;
+ return failureMessages;
}
private boolean isPrivateHealingNeededByFlag(String itemId, String version, String user) {
@@ -214,17 +218,39 @@ public class HealingManagerImpl implements HealingManager {
healingDao.setItemHealingFlag(false, user, itemId, versionId);
}
- private Map<String, Map<String, String>> getItemHealers(ItemType itemType) {
+ private void handleFailures(List<String> failureMessages) {
+ if (!failureMessages.isEmpty()) {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withCategory(ErrorCategory.APPLICATION)
+ .withMessage(CommonMethods.listToSeparatedString(failureMessages, '\n')).build());
+ }
+ }
+
+ private List<Healer> getHealersToRun(Collection<String> healersClassNames, String itemId,
+ Version version, List<String> failureMessages) {
+ return healersClassNames.stream()
+ .map(healerClassName -> getHealerInstance(healerClassName, failureMessages))
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .filter(healer -> healer.isHealingNeeded(itemId, version))
+ .collect(Collectors.toList());
+ }
+
+ private Optional<Healer> getHealerInstance(String healerClassName, List<String> failureMessages) {
+ try {
+ return Optional.of((Healer) Class.forName(healerClassName).getConstructor().newInstance());
+ } catch (Exception e) {
+ failureMessages
+ .add(String.format(Messages.CANT_LOAD_HEALING_CLASS.getErrorMessage(), healerClassName));
+ return Optional.empty();
+ }
+ }
+
+ private Map<String, Collection<String>> getItemHealers(ItemType itemType) {
Map healingConfig = FileUtils
.readViaInputStream(HEALERS_BY_ENTITY_TYPE_FILE,
stream -> JsonUtil.json2Object(stream, Map.class));
- return (Map<String, Map<String, String>>) healingConfig.get(itemType.name());
- }
-
- private Healer getHealerImplInstance(String implClassName)
- throws InstantiationException, IllegalAccessException, InvocationTargetException,
- NoSuchMethodException, ClassNotFoundException {
- return (Healer) Class.forName(implClassName).getConstructor().newInstance();
+ return (Map<String, Collection<String>>) healingConfig.get(itemType.name());
}
private String getUser() {
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json
index 64f43a6625..2fc23372de 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/entityHealingConfiguration.json
@@ -1,15 +1,15 @@
{
"vsp": {
- "structure": {
- "ownerHealer": "org.openecomp.sdc.healing.healers.OwnerHealer"
- },
- "data": {
- "toscaServiceModelHealer": "org.openecomp.sdc.healing.healers.ToscaServiceModelHealer"
- }
+ "structure": [
+ "org.openecomp.sdc.healing.healers.OwnerHealer"
+ ],
+ "data": [
+ "org.openecomp.sdc.healing.healers.ToscaServiceModelHealer"
+ ]
},
"vlm": {
- "structure": {
- "ownerHealer": "org.openecomp.sdc.healing.healers.OwnerHealer"
- }
+ "structure": [
+ "org.openecomp.sdc.healing.healers.OwnerHealer"
+ ]
}
} \ No newline at end of file
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(