summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2017-06-29 19:30:00 +0300
committerMichael Lando <ml636r@att.com>2017-06-29 21:32:19 +0300
commited7e1c3dfe332abc67ed943717db2ee94406f95e (patch)
treee0f2f39596656456272900f59aadc3dff6c6e828 /openecomp-be/tools
parent68ccc45de18f41cddb79de33a245bceb3b063ffb (diff)
[SDC] rebase code
Change-Id: I456ec65a233d277e6bae35e140f2e3da5765bae6 Signed-off-by: Tal Gitelman <tg851x@intl.att.com> Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/tools')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java62
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java43
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java12
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java100
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java20
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java62
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java74
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java116
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java42
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java51
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java41
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java41
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java14
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java74
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java27
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java78
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java62
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java40
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java168
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java128
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java89
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh6
22 files changed, 1332 insertions, 18 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java
new file mode 100644
index 0000000000..b92ba52000
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java
@@ -0,0 +1,62 @@
+package org.openecomp.core.tools.Commands;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.apache.commons.io.FileUtils;
+import org.openecomp.core.tools.Commands.exportdata.ElementHandler;
+import org.openecomp.core.tools.Commands.exportdata.ImportProperties;
+import org.openecomp.core.tools.Commands.exportdata.ItemHandler;
+import org.openecomp.core.tools.Commands.exportdata.VersionHandler;
+import org.openecomp.core.tools.util.ZipUtils;
+import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+import static java.nio.file.Files.createDirectories;
+public class ExportDataCommand {
+ private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
+
+ public static void exportData(SessionContext context, String filterItem) {
+ try {
+ ImportProperties.initParams();
+ CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
+ Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
+ initDir(rootDir);
+ if (filterItem != null) {
+ filterItem = filterItem.replaceAll("\\r", "");
+ }
+ new ItemHandler().createItemsData(context, filterItem);
+ new VersionHandler().loadVersions(filterItem);
+ new ElementHandler().loadElements(filterItem);
+ zipPath(rootDir,filterItem);
+ FileUtils.forceDelete(rootDir.toFile());
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+
+ }
+ private static void zipPath(Path rootDir,String filterItem ) throws Exception{
+ LocalDateTime date = LocalDateTime.now();
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+ String dateStr = date.format(formatter);
+ String zipFile = System.getProperty("user.home")+ File.separatorChar+"onboarding_import"+ dateStr + ".zip";
+ ZipUtils.createZip(zipFile, rootDir,filterItem);
+ }
+
+
+ public static void initDir(Path rootDir ) throws IOException{
+ if (Files.exists(rootDir)) {
+ FileUtils.forceDelete(rootDir.toFile());
+ }
+ createDirectories(rootDir);
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java
new file mode 100644
index 0000000000..57486b81e3
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java
@@ -0,0 +1,43 @@
+package org.openecomp.core.tools.Commands;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.apache.commons.io.FileUtils;
+import org.openecomp.core.tools.Commands.importdata.TreeWalker;
+import org.openecomp.core.tools.Commands.exportdata.ImportProperties;
+import org.openecomp.core.tools.util.ZipUtils;
+import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class ImportCommand {
+
+ private static final Logger logger = LoggerFactory.getLogger(ImportCommand.class);
+
+
+ public static void importData(SessionContext context, String zippedFile, String filterItem) {
+ try {
+ ImportProperties.initParams();
+ CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
+ if (zippedFile == null){
+ logger.error("Import must have a valid file as an input.");
+ }
+ zippedFile = zippedFile.replaceAll("\\r", "");
+ if(filterItem != null) {
+ filterItem = filterItem.replaceAll("\\r", "");
+ }
+ Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
+ ExportDataCommand.initDir(rootDir);
+ ZipUtils.unzip(Paths.get(zippedFile), rootDir);
+ TreeWalker.walkFiles(context, rootDir, filterItem);
+
+ FileUtils.forceDelete(rootDir.toFile()); // clear all unzip data at the end.
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java
index 185e80030f..527efa5fc6 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ResetOldVersion.java
@@ -2,22 +2,16 @@ package org.openecomp.core.tools.Commands;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.plugin.statestore.cassandra.dao.impl.ItemCassandraDao;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.impl.VersionCassandraDao;
-import org.openecomp.core.tools.loaders.VersionInfoCassandraLoader;
-import org.openecomp.core.tools.loaders.zusammen.VspGeneralLoader;
+import org.openecomp.core.tools.store.VersionInfoCassandraLoader;
+import org.openecomp.core.tools.store.VspGeneralLoader;
import org.openecomp.core.tools.store.ElementHandler;
import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
-import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class ResetOldVersion {
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java
new file mode 100644
index 0000000000..ebce90fb4a
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java
@@ -0,0 +1,100 @@
+package org.openecomp.core.tools.Commands.exportdata;
+
+
+import org.openecomp.core.tools.store.ElementCassandraLoader;
+import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static java.io.File.separator;
+import static java.nio.file.Files.*;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*;
+
+public class ElementHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(ElementHandler.class);
+
+ public ElementHandler() {
+ }
+
+ public void loadElements(String filteredItem) {
+ ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader();
+ elementCassandraLoader.list().forEach(elementEntity -> handleElementEntity(elementEntity,filteredItem));
+ }
+
+ private void handleElementEntity(ElementEntity elementEntity, String filteredItem) {
+ try {
+ String itemId = elementEntity.getItemId();
+ if (filteredItem != null && !itemId.contains(filteredItem)){
+ return;
+ }
+ String versionId = elementEntity.getVersionId();
+ String space = elementEntity.getSpace();
+ String namespace = elementEntity.getNamespace();
+ String elementId = elementEntity.getElement_id();
+
+ String namespacePath = separator;
+ if (!isNull(namespace)){
+ namespacePath = namespace.replace(ELEMENT_NAMESPACE_SPLITTER,separator)+separator;
+ }
+ Path elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
+ + separator + versionId + separator + space + separator + namespacePath+ separator + elementId);
+ if (notExists(elementDirectoryPath)) {
+ createDirectories(elementDirectoryPath);
+ }
+
+ String info = elementEntity.getInfo();
+ if (!isNull(info)) {
+ Path infoFilePath = Paths.get(elementDirectoryPath.toString() + separator + ELEMENT_INFO_PREFIX
+ + elementId + JSON_POSTFIX);
+ write(infoFilePath, info.getBytes());
+ }
+
+ String relations = elementEntity.getRelations();
+ if (!isNull(relations)) {
+ Path realtionsFilePath = Paths.get(elementDirectoryPath.toString() + separator
+ + ELEMENT_RELATION_PREFIX + elementId + JSON_POSTFIX);
+ write(realtionsFilePath, relations.getBytes());
+ }
+
+ ByteBuffer data = elementEntity.getData();
+ if (!Objects.isNull(data)) {
+ Path dataFilePath = Paths.get(elementDirectoryPath.toString() + separator
+ + ELEMENT_DATA_PREFIX + elementId + JSON_POSTFIX);
+ write(dataFilePath, data.array());
+ }
+
+ ByteBuffer visualization = elementEntity.getVisualization();
+ if (!Objects.isNull(visualization)) {
+ Path visualFilePath = Paths.get(elementDirectoryPath.toString() + separator
+ + ELEMENT_VISUALIZATION_PREFIX + elementId );
+ write(visualFilePath, visualization.array());
+ }
+
+ ByteBuffer searchableData = elementEntity.getSearchableData();
+ if (!Objects.isNull(searchableData)) {
+ Path searchableFilePath = Paths.get(elementDirectoryPath.toString() + separator
+ + ELEMENT_SEARCHABLE_PREFIX + elementId);
+ write(searchableFilePath, searchableData.array());
+ }
+
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+
+ }
+
+ private boolean isNull(String inStr){
+ if (Objects.isNull(inStr)){
+ return true;
+ }
+ return inStr.trim().equalsIgnoreCase("null");
+ }
+
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java
new file mode 100644
index 0000000000..3b7566fd1b
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java
@@ -0,0 +1,20 @@
+package org.openecomp.core.tools.Commands.exportdata;
+
+import java.io.File;
+
+public class ImportProperties {
+ public static final String VERSION_FILE_PREFIX = "version_";
+ public static final String VERSION_INFO_FILE_PREFIX = "version_info_";
+ public static final String JSON_POSTFIX = ".json";
+
+ public static final String ELEMENT_INFO_PREFIX = "elem_info";
+ public static final String ELEMENT_RELATION_PREFIX = "elem_relations";
+ public static final String ELEMENT_DATA_PREFIX = "elem_data";
+ public static final String ELEMENT_VISUALIZATION_PREFIX = "elem_visualization";
+ public static final String ELEMENT_SEARCHABLE_PREFIX = "elem_searchableData";
+ public static final String ELEMENT_NAMESPACE_SPLITTER = "/";
+ public static String ROOT_DIRECTORY;
+ public static final void initParams(){
+ 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/Commands/exportdata/ItemHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java
new file mode 100644
index 0000000000..9eea182609
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java
@@ -0,0 +1,62 @@
+package org.openecomp.core.tools.Commands.exportdata;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.Item;
+import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDao;
+import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDaoFactory;
+import org.openecomp.core.tools.Commands.ExportDataCommand;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import static java.nio.file.Files.*;
+import static java.io.File.separator;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*;
+
+public class ItemHandler {
+ private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
+
+
+ public ItemHandler() {
+ ImportProperties.initParams();
+ }
+
+ public void createItemsData(SessionContext context, String filteredItem) throws URISyntaxException, IOException {
+
+ List<Item> items = getItemDao(context).list(context);
+ items.parallelStream().forEach(item -> createItemDirectoryAndFiles(item,filteredItem));
+
+ }
+
+ private final void createItemDirectoryAndFiles(Item item,String filteredItem) {
+ try {
+ String itemId = item.getId().getValue();
+ if (filteredItem != null && !itemId.contains(filteredItem)){
+ return;
+ }
+ Path itemPath = Paths.get( ImportProperties.ROOT_DIRECTORY + separator + itemId);
+ Path itemFilePath = Paths.get( ImportProperties.ROOT_DIRECTORY + separator +
+ itemId + separator + itemId + JSON_POSTFIX);
+ if (notExists(itemPath)) {
+ createDirectories(itemPath);
+ }
+ String itemJson = JsonUtil.object2Json(item);
+ write(itemFilePath, itemJson.getBytes());
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+
+ }
+
+
+ private ItemDao getItemDao(SessionContext context) {
+ return ItemDaoFactory.getInstance().createInterface(context);
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java
new file mode 100644
index 0000000000..b8d82958c9
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java
@@ -0,0 +1,74 @@
+package org.openecomp.core.tools.Commands.exportdata;
+
+import org.openecomp.core.tools.Commands.ExportDataCommand;
+import org.openecomp.core.tools.store.VersionInfoCassandraLoader;
+import org.openecomp.core.tools.store.VersionCassandraLoader;
+
+import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+
+import static java.io.File.separator;
+import static java.nio.file.Files.*;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.ROOT_DIRECTORY;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class VersionHandler {
+ private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
+
+ public VersionHandler() {
+ }
+
+ public void loadVersions(String filteredItem) {
+ VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
+ versionCassandraLoader.list().forEach(versionEntity -> handleVersionEntity(versionEntity,filteredItem));
+ VersionInfoCassandraLoader versionInfoCassandraLoader = new VersionInfoCassandraLoader();
+ versionInfoCassandraLoader.list().forEach(versionInfoEntity -> handleVersionInfo(versionInfoEntity,filteredItem));
+ }
+
+ private void handleVersionEntity(VersionEntity versionEntity, String filteredItem) {
+ try {
+ String itemId = versionEntity.getItemId();
+ if (filteredItem != null && !itemId.contains(filteredItem)){
+ return;
+ }
+ String versionId = versionEntity.getVersionId();
+ String space = versionEntity.getSpace();
+ Path versionDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
+ + separator + versionId + separator + space);
+ Path versionFilePath = Paths.get(versionDirectoryPath.toString() + separator + VERSION_FILE_PREFIX
+ + versionId + JSON_POSTFIX);
+ if (notExists(versionDirectoryPath)) {
+ createDirectories(versionDirectoryPath);
+ }
+ String versionJson = JsonUtil.object2Json(versionEntity);
+ write(versionFilePath, versionJson.getBytes());
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+
+ }
+
+ private void handleVersionInfo(VersionInfoEntity versionInfoEntity, String filteredItem) {
+ try {
+ String itemId = versionInfoEntity.getEntityId();
+ Path itemDirectory = Paths.get( ROOT_DIRECTORY + separator + itemId);
+ Path versionInfoFilePath = Paths.get(itemDirectory.toString() + separator + VERSION_INFO_FILE_PREFIX
+ + itemId + JSON_POSTFIX);
+ if (exists(itemDirectory)) {
+ String versionJson = JsonUtil.object2Json(versionInfoEntity);
+ write(versionInfoFilePath, versionJson.getBytes());
+ }
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java
new file mode 100644
index 0000000000..7ba830906c
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java
@@ -0,0 +1,116 @@
+package org.openecomp.core.tools.Commands.importdata;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.openecomp.core.tools.store.ElementCassandraLoader;
+import org.openecomp.core.tools.store.ElementNamespaceHandler;
+import org.openecomp.core.tools.store.VersionCassandraLoader;
+import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static java.io.File.separator;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.*;
+
+public class ElementImport {
+ private static final Logger logger = LoggerFactory.getLogger(ElementImport.class);
+ private ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader();
+ private ElementNamespaceHandler cassandraElementRepository = new ElementNamespaceHandler();
+ private VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
+
+ public void loadPath(SessionContext sessionContext, Path elementDir, String elementId, String[] pathObjects) {
+ try {
+ // load info file
+ ElementEntity elementEntity = new ElementEntity();
+ Path infoFilePath = Paths.get(elementDir.toString() + separator + ELEMENT_INFO_PREFIX
+ + elementId + JSON_POSTFIX);
+ if (Files.exists(infoFilePath)) {
+ String info = new String(Files.readAllBytes(infoFilePath));
+ elementEntity.setInfo(info);
+ }
+
+ // load relation file
+ Path realtionsFilePath = Paths.get(elementDir.toString() + separator
+ + ELEMENT_RELATION_PREFIX + elementId + JSON_POSTFIX);
+ if (Files.exists(realtionsFilePath)) {
+ String relations = new String(Files.readAllBytes(realtionsFilePath));
+ elementEntity.setRelations(relations);
+ }
+
+ //load entity data
+ Path dataFilePath = Paths.get(elementDir.toString() + separator
+ + ELEMENT_DATA_PREFIX + elementId + JSON_POSTFIX);
+ if (Files.exists(dataFilePath)) {
+ byte[] bytes = Files.readAllBytes(dataFilePath);
+ ByteBuffer data = ByteBuffer.wrap(bytes);
+ elementEntity.setData(data);
+ }
+
+ //load visualization
+ Path visualFilePath = Paths.get(elementDir.toString() + separator
+ + ELEMENT_VISUALIZATION_PREFIX + elementId );
+ if (Files.exists(visualFilePath)) {
+ byte[] bytes = Files.readAllBytes(visualFilePath);
+ ByteBuffer visualization = ByteBuffer.wrap(bytes);
+ elementEntity.setVisualization(visualization);
+ }
+
+ //load searchable
+ Path searchableFilePath = Paths.get(elementDir.toString() + separator
+ + ELEMENT_SEARCHABLE_PREFIX + elementId );
+ if (Files.exists(searchableFilePath)) {
+ byte[] bytes = Files.readAllBytes(searchableFilePath);
+ ByteBuffer searchable = ByteBuffer.wrap(bytes);
+ elementEntity.setSearchableData(searchable);
+ }
+
+ elementEntity.setSpace(pathObjects[2]);
+ elementEntity.setItemId(pathObjects[0]);
+ elementEntity.setVersionId(pathObjects[1]);
+ elementEntity.setElement_id(pathObjects[pathObjects.length - 1]);
+ elementEntity.setNamespace(getNameSpace(pathObjects));
+ elementEntity.setParentId(getParentId(pathObjects));
+ elementEntity.setSubElementIds(getAllSubElementsIds(elementDir));
+ elementCassandraLoader.createEntity(elementEntity);
+ cassandraElementRepository.createElementNamespace(elementEntity);
+ versionCassandraLoader.insertElementToVersion(elementEntity);
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ }
+ }
+
+ private String getParentId(String[] pathObjects) {
+ if (pathObjects.length <= 4) {
+ return null;
+ }
+ return pathObjects[pathObjects.length - 2];
+ }
+
+ private Set<String> getAllSubElementsIds(Path root) throws IOException {
+ try (Stream<Path> walk = Files.walk(root)) {
+ return walk.filter(path -> Files.isDirectory(path))
+ .map(path -> path.toFile().getName() ).collect(Collectors.toSet());
+ }
+ }
+
+ private String getNameSpace(String[] pathObjects) {
+ if (pathObjects.length <= 4) {
+ return null;
+ }
+ if (pathObjects.length == 5) {
+ return pathObjects[3];
+ }
+ return Arrays.stream(pathObjects, 3, pathObjects.length - 1)
+ .reduce("", (s1, s2) -> s1 + File.separator + s2);
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java
new file mode 100644
index 0000000000..c7042743c2
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java
@@ -0,0 +1,42 @@
+package org.openecomp.core.tools.Commands.importdata;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.Item;
+import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDao;
+import com.amdocs.zusammen.plugin.statestore.cassandra.dao.ItemDaoFactory;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX;
+
+public class ItemImport {
+ private static final Logger logger = LoggerFactory.getLogger(ItemImport.class);
+
+ public void loadPath(SessionContext sessionContext, Path itemDir, String itemName) {
+ try {
+ Path itemPath = Paths.get(itemDir.toString() + File.separator + itemName + JSON_POSTFIX);
+ if (!Files.exists(itemPath)) {
+ return;
+ }
+ String itemJson = new String(Files.readAllBytes(itemPath));
+ if (itemJson == null || itemJson.trim().isEmpty()) {
+ return;
+ }
+ Item item = JsonUtil.json2Object(itemJson, Item.class);
+ ItemDao itemDao = getItemDao(sessionContext);
+ itemDao.create(sessionContext, item.getId(), item.getInfo(), item.getCreationTime());
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ }
+ }
+
+ private ItemDao getItemDao(SessionContext context) {
+ return ItemDaoFactory.getInstance().createInterface(context);
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java
new file mode 100644
index 0000000000..020b2f3c47
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java
@@ -0,0 +1,51 @@
+package org.openecomp.core.tools.Commands.importdata;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.stream.Stream;
+
+public class TreeWalker {
+ private static final Logger logger = LoggerFactory.getLogger(TreeWalker.class);
+
+ public static final void walkFiles(SessionContext sessionContext,Path rootDir, String filterItem) throws IOException {
+ try (Stream<Path> walk = Files.walk(rootDir)) {
+ walk.parallel().filter(path -> Files.isDirectory(path)).
+ forEach(path -> handlePath(sessionContext,path, rootDir, filterItem));
+ }
+ }
+
+ private static final void handlePath(SessionContext sessionContext, Path path, Path root,String filterItem) {
+ String logicalPath = path.toString().replace(root.toString()+File.separator, "");
+ String[] splitted = logicalPath.split(File.separator);
+ if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){
+ return;
+ }
+ switch (splitted.length) {
+ case 0:
+ //root - ignore
+ break;
+ case 1: // handle Item
+ new ItemImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
+ new VersionInfoImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
+ break;
+ case 2:
+ //ignore this level
+ break;
+ case 3: // handle version
+ new VersionImport().loadPath(sessionContext,path,splitted[splitted.length -2]);
+ break;
+ default:
+ //handle elements
+ new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);
+ break;
+ }
+
+ }
+
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java
new file mode 100644
index 0000000000..8f6c67d212
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java
@@ -0,0 +1,41 @@
+package org.openecomp.core.tools.Commands.importdata;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.openecomp.core.tools.store.VersionCassandraLoader;
+import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static java.io.File.separator;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.VERSION_FILE_PREFIX;
+
+public class VersionImport {
+ private static final Logger logger = LoggerFactory.getLogger(VersionImport.class);
+
+ public void loadPath(SessionContext sessionContext, Path versionDir , String versionId){
+ try {
+ Path versionPath = Paths.get(versionDir.toString() + separator + VERSION_FILE_PREFIX
+ + versionId + JSON_POSTFIX);
+ if (!Files.exists(versionPath)) {
+ return;
+ }
+ String versionJson = new String(Files.readAllBytes(versionPath));
+ if (versionJson == null || versionJson.trim().isEmpty()) {
+ return;
+ }
+ VersionEntity versionEntity = JsonUtil.json2Object(versionJson, VersionEntity.class);
+ VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
+ versionCassandraLoader.insertVersion(versionEntity);
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ }
+ }
+
+
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java
new file mode 100644
index 0000000000..5da7407c9f
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java
@@ -0,0 +1,41 @@
+package org.openecomp.core.tools.Commands.importdata;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.openecomp.core.tools.store.VersionInfoCassandraLoader;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static java.io.File.separator;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX;
+import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.VERSION_INFO_FILE_PREFIX;
+
+public class VersionInfoImport {
+ private static final Logger logger = LoggerFactory.getLogger(VersionInfoImport.class);
+
+ public void loadPath(SessionContext sessionContext, Path itemPath, String itemId) {
+ try {
+ Path versionInfoFilePath = Paths.get(itemPath.toString() + separator + VERSION_INFO_FILE_PREFIX
+ + itemId + JSON_POSTFIX);
+ if (!Files.exists(versionInfoFilePath)) {
+ return;
+ }
+ String versionInfoJson = new String(Files.readAllBytes(versionInfoFilePath));
+ if (versionInfoJson == null || versionInfoJson.trim().isEmpty()) {
+ return;
+ }
+ VersionInfoEntity versionInfoEntity = JsonUtil.json2Object(versionInfoJson, VersionInfoEntity.class);
+ VersionInfoCassandraLoader versionInfoCassandraLoader = new VersionInfoCassandraLoader();
+ versionInfoCassandraLoader.insertVersionInfo(versionInfoEntity);
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ }
+ }
+
+
+}
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 7bc4bb23fb..926566864f 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
@@ -2,6 +2,8 @@ package org.openecomp.core.tools.main;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.UserInfo;
+import org.openecomp.core.tools.Commands.ImportCommand;
+import org.openecomp.core.tools.Commands.ExportDataCommand;
import org.openecomp.core.tools.Commands.ResetOldVersion;
import org.openecomp.core.tools.util.ToolsUtil;
import org.openecomp.sdc.logging.api.Logger;
@@ -23,8 +25,8 @@ public class ZusammenMainTool {
String command = ToolsUtil.getParam("c",args);
if(command == null){
printMessage(logger,
- "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " +
- "[additional arguments depending on the command] ");
+ "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " +
+ "[additional arguments depending on the command] ");
System.exit(-1);
}
Instant startTime = Instant.now();
@@ -39,8 +41,10 @@ public class ZusammenMainTool {
ResetOldVersion.reset(context,ToolsUtil.getParam("v",args));
break;
case EXPORT:
+ ExportDataCommand.exportData(context,ToolsUtil.getParam("i",args));
break;
case IMPORT:
+ ImportCommand.importData(context, ToolsUtil.getParam("f",args),ToolsUtil.getParam("i",args));
break;
}
@@ -52,9 +56,9 @@ public class ZusammenMainTool {
printMessage(logger,
- "Zusammen tools command:[] finished . Total run time was : " + minutesPart + ":" +
- secondsPart
- + " minutes");
+ "Zusammen tools command:[] finished . Total run time was : " + minutesPart + ":" +
+ secondsPart
+ + " minutes");
System.exit(status);
}
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
new file mode 100644
index 0000000000..1c7e185e18
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementCassandraLoader.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.tools.store;
+
+import com.datastax.driver.mapping.Mapper;
+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 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 Mapper<ElementEntity> mapper = noSqlDb.getMappingManager().mapper(ElementEntity.class);
+ private static ElementAccessor accessor = noSqlDb.getMappingManager().createAccessor(ElementAccessor.class);
+ private String[] columns = {"space", "item_id", "version_id", "element_id", "data", "info", "namespace", "parent_id",
+ "relations", "searchable_data", "sub_element_ids"};
+
+
+ public void createEntity(ElementEntity elementEntity) {
+ accessor.insertElement(elementEntity.getSpace(),
+ elementEntity.getItemId(),
+ elementEntity.getVersionId(),
+ elementEntity.getElement_id(),
+ elementEntity.getData(),
+ elementEntity.getInfo(),
+ elementEntity.getNamespace(),
+ elementEntity.getParentId(),
+ elementEntity.getRelations(),
+ elementEntity.getSearchableData(),
+ elementEntity.getSubElementIds());
+ }
+
+ public Result<ElementEntity> list() {
+ return accessor.getAll();
+ }
+
+ @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<String> subElementsIds);
+
+
+ @Query("select * from zusammen_dox.element ")
+ @QueryParameters(fetchSize = 100)
+ Result<ElementEntity> getAll();
+ }
+}
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
new file mode 100644
index 0000000000..f1ed970b4d
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementNamespaceHandler.java
@@ -0,0 +1,27 @@
+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;
+import org.openecomp.core.nosqldb.api.NoSqlDb;
+import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
+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);
+
+ public void createElementNamespace(ElementEntity elementEntity) {
+ accessor.create(elementEntity.getSpace(),elementEntity.getItemId(),elementEntity.getElement_id(),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/VersionCassandraLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java
new file mode 100644
index 0000000000..851e92dcca
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.tools.store;
+
+import com.datastax.driver.mapping.Mapper;
+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 com.google.common.collect.Sets;
+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();
+ private static Mapper<VersionEntity> mapper = noSqlDb.getMappingManager().mapper(VersionEntity.class);
+ private static VersionAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionAccessor.class);
+
+ public void insertElementToVersion(ElementEntity elementEntity) {
+ accessor.addElements(Sets.newHashSet(elementEntity.getElement_id()), 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());
+ }
+
+
+ public Result<VersionEntity> list() {
+ return accessor.getAll();
+ }
+
+ @Accessor
+ interface VersionAccessor {
+
+ @Query("UPDATE zusammen_dox.version_elements SET element_ids=element_ids+? " +
+ "WHERE space=? AND item_id=? AND version_id=?")
+ void addElements(Set<String> 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);
+
+
+ @Query("select * from zusammen_dox.version ")
+ @QueryParameters(fetchSize = 400)
+ Result<VersionEntity> getAll();
+ }
+}
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
new file mode 100644
index 0000000000..d7ec93962c
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionInfoCassandraLoader.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.tools.store;
+
+import com.datastax.driver.mapping.Mapper;
+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 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<VersionInfoEntity> 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);
+ }
+
+ public Collection<VersionInfoEntity> list() {
+ return accessor.getAll().all();
+ }
+
+ @Accessor
+ interface VersionInfoAccessor {
+ @Query("select * from dox.version_info ")
+ @QueryParameters(fetchSize = 400)
+ Result<VersionInfoEntity> getAll();
+ }
+
+
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java
new file mode 100644
index 0000000000..54a3dd9ada
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java
@@ -0,0 +1,40 @@
+package org.openecomp.core.tools.store;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
+import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository;
+import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class VspGeneralLoader {
+ public static Map<String, ElementEntity> load(SessionContext context,
+ Map<String, List<String>> vspItemVersionsMap) {
+ Map<String, ElementEntity> elementEntityMap = new HashMap<>();
+ System.setProperty("cassandra.dox.keystore", "zusammen_dox");
+ CassandraElementRepository cassandraElementRepository = new CassandraElementRepository();
+ for (Map.Entry<String, List<String>> entry : vspItemVersionsMap.entrySet()) {
+
+ for (String version : entry.getValue()) {
+
+ Optional<ElementEntity> result =
+ cassandraElementRepository.get(context, new ElementEntityContext(
+ context.getUser().getUserName(),
+ new Id(entry.getKey()),
+ new Id(version)),
+ new ElementEntity(new Id(StructureElement.General.name())));
+ if (result.isPresent()) {
+ elementEntityMap.put(context.getUser().getUserName() + "_" + entry.getKey()
+ + "_" + version, result.get());
+ }
+ }
+ }
+
+ return elementEntityMap;
+ }
+}
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
new file mode 100644
index 0000000000..f4f450db70
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/ElementEntity.java
@@ -0,0 +1,168 @@
+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;
+
+/**
+ * CREATE TABLE zusammen_dox.element (
+ * space text,
+ * item_id text,
+ * version_id text,
+ * element_id text,
+ * data blob,
+ * info text,
+ * namespace text,
+ * parent_id text,
+ * relations text,
+ * searchable_data blob,
+ * sub_element_ids set<text>,
+ * visualization blob,
+ * PRIMARY KEY ((space, item_id, version_id, element_id))
+ * )
+ */
+@Table(
+ keyspace = "zusammen_dox",
+ name = "version"
+)
+public class ElementEntity {
+ @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 = "element_id")
+ @PartitionKey(3)
+ private String element_id;
+
+ @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<String> subElementIds;
+
+
+ @Column(name = "visualization")
+ private ByteBuffer visualization;
+
+ public String getSpace() {
+ return space;
+ }
+
+ public void setSpace(String space) {
+ this.space = space;
+ }
+
+ public String getItemId() {
+ return itemId;
+ }
+
+ public void setItemId(String itemId) {
+ this.itemId = itemId;
+ }
+
+ public String getVersionId() {
+ return versionId;
+ }
+
+ public void setVersionId(String versionId) {
+ this.versionId = versionId;
+ }
+
+ public String getElement_id() {
+ return element_id;
+ }
+
+ public void setElement_id(String element_id) {
+ this.element_id = element_id;
+ }
+
+ public ByteBuffer getData() {
+ return data;
+ }
+
+ public void setData(ByteBuffer data) {
+ this.data = data;
+ }
+
+ public String getInfo() {
+ return info;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getParentId() {
+ return parentId;
+ }
+
+ public void setParentId(String parentId) {
+ this.parentId = parentId;
+ }
+
+ public String getRelations() {
+ return relations;
+ }
+
+ public void setRelations(String relations) {
+ this.relations = relations;
+ }
+
+ public ByteBuffer getSearchableData() {
+ return searchableData;
+ }
+
+ public void setSearchableData(ByteBuffer searchableData) {
+ this.searchableData = searchableData;
+ }
+
+ public Set<String> getSubElementIds() {
+ return subElementIds;
+ }
+
+ public void setSubElementIds(Set<String> subElementIds) {
+ this.subElementIds = subElementIds;
+ }
+
+ public ByteBuffer getVisualization() {
+ return visualization;
+ }
+
+ public void setVisualization(ByteBuffer visualization) {
+ this.visualization = visualization;
+ }
+}
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
new file mode 100644
index 0000000000..c7280c8a9d
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java
@@ -0,0 +1,128 @@
+package org.openecomp.core.tools.store.zusammen.datatypes;
+
+import com.datastax.driver.mapping.annotations.*;
+
+import java.util.Date;
+
+/**
+ * CREATE TABLE zusammen_dox.version (
+ * space text,
+ * item_id text,
+ * version_id text,
+ * base_version_id text,
+ * creation_time timestamp,
+ * info text,
+ * modification_time timestamp,
+ * relations text,
+ * PRIMARY KEY ((space, item_id), version_id)
+ * ) WITH CLUSTERING ORDER BY (version_id ASC)
+ * AND bloom_filter_fp_chance = 0.01
+ * AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
+ * AND comment = ''
+ * AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
+ * AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
+ * AND dclocal_read_repair_chance = 0.1
+ * AND default_time_to_live = 0
+ * AND gc_grace_seconds = 864000
+ * AND max_index_interval = 2048
+ * AND memtable_flush_period_in_ms = 0
+ * AND min_index_interval = 128
+ * AND read_repair_chance = 0.0
+ * AND speculative_retry = '99.0PERCENTILE';
+ */
+@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;
+
+ public String getSpace() {
+ return space;
+ }
+
+ public void setSpace(String space) {
+ this.space = space;
+ }
+
+ public String getItemId() {
+ return itemId;
+ }
+
+ public void setItemId(String itemId) {
+ this.itemId = itemId;
+ }
+
+ public String getVersionId() {
+ return versionId;
+ }
+
+ public void setVersionId(String versionId) {
+ this.versionId = versionId;
+ }
+
+ public String getBaseVersionId() {
+ return baseVersionId;
+ }
+
+ public void setBaseVersionId(String baseVersionId) {
+ this.baseVersionId = baseVersionId;
+ }
+
+ public Date getCreationTime() {
+ return creationTime;
+ }
+
+ public void setCreationTime(Date creationTime) {
+ this.creationTime = creationTime;
+ }
+
+ public String getInfo() {
+ return info;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public Date getModificationTime() {
+ return modificationTime;
+ }
+
+ public void setModificationTime(Date modificationTime) {
+ this.modificationTime = modificationTime;
+ }
+
+ public String getRelations() {
+ return relations;
+ }
+
+ public void setRelations(String relations) {
+ this.relations = relations;
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java
new file mode 100644
index 0000000000..6447f85ea7
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java
@@ -0,0 +1,89 @@
+package org.openecomp.core.tools.util;
+
+import com.google.common.io.ByteStreams;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.Scanner;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+public class ZipUtils {
+ public static void createZip(String zipFileName, Path dir, String filterItem) throws Exception {
+ File dirObj = dir.toFile();
+ try (
+ FileOutputStream fileOutputStream = new FileOutputStream(zipFileName);
+ ZipOutputStream out = new ZipOutputStream(fileOutputStream)) {
+ addDir(dirObj, out, dir.toString(), filterItem);
+ }
+ }
+
+ public static final String cleanStr(String inFilterStr) {
+ if (Objects.isNull(inFilterStr)) {
+ return inFilterStr;
+ }
+ Scanner scan = new Scanner(inFilterStr);
+ while (scan.hasNextLine()) {
+ inFilterStr = scan.nextLine().replaceAll("[^a-zA-Z0-9]", "");
+ }
+ return inFilterStr;
+ }
+
+ static void addDir(File dirObj, ZipOutputStream out, String root, String filterItem) throws IOException {
+ File[] files = dirObj.listFiles();
+ filterItem = cleanStr(filterItem);
+
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ addDir(files[i], out, root, filterItem);
+ continue;
+ }
+ try (FileInputStream in = new FileInputStream((files[i].getAbsolutePath()))) {
+ String filePath = files[i].getAbsolutePath().replace(root + File.separator, "");
+ if (filterItem == null || filePath.contains(filterItem)) {
+ out.putNextEntry(new ZipEntry(filePath));
+ try {
+ ByteStreams.copy(in, out);
+
+ } finally {
+ out.closeEntry();
+ }
+ }
+
+ }
+ }
+ }
+
+ public static void unzip(Path zipFile, Path outputFolder) throws IOException {
+ if (zipFile == null || outputFolder == null) {
+ return;
+ }
+ if (!Files.exists(outputFolder)) {
+ Files.createDirectories(outputFolder);
+ }
+
+ try (FileInputStream fileInputStream = new FileInputStream(zipFile.toFile());
+ ZipInputStream zis = new ZipInputStream(fileInputStream)) {
+ ZipEntry ze = zis.getNextEntry();
+ while (ze != null) {
+ String fileName = ze.getName();
+ File newFile = new File(outputFolder.toString() + File.separator + fileName);
+ new File(newFile.getParent()).mkdirs();
+ try (FileOutputStream fos = new FileOutputStream(newFile)) {
+ ByteStreams.copy(zis, fos);
+ }
+ ze = zis.getNextEntry();
+ }
+
+ zis.closeEntry();
+ }
+
+ }
+}
+
diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
index c274d84424..da043b130d 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
+++ b/openecomp-be/tools/zusammen-tools/src/main/resources/zusammenMainTool.sh
@@ -10,7 +10,5 @@
# change exist package and service templates in db
-java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=/apps/jetty/base/be/config/catalog-be/configuration.yaml -jar openecomp-zusammen-tools-1.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4
-
-STATUS="${?}" echo "${STATUS}" echo "All log messages for the zusammenMainTool
-migration process are in /apps/jetty/base/be/logs/ASDC/ASDC-BE/zusammen_tool_debug.log"
+java -Dlog.home=/apps/jetty/base/be/logs -Dconfiguration.yaml=/apps/jetty/base/be/config/catalog-be/configuration.yaml -jar openecomp-zusammen-tools-1.0-SNAPSHOT.jar org.openecomp.core.tools.main.ZusammenMainTool $1 $2 $3 $4 $5 $6
+STATUS="${?}" echo "${STATUS}" echo "All log messages for the zusammenMainTool migration process are in /apps/jetty/base/be/logs/ASDC/ASDC-BE/zusammen_tool_debug.log"