Skip to content

Commit

Permalink
Finished adding dump and restore including the associated docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
payammeyer committed Apr 4, 2020
1 parent 92b2edc commit 08292d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions zulia-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies {

api("org.mongodb:mongodb-driver-sync:$mongoDriverVersion")

api("org.apache.commons:commons-compress:1.20")

implementation("io.reactivex.rxjava2:rxjava:2.2.0")

annotationProcessor("io.micronaut:micronaut-inject-java:$micronautVersion")
Expand Down
20 changes: 13 additions & 7 deletions zulia-server/src/main/java/io/zulia/server/cmd/ZuliaCmdUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
import io.zulia.server.config.cluster.MongoServer;
import io.zulia.server.config.single.SingleNodeService;
import io.zulia.server.util.MongoProvider;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.bson.Document;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
Expand All @@ -36,8 +40,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZuliaCmdUtil {

Expand Down Expand Up @@ -137,17 +139,21 @@ public static void index(String inputDir, String recordsFilename, String idField
workPool.store(store);

if (Files.exists(Paths.get(inputDir + File.separator + id.replaceAll("/", "_") + ".zip"))) {
try (ZipFile zipFile = new ZipFile(Paths.get(inputDir + File.separator + id.replaceAll("/", "_") + ".zip").toFile())) {
while (zipFile.entries().hasMoreElements()) {
ZipEntry entry = zipFile.entries().nextElement();

try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream(
new FileInputStream(Paths.get(inputDir + File.separator + id.replaceAll("/", "_") + ".zip").toFile()))) {
ZipArchiveEntry zipEntry;
while ((zipEntry = inputStream.getNextZipEntry()) != null) {
try {
workPool.storeLargeAssociated(new StoreLargeAssociated(id, index, entry.getName(), zipFile.getInputStream(entry)));
workPool.storeLargeAssociated(
new StoreLargeAssociated(id, index, zipEntry.getName(), new ByteArrayInputStream(inputStream.readAllBytes())));
}
catch (Throwable t) {
LOG.log(Level.SEVERE, "Could not restore associated file <" + entry.getName() + ">", t);
LOG.log(Level.SEVERE, "Could not restore associated file <" + zipEntry.getName() + ">", t);
}
}
}

}

int i = count.incrementAndGet();
Expand Down

0 comments on commit 08292d4

Please sign in to comment.