aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools
diff options
context:
space:
mode:
authorolegb <olegb@amdocs.com>2018-07-09 16:25:48 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-07-11 05:51:37 +0000
commita6ccc12ee2111e29e1243855ffe7c295d7f44b3d (patch)
tree137ec0d5b715ec82995d46f9fb472103d74be0a7 /openecomp-be/tools/zusammen-tools
parent35767f3c6ea98e643e2d0bc638fa87ac1ef65808 (diff)
Utility for healing flag reset per item/version
Change-Id: I1da96fcddbbc926a4e184934d7daaad2704feb44 Issue-ID: SDC-1467 Signed-off-by: Oleg Beltz <olegb@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/zusammen-tools')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java3
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java1
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlagByItemVersionCommand.java80
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java4
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh19
5 files changed, 96 insertions, 11 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java
index 7490f03a82..25a5f039f4 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java
@@ -8,5 +8,6 @@ public enum CommandName {
POPULATE_USER_PERMISSIONS,
ADD_CONTRIBUTOR,
CLEAN_USER_DATA,
- DELETE_PUBLIC_VERSION
+ DELETE_PUBLIC_VERSION,
+ SET_HEAL_BY_ITEM_VERSION
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java
index dc237b5ccc..e5def6f73e 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java
@@ -37,6 +37,7 @@ public class CommandsHolder {
new AddContributorCommand().register();
new CleanUserDataCommand().register();
new DeletePublicVersionCommand().register();
+ new SetHealingFlagByItemVersionCommand().register();
}
private CommandsHolder() {
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlagByItemVersionCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlagByItemVersionCommand.java
new file mode 100644
index 0000000000..db90652b8f
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlagByItemVersionCommand.java
@@ -0,0 +1,80 @@
+/*
+* 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.
+*/
+
+package org.openecomp.core.tools.commands;
+
+import static org.openecomp.core.tools.commands.CommandName.SET_HEAL_BY_ITEM_VERSION;
+
+import com.datastax.driver.core.ResultSet;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.openecomp.core.tools.store.HealingHandler;
+import org.openecomp.core.tools.store.VersionCassandraLoader;
+import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+public class SetHealingFlagByItemVersionCommand extends Command {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SetHealingFlagByItemVersionCommand.class);
+ private static final String ITEM_ID_OPTION = "i";
+ private static final String VERSION_ID_OPTION = "v";
+ private static final String PROJECT_OPTION = "o";
+
+ SetHealingFlagByItemVersionCommand() {
+ options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id")
+ .desc("id of the item to reset healing flag, mandatory").build());
+ options.addOption(Option.builder(VERSION_ID_OPTION).hasArg().argName("version_id")
+ .desc("id of the version to delete from public, mandatory").build());
+ options.addOption(Option.builder(PROJECT_OPTION).hasArg().argName("old_project_version")
+ .desc("old project version, mandatory").build());
+ }
+
+ @Override
+ public boolean execute(String[] args) {
+ CommandLine cmd = parseArgs(args);
+ if (!(cmd.hasOption(ITEM_ID_OPTION) && cmd.hasOption(VERSION_ID_OPTION) && cmd.hasOption(PROJECT_OPTION))) {
+ LOGGER.error("Arguments i, v and o are mandatory");
+ return false;
+ }
+ String itemId = cmd.getOptionValue(ITEM_ID_OPTION);
+ String versionId = cmd.getOptionValue(VERSION_ID_OPTION);
+ String projectVersion = cmd.getOptionValue(PROJECT_OPTION);
+
+ VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
+ ResultSet listItemVersion = versionCassandraLoader.listItemVersion();
+
+ List<HealingEntity> healingEntities = listItemVersion.all().stream().filter(
+ entry -> (entry.getString("item_id").equals(itemId)
+ && entry.getString("version_id").equals(versionId))).map(entry ->
+ new HealingEntity(entry.getString("space"), entry.getString("item_id"),
+ entry.getString("version_id"), true, projectVersion)).collect(Collectors.toList());
+
+ HealingHandler healingHandler = new HealingHandler();
+ healingHandler.populateHealingTable(healingEntities);
+
+ return true;
+ }
+
+ @Override
+ public CommandName getCommandName() {
+ return SET_HEAL_BY_ITEM_VERSION;
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java
index 78bbdf069e..f6d2c5ff7d 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java
@@ -7,7 +7,7 @@ import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity;
-import java.util.ArrayList;
+import java.util.List;
/**
* Created by ayalaben on 10/15/2017
@@ -19,7 +19,7 @@ public class HealingHandler {
nnoSqlDb.getMappingManager().createAccessor(HealingAccessor.class);
- public void populateHealingTable(ArrayList<HealingEntity> healingEntities) {
+ public void populateHealingTable(List<HealingEntity> healingEntities) {
healingEntities.forEach(healingEntity -> {
if (isHealingRecordExist(healingEntity)) {
accessor.updateFlag(healingEntity.getHealingFlag(), healingEntity.getSpace(),
diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
index 54be5e74ef..f02062be56 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
+++ b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
@@ -1,14 +1,17 @@
#!/bin/bash
-
###########################################################################################################
# script name - zusammenMainTool.sh
# run script - ./zusammenMainTool.sh
-# 1. Export all - ./zusammenMainTool.sh -c EXPORT
-# 2. Export one item ./zusammenMainTool.sh -c EXPORT -i ${elementId}
-# 3. Import one item - ./zusammenMainTool.sh -c IMPORT -f ${fileName} -i ${elementId}
-# 4. Import all - ./zusammenMainTool.sh -c IMPORT -f ${fileName}
-# 5. Reset old version - ./zusammenMainTool.sh -c RESET_OLD_VERSION
-# 6. Heal all - ./zusammenMainTool.sh -c HEAL_ALL -t ${thread number}
+# 1. Export all - ./zusammenMainTool.sh -c EXPORT
+# 2. Export one item - ./zusammenMainTool.sh -c EXPORT -i ${elementId}
+# 3. Import one item - ./zusammenMainTool.sh -c IMPORT -f ${fileName} -i ${elementId}
+# 4. Import all - ./zusammenMainTool.sh -c IMPORT -f ${fileName}
+# 5. Reset old version - ./zusammenMainTool.sh -c RESET_OLD_VERSION -v ${old_version}
+# 6. Set healing flag - ./zusammenMainTool.sh -c SET_HEAL_BY_ITEM_VERSION -i {item id} -v {version_id} -o ${old_project_version}
+# 7. Heal all - ./zusammenMainTool.sh -c HEAL_ALL -t ${thread number}
+# 8. Clean user data: - ./zusammenMainTool.sh -c CLEAN_USER_DATA -i {item id} -u {user}
+# 9. Delete public version: - ./zusammenMainTool.sh -c DELETE_PUBLIC_VERSION -i {item id} -v {version_id}
+# 10. Add user as contributor: - ./zusammenMainTool.sh -c ADD_CONTRIBUTOR [-p {item id list file path}] -u {user list file path}
# 7. Populate User Permissions - ./zusammenMainTool.sh -c POPULATE_USER_PERMISSIONS
#
##########################################################################################################
@@ -25,5 +28,5 @@ fi
echo "Configuration file location: ${CONF_FILE_LOCATION}"
mv lib/openecomp-zusammen-tools*.jar openecomp-zusammen-tools.jar &>/dev/null
-java -Dconfig.home=/opt/app/jetty/base/be/config -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=${CONF_FILE_LOCATION} -classpath openecomp-zusammen-tools.jar:lib/* org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 $5 $6
+java -Dconfig.home=/opt/app/jetty/base/be/config -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=${CONF_FILE_LOCATION} -classpath openecomp-zusammen-tools.jar:lib/* org.openecomp.core.tools.main.ZusammenMainTool ${*}
STATUS="${?}" echo "${STATUS}"