summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@verizonmedia.com>2021-09-09 18:56:34 +0200
committerValerij Fredriksen <valerijf@verizonmedia.com>2021-09-09 21:41:11 +0200
commit2acd3ea90f5deeff9714ec556fba610f6b0e130c (patch)
tree623cbdbb4a5bc7de406467a078886104fea1c1a1
parent381fa00f92922e011442a1ac8510986d4a5f0f64 (diff)
Use byte[] instead
-rw-r--r--container-core/src/main/java/com/yahoo/restapi/ByteArrayResponse.java26
-rw-r--r--container-core/src/main/java/com/yahoo/restapi/StringResponse.java18
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/ApplicationStore.java8
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiff.java10
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java4
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java6
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiffTest.java12
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationStoreMock.java12
8 files changed, 54 insertions, 42 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/ByteArrayResponse.java b/container-core/src/main/java/com/yahoo/restapi/ByteArrayResponse.java
new file mode 100644
index 00000000000..1299a2c6eb4
--- /dev/null
+++ b/container-core/src/main/java/com/yahoo/restapi/ByteArrayResponse.java
@@ -0,0 +1,26 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.restapi;
+
+import com.yahoo.container.jdisc.HttpResponse;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * @author freva
+ */
+public class ByteArrayResponse extends HttpResponse {
+
+ private final byte[] data;
+
+ public ByteArrayResponse(byte[] data) {
+ super(200);
+ this.data = data;
+ }
+
+ @Override
+ public void render(OutputStream stream) throws IOException {
+ stream.write(data);
+ }
+
+}
diff --git a/container-core/src/main/java/com/yahoo/restapi/StringResponse.java b/container-core/src/main/java/com/yahoo/restapi/StringResponse.java
index 55ea22880de..003b58de827 100644
--- a/container-core/src/main/java/com/yahoo/restapi/StringResponse.java
+++ b/container-core/src/main/java/com/yahoo/restapi/StringResponse.java
@@ -1,27 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.restapi;
-import com.yahoo.container.jdisc.HttpResponse;
-
-import java.io.IOException;
-import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/**
* @author bratseth
*/
-public class StringResponse extends HttpResponse {
-
- private final String message;
-
+public class StringResponse extends ByteArrayResponse {
public StringResponse(String message) {
- super(200);
- this.message = message;
+ super(message.getBytes(StandardCharsets.UTF_8));
}
-
- @Override
- public void render(OutputStream stream) throws IOException {
- stream.write(message.getBytes(StandardCharsets.UTF_8));
- }
-
}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/ApplicationStore.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/ApplicationStore.java
index 4295fff9ae3..71f1821ff9a 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/ApplicationStore.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/ApplicationStore.java
@@ -22,7 +22,7 @@ public interface ApplicationStore {
byte[] get(DeploymentId deploymentId, ApplicationVersion applicationVersion);
/** Returns the application package diff, compared to the previous build, for the given tenant, application and build number */
- Optional<String> getDiff(TenantName tenantName, ApplicationName applicationName, long buildNumber);
+ Optional<byte[]> getDiff(TenantName tenantName, ApplicationName applicationName, long buildNumber);
/** Removes diffs for packages before the given build number */
void pruneDiffs(TenantName tenantName, ApplicationName applicationName, long beforeBuildNumber);
@@ -31,7 +31,7 @@ public interface ApplicationStore {
Optional<byte[]> find(TenantName tenant, ApplicationName application, long buildNumber);
/** Stores the given tenant application package of the given version and diff since previous version. */
- void put(TenantName tenant, ApplicationName application, ApplicationVersion applicationVersion, byte[] applicationPackage, String diff);
+ void put(TenantName tenant, ApplicationName application, ApplicationVersion applicationVersion, byte[] applicationPackage, byte[] diff);
/** Removes applications older than the given version, for the given application, and returns whether something was removed. */
boolean prune(TenantName tenant, ApplicationName application, ApplicationVersion olderThanVersion);
@@ -52,13 +52,13 @@ public interface ApplicationStore {
void removeAllTesters(TenantName tenant, ApplicationName application);
/** Returns the application package diff, compared to the previous build, for the given deployment and build number */
- Optional<String> getDevDiff(DeploymentId deploymentId, long buildNumber);
+ Optional<byte[]> getDevDiff(DeploymentId deploymentId, long buildNumber);
/** Removes diffs for dev packages before the given build number */
void pruneDevDiffs(DeploymentId deploymentId, long beforeBuildNumber);
/** Stores the given application package as the development package for the given deployment and version and diff since previous version. */
- void putDev(DeploymentId deploymentId, ApplicationVersion version, byte[] applicationPackage, String diff);
+ void putDev(DeploymentId deploymentId, ApplicationVersion version, byte[] applicationPackage, byte[] diff);
/** Stores the given application meta data with the current time as part of the path. */
void putMeta(TenantName tenant, ApplicationName application, Instant now, byte[] metaZip);
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiff.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiff.java
index 6b106085b70..aa55326f7b7 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiff.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiff.java
@@ -22,17 +22,17 @@ import static com.yahoo.vespa.hosted.controller.application.pkg.ZipStreamReader.
*/
public class ApplicationPackageDiff {
- public static String diffAgainstEmpty(ApplicationPackage right) {
+ public static byte[] diffAgainstEmpty(ApplicationPackage right) {
byte[] emptyZip = new byte[]{80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
return diff(new ApplicationPackage(emptyZip), right);
}
- public static String diff(ApplicationPackage left, ApplicationPackage right) {
+ public static byte[] diff(ApplicationPackage left, ApplicationPackage right) {
return diff(left, right, 10 << 20, 1 << 20, 10 << 20);
}
- static String diff(ApplicationPackage left, ApplicationPackage right, int maxFileSizeToDiff, int maxDiffSizePerFile, int maxTotalDiffSize) {
- if (Arrays.equals(left.zippedContent(), right.zippedContent())) return "No diff\n";
+ static byte[] diff(ApplicationPackage left, ApplicationPackage right, int maxFileSizeToDiff, int maxDiffSizePerFile, int maxTotalDiffSize) {
+ if (Arrays.equals(left.zippedContent(), right.zippedContent())) return "No diff\n".getBytes(StandardCharsets.UTF_8);
Map<String, ZipEntryWithContent> leftContents = readContents(left, maxFileSizeToDiff);
Map<String, ZipEntryWithContent> rightContents = readContents(right, maxFileSizeToDiff);
@@ -51,7 +51,7 @@ public class ApplicationPackageDiff {
.ifPresent(diff -> sb.append("--- ").append(file).append('\n').append(diff).append('\n'));
}
- return sb.length() == 0 ? "No diff\n" : sb.toString();
+ return (sb.length() == 0 ? "No diff\n" : sb.toString()).getBytes(StandardCharsets.UTF_8);
}
private static Optional<String> diff(Optional<ZipEntryWithContent> left, Optional<ZipEntryWithContent> right, int maxDiffSizePerFile) {
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java
index 007f79ed994..122db567a61 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java
@@ -440,7 +440,7 @@ public class JobController {
sourceUrl,
revision.map(SourceRevision::commit),
false));
- String diff = application.get().latestVersion()
+ byte[] diff = application.get().latestVersion()
.map(ApplicationVersion::buildNumber)
.flatMap(build -> build.isPresent() ? Optional.of(build.getAsLong()) : Optional.empty())
.flatMap(prevBuild -> controller.applications().applicationStore().find(id.tenant(), id.application(), prevBuild))
@@ -509,7 +509,7 @@ public class JobController {
ApplicationVersion version = ApplicationVersion.from(Optional.empty(), build, Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(), true);
- String diff = lastRun.map(run -> run.versions().targetApplication())
+ byte[] diff = lastRun.map(run -> run.versions().targetApplication())
.map(prevVersion -> ApplicationPackageDiff.diff(new ApplicationPackage(controller.applications().applicationStore().get(deploymentId, prevVersion)), applicationPackage))
.orElseGet(() -> ApplicationPackageDiff.diffAgainstEmpty(applicationPackage));
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
index 73622e4ca4b..22bd3c9d062 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
@@ -25,12 +25,12 @@ import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.LoggingRequestHandler;
import com.yahoo.io.IOUtils;
+import com.yahoo.restapi.ByteArrayResponse;
import com.yahoo.restapi.ErrorResponse;
import com.yahoo.restapi.MessageResponse;
import com.yahoo.restapi.Path;
import com.yahoo.restapi.ResourceResponse;
import com.yahoo.restapi.SlimeJsonResponse;
-import com.yahoo.restapi.StringResponse;
import com.yahoo.security.KeyUtils;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.Inspector;
@@ -603,7 +603,7 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
private HttpResponse devApplicationPackageDiff(RunId runId) {
DeploymentId deploymentId = new DeploymentId(runId.application(), runId.job().type().zone(controller.system()));
return controller.applications().applicationStore().getDevDiff(deploymentId, runId.number())
- .map(StringResponse::new)
+ .map(ByteArrayResponse::new)
.orElseThrow(() -> new NotExistsException("No application package diff found for " + runId));
}
@@ -641,7 +641,7 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
private HttpResponse applicationPackageDiff(String tenant, String application, String number) {
TenantAndApplicationId tenantAndApplication = TenantAndApplicationId.from(tenant, application);
return controller.applications().applicationStore().getDiff(tenantAndApplication.tenant(), tenantAndApplication.application(), Long.parseLong(number))
- .map(StringResponse::new)
+ .map(ByteArrayResponse::new)
.orElseThrow(() -> new NotExistsException("No application package diff found for '" + tenantAndApplication + "' with build number " + number));
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiffTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiffTest.java
index 101ca42761d..b2aba721a6f 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiffTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/ApplicationPackageDiffTest.java
@@ -26,7 +26,7 @@ public class ApplicationPackageDiffTest {
@Test
public void no_diff() {
- assertEquals("No diff\n", diff(app1, app1));
+ assertEquals("No diff\n", new String(diff(app1, app1)));
}
@Test
@@ -42,7 +42,7 @@ public class ApplicationPackageDiffTest {
"@@ -1,0 +1,2 @@\n" +
"+ contents of the\n" +
"+ first file\n" +
- "\n", diffAgainstEmpty(app1));
+ "\n", new String(diffAgainstEmpty(app1)));
}
@Test
@@ -63,7 +63,7 @@ public class ApplicationPackageDiffTest {
"- contents of the\n" +
" first file\n" +
"+ after some changes\n" +
- "\n", diff(app1, app2));
+ "\n", new String(diff(app1, app2)));
}
@Test
@@ -78,7 +78,7 @@ public class ApplicationPackageDiffTest {
"\n" +
"--- file1\n" +
"Diff skipped: File too large (26B -> 53B)\n" +
- "\n", diff(app1, app2, 12, 1000, 1000));
+ "\n", new String(diff(app1, app2, 12, 1000, 1000)));
}
@Test
@@ -93,7 +93,7 @@ public class ApplicationPackageDiffTest {
"\n" +
"--- file1\n" +
"Diff skipped: Diff too large (96B)\n" +
- "\n", diff(app1, app2, 1000, 50, 1000));
+ "\n", new String(diff(app1, app2, 1000, 50, 1000)));
}
@Test
@@ -107,7 +107,7 @@ public class ApplicationPackageDiffTest {
"\n" +
"--- file1\n" +
"Diff skipped: Total diff size >20B)\n" +
- "\n", diff(app1, app2, 1000, 1000, 20));
+ "\n", new String(diff(app1, app2, 1000, 1000, 20)));
}
private static ApplicationPackage applicationPackage(Map<String, String> files) {
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationStoreMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationStoreMock.java
index c2dd04144ab..77ab9e7d17c 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationStoreMock.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationStoreMock.java
@@ -31,8 +31,8 @@ public class ApplicationStoreMock implements ApplicationStore {
private final Map<ApplicationId, Map<ApplicationVersion, byte[]>> store = new ConcurrentHashMap<>();
private final Map<DeploymentId, byte[]> devStore = new ConcurrentHashMap<>();
- private final Map<ApplicationId, Map<Long, String>> diffs = new ConcurrentHashMap<>();
- private final Map<DeploymentId, Map<Long, String>> devDiffs = new ConcurrentHashMap<>();
+ private final Map<ApplicationId, Map<Long, byte[]>> diffs = new ConcurrentHashMap<>();
+ private final Map<DeploymentId, Map<Long, byte[]>> devDiffs = new ConcurrentHashMap<>();
private final Map<ApplicationId, NavigableMap<Instant, byte[]>> meta = new ConcurrentHashMap<>();
private final Map<DeploymentId, NavigableMap<Instant, byte[]>> metaManual = new ConcurrentHashMap<>();
@@ -58,7 +58,7 @@ public class ApplicationStoreMock implements ApplicationStore {
}
@Override
- public Optional<String> getDiff(TenantName tenantName, ApplicationName applicationName, long buildNumber) {
+ public Optional<byte[]> getDiff(TenantName tenantName, ApplicationName applicationName, long buildNumber) {
return Optional.ofNullable(diffs.get(appId(tenantName, applicationName))).map(map -> map.get(buildNumber));
}
@@ -79,7 +79,7 @@ public class ApplicationStoreMock implements ApplicationStore {
}
@Override
- public void put(TenantName tenant, ApplicationName application, ApplicationVersion applicationVersion, byte[] applicationPackage, String diff) {
+ public void put(TenantName tenant, ApplicationName application, ApplicationVersion applicationVersion, byte[] applicationPackage, byte[] diff) {
store.computeIfAbsent(appId(tenant, application), __ -> new ConcurrentHashMap<>()).put(applicationVersion, applicationPackage);
applicationVersion.buildNumber().ifPresent(buildNumber ->
diffs.computeIfAbsent(appId(tenant, application), __ -> new ConcurrentHashMap<>()).put(buildNumber, diff));
@@ -119,7 +119,7 @@ public class ApplicationStoreMock implements ApplicationStore {
}
@Override
- public Optional<String> getDevDiff(DeploymentId deploymentId, long buildNumber) {
+ public Optional<byte[]> getDevDiff(DeploymentId deploymentId, long buildNumber) {
return Optional.ofNullable(devDiffs.get(deploymentId)).map(map -> map.get(buildNumber));
}
@@ -132,7 +132,7 @@ public class ApplicationStoreMock implements ApplicationStore {
}
@Override
- public void putDev(DeploymentId deploymentId, ApplicationVersion applicationVersion, byte[] applicationPackage, String diff) {
+ public void putDev(DeploymentId deploymentId, ApplicationVersion applicationVersion, byte[] applicationPackage, byte[] diff) {
devStore.put(deploymentId, applicationPackage);
applicationVersion.buildNumber().ifPresent(buildNumber ->
devDiffs.computeIfAbsent(deploymentId, __ -> new ConcurrentHashMap<>()).put(buildNumber, diff));