diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-09 12:06:18 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-09 12:06:18 +0200 |
commit | a57f7b13b5c3a192cf6a4b0638f24a30f45bf1cb (patch) | |
tree | 276adc7f436d363fc3be85f707ceda7cd10ae08f /standalone-container | |
parent | a68b6e0ce30a8ebaf804b95ad0dfc17520cbe9f2 (diff) |
Implement addBlob for LocalFileDB too.
Diffstat (limited to 'standalone-container')
-rw-r--r-- | standalone-container/src/main/java/com/yahoo/container/standalone/LocalFileDb.java | 40 | ||||
-rw-r--r-- | standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java | 4 |
2 files changed, 20 insertions, 24 deletions
diff --git a/standalone-container/src/main/java/com/yahoo/container/standalone/LocalFileDb.java b/standalone-container/src/main/java/com/yahoo/container/standalone/LocalFileDb.java index df31e454cd7..ed7d30c476f 100644 --- a/standalone-container/src/main/java/com/yahoo/container/standalone/LocalFileDb.java +++ b/standalone-container/src/main/java/com/yahoo/container/standalone/LocalFileDb.java @@ -4,11 +4,11 @@ package com.yahoo.container.standalone; import com.yahoo.config.FileReference; import com.yahoo.config.application.api.FileRegistry; import com.yahoo.filedistribution.fileacquirer.FileAcquirer; -import com.yahoo.net.HostName; +import net.jpountz.lz4.LZ4FrameOutputStream; import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; +import java.io.FileOutputStream; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.file.Path; import java.util.HashMap; @@ -24,9 +24,6 @@ import java.util.stream.Collectors; * @author ollivir */ public class LocalFileDb implements FileAcquirer, FileRegistry { - - private static final Constructor<FileReference> fileReferenceConstructor = createFileReferenceConstructor(); - private final Map<FileReference, File> fileReferenceToFile = new HashMap<>(); private final Path appPath; @@ -57,12 +54,7 @@ public class LocalFileDb implements FileAcquirer, FileRegistry { throw new RuntimeException("The file does not exist: " + file.getPath()); } - FileReference fileReference = null; - try { - fileReference = fileReferenceConstructor.newInstance("LocalFileDb:" + relativePath); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException("Unable to create new FileReference", e); - } + FileReference fileReference = new FileReference("LocalFileDb:" + relativePath); fileReferenceToFile.put(fileReference, file); return fileReference; } @@ -80,16 +72,24 @@ public class LocalFileDb implements FileAcquirer, FileRegistry { @Override public FileReference addBlob(String name, ByteBuffer blob) { - throw new RuntimeException("addBlob(String name, ByteBuffer blob) is not implemented here."); + writeBlob(blob, name); + File file = appPath.resolve(name).toFile(); + FileReference fileReference = new FileReference("LocalFileDb:" + name); + fileReferenceToFile.put(fileReference, file); + return fileReference; } - private static Constructor<FileReference> createFileReferenceConstructor() { - try { - Constructor<FileReference> method = FileReference.class.getDeclaredConstructor(String.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException ex) { - throw new IllegalStateException(ex); + private void writeBlob(ByteBuffer blob, String relativePath) { + try (FileOutputStream fos = new FileOutputStream(new File(appPath.toFile(), relativePath))) { + if (relativePath.endsWith(".lz4")) { + LZ4FrameOutputStream lz4 = new LZ4FrameOutputStream(fos); + lz4.write(blob.array(), blob.arrayOffset(), blob.remaining()); + lz4.close(); + } else { + fos.write(blob.array(), blob.arrayOffset(), blob.remaining()); + } + } catch (IOException e) { + throw new IllegalArgumentException("Failed writing temp file", e); } } diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java index a00ffd8b985..5d093aa2609 100644 --- a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java +++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java @@ -3,7 +3,6 @@ package com.yahoo.container.standalone; import com.yahoo.collections.Pair; import com.yahoo.config.model.ConfigModelRepo; -import com.yahoo.config.model.producer.AbstractConfigProducerRoot; import com.yahoo.io.IOUtils; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.container.xml.ContainerModelBuilder.Networking; @@ -22,9 +21,6 @@ import java.util.List; * @author ollivir */ public class StandaloneContainer { - public static String firstContainerId(AbstractConfigProducerRoot root) { - return root.getConfigProducer("container").get().getConfigId(); - } interface ThrowingFunction<T, U> { U apply(T input) throws Exception; |