From fc2b6e2d5888baf96dbedc4ebc251e99b5e63419 Mon Sep 17 00:00:00 2001 From: talig Date: Tue, 3 Jul 2018 10:51:29 +0300 Subject: Adapt zusammen tool to work with cassandra 3.4.0 In addition: fix bug in import-export command caused null to become empty string Change-Id: I1a47d0ede3b4760091213dec06f23971d58565b7 Issue-ID: SDC-1416 Signed-off-by: talig --- .../core/tools/exportinfo/ExportDataCommand.java | 1 + .../core/tools/exportinfo/ExportSerializer.java | 29 +++++++++++----------- .../core/tools/importinfo/ImportSingleTable.java | 5 +++- 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'openecomp-be/tools/zusammen-tools/src') diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java index aac1202506..decd0cee9a 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java @@ -46,6 +46,7 @@ public final class ExportDataCommand { public static final String MAP_DELIMITER = "!@"; public static final String MAP_DELIMITER_SPLITTER = "\\!\\@"; public static final int THREAD_POOL_SIZE = 6; + public static final String NULL_REPRESENTATION = "nnuullll"; private ExportDataCommand() { } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java index 92dfeca3c1..e4b0610019 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java @@ -3,21 +3,15 @@ */ package org.openecomp.core.tools.exportinfo; +import static org.openecomp.core.tools.exportinfo.ExportDataCommand.NULL_REPRESENTATION; +import static org.openecomp.core.tools.importinfo.ImportSingleTable.dataTypesMap; + import com.datastax.driver.core.DataType.Name; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; -import org.apache.commons.lang3.StringUtils; -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; @@ -30,8 +24,14 @@ 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; +import org.apache.commons.lang3.StringUtils; +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; public class ExportSerializer { @@ -39,6 +39,7 @@ public class ExportSerializer { private static final String ELEMENT_TABLE_NAME = "element"; private static final String ELEMENT_INFO_COLUMN_NAME = "info"; + public void serializeResult(final ResultSet resultSet, final Set filteredItems, final String filteredColumn, Set vlms) { try { TableData tableData = new TableData(); @@ -79,7 +80,7 @@ public class ExportSerializer { case ASCII: String string = row.getString(i); if (string == null) { - string = ""; + string = NULL_REPRESENTATION; } if (checkForVLM && vlms != null) { String vlm = extractVlm(string); @@ -117,12 +118,12 @@ public class ExportSerializer { data = row.getFloat(i); break; case SET: - Set set = row.getSet(i, Object.class); + Set set = (Set) row.getObject(i); Object joined = set.stream().map(Object::toString).collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER)); data = Base64.getEncoder().encodeToString(joined.toString().getBytes()); break; case MAP: - Map map = row.getMap(i, Object.class, Object.class); + Map map = (Map) row.getObject(i); Set> entrySet = map.entrySet(); Object mapAsString = entrySet.parallelStream().map(entry -> entry.getKey().toString() + ExportDataCommand.MAP_DELIMITER + entry.getValue().toString()) .collect(Collectors.joining(ExportDataCommand.JOIN_DELIMITER)); diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java index ed016aa997..3cac0e7892 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java @@ -1,5 +1,7 @@ package org.openecomp.core.tools.importinfo; +import static org.openecomp.core.tools.exportinfo.ExportDataCommand.NULL_REPRESENTATION; + import com.datastax.driver.core.BoundStatement; import com.datastax.driver.core.DataType.Name; import com.datastax.driver.core.PreparedStatement; @@ -74,7 +76,8 @@ public class ImportSingleTable { case VARCHAR: case TEXT: case ASCII: - bind.setString(i, new String(Base64.getDecoder().decode(rowData))); + String string = new String(Base64.getDecoder().decode(rowData)); + bind.setString(i, NULL_REPRESENTATION.equals(string) ? null : string); break; case BLOB: bind.setBytes(i, ByteBuffer.wrap(Base64.getDecoder().decode(rowData.getBytes()))); -- cgit 1.2.3-korg