diff --git a/tools/pom.xml b/tools/pom.xml
index 7402fe4708..16d511e6db 100644
--- a/tools/pom.xml
+++ b/tools/pom.xml
@@ -51,6 +51,38 @@
com.google.guava
guava
+
+ org.apache.cassandra
+ cassandra-all
+ 3.11.4
+ compile
+
+
+ commons-io
+ commons-io
+ 2.6
+ compile
+
+
+
+
+
+ maven-assembly-plugin
+
+
+
+ org.thingsboard.client.tools.migrator.MigratorTool
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+
+
diff --git a/tools/src/main/java/org/thingsboard/client/tools/migrator/MigratorTool.java b/tools/src/main/java/org/thingsboard/client/tools/migrator/MigratorTool.java
new file mode 100644
index 0000000000..fdc1917ca8
--- /dev/null
+++ b/tools/src/main/java/org/thingsboard/client/tools/migrator/MigratorTool.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright © 2016-2019 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.client.tools.migrator;
+
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+import java.io.File;
+
+public class MigratorTool {
+
+ public static void main(String[] args) {
+ CommandLine cmd = parseArgs(args);
+
+
+ try {
+ File latestSource = new File(cmd.getOptionValue("latestTelemetryFrom"));
+ File latestSaveDir = new File(cmd.getOptionValue("latestTelemetryOut"));
+ File tsSource = new File(cmd.getOptionValue("telemetryFrom"));
+ File tsSaveDir = new File(cmd.getOptionValue("telemetryOut"));
+ File partitionsSaveDir = new File(cmd.getOptionValue("partitionsOut"));
+ boolean castEnable = Boolean.parseBoolean(cmd.getOptionValue("castEnable"));
+
+ PgCaLatestMigrator.migrateLatest(latestSource, latestSaveDir, castEnable);
+ PostgresToCassandraTelemetryMigrator.migrateTs(tsSource, tsSaveDir, partitionsSaveDir, castEnable);
+
+ } catch (Throwable th) {
+ th.printStackTrace();
+ throw new IllegalStateException("failed", th);
+ }
+
+ }
+
+ private static CommandLine parseArgs(String[] args) {
+ Options options = new Options();
+
+ Option latestTsOpt = new Option("latestFrom", "latestTelemetryFrom", true, "latest telemetry source file path");
+ latestTsOpt.setRequired(true);
+ options.addOption(latestTsOpt);
+
+ Option latestTsOutOpt = new Option("latestOut", "latestTelemetryOut", true, "latest telemetry save dir");
+ latestTsOutOpt.setRequired(true);
+ options.addOption(latestTsOutOpt);
+
+ Option tsOpt = new Option("tsFrom", "telemetryFrom", true, "telemetry source file path");
+ tsOpt.setRequired(true);
+ options.addOption(tsOpt);
+
+ Option tsOutOpt = new Option("tsOut", "telemetryOut", true, "sstable save dir");
+ tsOutOpt.setRequired(true);
+ options.addOption(tsOutOpt);
+
+ Option partitionOutOpt = new Option("partitionsOut", "partitionsOut", true, "partitions save dir");
+ partitionOutOpt.setRequired(true);
+ options.addOption(partitionOutOpt);
+
+ Option castOpt = new Option("castEnable", "castEnable", true, "cast String to Double if possible");
+ castOpt.setRequired(true);
+ options.addOption(castOpt);
+
+ HelpFormatter formatter = new HelpFormatter();
+ CommandLineParser parser = new BasicParser();
+
+ try {
+ return parser.parse(options, args);
+ } catch (ParseException e) {
+ System.out.println(e.getMessage());
+ formatter.printHelp("utility-name", options);
+
+ System.exit(1);
+ }
+ return null;
+ }
+
+}
diff --git a/tools/src/main/java/org/thingsboard/client/tools/migrator/PgCaLatestMigrator.java b/tools/src/main/java/org/thingsboard/client/tools/migrator/PgCaLatestMigrator.java
new file mode 100644
index 0000000000..667f5e6d0f
--- /dev/null
+++ b/tools/src/main/java/org/thingsboard/client/tools/migrator/PgCaLatestMigrator.java
@@ -0,0 +1,179 @@
+/**
+ * Copyright © 2016-2019 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.client.tools.migrator;
+
+import com.google.common.collect.Lists;
+import org.apache.cassandra.io.sstable.CQLSSTableWriter;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.LineIterator;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+public class PgCaLatestMigrator {
+
+ private static final long LOG_BATCH = 1000000;
+ private static final long rowPerFile = 1000000;
+
+
+ private static long linesProcessed = 0;
+ private static long linesMigrated = 0;
+ private static long castErrors = 0;
+ private static long castedOk = 0;
+
+ private static long currentWriterCount = 1;
+ private static CQLSSTableWriter currentTsWriter = null;
+
+ public static void migrateLatest(File sourceFile, File outDir, boolean castStringsIfPossible) throws IOException {
+ long startTs = System.currentTimeMillis();
+ long stepLineTs = System.currentTimeMillis();
+ long stepOkLineTs = System.currentTimeMillis();
+ LineIterator iterator = FileUtils.lineIterator(sourceFile);
+ currentTsWriter = WriterBuilder.getTsWriter(outDir);
+
+ boolean isBlockStarted = false;
+ boolean isBlockFinished = false;
+
+ String line;
+ while (iterator.hasNext()) {
+ if (linesProcessed++ % LOG_BATCH == 0) {
+ System.out.println(new Date() + " linesProcessed = " + linesProcessed + " in " + (System.currentTimeMillis() - stepLineTs) + " castOk " + castedOk + " castErr " + castErrors);
+ stepLineTs = System.currentTimeMillis();
+ }
+
+ line = iterator.nextLine();
+
+ if (isBlockFinished) {
+ break;
+ }
+
+ if (!isBlockStarted) {
+ if (isBlockStarted(line)) {
+ System.out.println();
+ System.out.println();
+ System.out.println(line);
+ System.out.println();
+ System.out.println();
+ isBlockStarted = true;
+ }
+ continue;
+ }
+
+ if (isBlockFinished(line)) {
+ isBlockFinished = true;
+ } else {
+ try {
+ List raw = Arrays.stream(line.trim().split("\t"))
+ .map(String::trim)
+ .filter(StringUtils::isNotEmpty)
+ .collect(Collectors.toList());
+ List