From 22f1220c2dda43e3dcbadd70180db521a7984d1d Mon Sep 17 00:00:00 2001 From: shrek2000 Date: Sun, 24 Dec 2017 08:55:14 +0200 Subject: Import Export Tool add executors Issue-ID: SDC-773 Change-Id: Id203b671e9af0b3478b75032111b73a509a9a5df Signed-off-by: shrek2000 --- .../core/tools/exportinfo/ExportDataCommand.java | 31 +++++++++++++++------- .../core/tools/main/ZusammenMainTool.java | 2 +- 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 filteredItems = Sets.newHashSet(filterItem); @@ -59,18 +65,19 @@ public class ExportDataCommand { queries = (Map>) yaml.load(is); } List queriesList = queries.get("queries"); - List itempsColumns = queries.get("item_columns"); + List itemsColumns = queries.get("item_columns"); Set 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 filteredItems, final String filteredColumn, - final Set vlms, final CountDownLatch donequerying) { + final Set vlms, final CountDownLatch donequerying, Executor executor) { Session session = CassandraSessionFactory.getSession(); ResultSetFuture resultSetFuture = session.executeAsync(query); Futures.addCallback(resultSetFuture, new FutureCallback() { @@ -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)); -- cgit 1.2.3-korg