aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2017-12-24 08:55:14 +0200
committershrek2000 <orenkle@amdocs.com>2017-12-25 14:04:33 +0200
commit22f1220c2dda43e3dcbadd70180db521a7984d1d (patch)
tree5b8b9191fe049a7aa400ab046a1a38d64a6b3540 /openecomp-be/tools/zusammen-tools
parent8c2d513bed8aaea182e17babdd64101196e0c123 (diff)
Import Export Tool add executors
Issue-ID: SDC-773 Change-Id: Id203b671e9af0b3478b75032111b73a509a9a5df Signed-off-by: shrek2000 <orenkle@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/exportinfo/ExportDataCommand.java31
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java2
2 files changed, 22 insertions, 11 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java
index 5dcc72de59..c5e140ed7c 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java
@@ -3,7 +3,6 @@
*/
package org.openecomp.core.tools.exportinfo;
-import com.amdocs.zusammen.datatypes.SessionContext;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.Session;
@@ -32,20 +31,27 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import static java.nio.file.Files.createDirectories;
-public class ExportDataCommand {
+public final class ExportDataCommand {
private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
public static final String JOIN_DELIMITER = "$#";
public static final String JOIN_DELIMITER_SPILTTER = "\\$\\#";
public static final String MAP_DELIMITER = "!@";
public static final String MAP_DELIMITER_SPLITTER = "\\!\\@";
- public static final String EXPORT_FILE_NAME = "ITEM_EXPORT";
+ public static final int THREAD_POOL_SIZE = 4;
- public static void exportData(SessionContext sessionContext, String filterItem) {
+ private ExportDataCommand() {
+ }
+
+ public static void exportData(String filterItem) {
+ ExecutorService executor = null;
try {
CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
final Set<String> filteredItems = Sets.newHashSet(filterItem);
@@ -59,18 +65,19 @@ public class ExportDataCommand {
queries = (Map<String, List<String>>) yaml.load(is);
}
List<String> queriesList = queries.get("queries");
- List<String> itempsColumns = queries.get("item_columns");
+ List<String> itemsColumns = queries.get("item_columns");
Set<String> vlms = new HashSet<>();
CountDownLatch doneQueries = new CountDownLatch(queriesList.size());
+ executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
for (int i = 0; i < queriesList.size(); i++) {
- executeQuery(queriesList.get(i), fis, itempsColumns.get(i), vlms, doneQueries);
+ executeQuery(queriesList.get(i), fis, itemsColumns.get(i), vlms, doneQueries, executor);
}
doneQueries.await();
if (!vlms.isEmpty()) {
CountDownLatch doneVmls = new CountDownLatch(queriesList.size());
for (int i = 0; i < queriesList.size(); i++) {
- executeQuery(queriesList.get(i), vlms, itempsColumns.get(i), null, doneVmls);
+ executeQuery(queriesList.get(i), vlms, itemsColumns.get(i), null, doneVmls, executor);
}
doneVmls.await();
@@ -79,13 +86,17 @@ public class ExportDataCommand {
FileUtils.forceDelete(rootDir.toFile());
} catch (Exception ex) {
Utils.logError(logger, ex);
+ } finally {
+ if (executor != null) {
+ executor.shutdown();
+ }
}
}
private static boolean executeQuery(final String query, final Set<String> filteredItems, final String filteredColumn,
- final Set<String> vlms, final CountDownLatch donequerying) {
+ final Set<String> vlms, final CountDownLatch donequerying, Executor executor) {
Session session = CassandraSessionFactory.getSession();
ResultSetFuture resultSetFuture = session.executeAsync(query);
Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() {
@@ -100,11 +111,11 @@ public class ExportDataCommand {
Utils.logError(logger, "Query failed :" + query, t);
donequerying.countDown();
}
- });
+ }, executor);
return true;
}
- private static void zipPath(Path rootDir) throws Exception {
+ private static void zipPath(Path rootDir) throws IOException {
LocalDateTime date = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
String dateStr = date.format(formatter);
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java
index 182988717e..acc60deb16 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java
@@ -42,7 +42,7 @@ public class ZusammenMainTool {
SetHealingFlag.populateHealingTable(ToolsUtil.getParam("v",args));
break;
case EXPORT:
- ExportDataCommand.exportData(context,ToolsUtil.getParam("i",args));
+ ExportDataCommand.exportData(ToolsUtil.getParam("i",args));
break;
case IMPORT:
ImportDataCommand.execute(context, ToolsUtil.getParam("f",args));