summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-06-09 18:33:41 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2021-06-09 19:06:15 +0200
commitdd070f9b07b5b95e6840a75808394943b7bd0458 (patch)
treeaac910de125ae43eb98f79925f4910fb9033add1 /config-model
parentc6f31c85c466234df03228d997522860214a4501 (diff)
Wire in sendBlob interface
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java40
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java5
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java11
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java15
4 files changed, 60 insertions, 11 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java b/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java
index 77ce2dd41b5..60431c156fd 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/DistributableResource.java
@@ -5,15 +5,17 @@ import com.yahoo.path.Path;
import com.yahoo.vespa.model.AbstractService;
import com.yahoo.vespa.model.utils.FileSender;
+import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Objects;
public class DistributableResource {
- public enum PathType { FILE, URI };
+ public enum PathType { FILE, URI, BLOB };
/** The search definition-unique name of this constant */
private final String name;
- private String path = null;
+ private final ByteBuffer blob;
+ private String path;
private String fileReference = "";
private PathType pathType = PathType.FILE;
@@ -22,11 +24,20 @@ public class DistributableResource {
}
public DistributableResource(String name) {
- this(name, null);
+ this.name = name;
+ blob = null;
}
public DistributableResource(String name, String path) {
this.name = name;
this.path = path;
+ blob = null;
+ }
+ public DistributableResource(String name, ByteBuffer blob) {
+ Objects.requireNonNull(name, "Blob name cannot be null");
+ Objects.requireNonNull(blob, "Blob cannot be null");
+ this.name = name;
+ this.blob = blob;
+ pathType = PathType.BLOB;
}
public void setFileName(String fileName) {
@@ -44,13 +55,22 @@ public class DistributableResource {
protected void setFileReference(String fileReference) { this.fileReference = fileReference; }
/** Initiate sending of this constant to some services over file distribution */
public void sendTo(Collection<? extends AbstractService> services) {
- FileReference reference = (pathType == PathType.FILE)
- ? FileSender.sendFileToServices(path, services)
- : FileSender.sendUriToServices(path, services);
- this.fileReference = reference.value();
+ fileReference = sendToServices(services).value();
+ }
+ private FileReference sendToServices(Collection<? extends AbstractService> services) {
+ switch (pathType) {
+ case FILE:
+ return FileSender.sendFileToServices(path, services);
+ case URI:
+ return FileSender.sendUriToServices(path, services);
+ case BLOB:
+ return FileSender.sendBlobToServices(blob, services);
+ }
+ throw new IllegalArgumentException("Unknown path type " + pathType);
}
public String getName() { return name; }
+ public ByteBuffer getBlob() { return blob; }
public String getFileName() { return path; }
public Path getFilePath() { return Path.fromString(path); }
public String getUri() { return path; }
@@ -63,10 +83,8 @@ public class DistributableResource {
public String toString() {
StringBuilder b = new StringBuilder();
- b.append("resource '").append(name)
- .append(pathType == PathType.FILE ? "' from file '" : " from uri ").append(path)
- .append("' with ref '").append(fileReference)
- .append("'");
+ b.append("resource '").append(name).append(" of type '").append(pathType)
+ .append("' with ref '").append(fileReference).append("'");
return b.toString();
}
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java
index 8dea1b65079..ea0452a6c49 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java
@@ -8,6 +8,7 @@ import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.defaults.Defaults;
+import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -470,6 +471,10 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon
return getRoot().getFileDistributor().sendUriToHost(uri, getHost().getHost());
}
+ public FileReference sendBlob(ByteBuffer blob) {
+ return getRoot().getFileDistributor().sendBlobToHost(blob, getHost().getHost());
+ }
+
/** The service HTTP port for health status */
public int getHealthPort() { return -1;}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java
index 5bb57f4ff6c..d8da911e32f 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java
@@ -8,6 +8,7 @@ import com.yahoo.config.application.api.FileRegistry;
import com.yahoo.vespa.model.ConfigProxy;
import com.yahoo.vespa.model.Host;
+import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -58,6 +59,16 @@ public class FileDistributor {
return addFileReference(fileRegistry.addUri(uri), host);
}
+ /**
+ * Adds the given blob to the associated application packages' registry of file and marks the file
+ * for distribution to the given host.
+ *
+ * @return the reference to the file, created by the application package
+ */
+ public FileReference sendBlobToHost(ByteBuffer blob, Host host) {
+ return addFileReference(fileRegistry.addBlob(blob), host);
+ }
+
private FileReference addFileReference(FileReference reference, Host host) {
filesToHosts.computeIfAbsent(reference, k -> new HashSet<>()).add(host);
return reference;
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java b/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java
index 5e7ac0cabec..52edec7114b 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/utils/FileSender.java
@@ -12,6 +12,7 @@ import com.yahoo.vespa.config.ConfigPayloadBuilder;
import com.yahoo.vespa.model.AbstractService;
import java.io.Serializable;
+import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -61,6 +62,20 @@ public class FileSender implements Serializable {
return fileref;
}
+ public static FileReference sendBlobToServices(ByteBuffer blob, Collection<? extends AbstractService> services) {
+ if (services.isEmpty()) {
+ throw new IllegalStateException("No service instances. Probably a standalone cluster setting up <nodes> " +
+ "using 'count' instead of <node> tags.");
+ }
+
+ FileReference fileref = null;
+ for (AbstractService service : services) {
+ // The same reference will be returned from each call.
+ fileref = service.sendBlob(blob);
+ }
+ return fileref;
+ }
+
/**
* Sends all user configured files for a producer to all given services.
*/