summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-12-20 14:30:43 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-21 11:12:33 +0000
commit8e9c0653dd6c6862123c9609ae34e1206d86456e (patch)
tree5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/tools/zusammen-tools
parent785ebcc95de3e064e843bec04ba7a209d854fc7c (diff)
Add collaboration feature
Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/zusammen-tools')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java67
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java29
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java45
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java31
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java108
-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.java87
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java73
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java135
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java44
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java54
-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/concurrent/ItemHealingTask.java64
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java125
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java152
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.java37
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportProperties.java7
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java166
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspGeneralLoader.java40
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspItemLoader.java4
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java10
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/ColumnDefinition.java84
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/TableData.java12
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/CassandraElementRepository.java23
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java13
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java54
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VersionCassandraLoader.java6
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/VspGeneralLoader.java21
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/HealingEntity.java78
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/VersionEntity.java4
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/Utils.java23
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/util/ZipUtils.java30
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml1
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/resources/queries.yaml16
-rw-r--r--openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java48
-rw-r--r--openecomp-be/tools/zusammen-tools/src/test/resources/configuration.yaml251
-rw-r--r--openecomp-be/tools/zusammen-tools/src/test/resources/queries.yaml16
38 files changed, 1204 insertions, 856 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
deleted file mode 100644
index 487b4131e6..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ExportDataCommand.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.openecomp.core.tools.Commands;
-
-import static java.nio.file.Files.createDirectories;
-
-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 java.util.HashSet;
-import java.util.Set;
-public class ExportDataCommand {
- private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
-
- public static void exportData(SessionContext context, String filterItem) {
- try {
- Set<String> filteredItem = new HashSet<>();
- filteredItem.add(filterItem);
- ImportProperties.initParams();
- CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
- Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
- initDir(rootDir);
- if (filterItem != null) {
- filterItem = filterItem.replaceAll("\\r", "");
- }
- new ItemHandler().createItemsData(context, filteredItem);
- new VersionHandler().loadVersions(filteredItem);
- new ElementHandler().loadElements(filteredItem);
- zipPath(rootDir,filteredItem);
- FileUtils.forceDelete(rootDir.toFile());
- } catch (Exception ex) {
- logger.error(ex.getMessage(), ex);
- }
-
- }
- private static void zipPath(Path rootDir,Set<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);
- logger.info("Exported file :" + zipFile);
- System.out.println("Exported file :" + zipFile);
- }
-
-
- 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/HealAll.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java
index 2bc48bd0e8..40a56eda83 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
@@ -3,6 +3,8 @@ package org.openecomp.core.tools.Commands;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.core.tools.concurrent.ItemHealingTask;
import org.openecomp.core.tools.loaders.VersionInfoCassandraLoader;
+import org.openecomp.sdc.healing.api.HealingManager;
+import org.openecomp.sdc.healing.factory.HealingManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
@@ -31,18 +33,20 @@ import java.util.stream.Stream;
public class HealAll {
private static final String HEALING_USER = "healing_user";
- private static final int defaulThreadNumber =100;
+ private static final int defaulThreadNumber = 100;
private static BufferedWriter log;
private static List<ItemHealingTask> tasks = new ArrayList<>();
private static VendorSoftwareProductManager vspManager = VspManagerFactory
.getInstance().createInterface();
+ private static HealingManager healingManager = HealingManagerFactory.getInstance()
+ .createInterface();
private static VersioningManager versioningManager = VersioningManagerFactory.getInstance()
.createInterface();
static {
try {
log =
- new BufferedWriter(new FileWriter("healing.log",true));
+ new BufferedWriter(new FileWriter("healing.log", true));
} catch (IOException e) {
if (log != null) {
try {
@@ -64,13 +68,13 @@ public class HealAll {
defaulThreadNumber;
ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
- filterByEntityType(VersionInfoCassandraLoader.list(),
+ filterByEntityType(VersionInfoCassandraLoader.list(),
VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE).forEach
- (HealAll::addTaskToTasks);
+ (HealAll::addTaskToTasks);
executeAllTasks(executor);
- writeToLog("----finished healing------" );
+ writeToLog("----finished healing------");
Instant endTime = Instant.now();
writeToLog("Total runtime was: " + Duration.between(startTime, endTime));
@@ -112,7 +116,7 @@ public class HealAll {
if (Objects.nonNull(versionInfoEntity.getCandidate())) {
return versionInfoEntity.getCandidate().getVersion();
} else if (!CollectionUtils.isEmpty(versionInfoEntity.getViewableVersions())) {
- return versionInfoEntity.getViewableVersions().stream().max(Version::compateTo).get();
+ return versionInfoEntity.getViewableVersions().stream().max(Version::compateTo).get();
}
return versionInfoEntity.getActiveVersion();
}
@@ -126,17 +130,16 @@ public class HealAll {
}
}
- private static Stream<VersionInfoEntity> filterByEntityType(Collection<VersionInfoEntity>
- versionInfoEntities,
- String entityType){
+ private static Stream<VersionInfoEntity> filterByEntityType(
+ Collection<VersionInfoEntity> versionInfoEntities, String entityType) {
return versionInfoEntities.stream().filter(versionInfoEntity -> versionInfoEntity
.getEntityType().equals(entityType));
}
- private static void addTaskToTasks(VersionInfoEntity versionInfoEntity){
+
+ private static void addTaskToTasks(VersionInfoEntity versionInfoEntity) {
tasks.add(new ItemHealingTask(versionInfoEntity.getEntityId(), resolveVersion
- (versionInfoEntity).toString(), versionInfoEntity.getCandidate() == null ?
- HEALING_USER : versionInfoEntity.getCandidate().getUser(),
- vspManager, versioningManager));
+ (versionInfoEntity).toString(),
+ vspManager, healingManager));
}
}
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
deleted file mode 100644
index cebff91160..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-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.");
- }
- if (zippedFile != null) {
- 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);
- }
- }
-
-}
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
new file mode 100644
index 0000000000..b885ac5d05
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java
@@ -0,0 +1,31 @@
+package org.openecomp.core.tools.Commands;
+
+import com.datastax.driver.core.ResultSet;
+import org.openecomp.core.tools.store.HealingHandler;
+import org.openecomp.core.tools.store.VersionCassandraLoader;
+import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity;
+
+import java.util.ArrayList;
+
+
+/**
+ * Created by ayalaben on 10/15/2017
+ */
+public class SetHealingFlag {
+
+
+ public static void populateHealingTable(String oldVersion) {
+
+ VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
+ ResultSet listItemVersion = versionCassandraLoader.listItemVersion();
+
+ ArrayList<HealingEntity> healingEntities = new ArrayList<HealingEntity>();
+
+ 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);
+
+ }
+}
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
deleted file mode 100644
index e03b7ffa82..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ElementHandler.java
+++ /dev/null
@@ -1,108 +0,0 @@
-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 java.util.Set;
-
-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(Set<String> filteredItem) {
- ElementCassandraLoader elementCassandraLoader = new ElementCassandraLoader();
- elementCassandraLoader.list().forEach(elementEntity -> handleElementEntity(elementEntity,filteredItem));
- }
-
- private void handleElementEntity(ElementEntity elementEntity, Set<String> filteredItem) {
- try {
- String itemId = elementEntity.getItemId();
-
- if (!filteredItem.isEmpty() && !filteredItem.contains(itemId)){
- 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;
- if (!isNull(namespace)){
- elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
- + separator + versionId + separator + space + separator + namespacePath+ separator + elementId);
- } else {
- elementDirectoryPath = Paths.get( ROOT_DIRECTORY + separator + itemId
- + separator + versionId + separator + space + separator + elementId);
- }
-
- if (notExists(elementDirectoryPath)) {
- Path created = 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);
- }
-
- }
-
- 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
deleted file mode 100644
index 3b7566fd1b..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ImportProperties.java
+++ /dev/null
@@ -1,20 +0,0 @@
-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
deleted file mode 100644
index ebbfb56ed0..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/ItemHandler.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.openecomp.core.tools.Commands.exportdata;
-
-import com.amdocs.zusammen.datatypes.Id;
-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 com.google.common.base.Strings;
-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.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static java.io.File.separator;
-import static java.nio.file.Files.*;
-import static org.openecomp.core.tools.Commands.exportdata.ImportProperties.JSON_POSTFIX;
-
-public class ItemHandler {
- private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
-
-
- public ItemHandler() {
- ImportProperties.initParams();
- }
-
- public void createItemsData(SessionContext context, Set<String> filteredItem) throws URISyntaxException, IOException {
- final List<Item> items = new ArrayList<>();
- if (filteredItem.isEmpty()) {
- items.addAll(getItemDao(context).list(context));
- } else {
- Optional<Item> item = addItem(context, filteredItem.iterator().next(), items);
- item.ifPresent(foundedItem -> {
- Object vendorId = foundedItem.getInfo().getProperty("vendorId");
- if (vendorId != null) {
- String vendorIdStr = vendorId.toString();
- addItem(context, vendorIdStr, items);
- filteredItem.add(vendorIdStr);
- }
- });
- }
-
- items.parallelStream().forEach(item -> createItemDirectoryAndFiles(item, filteredItem));
-
- }
-
-
-
- private Optional<Item> addItem(SessionContext context, String filteredItem, List<Item> items) {
- Optional<Item> item = getItemDao(context).get(context, new Id(filteredItem));
- item.ifPresent(itemData -> items.add(itemData));
- return item;
- }
-
- private final void createItemDirectoryAndFiles(Item item, Set<String> filteredItem) {
- try {
- String itemId = item.getId().getValue();
- if (!filteredItem.isEmpty() && !filteredItem.contains(itemId)) {
- 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);
- }
-
- }
-
-
- 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
deleted file mode 100644
index 4ff562484c..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/exportdata/VersionHandler.java
+++ /dev/null
@@ -1,73 +0,0 @@
-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;
-import java.util.Set;
-
-public class VersionHandler {
- private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
-
- public VersionHandler() {
- }
-
- public void loadVersions(Set<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, Set<String> filteredItem) {
- try {
- String itemId = versionEntity.getItemId();
- if (!filteredItem.isEmpty() && !filteredItem.contains(itemId)){
- 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);
- }
-
- }
-
- private void handleVersionInfo(VersionInfoEntity versionInfoEntity, Set<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);
- }
-
- }
-}
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
deleted file mode 100644
index d439468e97..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ElementImport.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package org.openecomp.core.tools.Commands.importdata;
-
-import com.amdocs.zusammen.datatypes.Id;
-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.HashSet;
-import java.util.Set;
-
-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);
- public static final String ROOT_ITEM = Id.ZERO.getValue();
-
- 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 {
- if (!Files.isDirectory(elementDir)){
- return;
- }
- // 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);
- }
- String element_Id = pathObjects[pathObjects.length - 1];
- elementEntity.setSpace(pathObjects[2]);
- elementEntity.setItemId(pathObjects[0]);
- elementEntity.setVersionId(pathObjects[1]);
- elementEntity.setElement_id(element_Id);
- elementEntity.setNamespace(getNameSpace(pathObjects));
- elementEntity.setParentId(getParentId(pathObjects));
- elementEntity.setSubElementIds(getAllSubElementsIds(elementDir, element_Id));
- elementCassandraLoader.createEntity(elementEntity);
- cassandraElementRepository.createElementNamespace(elementEntity);
- versionCassandraLoader.insertElementToVersion(elementEntity);
- } catch (Exception ex) {
- logger.error(ex.getMessage(), ex);
- }
- }
-
- private String getParentId(String[] pathObjects) {
-
- if (pathObjects[pathObjects.length - 1].equals(ROOT_ITEM)) {
- return null;
- }
- if (pathObjects.length == 4) {
- return ROOT_ITEM;
- }
- return pathObjects[pathObjects.length - 2];
- }
-
- private Set<String> getAllSubElementsIds(Path root, String elementId) throws IOException {
- if (elementId.equals(ROOT_ITEM)) {
- root = root.getParent();
- }
- File file = root.toFile();
- Set<String> retVal = new HashSet<>();
- File[] files = file.listFiles();
- for (File f : files){
- if (f.isDirectory()){
- retVal.add(f.getName());
- }
- }
- retVal.remove(ROOT_ITEM);
- return retVal;
-
- }
-
- private String getNameSpace(String[] pathObjects) {
- if (pathObjects.length <= 4) {
- return "";
- }
- 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
deleted file mode 100644
index 4dd4a1f2c8..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/ItemImport.java
+++ /dev/null
@@ -1,44 +0,0 @@
-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.trim().isEmpty()) {
- return;
- }
- Item item = JsonUtil.json2Object(itemJson, Item.class);
- ItemDao itemDao = getItemDao(sessionContext);
- itemDao.create(sessionContext, item.getId(), item.getInfo(), item.getCreationTime());
- logger.info("Item Created :"+item.getInfo().getName()+" , "+item.getId());
- System.out.println("Item Created :"+item.getInfo().getName()+" , "+item.getId());
- } 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
deleted file mode 100644
index 30c4152491..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/TreeWalker.java
+++ /dev/null
@@ -1,54 +0,0 @@
-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(), "");
- if (logicalPath.startsWith(File.separator)){
- logicalPath = logicalPath.substring(1);
- }
- 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
deleted file mode 100644
index 48433d8a90..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionImport.java
+++ /dev/null
@@ -1,41 +0,0 @@
-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.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
deleted file mode 100644
index e9d4174d6c..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/importdata/VersionInfoImport.java
+++ /dev/null
@@ -1,41 +0,0 @@
-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.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/concurrent/ItemHealingTask.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemHealingTask.java
index 39b62d4e99..878390fdc2 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemHealingTask.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemHealingTask.java
@@ -1,13 +1,8 @@
package org.openecomp.core.tools.concurrent;
-import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
+import org.openecomp.sdc.healing.api.HealingManager;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.VersioningUtil;
import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.types.VersionInfo;
-import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import java.util.concurrent.Callable;
@@ -17,55 +12,44 @@ import java.util.concurrent.Callable;
public class ItemHealingTask implements Callable<String> {
private String itemId;
- private String versionId;
- private String user;
+ private Version version;
private VendorSoftwareProductManager vspManager;
- private VersioningManager versioningManager;
+ private HealingManager healingManager;
public String getItemId() {
return itemId;
}
public String getVersionId() {
- return versionId;
+// return version.getId();
+ return null;
}
- public ItemHealingTask(String itemId, String versionId, String user,
+ public ItemHealingTask(String itemId, String versionId,
VendorSoftwareProductManager vspManager,
- VersioningManager versioningManager) {
- this.itemId = itemId;
- this.versionId = versionId;
- this.user = user;
- this.versioningManager = versioningManager;
+ HealingManager healingManager) {
+// this.itemId = itemId;
+// this.version = new Version(versionId);
this.vspManager = vspManager;
+ this.healingManager = healingManager;
+
}
@Override
public String call() throws Exception {
-
- VersionInfo versionInfo = getVersionInfo(itemId, VersionableEntityAction.Read, user);
- Version resolvedVersion = VersioningUtil.resolveVersion(Version.valueOf(versionId),
- versionInfo, user);
- VspDetails vspDetails = vspManager.getVsp(itemId, resolvedVersion, user);
-
- try {
- vspManager.callAutoHeal(itemId, versionInfo, vspDetails, user);
-
- } catch (Exception e) {
- return (String.format("healing failed on vsp: %s with id: %s, versionId: %s, resolved " +
- "Version: %s, with message: %s",vspDetails.getName(),itemId,
- versionId,resolvedVersion,e.getMessage()));
- }
-
- return String.format("healed vsp: %s, with id: %s, versionId:%s, resolved version: %s",
- vspDetails.getName(), itemId, versionId,resolvedVersion );
- }
-
- private VersionInfo getVersionInfo(String vendorSoftwareProductId, VersionableEntityAction action,
- String user) {
- return versioningManager.getEntityVersionInfo(
- VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
- vendorSoftwareProductId, user, action);
+// VspDetails vspDetails = vspManager.getVsp(itemId, version);
+//
+// try {
+// healingManager.healItemVersion(itemId, version, ItemType.vsp, true);
+// } catch (Exception e) {
+// return (String
+// .format("healing failed on vsp: %s with id: %s, versionId: %s, with message: %s",
+// vspDetails.getName(), itemId, version.getId(), e.getMessage()));
+// }
+//
+// return String.format("healed vsp: %s, with id: %s, versionId: %s",
+// vspDetails.getName(), itemId, version.getId());
+ return null;
}
}
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
new file mode 100644
index 0000000000..5dcc72de59
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java
@@ -0,0 +1,125 @@
+/**
+ * Copyright © 2016-2017 European Support Limited.
+ */
+package org.openecomp.core.tools.exportinfo;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.ResultSetFuture;
+import com.datastax.driver.core.Session;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import org.apache.commons.io.FileUtils;
+import org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory;
+import org.openecomp.core.tools.importinfo.ImportProperties;
+import org.openecomp.core.tools.util.Utils;
+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 org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.stream.Collectors;
+
+import static java.nio.file.Files.createDirectories;
+
+
+public class ExportDataCommand {
+ private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
+ public static final String JOIN_DELIMITER = "$#";
+ public static final String JOIN_DELIMITER_SPILTTER = "\\$\\#";
+ public static final String MAP_DELIMITER = "!@";
+ public static final String MAP_DELIMITER_SPLITTER = "\\!\\@";
+ public static final String EXPORT_FILE_NAME = "ITEM_EXPORT";
+
+ public static void exportData(SessionContext sessionContext, String filterItem) {
+ try {
+ CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
+ final Set<String> filteredItems = Sets.newHashSet(filterItem);
+ Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
+ initDir(rootDir);
+ Set<String> fis = filteredItems.stream().map(fi -> fi.replaceAll("\\r", "")).collect(Collectors.toSet());
+
+ Map<String, List<String>> queries;
+ Yaml yaml = new Yaml();
+ try (InputStream is = ExportDataCommand.class.getResourceAsStream("/queries.yaml")) {
+ queries = (Map<String, List<String>>) yaml.load(is);
+ }
+ List<String> queriesList = queries.get("queries");
+ List<String> itempsColumns = queries.get("item_columns");
+ Set<String> vlms = new HashSet<>();
+ CountDownLatch doneQueries = new CountDownLatch(queriesList.size());
+ for (int i = 0; i < queriesList.size(); i++) {
+ executeQuery(queriesList.get(i), fis, itempsColumns.get(i), vlms, doneQueries);
+ }
+ doneQueries.await();
+ if (!vlms.isEmpty()) {
+ CountDownLatch doneVmls = new CountDownLatch(queriesList.size());
+
+ for (int i = 0; i < queriesList.size(); i++) {
+ executeQuery(queriesList.get(i), vlms, itempsColumns.get(i), null, doneVmls);
+ }
+
+ doneVmls.await();
+ }
+ zipPath(rootDir);
+ FileUtils.forceDelete(rootDir.toFile());
+ } catch (Exception ex) {
+ Utils.logError(logger, ex);
+ }
+
+ }
+
+
+ private static boolean executeQuery(final String query, final Set<String> filteredItems, final String filteredColumn,
+ final Set<String> vlms, final CountDownLatch donequerying) {
+ Session session = CassandraSessionFactory.getSession();
+ ResultSetFuture resultSetFuture = session.executeAsync(query);
+ Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() {
+ @Override
+ public void onSuccess(ResultSet resultSet) {
+ new ExportSerializer().serializeResult(resultSet, filteredItems, filteredColumn, vlms);
+ donequerying.countDown();
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ Utils.logError(logger, "Query failed :" + query, t);
+ donequerying.countDown();
+ }
+ });
+ return true;
+ }
+
+ private static void zipPath(Path rootDir) throws Exception {
+ LocalDateTime date = LocalDateTime.now();
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+ String dateStr = date.format(formatter);
+ dateStr = dateStr.replaceAll(":", "_");
+ String zipFile = System.getProperty("user.home") + File.separatorChar + "onboarding_import" + dateStr + ".zip";
+ ZipUtils.createZip(zipFile, rootDir);
+ Utils.printMessage(logger, "Exported file :" + zipFile);
+ }
+
+
+ public static void initDir(Path rootDir) throws IOException {
+ if (rootDir.toFile().exists()) {
+ 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/exportinfo/ExportSerializer.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java
new file mode 100644
index 0000000000..3c917b1c7e
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java
@@ -0,0 +1,152 @@
+/**
+ * Copyright © 2016-2017 European Support Limited.
+ */
+package org.openecomp.core.tools.exportinfo;
+
+import com.datastax.driver.core.DataType.Name;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openecomp.core.tools.importinfo.ImportProperties;
+import org.openecomp.core.tools.model.ColumnDefinition;
+import org.openecomp.core.tools.model.TableData;
+import org.openecomp.core.tools.util.Utils;
+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.Paths;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.openecomp.core.tools.importinfo.ImportSingleTable.dataTypesMap;
+
+public class ExportSerializer {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExportDataCommand.class);
+ 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<String> filteredItems, final String filteredColumn, Set<String> vlms) {
+ try {
+ TableData tableData = new TableData();
+ tableData.definitions = resultSet.getColumnDefinitions().asList().stream().map(column -> new ColumnDefinition(column)).collect(Collectors.toList());
+ String table = tableData.definitions.iterator().next().getTable();
+ boolean isElementTable = table.equals(ELEMENT_TABLE_NAME);
+ Iterator<Row> iterator = resultSet.iterator();
+ iterator.forEachRemaining(row -> {
+ if (!filteredItems.contains(row.getString(filteredColumn))) {
+ return;
+ }
+ List<String> rowData = new ArrayList<>();
+ for (int i = 0; i < tableData.definitions.size(); i++) {
+ ColumnDefinition columnDefinition = tableData.definitions.get(i);
+ Name name = dataTypesMap.get(columnDefinition.getType());
+ boolean checkForVLM = isElementTable && columnDefinition.getName().equals(ELEMENT_INFO_COLUMN_NAME);
+ Object data;
+ data = convertByType(vlms, row, i, name, checkForVLM);
+ rowData.add(data.toString());
+ }
+ tableData.rows.add(rowData);
+ });
+ ObjectMapper objectMapper = new ObjectMapper();
+ 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);
+ }
+ }
+
+ private Object convertByType(Set<String> vlms, Row row, int i, Name name, boolean checkForVLM) {
+ Object data;
+ switch (name) {
+ case VARCHAR:
+ case TEXT:
+ case ASCII:
+ String string = row.getString(i);
+ if (string == null) {
+ string = "";
+ }
+ if (checkForVLM && vlms != null){
+ String vlm = extractVlm(string);
+ if (vlm!= null) {
+ vlms.add(vlm);
+ }
+ }
+ data = Base64.getEncoder().encodeToString(string.getBytes());
+ break;
+ case BLOB:
+ ByteBuffer bytes = row.getBytes(i);
+ if (bytes == null) {
+ bytes = ByteBuffer.wrap("".getBytes());
+ }
+ data = Base64.getEncoder().encodeToString(bytes.array());
+ break;
+ case TIMESTAMP:
+ data = row.getDate(i).getTime();
+ break;
+ case BOOLEAN:
+ data = row.getBool(i);
+ break;
+ case COUNTER:
+ data = row.getLong(i);
+ break;
+ case INT:
+ data = row.getInt(i);
+ break;
+ case FLOAT:
+ data = row.getFloat(i);
+ break;
+ case SET:
+ Set set = row.getSet(i, Object.class);
+ Object joined = set.stream().map(o -> o.toString()).collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER));
+ data = Base64.getEncoder().encodeToString(joined.toString().getBytes());
+ break;
+ case MAP:
+ Map<Object,Object> map = row.getMap(i, Object.class, Object.class);
+ Set<Map.Entry<Object,Object>> entrySet = map.entrySet();
+ Object mapAsString = entrySet.parallelStream().map(entry -> entry.getKey().toString() + ExportDataCommand.MAP_DELIMITER +entry.getValue().toString())
+ .collect(Collectors.joining(ExportDataCommand.MAP_DELIMITER));
+ data = Base64.getEncoder().encodeToString(mapAsString.toString().getBytes());
+ break;
+ default:
+ throw new UnsupportedOperationException("Name is not supported :" + name);
+ }
+ return data;
+ }
+
+ protected String extractVlm(String injson) {
+ try {
+ if (injson == null){
+ return null;
+ }
+ JsonElement root = new JsonParser().parse(injson);
+ if (root == null){
+ return null;
+ }
+ JsonElement properties = root.getAsJsonObject().get("properties");
+ if (properties == null){
+ return null;
+ }
+ JsonElement vendorId = properties.getAsJsonObject().get("vendorId");
+ if (vendorId == null){
+ return null;
+ }
+ return vendorId.getAsString();
+ } catch (Exception ex){
+ return null;
+ }
+ }
+}
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
new file mode 100644
index 0000000000..bae6cfa4dd
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.java
@@ -0,0 +1,37 @@
+package org.openecomp.core.tools.importinfo;
+
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.apache.commons.io.FileUtils;
+import org.openecomp.core.tools.exportinfo.ExportDataCommand;
+import org.openecomp.core.tools.util.Utils;
+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.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.stream.Stream;
+
+public class ImportDataCommand {
+
+ private static final Logger logger = LoggerFactory.getLogger(ImportDataCommand.class);
+
+ public static final void execute(SessionContext sessionContext, String uploadFile) {
+ try {
+ CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
+ Path outputFolder = Paths.get(ImportProperties.ROOT_DIRECTORY);
+ ExportDataCommand.initDir(outputFolder); //clear old imports.
+ ZipUtils.unzip(Paths.get(uploadFile), outputFolder);
+ try( Stream<Path> files = Files.list(outputFolder)) {
+ files.forEach(file -> new ImportSingleTable().importFile(file));
+ }
+ FileUtils.forceDelete(outputFolder.toFile()); // leaves directory clean
+ } catch (IOException e) {
+ Utils.logError(logger, e);
+ }
+ }
+}
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
new file mode 100644
index 0000000000..b9a27faeef
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportProperties.java
@@ -0,0 +1,7 @@
+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";
+}
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
new file mode 100644
index 0000000000..7504ad1194
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java
@@ -0,0 +1,166 @@
+package org.openecomp.core.tools.importinfo;
+
+import com.datastax.driver.core.BoundStatement;
+import com.datastax.driver.core.DataType.Name;
+import com.datastax.driver.core.PreparedStatement;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.ResultSetFuture;
+import com.datastax.driver.core.Session;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import org.apache.commons.lang3.StringUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory;
+import org.openecomp.core.tools.exportinfo.ExportDataCommand;
+import org.openecomp.core.tools.model.ColumnDefinition;
+import org.openecomp.core.tools.model.TableData;
+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.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;
+
+public class ImportSingleTable {
+
+ private static final Logger logger = LoggerFactory.getLogger(ImportSingleTable.class);
+
+ public static final String INSERT_INTO = "INSERT INTO ";
+ public static final String VALUES = " VALUES ";
+ private static final Map<String, PreparedStatement> statementsCache = new HashMap<>();
+
+ public void importFile(Path file) {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ TableData tableData = objectMapper.readValue(file.toFile(), TableData.class);
+ Session session = CassandraSessionFactory.getSession();
+ PreparedStatement ps = getPrepareStatement(tableData, session);
+ tableData.rows.parallelStream().forEach(row -> executeQuery(session, ps, tableData.definitions, row));
+ } catch (IOException e) {
+ Utils.logError(logger, e);
+ }
+
+ }
+
+ private PreparedStatement getPrepareStatement(TableData tableData, Session session) {
+ String query = createQuery(tableData);
+ if (statementsCache.containsKey(query)) {
+ return statementsCache.get(query);
+ }
+ PreparedStatement preparedStatement = session.prepare(query);
+ statementsCache.put(query, preparedStatement);
+ return preparedStatement;
+ }
+
+ private void executeQuery(Session session, PreparedStatement ps, List<ColumnDefinition> definitions, List<String> rows) {
+ BoundStatement bind = ps.bind();
+ for (int i = 0; i < definitions.size(); i++) {
+ ColumnDefinition columnDefinition = definitions.get(i);
+ String rowData = rows.get(i);
+ Name name = dataTypesMap.get(columnDefinition.getType());
+ handleByType(bind, i, rowData, name);
+ }
+ ResultSetFuture resultSetFuture = session.executeAsync(bind);
+ Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() {
+ @Override
+ public void onSuccess(ResultSet resultSet) {
+ Utils.printMessage(logger, "successful write ");
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ Utils.logError(logger, t);
+ }
+ });
+ }
+
+ private void handleByType(BoundStatement bind, int i, String rowData, Name name) {
+ switch (name) {
+ case VARCHAR:
+ case TEXT:
+ case ASCII:
+ bind.setString(i, new String(Base64.getDecoder().decode(rowData)));
+ break;
+ case BLOB:
+ bind.setBytes(i, ByteBuffer.wrap(Base64.getDecoder().decode(rowData.getBytes())));
+ break;
+ case TIMESTAMP:
+ bind.setDate(i, new Date(Long.parseLong(rowData)));
+ break;
+ case BOOLEAN:
+ bind.setBool(i, Boolean.parseBoolean(rowData));
+ break;
+ case COUNTER:
+ bind.setLong(i, Long.parseLong(rowData));
+ break;
+ case INT:
+ bind.setInt(i, Integer.parseInt(rowData));
+ break;
+ case FLOAT:
+ bind.setFloat(i, Float.parseFloat(rowData));
+ break;
+ case SET:
+ byte[] decoded = Base64.getDecoder().decode(rowData);
+ String decodedStr = new String(decoded);
+ if (!StringUtils.isEmpty(decodedStr)) {
+ String[] splitted = decodedStr.split(ExportDataCommand.JOIN_DELIMITER_SPILTTER);
+ Set set = Sets.newHashSet(splitted);
+ set.remove("");
+ bind.setSet(i, set);
+ } else {
+ bind.setSet(i, null);
+ }
+ break;
+ case MAP:
+ byte[] decodedMap = Base64.getDecoder().decode(rowData);
+ String mapStr = new String(decodedMap);
+ if (!StringUtils.isEmpty(mapStr)) {
+ String[] splittedMap = mapStr.split(ExportDataCommand.JOIN_DELIMITER_SPILTTER);
+ Map<String, String> map = new HashMap<>();
+ for (String keyValue : splittedMap) {
+ String[] split = keyValue.split(ExportDataCommand.MAP_DELIMITER_SPLITTER);
+ map.put(split[0], split[1]);
+ }
+ bind.setMap(i, map);
+ } else {
+ bind.setMap(i, null);
+ }
+ break;
+ default:
+ throw new UnsupportedOperationException("Name is not supported :" + name);
+
+ }
+ }
+
+ private String createQuery(TableData tableData) {
+ ColumnDefinition def = tableData.definitions.iterator().next();
+ StringBuilder sb = new StringBuilder();
+ sb.append(INSERT_INTO).append(def.getKeyspace()).append(".").append(def.getTable());
+ sb.append(tableData.definitions.stream().map(definition -> definition.getName()).collect(Collectors.joining(" , ", " ( ", " ) ")));
+ sb.append(VALUES).append(tableData.definitions.stream().map(definition -> "?").collect(Collectors.joining(" , ", " ( ", " ) "))).append(";");
+ return sb.toString();
+ }
+
+ public static final ImmutableMap<String, Name> dataTypesMap;
+
+ static {
+ Builder<String, Name> 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/loaders/zusammen/VspGeneralLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspGeneralLoader.java
deleted file mode 100644
index d92866bb47..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspGeneralLoader.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.openecomp.core.tools.loaders.zusammen;
-
-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/loaders/zusammen/VspItemLoader.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspItemLoader.java
deleted file mode 100644
index 78b915c525..0000000000
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/loaders/zusammen/VspItemLoader.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package org.openecomp.core.tools.loaders.zusammen;
-
-public class VspItemLoader {
-}
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 b55d51709d..182988717e 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
@@ -3,9 +3,9 @@ package org.openecomp.core.tools.main;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.UserInfo;
import org.openecomp.core.tools.Commands.HealAll;
-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.Commands.SetHealingFlag;
+import org.openecomp.core.tools.exportinfo.ExportDataCommand;
+import org.openecomp.core.tools.importinfo.ImportDataCommand;
import org.openecomp.core.tools.util.ToolsUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -39,13 +39,13 @@ public class ZusammenMainTool {
switch (COMMANDS.valueOf(command)){
case RESET_OLD_VERSION:
- ResetOldVersion.reset(context,ToolsUtil.getParam("v",args),ToolsUtil.getParam("n",args));
+ SetHealingFlag.populateHealingTable(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));
+ ImportDataCommand.execute(context, ToolsUtil.getParam("f",args));
break;
case HEAL_ALL:
HealAll.healAll(ToolsUtil.getParam("t",args));
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
new file mode 100644
index 0000000000..846392c1ab
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/ColumnDefinition.java
@@ -0,0 +1,84 @@
+/**
+ * Copyright © 2016-2017 European Support Limited.
+ */
+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 {
+
+ private String keyspace;
+ private String table;
+ private String name;
+ private String type;
+
+ public ColumnDefinition() {
+ }
+
+ public ColumnDefinition(String keyspace, String table, String name, DataType type) {
+ this.keyspace = keyspace;
+ this.table = table;
+ this.name = name;
+ this.type = type.getName().toString();
+ }
+
+ public ColumnDefinition(Definition definition) {
+ this(definition.getKeyspace(), definition.getTable(), definition.getName(), definition.getType());
+ }
+
+ /**
+ * The name of the keyspace this column is part of.
+ *
+ * @return the name of the keyspace this column is part of.
+ */
+ public String getKeyspace() {
+ return keyspace;
+ }
+
+ /**
+ * Returns the name of the table this column is part of.
+ *
+ * @return the name of the table this column is part of.
+ */
+ public String getTable() {
+ return table;
+ }
+
+ /**
+ * Returns the name of the column.
+ *
+ * @return the name of the column.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the type of the column.
+ *
+ * @return the type of the column.
+ */
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Arrays.hashCode(new Object[]{keyspace, table, name, type});
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ 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);
+ }
+}
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
new file mode 100644
index 0000000000..155f35c006
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/model/TableData.java
@@ -0,0 +1,12 @@
+/**
+ * Copyright © 2016-2017 European Support Limited.
+ */
+package org.openecomp.core.tools.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TableData {
+ public List<ColumnDefinition> definitions = new ArrayList<>();
+ public List<List<String>> rows = new ArrayList<>();
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/CassandraElementRepository.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/CassandraElementRepository.java
index c41b46ea14..fcc67e11d0 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/CassandraElementRepository.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/CassandraElementRepository.java
@@ -34,7 +34,12 @@ import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
public class CassandraElementRepository {
@@ -61,18 +66,18 @@ public class CassandraElementRepository {
ElementEntity element) {
Row row = getElementAccessor(context).get(
elementContext.getSpace(),
- elementContext.getItemId().toString(),
+ elementContext.getItemId().getValue(),
getVersionId(elementContext),
- element.getId().toString()).one();
+ element.getId().getValue()).one();
return row == null ? Optional.empty() : Optional.of(getElementEntity(element, row));
}
private String getVersionId(ElementEntityContext elementContext) {
- return elementContext.getChangeRef() == null
- ? elementContext.getVersionId().toString()
- : elementContext.getChangeRef();
+ return elementContext.getRevisionId() == null
+ ? elementContext.getVersionId().getValue()
+ : elementContext.getRevisionId().getValue();
}
@@ -92,7 +97,7 @@ public class CassandraElementRepository {
private void updateElement(SessionContext context, ElementEntityContext elementContext,
ElementEntity element) {
- if (elementContext.getChangeRef() == null) {
+ if (elementContext.getRevisionId() == null) {
getElementAccessor(context).update(
JsonUtil.object2Json(element.getInfo()),
@@ -113,7 +118,7 @@ public class CassandraElementRepository {
element.getVisualization(),
elementContext.getSpace(),
elementContext.getItemId().toString(),
- elementContext.getChangeRef(),
+ elementContext.getRevisionId().getValue(),
element.getId().toString());
}
}
@@ -154,7 +159,7 @@ public class CassandraElementRepository {
getVersionId(elementContext)).one();
return row == null
? new HashSet<>()
- : row.getSet(CassandraElementRepository.VersionElementsField.ELEMENT_IDS, String.class);
+ : row.getSet(VersionElementsField.ELEMENT_IDS, String.class);
}
/*
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java
index 5c72c95f49..d8929ea720 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ElementHandler.java
@@ -2,7 +2,6 @@ package org.openecomp.core.tools.store;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
@@ -11,23 +10,17 @@ public class ElementHandler {
private static final String GLOBAL_USER = "GLOBAL_USER";
public static void update(SessionContext context,
- String itemId, String versionId, String changeRef,
+ String itemId, String versionId, String revisionId,
ElementEntity elementEntity) {
ElementEntityContext elementContext;
CassandraElementRepository cassandraElementRepository = new CassandraElementRepository();
- if (changeRef == null) {
+ if (revisionId == null) {
elementContext = new ElementEntityContext(GLOBAL_USER, new Id(itemId),
- new Id(versionId));
+ new Id(versionId));
- } else {
- elementContext = new ElementEntityContext(GLOBAL_USER, new ElementContext(new Id(itemId),
- new Id(versionId),
- changeRef));
}
- cassandraElementRepository.update(context, elementContext, elementEntity);
-
}
}
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
new file mode 100644
index 0000000000..78bbdf069e
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/HealingHandler.java
@@ -0,0 +1,54 @@
+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 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.ArrayList;
+
+/**
+ * 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(ArrayList<HealingEntity> healingEntities) {
+ healingEntities.forEach(healingEntity -> {
+ if (isHealingRecordExist(healingEntity)) {
+ accessor.updateFlag(healingEntity.getHealingFlag(), healingEntity.getSpace(),
+ healingEntity.getItemId(), healingEntity.getVersionId());
+ } else {
+ accessor.create(healingEntity.getSpace(), healingEntity.getItemId(),
+ healingEntity.getVersionId(), healingEntity.getHealingFlag(),
+ healingEntity.getOldVersion());
+ }
+ });
+ }
+
+ private boolean isHealingRecordExist(HealingEntity healingEntity) {
+ return accessor.getFlag(healingEntity.getSpace(), healingEntity.getItemId(),
+ healingEntity.getVersionId()).getAvailableWithoutFetching() == 1;
+ }
+
+ @Accessor
+ interface HealingAccessor {
+
+ @Query("SELECT healing_needed FROM healing WHERE space=? AND item_id=? AND version_id=?")
+ ResultSet getFlag(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);
+ }
+
+} \ No newline at end of file
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 851e92dcca..fd9dc25daa 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
@@ -20,6 +20,7 @@
package org.openecomp.core.tools.store;
+import com.datastax.driver.core.ResultSet;
import com.datastax.driver.mapping.Mapper;
import com.datastax.driver.mapping.Result;
import com.datastax.driver.mapping.annotations.Accessor;
@@ -60,6 +61,8 @@ public class VersionCassandraLoader {
return accessor.getAll();
}
+ public ResultSet listItemVersion() { return accessor.getAllItemVersion();}
+
@Accessor
interface VersionAccessor {
@@ -74,5 +77,8 @@ public class VersionCassandraLoader {
@Query("select * from zusammen_dox.version ")
@QueryParameters(fetchSize = 400)
Result<VersionEntity> getAll();
+
+ @Query("select space,item_id,version_id from zusammen_dox.version ")
+ ResultSet getAllItemVersion();
}
}
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
index 1d9d2d9774..b8620b8283 100644
--- 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
@@ -4,14 +4,13 @@ import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Info;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Objects;
+import java.util.Optional;
public class VspGeneralLoader {
@@ -56,24 +55,24 @@ public class VspGeneralLoader {
for (Map.Entry<String, List<String>> entry : vspItemChangeRefssMap.entrySet()) {
- for (String changeRef : entry.getValue()) {
+ for (String revisionId : entry.getValue()) {
itemId = new Id(entry.getKey());
- entityId = getEntityIdByInfoNameValue(context, itemId, null, changeRef,null, NAME,
+ entityId = getEntityIdByInfoNameValue(context, itemId, null, revisionId,null, NAME,
GENERAL);
if (entityId != null) {
ElementEntityContext elementContext = new ElementEntityContext(
context.getUser().getUserName(),
itemId,
null);
- elementContext.setChangeRef(changeRef);
+ elementContext.setRevisionId(new Id(revisionId));
Optional<ElementEntity> result =
cassandraElementRepository.get(context, elementContext,
new ElementEntity(entityId));
if (result.isPresent()) {
- elementEntityMap.put(buildKey(context, entry, changeRef), result.get());
+ elementEntityMap.put(buildKey(context, entry, revisionId), result.get());
}
}
}
@@ -90,7 +89,7 @@ public class VspGeneralLoader {
private static Id getEntityIdByInfoNameValue(SessionContext context,
Id itemId,
Id versionId,
- String changeRef,
+ String revisionId,
Id elementId,
String name,
String value) {
@@ -100,8 +99,8 @@ public class VspGeneralLoader {
context.getUser().getUserName(),
itemId,
versionId);
- if (changeRef != null) {
- elementContext.setChangeRef(changeRef);
+ if (revisionId != null) {
+ elementContext.setRevisionId(new Id(revisionId));
}
Optional<ElementEntity> result =
cassandraElementRepository.get(context, elementContext,
@@ -113,8 +112,8 @@ public class VspGeneralLoader {
context.getUser().getUserName(),
itemId,
versionId);
- if(changeRef!= null){
- subElementContext.setChangeRef(changeRef);
+ if(revisionId!= null){
+ subElementContext.setRevisionId(new Id(revisionId));
}
Optional<ElementEntity> subElementEntityOptional =
cassandraElementRepository.get(context, subElementContext,
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
new file mode 100644
index 0000000000..8c95f795a6
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/zusammen/datatypes/HealingEntity.java
@@ -0,0 +1,78 @@
+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;
+
+/**
+ * Created by ayalaben on 10/15/2017
+ */
+@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 old_version;
+
+ 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 boolean getHealingFlag() {
+ return healingFlag;
+ }
+
+ public void setHealingFlag(boolean healingFlag) {
+ this.healingFlag = healingFlag;
+ }
+
+ public HealingEntity(String space, String itemId, String versionId, boolean healingFlag,String
+ oldVersion) {
+ this.space = space;
+ this.itemId = itemId;
+ this.versionId = versionId;
+ this.healingFlag = healingFlag;
+ this.old_version = oldVersion;
+ }
+
+ public String getOldVersion() {
+ return old_version;
+ }
+
+ public void setOldVersion(String old_version) {
+ this.old_version = old_version;
+ }
+} \ No newline at end of file
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 c7280c8a9d..946c05ef84 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
@@ -1,6 +1,8 @@
package org.openecomp.core.tools.store.zusammen.datatypes;
-import com.datastax.driver.mapping.annotations.*;
+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;
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 d1621ad672..f48b212327 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
@@ -3,13 +3,36 @@ 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 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);
+ }
}
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
index 2f6693d133..e0fd1a7535 100644
--- 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
@@ -1,13 +1,17 @@
package org.openecomp.core.tools.util;
import com.google.common.io.ByteStreams;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import java.io.BufferedOutputStream;
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.nio.file.Paths;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;
@@ -17,12 +21,23 @@ import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class ZipUtils {
- public static void createZip(String zipFileName, Path dir, Set<String> filterItem) throws Exception {
+
+ private static final Logger logger = LoggerFactory.getLogger(ZipUtils.class);
+
+ public static void createZip(String zipFileName, Path dir) throws IOException {
File dirObj = dir.toFile();
+ Path zippedFile = Files.createFile(Paths.get(zipFileName));
try (
- FileOutputStream fileOutputStream = new FileOutputStream(zipFileName);
- ZipOutputStream out = new ZipOutputStream(fileOutputStream)) {
- addDir(dirObj, out, dir.toString(), filterItem);
+ FileOutputStream fileOutputStream = new FileOutputStream(File.separator + zippedFile.toFile());
+ BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
+ ZipOutputStream out = new ZipOutputStream(bos)) {
+ File[] files = dirObj.listFiles();
+ for (File file : files) {
+ out.putNextEntry(new ZipEntry(file.getName()));
+ Files.copy(Paths.get(file.getPath()), out);
+ out.closeEntry();
+ }
+ Utils.printMessage(logger, "Zip file was created " + zipFileName);
}
}
@@ -47,7 +62,7 @@ public class ZipUtils {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
addDir(files[i], out, root, filterItem);
- String filePath = files[i].getAbsolutePath().replace(root + File.separator, "") + "/";
+ String filePath = files[i].getAbsolutePath().replace(root + File.separator, "") + File.separator;
out.putNextEntry(new ZipEntry(filePath));
continue;
}
@@ -57,7 +72,6 @@ public class ZipUtils {
out.putNextEntry(new ZipEntry(filePath));
try {
ByteStreams.copy(in, out);
-
} finally {
out.closeEntry();
}
@@ -71,7 +85,7 @@ public class ZipUtils {
if (zipFile == null || outputFolder == null) {
return;
}
- if (!Files.exists(outputFolder)) {
+ if (!outputFolder.toFile().exists()) {
Files.createDirectories(outputFolder);
}
@@ -83,7 +97,7 @@ public class ZipUtils {
File newFile = new File(outputFolder.toString() + File.separator + fileName);
if (ze.isDirectory()) {
Path path = newFile.toPath();
- if (!Files.exists(path)) {
+ if (!path.toFile().exists()) {
Files.createDirectories(path);
}
} else {
diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml b/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml
index a13dc82e22..2461aed504 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml
+++ b/openecomp-be/tools/zusammen-tools/src/main/resources/logback.xml
@@ -1,5 +1,6 @@
<configuration>
+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
diff --git a/openecomp-be/tools/zusammen-tools/src/main/resources/queries.yaml b/openecomp-be/tools/zusammen-tools/src/main/resources/queries.yaml
new file mode 100644
index 0000000000..a93a5a46e8
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/resources/queries.yaml
@@ -0,0 +1,16 @@
+queries:
+ - select * from zusammen_dox.element;
+ - select * from zusammen_dox.element_namespace;
+ - select * from zusammen_dox.item;
+ - select * from zusammen_dox.version;
+ - select * from zusammen_dox.version_elements;
+ - select * from dox.item_permissions;
+ - select * from dox.vsp_merge_hint ;
+item_columns:
+ - item_id
+ - item_id
+ - item_id
+ - item_id
+ - item_id
+ - item_id
+ - item_id \ No newline at end of file
diff --git a/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java
new file mode 100644
index 0000000000..7b43c4624f
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java
@@ -0,0 +1,48 @@
+package org.openecomp.core.tools.Commands.exportinfo.serialize;
+
+import org.openecomp.core.tools.exportinfo.ExportSerializer;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+public class VLMExtractTest {
+
+
+
+ @Test
+ public void extractVLM(){
+ String vlmId = "979a56c7b2fa41e6a5742137f53a5c1b";
+ String elemenet_info_string = "{\n" +
+ " \"name\": \"VendorSoftwareProduct\",\n" +
+ " \"properties\": {\n" +
+ " \"subCategory\": \"resourceNewCategory.dcae component.collector\",\n" +
+ " \"name\": \"vsp1\",\n" +
+ " \"icon\": \"icon\",\n" +
+ " \"onboardingMethod\": \"NetworkPackage\",\n" +
+ " \"description\": \"d\",\n" +
+ " \"vendorId\": \""+vlmId+"\",\n" +
+ " \"category\": \"resourceNewCategory.dcae component\",\n" +
+ " \"vendorName\": \"vlm1\",\n" +
+ " \"elementType\": \"VendorSoftwareProduct\"\n" +
+ " }\n" +
+ "}\n" ;
+ String extractedVlmId = new CustomExportSerializer().extractVlm(elemenet_info_string);
+ assertNotNull(extractedVlmId);
+ assertEquals(extractedVlmId,vlmId);
+
+ }
+
+ @Test
+ public void failToExtractVLMBecauseJsonIsCorrupted(){
+ String elemenet_info_string = "gfhhhghgh";
+ String extractedVlmId = new CustomExportSerializer().extractVlm(elemenet_info_string);
+ assertNull(extractedVlmId);
+ }
+
+ private static final class CustomExportSerializer extends ExportSerializer{
+ public String extractVlm(String injson) {
+ return super.extractVlm(injson);
+ }
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/test/resources/configuration.yaml b/openecomp-be/tools/zusammen-tools/src/test/resources/configuration.yaml
new file mode 100644
index 0000000000..6636e20726
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/test/resources/configuration.yaml
@@ -0,0 +1,251 @@
+identificationHeaderFields:
+ - HTTP_IV_USER
+ - HTTP_CSP_FIRSTNAME
+ - HTTP_CSP_LASTNAME
+ - HTTP_IV_REMOTE_ADDRESS
+ - HTTP_CSP_WSTYPE
+
+
+
+# catalog backend http port
+beHttpPort: 8080
+
+# catalog backend http context
+beContext: /sdc/rest/config/get
+
+# catalog backend protocol
+beProtocol: http
+
+# catalog backend ssl port
+beSslPort: 8443
+
+version: 1.0
+released: 2012-11-30
+
+titanCfgFile: /home/vagrant/catalog-be/config/catalog-be/titan.properties
+titanInMemoryGraph: false
+titanLockTimeout: 30
+titanReconnectIntervalInSeconds: 3
+titanHealthCheckReadTimeout: 1
+esReconnectIntervalInSeconds: 3
+uebHealthCheckReconnectIntervalInSeconds: 15
+uebHealthCheckReadTimeout: 4
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd
+
+neo4j:
+ host: neo4jhost
+ port: 7474
+ user: neo4j
+ password: "12345"
+
+cassandraConfig:
+ cassandraHosts: ['localhost']
+ reconnectTimeout : 30000
+ authenticate: true
+ username: asdc_user
+ password: password
+ ssl: false
+ truststorePath : /path/path
+ truststorePassword : password
+ keySpaces:
+ - { name: dox, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+ - { name: zusammen_dox, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+ - { name: sdcartifact, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+
+#Application-specific settings of ES
+elasticSearch:
+ # Mapping of index prefix to time-based frame. For example, if below is configured:
+ #
+ # - indexPrefix: auditingevents
+ # creationPeriod: minute
+ #
+ # then ES object of type which is mapped to "auditingevents-*" template, and created on 2015-12-23 13:24:54, will enter "auditingevents-2015-12-23-13-24" index.
+ # Another object created on 2015-12-23 13:25:54, will enter "auditingevents-2015-12-23-13-25" index.
+ # If creationPeriod: month, both of the above will enter "auditingevents-2015-12" index.
+ #
+ # PLEASE NOTE: the timestamps are created in UTC/GMT timezone! This is needed so that timestamps will be correctly presented in Kibana.
+ #
+ # Legal values for creationPeriod - year, month, day, hour, minute, none (meaning no time-based behaviour).
+ #
+ # If no creationPeriod is configured for indexPrefix, default behavour is creationPeriod: month.
+
+ indicesTimeFrequency:
+ - indexPrefix: auditingevents
+ creationPeriod: month
+ - indexPrefix: monitoring_events
+ creationPeriod: month
+
+artifactTypes:
+ - CHEF
+ - PUPPET
+ - SHELL
+ - YANG
+ - YANG_XML
+ - HEAT
+ - BPEL
+ - DG_XML
+ - MURANO_PKG
+ - OTHER
+
+licenseTypes:
+ - User
+ - Installation
+ - CPU
+
+#Deployment artifacts placeHolder
+deploymentResourceArtifacts:
+ heat:
+ displayName: "HEAT Template"
+ type: HEAT
+
+deploymentResourceInstanceArtifacts:
+ heatEnv:
+ displayName: "HEAT ENV"
+ type: HEAT_ENV
+ description: "Auto-generated HEAT Environment deployment artifact"
+ fileExtension: "env"
+
+#Informational artifacts placeHolder
+excludeResourceCategory:
+ - Generic
+informationalResourceArtifacts:
+ features:
+ displayName: Features
+ type: OTHER
+ capacity:
+ displayName: Capacity
+ type: OTHER
+ vendorTestResult:
+ displayName: Vendor Test Result
+ type: OTHER
+ testScripts:
+ displayName: Test Scripts
+ type: OTHER
+ cloudQuestionnaire:
+ displayName: Cloud Questionnaire (completed)
+ type: OTHER
+ HEATTemplateFromVendor:
+ displayName: HEAT Template from Vendor
+ type: HEAT
+
+excludeServiceCategory:
+
+informationalServiceArtifacts:
+ messageFlows:
+ displayName: Message Flows
+ type: OTHER
+ instantiationFlows:
+ displayName: Management Flows
+ type: OTHER
+ serviceArtifactPlan:
+ displayName: Service Artifact Plan
+ type: OTHER
+ summaryOfImpactsToECOMPElements:
+ displayName: Summary of impacts to OPENECOMP elements,OSSs, BSSs
+ type: OTHER
+ controlLoopFunctions:
+ displayName: Control Loop Functions
+ type: OTHER
+ dimensioningInfo:
+ displayName: Dimensioning Info
+ type: OTHER
+ affinityRules:
+ displayName: Affinity Rules
+ type: OTHER
+ operationalPolicies:
+ displayName: Operational Policies
+ type: OTHER
+ serviceSpecificPolicies:
+ displayName: Service-specific Policies
+ type: OTHER
+ engineeringRules:
+ displayName: Engineering Rules (ERD)
+ type: OTHER
+ distributionInstructions:
+ displayName: Distribution Instructions
+ type: OTHER
+ certificationTestResults:
+ displayName: TD Certification Test Results
+ type: OTHER
+ deploymentVotingRecord:
+ displayName: Deployment Voting Record
+ type: OTHER
+ serviceQuestionnaire:
+ displayName: Service Questionnaire
+ type: OTHER
+
+serviceApiArtifacts:
+ configuration:
+ displayName: Configuration
+ type: OTHER
+ instantiation:
+ displayName: Instantiation
+ type: OTHER
+ monitoring:
+ displayName: Monitoring
+ type: OTHER
+ reporting:
+ displayName: Reporting
+ type: OTHER
+ logging:
+ displayName: Logging
+ type: OTHER
+ testing:
+ displayName: Testing
+ type: OTHER
+
+
+additionalInformationMaxNumberOfKeys: 50
+
+systemMonitoring:
+ enabled: false
+ isProxy: false
+ probeIntervalInSeconds: 15
+
+defaultHeatArtifactTimeoutMinutes: 60
+
+serviceDeploymentArtifacts:
+
+resourceDeploymentArtifacts:
+ HEAT:
+ acceptedTypes:
+ - yaml
+ - yml
+
+resourceInformationalDeployedArtifacts:
+ YANG_XML:
+ acceptedTypes:
+ - xml
+
+
+unLoggedUrls:
+ - /sdc2/rest/healthCheck
+
+cleanComponentsConfiguration:
+ cleanIntervalInMinutes: 1440
+ componentsToClean:
+ - Resource
+
+artifactsIndex: resources
+
+heatEnvArtifactHeader:
+ " # _______________________________________________________________________________________________________________________________________\n
+ #| AT&T Proprietary (Restricted) |\n
+ #| Only for use by authorized individuals or any above-designated team(s) |\n
+ #| within the AT&T companies and not for general distribution |\n
+ #|_______________________________________________________________________________________________________________________________________|\n"
+heatEnvArtifactFooter:
+ " # _______________________________________________________________________________________________________________________________________\n
+ #| AT&T Proprietary (Restricted) |\n
+ #| Only for use by authorized individuals or any above-designated team(s) |\n
+ #| within the AT&T companies and not for general distribution |\n
+ #|_______________________________________________________________________________________________________________________________________|\n"
diff --git a/openecomp-be/tools/zusammen-tools/src/test/resources/queries.yaml b/openecomp-be/tools/zusammen-tools/src/test/resources/queries.yaml
new file mode 100644
index 0000000000..6ca8cd6efe
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/test/resources/queries.yaml
@@ -0,0 +1,16 @@
+queries:
+ - select * from zusammen_dox.element;
+ - select * from zusammen_dox.element_namespace;
+ - select * from zusammen_dox.item;
+ - select * from zusammen_dox.version;
+ - select * from zusammen_dox.version_elements;
+ - select * from dox.item_permissions;
+ - select * from dox.vsp_merge_hint;
+item_columns:
+ - item_id
+ - item_id
+ - item_id
+ - item_id
+ - item_id
+ - item_id
+ - item_id \ No newline at end of file