diff options
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java')
-rw-r--r-- | openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java | 108 |
1 files changed, 50 insertions, 58 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 2907d1e0cc..893c605784 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 @@ -7,9 +7,9 @@ * 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. @@ -58,32 +58,69 @@ import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.yaml.snakeyaml.Yaml; - public final class ExportDataCommand extends Command { - private static final Logger LOGGER = LoggerFactory.getLogger(ExportDataCommand.class); - private static final String ITEM_ID_OPTION = "i"; - static final String JOIN_DELIMITER = "$#"; public static final String JOIN_DELIMITER_SPLITTER = "\\$\\#"; - static final String MAP_DELIMITER = "!@"; public static final String MAP_DELIMITER_SPLITTER = "\\!\\@"; - private static final int THREAD_POOL_SIZE = 6; public static final String NULL_REPRESENTATION = "nnuullll"; + static final String JOIN_DELIMITER = "$#"; + static final String MAP_DELIMITER = "!@"; + private static final Logger LOGGER = LoggerFactory.getLogger(ExportDataCommand.class); + private static final String ITEM_ID_OPTION = "i"; + private static final int THREAD_POOL_SIZE = 6; public ExportDataCommand() { - options.addOption( - Option.builder(ITEM_ID_OPTION).hasArg().argName("item id").desc("id of item to export, mandatory").build()); + options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item id").desc("id of item to export, mandatory").build()); + } + + private static void executeQuery(final Session session, final String query, final Set<String> filteredItems, final String filteredColumn, + final Set<String> vlms, final CountDownLatch donequerying, Executor executor) { + ResultSetFuture resultSetFuture = session.executeAsync(query); + Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() { + @Override + public void onSuccess(ResultSet resultSet) { + try { + Utils.printMessage(LOGGER, "Start to serialize " + query); + new ExportSerializer().serializeResult(resultSet, filteredItems, filteredColumn, vlms); + donequerying.countDown(); + } catch (Exception e) { + Utils.logError(LOGGER, "Serialization failed :" + query, e); + System.exit(-1); + } + } + + @Override + public void onFailure(Throwable t) { + Utils.logError(LOGGER, "Query failed :" + query, t); + System.exit(-1); + } + }, executor); + } + + private static void zipPath(final Path rootDir) throws ZipException { + final LocalDateTime date = LocalDateTime.now(); + final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + final String dateStr = date.format(formatter).replace(":", "_"); + final Path zipFile = Paths.get(System.getProperty("user.home"), String.format("onboarding_import%s.zip", dateStr)); + ZipUtils.createZipFromPath(rootDir, zipFile); + Utils.printMessage(LOGGER, "Zip file was created " + zipFile.toString()); + Utils.printMessage(LOGGER, "Exported file :" + zipFile.toString()); + } + + public static void initDir(Path rootDir) throws IOException { + if (rootDir.toFile().exists()) { + FileUtils.forceDelete(rootDir.toFile()); + } + createDirectories(rootDir); } @Override public boolean execute(String[] args) { CommandLine cmd = parseArgs(args); - if (!cmd.hasOption(ITEM_ID_OPTION) || cmd.getOptionValue(ITEM_ID_OPTION) == null) { LOGGER.error("Argument i is mandatory"); return false; } - ExecutorService executor = null; try { CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); @@ -91,8 +128,7 @@ public final class ExportDataCommand extends Command { initDir(rootDir); try (Session session = CassandraSessionFactory.getSession()) { final Set<String> filteredItems = Sets.newHashSet(cmd.getOptionValue(ITEM_ID_OPTION)); - Set<String> fis = - filteredItems.stream().map(fi -> fi.replaceAll("\\r", "")).collect(Collectors.toSet()); + Set<String> fis = filteredItems.stream().map(fi -> fi.replaceAll("\\r", "")).collect(Collectors.toSet()); Map<String, List<String>> queries; Yaml yaml = new Yaml(); try (InputStream is = ExportDataCommand.class.getResourceAsStream("/queries.yaml")) { @@ -112,7 +148,6 @@ public final class ExportDataCommand extends Command { for (int i = 0; i < queriesList.size(); i++) { executeQuery(session, queriesList.get(i), vlms, itemsColumns.get(i), null, doneVmls, executor); } - doneVmls.await(); } } @@ -132,47 +167,4 @@ public final class ExportDataCommand extends Command { public CommandName getCommandName() { return EXPORT; } - - private static void executeQuery(final Session session, final String query, final Set<String> filteredItems, - final String filteredColumn, final Set<String> vlms, final CountDownLatch donequerying, Executor executor) { - ResultSetFuture resultSetFuture = session.executeAsync(query); - Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() { - @Override - public void onSuccess(ResultSet resultSet) { - try { - Utils.printMessage(LOGGER, "Start to serialize " + query); - new ExportSerializer().serializeResult(resultSet, filteredItems, filteredColumn, vlms); - donequerying.countDown(); - } catch (Exception e) { - Utils.logError(LOGGER, "Serialization failed :" + query, e); - System.exit(-1); - } - } - - @Override - public void onFailure(Throwable t) { - Utils.logError(LOGGER, "Query failed :" + query, t); - System.exit(-1); - } - }, executor); - } - - private static void zipPath(final Path rootDir) throws ZipException { - final LocalDateTime date = LocalDateTime.now(); - final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; - final String dateStr = date.format(formatter).replace(":", "_"); - final Path zipFile = Paths.get(System.getProperty("user.home"),String.format("onboarding_import%s.zip", dateStr)); - ZipUtils.createZipFromPath(rootDir, zipFile); - Utils.printMessage(LOGGER, "Zip file was created " + zipFile.toString()); - Utils.printMessage(LOGGER, "Exported file :" + zipFile.toString()); - } - - - public static void initDir(Path rootDir) throws IOException { - if (rootDir.toFile().exists()) { - FileUtils.forceDelete(rootDir.toFile()); - } - createDirectories(rootDir); - } - } |