From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../core/tools/commands/AddContributorCommand.java | 81 +++++------ .../core/tools/commands/CleanUserDataCommand.java | 31 ++--- .../org/openecomp/core/tools/commands/Command.java | 10 +- .../openecomp/core/tools/commands/CommandName.java | 15 +- .../core/tools/commands/CommandsHolder.java | 18 +-- .../tools/commands/DeletePublicVersionCommand.java | 31 ++--- .../org/openecomp/core/tools/commands/HealAll.java | 86 +++++------- .../tools/commands/PopulateUserPermissions.java | 8 +- .../core/tools/commands/SetHealingFlag.java | 15 +- .../SetHealingFlagByItemVersionCommand.java | 54 +++----- .../tools/concurrent/ItemAddContributorsTask.java | 77 +++++------ .../CommandExecutionRuntimeException.java | 6 +- .../tools/exceptions/HealingRuntimeException.java | 6 +- .../core/tools/exportinfo/ExportDataCommand.java | 108 +++++++-------- .../core/tools/exportinfo/ExportSerializer.java | 24 ++-- .../core/tools/importinfo/ImportDataCommand.java | 7 +- .../core/tools/importinfo/ImportProperties.java | 8 +- .../core/tools/importinfo/ImportSingleTable.java | 58 ++++---- .../core/tools/itemvalidation/ItemValidation.java | 154 ++++++++------------- .../tools/loaders/VersionInfoCassandraLoader.java | 29 ++-- .../core/tools/main/ZusammenMainTool.java | 12 +- .../core/tools/model/ColumnDefinition.java | 14 +- .../org/openecomp/core/tools/model/TableData.java | 5 +- .../core/tools/store/ElementCassandraLoader.java | 70 ++++------ .../core/tools/store/ElementNamespaceHandler.java | 15 +- .../openecomp/core/tools/store/HealingHandler.java | 63 ++++----- .../openecomp/core/tools/store/ItemHandler.java | 34 ++--- .../core/tools/store/NotificationHandler.java | 33 ++--- .../core/tools/store/PermissionHandler.java | 81 +++++------ .../core/tools/store/VersionCassandraLoader.java | 35 ++--- .../store/VersionElementsCassandraLoader.java | 37 +++-- .../tools/store/VersionInfoCassandraLoader.java | 20 +-- .../store/zusammen/datatypes/ElementEntity.java | 54 +++----- .../store/zusammen/datatypes/HealingEntity.java | 30 ++-- .../zusammen/datatypes/VersionElementsEntity.java | 78 +++++------ .../store/zusammen/datatypes/VersionEntity.java | 19 +-- .../org/openecomp/core/tools/util/ToolsUtil.java | 20 ++- .../java/org/openecomp/core/tools/util/Utils.java | 51 ++++--- 38 files changed, 627 insertions(+), 870 deletions(-) (limited to 'openecomp-be/tools/zusammen-tools') diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java index 8bdf178938..33bf2f1762 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import java.io.IOException; @@ -51,24 +50,46 @@ public class AddContributorCommand extends Command { private static final String COMMAND_ADD_CONTRIBUTOR_FAILED = "Command AddContributor execution failed."; AddContributorCommand() { - options.addOption(Option.builder(ITEMS_PATH_OPTION).hasArg().argName("file") - .desc("file containing list of item ids, mandatory").build()); - options.addOption(Option.builder(UUSERS_PATH_OPTION).hasArg().argName("file") - .desc("file containing list of users, mandatory").build()); + options.addOption(Option.builder(ITEMS_PATH_OPTION).hasArg().argName("file").desc("file containing list of item ids, mandatory").build()); + options.addOption(Option.builder(UUSERS_PATH_OPTION).hasArg().argName("file").desc("file containing list of users, mandatory").build()); + } + + private static List getItemList(String itemListPath) throws IOException { + List itemList; + if (itemListPath != null) { + itemList = load(itemListPath).collect(Collectors.toList()); + } else { + itemList = new ItemHandler().getItemList(); + } + return itemList; + } + + private static void executeAllTasks(ExecutorService executor, Collection> tasks) throws InterruptedException { + List> futureTasks; + futureTasks = executor.invokeAll(tasks); + boolean isThreadOpen = true; + while (isThreadOpen) { + isThreadOpen = futureTasks.stream().anyMatch(future -> !future.isDone()); + } + } + + private static ItemAddContributorsTask createTask(String itemId, List users) { + return new ItemAddContributorsTask(new PermissionHandler(), new NotificationHandler(), itemId, users); + } + + private static Stream load(String filePath) throws IOException { + return Files.lines(Paths.get(filePath)); } @Override public boolean execute(String[] args) { CommandLine cmd = parseArgs(args); - if (!cmd.hasOption(ITEMS_PATH_OPTION) || !cmd.hasOption(UUSERS_PATH_OPTION)) { LOGGER.error("Arguments p and u are mandatory"); return false; } - String itemListPath = cmd.getOptionValue(ITEMS_PATH_OPTION); String userListPath = cmd.getOptionValue(UUSERS_PATH_OPTION); - List itemList; try { itemList = getItemList(itemListPath); @@ -81,12 +102,8 @@ public class AddContributorCommand extends Command { } catch (IOException e) { throw new CommandExecutionRuntimeException(ERROR_TRYING_TO_READ_FILE + "from:" + userListPath, e); } - - List tasks = - itemList.stream().map(itemid -> createTask(itemid, userList)).collect(Collectors.toList()); - + List tasks = itemList.stream().map(itemid -> createTask(itemid, userList)).collect(Collectors.toList()); ExecutorService executor = null; - try { executor = Executors.newFixedThreadPool(DEFAULT_THREAD_NUMBER); executeAllTasks(executor, tasks); @@ -105,38 +122,4 @@ public class AddContributorCommand extends Command { public CommandName getCommandName() { return CommandName.ADD_CONTRIBUTOR; } - - private static List getItemList(String itemListPath) throws IOException { - List itemList; - if (itemListPath != null) { - itemList = load(itemListPath).collect(Collectors.toList()); - } else { - itemList = new ItemHandler().getItemList(); - } - - return itemList; - } - - private static void executeAllTasks(ExecutorService executor, Collection> tasks) - throws InterruptedException { - List> futureTasks; - futureTasks = executor.invokeAll(tasks); - boolean isThreadOpen = true; - while (isThreadOpen) { - isThreadOpen = futureTasks.stream().anyMatch(future -> !future.isDone()); - - } - } - - - private static ItemAddContributorsTask createTask(String itemId, List users) { - return new ItemAddContributorsTask(new PermissionHandler(), new NotificationHandler(), itemId, users); - } - - private static Stream load(String filePath) throws IOException { - return Files.lines(Paths.get(filePath)); - - } - - } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java index abca1e895f..cb54ea2f77 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import static org.openecomp.core.tools.commands.CommandName.CLEAN_USER_DATA; @@ -41,11 +40,16 @@ public class CleanUserDataCommand extends Command { private static final String USER_OPTION = "u"; CleanUserDataCommand() { + options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id").desc("id of the item to clean, mandatory").build()); options.addOption( - Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id").desc("id of the item to clean, mandatory") - .build()); - options.addOption(Option.builder(USER_OPTION).hasArg().argName("user") - .desc("the user of which the item data will be cleaned for, mandatory").build()); + Option.builder(USER_OPTION).hasArg().argName("user").desc("the user of which the item data will be cleaned for, mandatory").build()); + } + + private static SessionContext createSessionContext(String user) { + SessionContext sessionContext = new SessionContext(); + sessionContext.setUser(new UserInfo(user)); + sessionContext.setTenant("dox"); + return sessionContext; } @Override @@ -57,19 +61,15 @@ public class CleanUserDataCommand extends Command { } String itemId = cmd.getOptionValue(ITEM_ID_OPTION); String user = cmd.getOptionValue(USER_OPTION); - SessionContext context = createSessionContext(user); ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface(); - Id itemIdObj = new Id(itemId); Collection versions = zusammenConnector.listPublicVersions(context, itemIdObj); for (ItemVersion version : versions) { try { zusammenConnector.cleanVersion(context, itemIdObj, version.getId()); } catch (Exception e) { - LOGGER.error( - String.format("Error occurred while cleaning item %s version %s from user %s space", itemId, - version.getId(), user), e); + LOGGER.error(String.format("Error occurred while cleaning item %s version %s from user %s space", itemId, version.getId(), user), e); } } return true; @@ -79,11 +79,4 @@ public class CleanUserDataCommand extends Command { public CommandName getCommandName() { return CLEAN_USER_DATA; } - - private static SessionContext createSessionContext(String user) { - SessionContext sessionContext = new SessionContext(); - sessionContext.setUser(new UserInfo(user)); - sessionContext.setTenant("dox"); - return sessionContext; - } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/Command.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/Command.java index 6dc78f158e..875c951754 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/Command.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/Command.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import org.apache.commons.cli.CommandLine; @@ -34,8 +33,7 @@ public abstract class Command { protected final Options options = new Options(); protected Command() { - options.addOption( - Option.builder(COMMAND_OPTION).hasArg().argName("command").desc(getCommandName().name()).build()); + options.addOption(Option.builder(COMMAND_OPTION).hasArg().argName("command").desc(getCommandName().name()).build()); } protected CommandLine parseArgs(String[] args) { @@ -54,7 +52,7 @@ public abstract class Command { formater.printHelp("zusammenMainTool", options); } - public void register(){ + public void register() { CommandsHolder.addCommand(this); } 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 f53cd95c35..4e08c4600a 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 @@ -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. @@ -17,17 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; public enum CommandName { - RESET_OLD_VERSION, - EXPORT, - IMPORT, - HEAL_ALL, - POPULATE_USER_PERMISSIONS, - ADD_CONTRIBUTOR, - CLEAN_USER_DATA, - DELETE_PUBLIC_VERSION, - SET_HEAL_BY_ITEM_VERSION + RESET_OLD_VERSION, EXPORT, IMPORT, HEAL_ALL, POPULATE_USER_PERMISSIONS, ADD_CONTRIBUTOR, CLEAN_USER_DATA, 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 1c632a6ccf..3984ec702b 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 @@ -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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import static org.openecomp.core.tools.commands.Command.COMMAND_OPTION; @@ -43,11 +42,10 @@ public class CommandsHolder { private static final Map COMMANDS = new EnumMap<>(CommandName.class); static { - OPTIONS.addOption( - Option.builder(COMMAND_OPTION).hasArg().argName("command").desc("command name, mandatory").build()); + OPTIONS.addOption(Option.builder(COMMAND_OPTION).hasArg().argName("command").desc("command name, mandatory").build()); registerCommands(); } - + private CommandsHolder() { } @@ -65,9 +63,8 @@ public class CommandsHolder { public static Optional getCommand(String[] args) { CommandLine cmd = parseArgs(args); - return cmd == null || !cmd.hasOption(COMMAND_OPTION) || cmd.getOptionValue(COMMAND_OPTION) == null - ? Optional.empty() - : getCommandName(cmd.getOptionValue(COMMAND_OPTION)).map(COMMANDS::get); + return cmd == null || !cmd.hasOption(COMMAND_OPTION) || cmd.getOptionValue(COMMAND_OPTION) == null ? Optional.empty() + : getCommandName(cmd.getOptionValue(COMMAND_OPTION)).map(COMMANDS::get); } public static void printUsages() { @@ -95,8 +92,7 @@ public class CommandsHolder { static void addCommand(Command command) { CommandName commandName = command.getCommandName(); if (COMMANDS.containsKey(commandName)) { - throw new IllegalArgumentException( - String.format("Command with the name %s was already registered", commandName)); + throw new IllegalArgumentException(String.format("Command with the name %s was already registered", commandName)); } COMMANDS.put(commandName, command); } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java index 85b28ec695..450d497510 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import static org.openecomp.core.tools.commands.CommandName.DELETE_PUBLIC_VERSION; @@ -39,10 +38,16 @@ public class DeletePublicVersionCommand extends Command { private static final String VERSION_ID_OPTION = "v"; DeletePublicVersionCommand() { - options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id") - .desc("id of the item to delete from public, 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(ITEM_ID_OPTION).hasArg().argName("item_id").desc("id of the item to delete from public, mandatory").build()); + options.addOption( + Option.builder(VERSION_ID_OPTION).hasArg().argName("version_id").desc("id of the version to delete from public, mandatory").build()); + } + + private static SessionContext createSessionContext() { + SessionContext sessionContext = new SessionContext(); + sessionContext.setUser(new UserInfo("public")); + sessionContext.setTenant("dox"); + return sessionContext; } @Override @@ -54,15 +59,12 @@ public class DeletePublicVersionCommand extends Command { } String itemId = cmd.getOptionValue(ITEM_ID_OPTION); String versionId = cmd.getOptionValue(VERSION_ID_OPTION); - SessionContext context = createSessionContext(); ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface(); - try { zusammenConnector.cleanVersion(context, new Id(itemId), new Id(versionId)); } catch (Exception e) { - LOGGER.error(String.format("Error occurred while deleting item %s version %s from public space", itemId, - versionId), e); + LOGGER.error(String.format("Error occurred while deleting item %s version %s from public space", itemId, versionId), e); } return true; } @@ -71,11 +73,4 @@ public class DeletePublicVersionCommand extends Command { public CommandName getCommandName() { return DELETE_PUBLIC_VERSION; } - - private static SessionContext createSessionContext() { - SessionContext sessionContext = new SessionContext(); - sessionContext.setUser(new UserInfo("public")); - sessionContext.setTenant("dox"); - return sessionContext; - } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java index 7b4e05f615..fbbec19149 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import java.io.BufferedWriter; @@ -25,13 +24,10 @@ import java.io.FileWriter; import java.io.IOException; import java.time.Duration; import java.time.Instant; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.stream.Stream; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -57,35 +53,49 @@ public class HealAll extends Command { private HealingManager healingManager; HealAll() { - options.addOption( - Option.builder(THREAD_NUM_OPTION).hasArg().argName("number").desc("number of threads").build()); + options.addOption(Option.builder(THREAD_NUM_OPTION).hasArg().argName("number").desc("number of threads").build()); + } + + private static void executeAllTasks(ExecutorService executor, BufferedWriter log) { + } + + private static Version resolveVersion(VersionInfoEntity versionInfoEntity) { + if (Objects.nonNull(versionInfoEntity.getCandidate())) { + return versionInfoEntity.getCandidate().getVersion(); + } else if (!CollectionUtils.isEmpty(versionInfoEntity.getViewableVersions())) { + return versionInfoEntity.getViewableVersions().stream().max(Version::compareTo).orElse(new Version()); + } + return versionInfoEntity.getActiveVersion(); + } + + private static void writeToLog(String message, BufferedWriter log) { + try { + log.write(message); + log.newLine(); + } catch (IOException e) { + throw new HealingRuntimeException("unable to write to healing all log file.", e); + } + } + + private static Stream filterByEntityType(Collection versionInfoEntities, String entityType) { + return versionInfoEntities.stream().filter(versionInfoEntity -> versionInfoEntity.getEntityType().equals(entityType)); } @Override public boolean execute(String[] args) { CommandLine cmd = parseArgs(args); - vspManager = VspManagerFactory.getInstance().createInterface(); healingManager = HealingManagerFactory.getInstance().createInterface(); - String logFileName = "healing.log"; try (BufferedWriter log = new BufferedWriter(new FileWriter(logFileName, true))) { - writeToLog("----starting healing------", log); Instant startTime = Instant.now(); - - int numberOfThreads = - cmd.hasOption(THREAD_NUM_OPTION) && Objects.nonNull(cmd.getOptionValue(THREAD_NUM_OPTION)) - ? Integer.valueOf(cmd.getOptionValue(THREAD_NUM_OPTION)) - : DEFAULT_THREAD_NUMBER; + int numberOfThreads = cmd.hasOption(THREAD_NUM_OPTION) && Objects.nonNull(cmd.getOptionValue(THREAD_NUM_OPTION)) ? Integer + .valueOf(cmd.getOptionValue(THREAD_NUM_OPTION)) : DEFAULT_THREAD_NUMBER; ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads); - - filterByEntityType(VersionInfoCassandraLoader.list(), - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE) - .forEach(this::addTaskToTasks); - + filterByEntityType(VersionInfoCassandraLoader.list(), VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE) + .forEach(this::addTaskToTasks); executeAllTasks(executor, log); - writeToLog("----finished healing------", log); Instant endTime = Instant.now(); writeToLog("Total runtime was: " + Duration.between(startTime, endTime), log); @@ -100,38 +110,6 @@ public class HealAll extends Command { return CommandName.HEAL_ALL; } - private static void executeAllTasks(ExecutorService executor, BufferedWriter log) { - - } - - - private static Version resolveVersion(VersionInfoEntity versionInfoEntity) { - if (Objects.nonNull(versionInfoEntity.getCandidate())) { - return versionInfoEntity.getCandidate().getVersion(); - } else if (!CollectionUtils.isEmpty(versionInfoEntity.getViewableVersions())) { - - return versionInfoEntity.getViewableVersions().stream().max(Version::compareTo).orElse(new Version()); - } - return versionInfoEntity.getActiveVersion(); - } - - private static void writeToLog(String message, BufferedWriter log) { - try { - log.write(message); - log.newLine(); - } catch (IOException e) { - throw new HealingRuntimeException("unable to write to healing all log file.", e); - } - } - - private static Stream filterByEntityType(Collection versionInfoEntities, - String entityType) { - return versionInfoEntities.stream() - .filter(versionInfoEntity -> versionInfoEntity.getEntityType().equals(entityType)); - } - private void addTaskToTasks(VersionInfoEntity versionInfoEntity) { - } - } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java index ad280e16c6..3958b2b5e9 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java @@ -13,7 +13,6 @@ * 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.POPULATE_USER_PERMISSIONS; @@ -23,21 +22,18 @@ import java.util.List; import org.openecomp.core.tools.store.PermissionHandler; import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; - public class PopulateUserPermissions extends Command { @Override public boolean execute(String[] args) { PermissionHandler permissionHandler = new PermissionHandler(); List permissions = permissionHandler.getAll(); - permissions.forEach(itemPermissionsEntity -> { if (!itemPermissionsEntity.getUserId().isEmpty() && !itemPermissionsEntity.getPermission().isEmpty()) { - permissionHandler.addItem(Collections.singleton(itemPermissionsEntity.getItemId()), - itemPermissionsEntity.getUserId(), itemPermissionsEntity.getPermission()); + permissionHandler.addItem(Collections.singleton(itemPermissionsEntity.getItemId()), itemPermissionsEntity.getUserId(), + itemPermissionsEntity.getPermission()); } }); - return true; } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java index df9b9a5ae9..b5a879d976 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.commands; import static org.openecomp.core.tools.commands.CommandName.RESET_OLD_VERSION; @@ -30,7 +29,6 @@ import org.openecomp.core.tools.store.HealingHandler; import org.openecomp.core.tools.store.VersionCassandraLoader; import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity; - /** * Created by ayalaben on 10/15/2017 */ @@ -46,18 +44,13 @@ public class SetHealingFlag extends Command { public boolean execute(String[] args) { CommandLine cmd = parseArgs(args); String oldVersion = cmd.hasOption(VERSION_OPTION) ? cmd.getOptionValue(VERSION_OPTION) : null; - VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader(); ResultSet listItemVersion = versionCassandraLoader.listItemVersion(); - ArrayList healingEntities = new ArrayList<>(); - - listItemVersion.iterator().forEachRemaining(entry -> healingEntities.add(new HealingEntity(entry.getString(0), - entry.getString(1), entry.getString(2), true, oldVersion))); - + listItemVersion.iterator().forEachRemaining( + entry -> healingEntities.add(new HealingEntity(entry.getString(0), entry.getString(1), entry.getString(2), true, oldVersion))); HealingHandler healingHandler = new HealingHandler(); healingHandler.populateHealingTable(healingEntities); - return true; } 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 index ce2f9acf62..00b4339b6f 100644 --- 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 @@ -1,28 +1,25 @@ /* -* 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. -*/ - + * 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; @@ -41,12 +38,10 @@ public class SetHealingFlagByItemVersionCommand extends Command { private static final String VERSION_ID = "version_id"; 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()); + 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 @@ -59,19 +54,14 @@ public class SetHealingFlagByItemVersionCommand extends Command { 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 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()); - + List 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; } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java index f6cb427005..bc8c0722f7 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.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. @@ -17,59 +17,54 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.concurrent; -import org.openecomp.core.tools.store.NotificationHandler; -import org.openecomp.core.tools.store.PermissionHandler; - import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.Callable; - +import org.openecomp.core.tools.store.NotificationHandler; +import org.openecomp.core.tools.store.PermissionHandler; public class ItemAddContributorsTask implements Callable { - private static final String CONTRIBUTOR = "Contributor"; - private static final String SUCCESSFUL_RETURN_MESSAGE = "Users added successfully as " + - "contributors to item id:%s."; - private final String itemId; - private final List users; - private final PermissionHandler permissionHandler; - private final NotificationHandler notificationHandler; + private static final String CONTRIBUTOR = "Contributor"; + private static final String SUCCESSFUL_RETURN_MESSAGE = "Users added successfully as " + "contributors to item id:%s."; + private final String itemId; + private final List users; + private final PermissionHandler permissionHandler; + private final NotificationHandler notificationHandler; - public ItemAddContributorsTask(PermissionHandler permissionHandler, NotificationHandler - notificationHandler, String itemId, List users) { - this.itemId = itemId.trim(); - this.users = new ArrayList<>(users); - this.permissionHandler = permissionHandler; - this.notificationHandler = notificationHandler; - } + public ItemAddContributorsTask(PermissionHandler permissionHandler, NotificationHandler notificationHandler, String itemId, List users) { + this.itemId = itemId.trim(); + this.users = new ArrayList<>(users); + this.permissionHandler = permissionHandler; + this.notificationHandler = notificationHandler; + } - @Override - public String call() { - users.forEach(this::handleUser); - return String.format(SUCCESSFUL_RETURN_MESSAGE, itemId); - } + @Override + public String call() { + users.forEach(this::handleUser); + return String.format(SUCCESSFUL_RETURN_MESSAGE, itemId); + } - private void handleUser(String user) { - Optional userPermission = getUserPermission(user); - if (!userPermission.isPresent()) { - setUserPermission(user, CONTRIBUTOR); - registerUserNotificationSubscription(user); + private void handleUser(String user) { + Optional userPermission = getUserPermission(user); + if (!userPermission.isPresent()) { + setUserPermission(user, CONTRIBUTOR); + registerUserNotificationSubscription(user); + } } - } - private void registerUserNotificationSubscription(String user) { - notificationHandler.registerNotificationForUserOnEntity(user, itemId); - } + private void registerUserNotificationSubscription(String user) { + notificationHandler.registerNotificationForUserOnEntity(user, itemId); + } - private void setUserPermission(String user, String permission) { - permissionHandler.setItemUserPermission(itemId, user, permission); - } + private void setUserPermission(String user, String permission) { + permissionHandler.setItemUserPermission(itemId, user, permission); + } - private Optional getUserPermission(String user) { - return permissionHandler.getItemUserPermission(itemId, user); - } + private Optional getUserPermission(String user) { + return permissionHandler.getItemUserPermission(itemId, user); + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java index d4eff2b40f..daffa68fb8 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.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. @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.exceptions; public class CommandExecutionRuntimeException extends RuntimeException { + public CommandExecutionRuntimeException(String message, Exception exception) { super(message, exception); } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/HealingRuntimeException.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/HealingRuntimeException.java index 036cf1bf89..fa8d67cd96 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/HealingRuntimeException.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/HealingRuntimeException.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. @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.exceptions; public class HealingRuntimeException extends RuntimeException { + public HealingRuntimeException(String message, Exception exception) { super(message, exception); } 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 filteredItems, final String filteredColumn, + final Set vlms, final CountDownLatch donequerying, Executor executor) { + ResultSetFuture resultSetFuture = session.executeAsync(query); + Futures.addCallback(resultSetFuture, new FutureCallback() { + @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 filteredItems = Sets.newHashSet(cmd.getOptionValue(ITEM_ID_OPTION)); - Set fis = - filteredItems.stream().map(fi -> fi.replaceAll("\\r", "")).collect(Collectors.toSet()); + Set fis = filteredItems.stream().map(fi -> fi.replaceAll("\\r", "")).collect(Collectors.toSet()); Map> 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 filteredItems, - final String filteredColumn, final Set vlms, final CountDownLatch donequerying, Executor executor) { - ResultSetFuture resultSetFuture = session.executeAsync(query); - Futures.addCallback(resultSetFuture, new FutureCallback() { - @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); - } - } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java index 3454b99dc2..152141bc17 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.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. @@ -25,6 +25,7 @@ import static org.openecomp.core.tools.importinfo.ImportSingleTable.dataTypesMap import com.datastax.driver.core.DataType.Name; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; @@ -32,10 +33,15 @@ import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; -import com.fasterxml.jackson.databind.ObjectMapper; import org.openecomp.core.tools.importinfo.ImportProperties; import org.openecomp.core.tools.model.ColumnDefinition; import org.openecomp.core.tools.model.TableData; @@ -49,11 +55,11 @@ public class ExportSerializer { private static final String ELEMENT_TABLE_NAME = "element"; private static final String ELEMENT_INFO_COLUMN_NAME = "info"; - public void serializeResult(final ResultSet resultSet, final Set filteredItems, final String filteredColumn, Set vlms) { try { TableData tableData = new TableData(); - tableData.getDefinitions().addAll(resultSet.getColumnDefinitions().asList().stream().map(ColumnDefinition::new).collect(Collectors.toList())); + tableData.getDefinitions() + .addAll(resultSet.getColumnDefinitions().asList().stream().map(ColumnDefinition::new).collect(Collectors.toList())); String table = tableData.getDefinitions().iterator().next().getTable(); boolean isElementTable = table.equals(ELEMENT_TABLE_NAME); Iterator iterator = resultSet.iterator(); @@ -75,7 +81,6 @@ public class ExportSerializer { String fileName = ImportProperties.ROOT_DIRECTORY + File.separator + table + "_" + System.currentTimeMillis() + ".json"; objectMapper.writeValue(Paths.get(fileName).toFile(), tableData); Utils.printMessage(logger, "File exported is :" + fileName); - } catch (IOException e) { Utils.logError(logger, e); System.exit(1); @@ -135,8 +140,9 @@ public class ExportSerializer { case MAP: Map map = (Map) row.getObject(i); Set> entrySet = map.entrySet(); - Object mapAsString = entrySet.parallelStream().map(entry -> entry.getKey().toString() + ExportDataCommand.MAP_DELIMITER + entry.getValue().toString()) - .collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER)); + Object mapAsString = entrySet.parallelStream() + .map(entry -> entry.getKey().toString() + ExportDataCommand.MAP_DELIMITER + entry.getValue().toString()) + .collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER)); data = Base64.getEncoder().encodeToString(mapAsString.toString().getBytes()); break; default: diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.java index cff8eb98cf..4f58df6276 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.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. @@ -17,10 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.importinfo; - import static org.openecomp.core.tools.commands.CommandName.IMPORT; import java.io.IOException; @@ -53,7 +51,6 @@ public class ImportDataCommand extends Command { @Override public boolean execute(String[] args) { CommandLine cmd = parseArgs(args); - if (!cmd.hasOption(FILE_OPTION) || cmd.getOptionValue(FILE_OPTION) == null) { LOGGER.error("Argument f is mandatory"); return false; diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportProperties.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportProperties.java index 9d9530d860..1339ed5dc6 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportProperties.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportProperties.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. @@ -17,11 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.importinfo; import java.io.File; public class ImportProperties { - public static final String ROOT_DIRECTORY = System.getProperty("user.home")+File.separator+ "onboarding_import"; + + public static final String ROOT_DIRECTORY = System.getProperty("user.home") + File.separator + "onboarding_import"; } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java index 64c595caa5..71cce34fe4 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.importinfo; import static org.openecomp.core.tools.exportinfo.ExportDataCommand.NULL_REPRESENTATION; @@ -26,11 +25,21 @@ import com.datastax.driver.core.BoundStatement; import com.datastax.driver.core.DataType.Name; import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.Session; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Sets; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.Path; +import java.util.Base64; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; -import com.fasterxml.jackson.databind.ObjectMapper; import org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory; import org.openecomp.core.tools.exportinfo.ExportDataCommand; import org.openecomp.core.tools.model.ColumnDefinition; @@ -39,21 +48,22 @@ import org.openecomp.core.tools.util.Utils; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.file.Path; -import java.util.*; -import java.util.stream.Collectors; - public class ImportSingleTable { + public static final ImmutableMap dataTypesMap; private static final Logger logger = LoggerFactory.getLogger(ImportSingleTable.class); - private static final String INSERT_INTO = "INSERT INTO "; private static final String VALUES = " VALUES "; private static final Map statementsCache = new HashMap<>(); - - public static final ImmutableMap dataTypesMap; + + static { + Builder builder = ImmutableMap.builder(); + Name[] values = Name.values(); + for (Name name : values) { + builder.put(name.name().toLowerCase(), name); + } + dataTypesMap = builder.build(); + } public void importFile(Path file) { try { @@ -65,7 +75,6 @@ public class ImportSingleTable { } catch (IOException e) { Utils.logError(logger, e); } - } private PreparedStatement getPrepareStatement(TableData tableData, Session session) { @@ -101,7 +110,7 @@ public class ImportSingleTable { bind.setBytes(i, ByteBuffer.wrap(Base64.getDecoder().decode(rowData.getBytes()))); break; case TIMESTAMP: - if (StringUtils.isEmpty(rowData)){ + if (StringUtils.isEmpty(rowData)) { bind.setTimestamp(i, null); } else { bind.setTimestamp(i, new Date(Long.parseLong(rowData))); @@ -148,7 +157,6 @@ public class ImportSingleTable { break; default: throw new UnsupportedOperationException("Name is not supported :" + name); - } } @@ -156,21 +164,9 @@ public class ImportSingleTable { ColumnDefinition def = tableData.getDefinitions().iterator().next(); StringBuilder sb = new StringBuilder(1024); sb.append(INSERT_INTO).append(def.getKeyspace()).append(".").append(def.getTable()); - sb.append(tableData.getDefinitions().stream().map(ColumnDefinition::getName) - .collect(Collectors.joining(" , ", " ( ", " ) "))); - sb.append(VALUES).append(tableData.getDefinitions().stream().map(definition -> "?") - .collect(Collectors.joining(" , ", " ( ", " ) "))).append(";"); + sb.append(tableData.getDefinitions().stream().map(ColumnDefinition::getName).collect(Collectors.joining(" , ", " ( ", " ) "))); + sb.append(VALUES).append(tableData.getDefinitions().stream().map(definition -> "?").collect(Collectors.joining(" , ", " ( ", " ) "))) + .append(";"); return sb.toString(); } - - - static { - Builder builder = ImmutableMap.builder(); - Name[] values = Name.values(); - for (Name name : values) { - builder.put(name.name().toLowerCase(), name); - } - dataTypesMap = builder.build(); - } - } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/itemvalidation/ItemValidation.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/itemvalidation/ItemValidation.java index 40ed4f8fec..19ba419c94 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/itemvalidation/ItemValidation.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/itemvalidation/ItemValidation.java @@ -1,21 +1,28 @@ /* -* 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. -*/ - + * 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.itemvalidation; +import static org.openecomp.core.tools.util.Utils.logError; +import static org.openecomp.core.tools.util.Utils.printMessage; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; import org.openecomp.core.tools.store.ElementCassandraLoader; import org.openecomp.core.tools.store.ItemHandler; import org.openecomp.core.tools.store.VersionCassandraLoader; @@ -28,14 +35,8 @@ import org.openecomp.sdc.common.session.SessionContextProviderFactory; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static org.openecomp.core.tools.util.Utils.printMessage; -import static org.openecomp.core.tools.util.Utils.logError; - public class ItemValidation { + private static final Logger logger = LoggerFactory.getLogger(ItemValidation.class); private static final String NEW_LINE = System.getProperty("line.separator"); private static final String PUBLIC_SPACE = "public"; @@ -46,131 +47,96 @@ public class ItemValidation { public static void main(String[] args) { for (int i = 0; i < args.length; i++) { if ("-i".equals(args[i])) { - if (args[i+1] != null) { + if (args[i + 1] != null) { itemId = args[i + 1]; } break; } } - if (itemId == null) { printMessage(logger, "-i 123456 "); System.exit(-1); } - ItemValidation itemValidation = new ItemValidation(); itemValidation.validate(); System.exit(1); } private void validate() { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); subElementsList = new LinkedList<>(); validationMessage = new LinkedList<>(); - try { SessionContextProviderFactory.getInstance().createInterface().create("GLOBAL_USER", "dox"); CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem(); - List itemList = new ItemHandler().getItemList(); if (itemList.stream().filter(item -> item.equals(itemId)).collect(Collectors.toList()).isEmpty()) { - printMessage(logger,String.format("%s No data found for itemId: %s %s", NEW_LINE, itemId, NEW_LINE)); + printMessage(logger, String.format("%s No data found for itemId: %s %s", NEW_LINE, itemId, NEW_LINE)); return; } - printMessage(logger,String.format("%s Validation started at %s %S", NEW_LINE, - sdf.format(new Date()), NEW_LINE)); - - List versionEntityList = new VersionCassandraLoader().list().all().stream(). - filter(entry -> entry.getItemId().equals(itemId)).collect(Collectors.toList()); - - versionEntityList.sort(( VersionEntity e1, VersionEntity e2) -> { - if (e1.getSpace().equals(PUBLIC_SPACE)) { - return -1; - } else if (e2.getSpace().equals(PUBLIC_SPACE)) { - return 1; - } else { - return e1.getSpace().compareTo(e2.getSpace()); - } + printMessage(logger, String.format("%s Validation started at %s %S", NEW_LINE, sdf.format(new Date()), NEW_LINE)); + List versionEntityList = new VersionCassandraLoader().list().all().stream() + .filter(entry -> entry.getItemId().equals(itemId)).collect(Collectors.toList()); + versionEntityList.sort((VersionEntity e1, VersionEntity e2) -> { + if (e1.getSpace().equals(PUBLIC_SPACE)) { + return -1; + } else if (e2.getSpace().equals(PUBLIC_SPACE)) { + return 1; + } else { + return e1.getSpace().compareTo(e2.getSpace()); + } }); - versionEntityList.forEach((VersionEntity versionEntity) -> { - List versionElementsEntityList = new VersionElementsCassandraLoader(). - listVersionElementsByPK(versionEntity.getSpace(), versionEntity.getItemId(), - versionEntity.getVersionId()).all(); + List versionElementsEntityList = new VersionElementsCassandraLoader() + .listVersionElementsByPK(versionEntity.getSpace(), versionEntity.getItemId(), versionEntity.getVersionId()).all(); versionElementsEntityList.forEach(this::accept); }); - }catch (Exception ex) { - logError(logger,ex); + } catch (Exception ex) { + logError(logger, ex); } if (validationMessage.isEmpty()) { - printMessage(logger,String.format("%s Item %s is successfully validated.", NEW_LINE, itemId)); + printMessage(logger, String.format("%s Item %s is successfully validated.", NEW_LINE, itemId)); } else { - printMessage(logger,"\n Errors:"); + printMessage(logger, "\n Errors:"); for (String message : validationMessage) { - printMessage(logger,message); + printMessage(logger, message); } } - printMessage(logger,String.format("%s Validation ended at %s %s", NEW_LINE, sdf.format(new Date()), NEW_LINE)); + printMessage(logger, String.format("%s Validation ended at %s %s", NEW_LINE, sdf.format(new Date()), NEW_LINE)); } - private void validateElement(String space, String itemId, String versionId, - String elementId, String revisionId) { - - ElementEntity elementEntity = - new ElementCassandraLoader().getByPK(space, itemId, versionId, elementId, revisionId).one(); - + private void validateElement(String space, String itemId, String versionId, String elementId, String revisionId) { + ElementEntity elementEntity = new ElementCassandraLoader().getByPK(space, itemId, versionId, elementId, revisionId).one(); if (elementEntity == null) { - validationMessage.add(String.format( - "Element is defined in VERSION_ELEMENTS.element_ids is not found in ELEMENT. " + - "Space:%s, ItemID:%s ,VersionID:%s, ElementID:%s, element revisionID:%s", - space, itemId, versionId, elementId, revisionId)); + validationMessage.add(String.format("Element is defined in VERSION_ELEMENTS.element_ids is not found in ELEMENT. " + + "Space:%s, ItemID:%s ,VersionID:%s, ElementID:%s, element revisionID:%s", space, itemId, versionId, elementId, revisionId)); return; } - if (elementEntity.getSubElementIds() != null) { subElementsList.addAll(elementEntity.getSubElementIds()); } } private void accept(VersionElementsEntity versionElementsEntity) { - printMessage(logger, String.format( - "Found VERSION_ELEMENTS entry. Space: %s, ItemID: %s, VersionId: %s, Revision: %s", - versionElementsEntity.getSpace(), - versionElementsEntity.getItemId(), - versionElementsEntity.getVersionId(), - versionElementsEntity.getRevisionId())); - + printMessage(logger, String + .format("Found VERSION_ELEMENTS entry. Space: %s, ItemID: %s, VersionId: %s, Revision: %s", versionElementsEntity.getSpace(), + versionElementsEntity.getItemId(), versionElementsEntity.getVersionId(), versionElementsEntity.getRevisionId())); subElementsList.clear(); if (versionElementsEntity.getElementIds().isEmpty()) { - validationMessage.add(String.format - ("Empty field VERSION_ELEMENT.element_ids. Space: %s, ItemID: %s, VersionId: %s, Revision: %s", - versionElementsEntity.getSpace(), - versionElementsEntity.getItemId(), - versionElementsEntity.getVersionId(), - versionElementsEntity.getRevisionId())); + validationMessage.add(String.format("Empty field VERSION_ELEMENT.element_ids. Space: %s, ItemID: %s, VersionId: %s, Revision: %s", + versionElementsEntity.getSpace(), versionElementsEntity.getItemId(), versionElementsEntity.getVersionId(), + versionElementsEntity.getRevisionId())); } else { - //loop over element_ids stored in version_elements - versionElementsEntity.getElementIds().forEach((key, value) -> - validateElement(versionElementsEntity.getSpace(), - versionElementsEntity.getItemId(), - versionElementsEntity.getVersionId(), - key, - value) - ); - + versionElementsEntity.getElementIds().forEach( + (key, value) -> validateElement(versionElementsEntity.getSpace(), versionElementsEntity.getItemId(), + versionElementsEntity.getVersionId(), key, value)); //loop over collected sub-elements to insure existence in version_elements.elements_ids subElementsList.forEach((String key) -> { if (!versionElementsEntity.getElementIds().containsKey(key)) { - validationMessage.add(String.format( - "Element is defined in table ELEMENT but not found in VERSION_ELEMENTS.element_ids." - + " Space:%s, ItemID:%s, VersionID:%s, Version RevisionID:%s, ElementID:%s", - versionElementsEntity.getSpace(), - versionElementsEntity.getItemId(), - versionElementsEntity.getVersionId(), - versionElementsEntity.getRevisionId(), - key)); + validationMessage.add(String.format("Element is defined in table ELEMENT but not found in VERSION_ELEMENTS.element_ids." + + " Space:%s, ItemID:%s, VersionID:%s, Version RevisionID:%s, ElementID:%s", versionElementsEntity.getSpace(), + versionElementsEntity.getItemId(), versionElementsEntity.getVersionId(), versionElementsEntity.getRevisionId(), key)); } }); } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.java index 970f26ac21..4f70cce460 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/VersionInfoCassandraLoader.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. @@ -17,32 +17,29 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.loaders; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; +import java.util.Collection; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; -import java.util.Collection; - public class VersionInfoCassandraLoader { - private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static VersionInfoAccessor accessor = - noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class); + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static VersionInfoAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class); + public static Collection list() { + return accessor.getAll().all(); + } - public static Collection list() { - return accessor.getAll().all(); - } + @Accessor + interface VersionInfoAccessor { - @Accessor - interface VersionInfoAccessor { - @Query("select * from version_info ") - Result getAll(); - } + @Query("select * from version_info ") + Result getAll(); + } } 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 1eca7bc2e3..816b06e907 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 @@ -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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.main; import static org.openecomp.core.tools.util.Utils.printMessage; @@ -37,7 +36,6 @@ public class ZusammenMainTool { public static void main(String[] args) { Command command = getCommandToRun(args); - Instant startTime = Instant.now(); SessionContextProviderFactory.getInstance().createInterface().create("GLOBAL_USER", "dox"); if (!command.execute(args)) { @@ -45,7 +43,6 @@ public class ZusammenMainTool { System.exit(-1); } Instant stopTime = Instant.now(); - printDuration(command, startTime, stopTime); System.exit(0); } @@ -64,8 +61,7 @@ public class ZusammenMainTool { Duration duration = Duration.between(startTime, stopTime); long minutesPart = duration.toMinutes(); long secondsPart = duration.minusMinutes(minutesPart).getSeconds(); - - printMessage(LOGGER, String.format("Zusammen tools command %s finished. Total run time was %s:%s minutes.", - command.getCommandName(), minutesPart, secondsPart)); + printMessage(LOGGER, String + .format("Zusammen tools command %s finished. Total run time was %s:%s minutes.", command.getCommandName(), minutesPart, secondsPart)); } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/ColumnDefinition.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/ColumnDefinition.java index 35e25f2e7d..6d1ebbf83a 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/ColumnDefinition.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/ColumnDefinition.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. @@ -21,7 +21,6 @@ package org.openecomp.core.tools.model; import com.datastax.driver.core.ColumnDefinitions.Definition; import com.datastax.driver.core.DataType; - import java.util.Arrays; public class ColumnDefinition { @@ -88,13 +87,10 @@ public class ColumnDefinition { @Override public final boolean equals(Object o) { - if (!(o instanceof ColumnDefinition)) + if (!(o instanceof ColumnDefinition)) { return false; - + } ColumnDefinition other = (ColumnDefinition) o; - return keyspace.equals(other.keyspace) - && table.equals(other.table) - && name.equals(other.name) - && type.equals(other.type); + return keyspace.equals(other.keyspace) && table.equals(other.table) && name.equals(other.name) && type.equals(other.type); } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/TableData.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/TableData.java index 77b6ca1b76..8dfcc79cb8 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/TableData.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/TableData.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. @@ -25,6 +25,7 @@ import lombok.Getter; @Getter public class TableData { + private final List definitions = new ArrayList<>(); private final List> rows = new ArrayList<>(); } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java index d7f2ba63d6..faf2528a50 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java @@ -1,75 +1,61 @@ /* -* 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. -*/ - - + * 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.store; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; import com.datastax.driver.mapping.annotations.QueryParameters; +import java.nio.ByteBuffer; +import java.util.Set; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; -import java.nio.ByteBuffer; -import java.util.Set; - public class ElementCassandraLoader { private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); private static ElementAccessor accessor = noSqlDb.getMappingManager().createAccessor(ElementAccessor.class); public void createEntity(ElementEntity elementEntity) { - accessor.insertElement(elementEntity.getSpace(), - elementEntity.getItemId(), - elementEntity.getVersionId(), - elementEntity.getElementId(), - elementEntity.getData(), - elementEntity.getInfo(), - elementEntity.getNamespace(), - elementEntity.getParentId(), - elementEntity.getRelations(), - elementEntity.getSearchableData(), - elementEntity.getSubElementIds()); + accessor.insertElement(elementEntity.getSpace(), elementEntity.getItemId(), elementEntity.getVersionId(), elementEntity.getElementId(), + elementEntity.getData(), elementEntity.getInfo(), elementEntity.getNamespace(), elementEntity.getParentId(), elementEntity.getRelations(), + elementEntity.getSearchableData(), elementEntity.getSubElementIds()); } public Result list() { return accessor.getAll(); } - public Result getByPK(String space, String itemId, String versionId, String elementId, - String revisionId) { + + public Result getByPK(String space, String itemId, String versionId, String elementId, String revisionId) { return accessor.getByPK(space, itemId, versionId, elementId, revisionId); } + @Accessor interface ElementAccessor { - @Query("insert into zusammen_dox.element (space,item_id,version_id,element_id,data,info," + - "namespace,parent_id,relations,searchable_data,sub_element_ids) values (?,?,?,?,?,?,?,?,?,?,?)") - void insertElement(String space, String itemId, String versionId, String elementId, ByteBuffer data, - String info, String namespaceStr, String parentId, String relations, ByteBuffer searchable, - Set subElementsIds); - + @Query("insert into zusammen_dox.element (space,item_id,version_id,element_id,data,info, namespace,parent_id,relations,searchable_data,sub_element_ids) values (?,?,?,?,?,?,?,?,?,?,?)") + void insertElement(String space, String itemId, String versionId, String elementId, ByteBuffer data, String info, String namespaceStr, + String parentId, String relations, ByteBuffer searchable, Set subElementsIds); @Query("select * from zusammen_dox.element ") @QueryParameters(fetchSize = 100) Result getAll(); - @Query("select * from zusammen_dox.element where space = ? and item_id = ? and version_id = ? and " + - "element_id = ? and revision_id = ?") - Result getByPK(String space, String itemId, String versionId, String elementId, - String revisionId); + + @Query("select * from zusammen_dox.element where space = ? and item_id = ? and version_id = ? and element_id = ? and revision_id = ?") + Result getByPK(String space, String itemId, String versionId, String elementId, String revisionId); } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java index c8ceaabf82..fe19ecfe03 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.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. @@ -17,10 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; - import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Param; import com.datastax.driver.mapping.annotations.Query; @@ -30,18 +28,17 @@ import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; public class ElementNamespaceHandler { - private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static ElementNamespaceAccessor accessor = nnoSqlDb.getMappingManager().createAccessor(ElementNamespaceAccessor.class); + private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static ElementNamespaceAccessor accessor = nnoSqlDb.getMappingManager().createAccessor(ElementNamespaceAccessor.class); public void createElementNamespace(ElementEntity elementEntity) { - accessor.create(elementEntity.getSpace(),elementEntity.getItemId(),elementEntity.getElementId(),elementEntity.getNamespace()); + accessor.create(elementEntity.getSpace(), elementEntity.getItemId(), elementEntity.getElementId(), elementEntity.getNamespace()); } @Accessor interface ElementNamespaceAccessor { + @Query("UPDATE zusammen_dox.element_namespace SET namespace=:ns WHERE space=:space AND item_id=:item AND element_id=:id ") void create(@Param("space") String space, @Param("item") String item, @Param("id") String id, @Param("ns") String ns); } - - } 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 e5c541216c..2d0a5b5d5a 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,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. @@ -17,58 +17,49 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; import com.datastax.driver.core.ResultSet; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; +import java.util.List; 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.List; - /** * Created by ayalaben on 10/15/2017 */ public class HealingHandler { - private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static HealingAccessor accessor = - nnoSqlDb.getMappingManager().createAccessor(HealingAccessor.class); - - - public void populateHealingTable(List healingEntities) { - healingEntities.forEach(healingEntity -> { - if (isHealingRecordExist(healingEntity)) { - accessor.updateFlag(healingEntity.isHealingFlag(), healingEntity.getSpace(), - healingEntity.getItemId(), healingEntity.getVersionId()); - } else { - accessor.create(healingEntity.getSpace(), healingEntity.getItemId(), - healingEntity.getVersionId(), healingEntity.isHealingFlag(), - healingEntity.getOldVersion()); - } - }); - } + private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static HealingAccessor accessor = nnoSqlDb.getMappingManager().createAccessor(HealingAccessor.class); - private boolean isHealingRecordExist(HealingEntity healingEntity) { - return accessor.getFlag(healingEntity.getSpace(), healingEntity.getItemId(), - healingEntity.getVersionId()).getAvailableWithoutFetching() == 1; - } + public void populateHealingTable(List healingEntities) { + healingEntities.forEach(healingEntity -> { + if (isHealingRecordExist(healingEntity)) { + accessor.updateFlag(healingEntity.isHealingFlag(), healingEntity.getSpace(), healingEntity.getItemId(), healingEntity.getVersionId()); + } else { + accessor.create(healingEntity.getSpace(), healingEntity.getItemId(), healingEntity.getVersionId(), healingEntity.isHealingFlag(), + healingEntity.getOldVersion()); + } + }); + } - @Accessor - interface HealingAccessor { + private boolean isHealingRecordExist(HealingEntity healingEntity) { + return accessor.getFlag(healingEntity.getSpace(), healingEntity.getItemId(), healingEntity.getVersionId()).getAvailableWithoutFetching() == 1; + } - @Query("SELECT healing_needed FROM healing WHERE space=? AND item_id=? AND version_id=?") - ResultSet getFlag(String space, String itemId, String versionId); + @Accessor + interface HealingAccessor { - @Query("Insert into healing (space, item_id, version_id, healing_needed, old_version) " + - "values (?,?,?,?,?)") - void create(String space, String itemId, String versionId, boolean flag, String oldVersion); + @Query("SELECT healing_needed FROM healing WHERE space=? AND item_id=? AND version_id=?") + ResultSet getFlag(String space, String itemId, String versionId); - @Query("UPDATE healing SET healing_needed=? WHERE space=? AND item_id=? AND version_id=?") - void updateFlag(boolean flag, String space, String itemId, String versionId); - } + @Query("Insert into healing (space, item_id, version_id, healing_needed, old_version) " + "values (?,?,?,?,?)") + void create(String space, String itemId, String versionId, boolean flag, String oldVersion); + @Query("UPDATE healing SET healing_needed=? WHERE space=? AND item_id=? AND version_id=?") + void updateFlag(boolean flag, String space, String itemId, String versionId); + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java index 8260d0c09b..67d0ba717f 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.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. @@ -17,36 +17,32 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; - import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; public class ItemHandler { - public List getItemList() { - ResultSet resultSet = NoSqlDbFactory.getInstance().createInterface() - .getMappingManager().createAccessor(ItemAccessor.class).list(); - List rows = resultSet.all(); - - if (rows != null) { - return rows.stream().map(row -> row.getString("item_id")).collect(Collectors.toList()); + public List getItemList() { + ResultSet resultSet = NoSqlDbFactory.getInstance().createInterface().getMappingManager().createAccessor(ItemAccessor.class).list(); + List rows = resultSet.all(); + if (rows != null) { + return rows.stream().map(row -> row.getString("item_id")).collect(Collectors.toList()); + } + return Collections.emptyList(); } - return Collections.emptyList(); - } - @Accessor - interface ItemAccessor { - @Query("SELECT item_id FROM zusammen_dox.item") - ResultSet list(); - } + @Accessor + interface ItemAccessor { + @Query("SELECT item_id FROM zusammen_dox.item") + ResultSet list(); + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java index 6b3bcb6a3a..9dd111cd73 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.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. @@ -17,32 +17,27 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; - import java.util.HashSet; import java.util.Set; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; public class NotificationHandler { - public void registerNotificationForUserOnEntity(String user, String entityId) { - - Set userSet = new HashSet<>(); - userSet.add(user); - NoSqlDbFactory.getInstance().createInterface().getMappingManager() - .createAccessor(NotificationAccessor.class) - .updateNotificationSubscription(userSet, entityId); - } + public void registerNotificationForUserOnEntity(String user, String entityId) { + Set userSet = new HashSet<>(); + userSet.add(user); + NoSqlDbFactory.getInstance().createInterface().getMappingManager().createAccessor(NotificationAccessor.class) + .updateNotificationSubscription(userSet, entityId); + } - @Accessor - interface NotificationAccessor { + @Accessor + interface NotificationAccessor { - @Query("UPDATE dox.notification_subscribers SET subscribers = subscribers + ? where " + - "entity_id = ?") - void updateNotificationSubscription(Set users, String entityId); - } + @Query("UPDATE dox.notification_subscribers SET subscribers = subscribers + ? where " + "entity_id = ?") + void updateNotificationSubscription(Set users, String entityId); + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java index 1a339e80f3..d3e31b12e0 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; import com.datastax.driver.core.ResultSet; @@ -25,62 +24,54 @@ import com.datastax.driver.core.Row; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.api.NoSqlDb; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; -import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; - import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; public class PermissionHandler { - private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static PermissionAccessor accessor = - noSqlDb.getMappingManager().createAccessor(PermissionAccessor.class); - - - public Optional getItemUserPermission(String itemId, String user) { - ResultSet resultSet = accessor.getItemUserPermission(itemId, user); - Row row = resultSet.one(); - - if (Objects.nonNull(row)) { - return Optional.of(row.getString("permission")); - } else { - return Optional.empty(); + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static PermissionAccessor accessor = noSqlDb.getMappingManager().createAccessor(PermissionAccessor.class); + + public Optional getItemUserPermission(String itemId, String user) { + ResultSet resultSet = accessor.getItemUserPermission(itemId, user); + Row row = resultSet.one(); + if (Objects.nonNull(row)) { + return Optional.of(row.getString("permission")); + } else { + return Optional.empty(); + } } - } - - public void setItemUserPermission(String itemId, String user, String permission) { - accessor.setItemUserPermission(itemId, user, permission); - } - - public void addItem(Set items, String userId, String permission){ - accessor.addItem(items,userId,permission); - } - - public List getAll(){ - return accessor.getAll().all(); - } - - @Accessor - interface PermissionAccessor { + public void setItemUserPermission(String itemId, String user, String permission) { + accessor.setItemUserPermission(itemId, user, permission); + } + public void addItem(Set items, String userId, String permission) { + accessor.addItem(items, userId, permission); + } - @Query("INSERT into dox.item_permissions (item_id,user_id,permission) VALUES (?,?,?)") - void setItemUserPermission(String permission, String itemId, String userId); + public List getAll() { + return accessor.getAll().all(); + } + @Accessor + interface PermissionAccessor { - @Query("SELECT permission FROM dox.item_permissions WHERE item_id=? AND user_id=?") - ResultSet getItemUserPermission(String itemId, String userId); + @Query("INSERT into dox.item_permissions (item_id,user_id,permission) VALUES (?,?,?)") + void setItemUserPermission(String permission, String itemId, String userId); - @Query("SELECT * from dox.item_permissions") - Result getAll(); + @Query("SELECT permission FROM dox.item_permissions WHERE item_id=? AND user_id=?") + ResultSet getItemUserPermission(String itemId, String userId); - @Query("update dox.user_permission_items set item_list=item_list+? WHERE user_id = ? AND permission = ?") - void addItem(Set items, String userId, String permission); - } + @Query("SELECT * from dox.item_permissions") + Result getAll(); + @Query("update dox.user_permission_items set item_list=item_list+? WHERE user_id = ? AND permission = ?") + void addItem(Set items, String userId, String permission); + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java index 38bb21ccf1..10d3099cfa 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; import com.datastax.driver.core.ResultSet; @@ -27,14 +26,13 @@ import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; import com.datastax.driver.mapping.annotations.QueryParameters; import com.google.common.collect.Sets; +import java.util.Date; +import java.util.Set; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity; import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity; -import java.util.Date; -import java.util.Set; - public class VersionCassandraLoader { private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); @@ -42,37 +40,32 @@ public class VersionCassandraLoader { private static VersionAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionAccessor.class); public void insertElementToVersion(ElementEntity elementEntity) { - accessor.addElements(Sets.newHashSet(elementEntity.getElementId()), elementEntity.getSpace(), elementEntity.getItemId(), elementEntity.getVersionId()); + accessor.addElements(Sets.newHashSet(elementEntity.getElementId()), elementEntity.getSpace(), elementEntity.getItemId(), + elementEntity.getVersionId()); } public void insertVersion(VersionEntity versionEntity) { - accessor.insertVersion( versionEntity.getSpace(), - versionEntity.getItemId(), - versionEntity.getVersionId(), - versionEntity.getBaseVersionId(), - versionEntity.getCreationTime(), - versionEntity.getInfo(), - versionEntity.getModificationTime(), - versionEntity.getRelations()); + accessor.insertVersion(versionEntity.getSpace(), versionEntity.getItemId(), versionEntity.getVersionId(), versionEntity.getBaseVersionId(), + versionEntity.getCreationTime(), versionEntity.getInfo(), versionEntity.getModificationTime(), versionEntity.getRelations()); } - public Result list() { return accessor.getAll(); } - public ResultSet listItemVersion() { return accessor.getAllItemVersion();} + public ResultSet listItemVersion() { + return accessor.getAllItemVersion(); + } @Accessor interface VersionAccessor { - @Query("UPDATE zusammen_dox.version_elements SET element_ids=element_ids+? " + - "WHERE space=? AND item_id=? AND version_id=?") + @Query("UPDATE zusammen_dox.version_elements SET element_ids=element_ids+? " + "WHERE space=? AND item_id=? AND version_id=?") void addElements(Set elementIds, String space, String itemId, String versionId); @Query("insert into zusammen_dox.version (space,item_id,version_id,base_version_id,creation_time,info,modification_time,relations) values (?,?,?,?,?,?,?,?)") - void insertVersion(String space, String itemId, String versionId, String baseVersionId, Date createTime, String info, Date modificationTime, String relations); - + void insertVersion(String space, String itemId, String versionId, String baseVersionId, Date createTime, String info, Date modificationTime, + String relations); @Query("select * from zusammen_dox.version ") @QueryParameters(fetchSize = 400) diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionElementsCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionElementsCassandraLoader.java index 5c02af408f..17b6730258 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionElementsCassandraLoader.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionElementsCassandraLoader.java @@ -1,19 +1,18 @@ /* -* 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. -*/ - + * 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.store; import com.datastax.driver.mapping.Result; @@ -25,9 +24,9 @@ import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.core.tools.store.zusammen.datatypes.VersionElementsEntity; public class VersionElementsCassandraLoader { + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static VersionElementsAccessor accessor = noSqlDb.getMappingManager(). - createAccessor(VersionElementsAccessor.class); + private static VersionElementsAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionElementsAccessor.class); public Result listVersionElementsByPK(String space, String itemId, String versionId) { return accessor.getByPK(space, itemId, versionId); @@ -36,9 +35,7 @@ public class VersionElementsCassandraLoader { @Accessor interface VersionElementsAccessor { - @Query("SELECT space, item_id, version_id, revision_id, element_ids " + - "FROM zusammen_dox.version_elements WHERE space=? and item_id=? and version_id=?") - + @Query("SELECT space, item_id, version_id, revision_id, element_ids FROM zusammen_dox.version_elements WHERE space=? and item_id=? and version_id=?") @QueryParameters(fetchSize = 400) Result getByPK(String space, String itemId, String versionId); } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java index 1d66aa32bf..7a2dd79869 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store; import com.datastax.driver.mapping.Mapper; @@ -25,23 +24,19 @@ import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; import com.datastax.driver.mapping.annotations.QueryParameters; +import java.util.Collection; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.versioning.dao.VersionInfoDao; import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory; import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; -import java.util.Collection; - public class VersionInfoCassandraLoader { private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static Mapper mapper = - noSqlDb.getMappingManager().mapper(VersionInfoEntity.class); - private static VersionInfoAccessor accessor = - noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class); - private static VersionInfoDao versionInfoDao = - VersionInfoDaoFactory.getInstance().createInterface(); + private static Mapper mapper = noSqlDb.getMappingManager().mapper(VersionInfoEntity.class); + private static VersionInfoAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class); + private static VersionInfoDao versionInfoDao = VersionInfoDaoFactory.getInstance().createInterface(); public void insertVersionInfo(VersionInfoEntity versionInfoEntity) { versionInfoDao.create(versionInfoEntity); @@ -53,10 +48,9 @@ public class VersionInfoCassandraLoader { @Accessor interface VersionInfoAccessor { + @Query("select * from dox.version_info ") @QueryParameters(fetchSize = 400) Result getAll(); } - - } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java index d1fd93dd71..d88f36b8dd 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java @@ -1,25 +1,23 @@ /* -* 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. -*/ - + * 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.store.zusammen.datatypes; import com.datastax.driver.mapping.annotations.Column; import com.datastax.driver.mapping.annotations.PartitionKey; import com.datastax.driver.mapping.annotations.Table; - import java.nio.ByteBuffer; import java.util.Set; @@ -40,49 +38,35 @@ import java.util.Set; * PRIMARY KEY ((space, item_id, version_id, element_id)) * ) */ -@Table( - keyspace = "zusammen_dox", - name = "element" -) +@Table(keyspace = "zusammen_dox", name = "element") public class ElementEntity { - @Column( name = "space" ) + + @Column(name = "space") @PartitionKey(0) private String space; - - @Column( name = "item_id" ) + @Column(name = "item_id") @PartitionKey(1) private String itemId; - - @Column( name = "version_id" ) + @Column(name = "version_id") @PartitionKey(2) private String versionId; - @Column(name = "element_id") @PartitionKey(3) private String elementId; - @Column(name = "data") private ByteBuffer data; - @Column(name = "info") private String info; - @Column(name = "namespace") private String namespace; - @Column(name = "parent_id") private String parentId; - @Column(name = "relations") private String relations; - @Column(name = "searchable_data") private ByteBuffer searchableData; - @Column(name = "sub_element_ids") private Set subElementIds; - - @Column(name = "visualization") private ByteBuffer visualization; diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/HealingEntity.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/HealingEntity.java index 155c8e2215..bde7855c9c 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/HealingEntity.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/HealingEntity.java @@ -33,21 +33,17 @@ import lombok.Setter; @Table(keyspace = "dox", name = "healing") public class HealingEntity { - @Column(name = "space") - @PartitionKey(0) - private String space; - - @Column(name = "item_id") - @PartitionKey(1) - private String itemId; - - @Column(name = "version_id") - @PartitionKey(2) - private String versionId; - - @Column(name = "healing_needed") - private boolean healingFlag; - - @Column(name = "old_version") - private String oldVersion; + @Column(name = "space") + @PartitionKey(0) + private String space; + @Column(name = "item_id") + @PartitionKey(1) + private String itemId; + @Column(name = "version_id") + @PartitionKey(2) + private String versionId; + @Column(name = "healing_needed") + private boolean healingFlag; + @Column(name = "old_version") + private String oldVersion; } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionElementsEntity.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionElementsEntity.java index 936d7198c8..41649d2b48 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionElementsEntity.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionElementsEntity.java @@ -1,26 +1,24 @@ /* -* 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. -*/ - + * 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.store.zusammen.datatypes; import com.datastax.driver.mapping.annotations.ClusteringColumn; import com.datastax.driver.mapping.annotations.Column; import com.datastax.driver.mapping.annotations.PartitionKey; import com.datastax.driver.mapping.annotations.Table; - import java.util.Map; /** @@ -39,63 +37,61 @@ import java.util.Map; * PRIMARY KEY ((space, item_id, version_id), revision_id)) * WITH CLUSTERING ORDER BY (revision_id ASC) */ - -@Table( - keyspace = "zusammen_dox", - name = "version_elements" -) +@Table(keyspace = "zusammen_dox", name = "version_elements") public class VersionElementsEntity { - @Column( name = "space" ) + + @Column(name = "space") @PartitionKey(0) private String space; - - @Column( name = "item_id" ) + @Column(name = "item_id") @PartitionKey(1) private String itemId; - - @Column( name = "version_id" ) + @Column(name = "version_id") @PartitionKey(2) private String versionId; - @Column(name = "revision_id") @ClusteringColumn private String revisionId; - @Column(name = "element_ids") - private Map elementIds; + private Map elementIds; - public void setSpace(String space) { - this.space = space; - } public String getSpace() { return space; } - public void setItemId(String itemId) { - this.itemId = itemId; + public void setSpace(String space) { + this.space = space; } + public String getItemId() { return itemId; } - public void setVersionId(String versionId) { - this.versionId = versionId; + public void setItemId(String itemId) { + this.itemId = itemId; } + public String getVersionId() { return versionId; } - public void setRevisionId(String revisionId) { - this.revisionId = revisionId; + public void setVersionId(String versionId) { + this.versionId = versionId; } + public String getRevisionId() { return revisionId; } - public void setElementIds(Map elementIds) { - this.elementIds = elementIds; + public void setRevisionId(String revisionId) { + this.revisionId = revisionId; } - public Map getElementIds() { + + public Map getElementIds() { return elementIds; } + + public void setElementIds(Map elementIds) { + this.elementIds = elementIds; + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java index e9f7d51038..652565d35b 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.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. @@ -17,13 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.store.zusammen.datatypes; import com.datastax.driver.mapping.annotations.Column; import com.datastax.driver.mapping.annotations.PartitionKey; import com.datastax.driver.mapping.annotations.Table; - import java.util.Date; /** @@ -52,35 +50,26 @@ import java.util.Date; * AND read_repair_chance = 0.0 * AND speculative_retry = '99.0PERCENTILE'; */ -@Table( - keyspace = "zusammen_dox", - name = "version" -) +@Table(keyspace = "zusammen_dox", name = "version") public class VersionEntity { + @Column(name = "space") @PartitionKey(0) private String space; - @Column(name = "item_id") @PartitionKey(1) private String itemId; - @Column(name = "version_id") @PartitionKey(2) private String versionId; - @Column(name = "base_version_id") private String baseVersionId; - @Column(name = "creation_time") private Date creationTime; - @Column(name = "info") private String info; - @Column(name = "modification_time") private Date modificationTime; - @Column(name = "relations") private String relations; diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.java index a7ef55ecab..0727e3c21d 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ToolsUtil.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. @@ -17,18 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.util; public class ToolsUtil { - public static String getParam(String key, String[] args) { - - for (int j = 0; j < args.length; j++) { - if (args[j].equals("-" + key)) { - return args[j + 1]; - } + public static String getParam(String key, String[] args) { + for (int j = 0; j < args.length; j++) { + if (args[j].equals("-" + key)) { + return args[j + 1]; + } + } + return null; } - return null; - } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java index 018019eac8..67bcefe355 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.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. @@ -17,42 +17,41 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.util; import org.openecomp.sdc.logging.api.Logger; /** * Copyright © 2016-2017 European Support Limited. + * * @author Avrahamg * @since April 24, 2017 * Since it is a command line tools writing to console will be helpful to users. */ public class Utils { - public static void printMessage(Logger logger, String message) { - /** - * Since it is a command line tools writing to console will be helpful to users. - */ - System.out.println(message); - logger.debug(message); - } + public static void printMessage(Logger logger, String message) { + /** + * Since it is a command line tools writing to console will be helpful to users. + */ + System.out.println(message); + logger.debug(message); + } - public static void logError(Logger logger, Throwable ex) { - /** - * Since it is a command line tools writing to console will be helpful to users. - */ - ex.printStackTrace(); - logger.error(ex.getMessage(),ex); - } + public static void logError(Logger logger, Throwable ex) { + /** + * Since it is a command line tools writing to console will be helpful to users. + */ + ex.printStackTrace(); + logger.error(ex.getMessage(), ex); + } - public static void logError(Logger logger, String message, Throwable ex) { - /** - * Since it is a command line tools writing to console will be helpful to users. - */ - System.out.println(message); - ex.printStackTrace(); - logger.error(message,ex); - } + public static void logError(Logger logger, String message, Throwable ex) { + /** + * Since it is a command line tools writing to console will be helpful to users. + */ + System.out.println(message); + ex.printStackTrace(); + logger.error(message, ex); + } } - -- cgit 1.2.3-korg