summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2018-04-12 12:24:41 +0200
committerHarald Musum <musum@oath.com>2018-04-12 12:24:41 +0200
commit19ae6a1b5ceaee187a144a28688b2ffd5bdf1f4c (patch)
tree09acd4f3b2e74dbc70f555a52cce8175f331e3cf /configserver
parenteac5237fb03725d42556f1a54558411a5ee178ab (diff)
Add simpler deploy method
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java21
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java12
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java1
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java5
4 files changed, 28 insertions, 11 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
index 6aba6d12751..ad52de5eede 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
@@ -360,21 +360,36 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
return result;
}
- public PrepareResult deploy(Tenant tenant, InputStream in, String contentType, PrepareParams prepareParams,
+ public PrepareResult deploy(CompressedApplicationInputStream in, PrepareParams prepareParams) {
+ Tenant tenant = tenants.getTenant(prepareParams.getApplicationId().tenant());
+ return deploy(tenant, in, prepareParams, false, false, clock.instant());
+ }
+
+ public PrepareResult deploy(Tenant tenant, CompressedApplicationInputStream in, PrepareParams prepareParams,
boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) {
- long sessionId = createSession(tenant, prepareParams.getTimeoutBudget(), in, contentType, prepareParams.getApplicationName());
+ File tempDir = Files.createTempDir();
+ long sessionId = createSession(tenant, prepareParams.getTimeoutBudget(), decompressApplication(in, tempDir), prepareParams.getApplicationName());
+ cleanupApplicationDirectory(tempDir, logger);
return prepareAndActivate(tenant, sessionId, prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now);
}
private File decompressApplication(InputStream in, String contentType, File tempDir) {
try (CompressedApplicationInputStream application =
CompressedApplicationInputStream.createFromCompressedStream(in, contentType)) {
- return application.decompress(tempDir);
+ return decompressApplication(application, tempDir);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to decompress data in body", e);
}
}
+ private File decompressApplication(CompressedApplicationInputStream in, File tempDir) {
+ try {
+ return in.decompress(tempDir);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Unable to decompress stream", e);
+ }
+ }
+
private List<ApplicationId> listApplicationIds(Tenant tenant) {
TenantApplications applicationRepo = tenant.getApplicationRepo();
return applicationRepo.listApplications();
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java
index c5b2464f88f..4c1d0744848 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java
@@ -3,13 +3,12 @@ package com.yahoo.vespa.config.server.http.v2;
import com.google.inject.Inject;
import com.yahoo.cloud.config.ConfigserverConfig;
-import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
-import com.yahoo.slime.Slime;
import com.yahoo.vespa.config.server.ApplicationRepository;
+import com.yahoo.vespa.config.server.http.CompressedApplicationInputStream;
import com.yahoo.vespa.config.server.http.SessionHandler;
import com.yahoo.vespa.config.server.http.Utils;
import com.yahoo.vespa.config.server.session.PrepareParams;
@@ -66,15 +65,14 @@ public class ApplicationApiHandler extends SessionHandler {
Tenant tenant = getExistingTenant(request);
TenantName tenantName = tenant.getName();
PrepareParams prepareParams = PrepareParams.fromHttpRequest(request, tenantName, zookeeperBarrierTimeout);
- Slime deployLog = createDeployLog();
- DeployLogger logger = SessionCreateHandler.createLogger(request, deployLog, tenantName);
SessionCreateHandler.validateDataAndHeader(request);
PrepareResult result =
- applicationRepository.deploy(tenant, request.getData(),
- request.getHeader(contentTypeHeader),
+ applicationRepository.deploy(tenant,
+ CompressedApplicationInputStream.createFromCompressedStream(request.getData(), request.getHeader(contentTypeHeader)),
prepareParams,
- shouldIgnoreLockFailure(request), shouldIgnoreSessionStaleFailure(request),
+ shouldIgnoreLockFailure(request),
+ shouldIgnoreSessionStaleFailure(request),
Instant.now());
return new SessionPrepareAndActivateResponse(result, tenantName, request, prepareParams.getApplicationId(), zone);
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java
index eb81ce15b3a..316160df6ac 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java
@@ -13,6 +13,7 @@ import com.yahoo.log.LogLevel;
import com.yahoo.slime.Slime;
import com.yahoo.vespa.config.server.ApplicationRepository;
import com.yahoo.vespa.config.server.deploy.DeployHandlerLogger;
+import com.yahoo.vespa.config.server.http.CompressedApplicationInputStream;
import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.config.server.TimeoutBudget;
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index c5e50e97adb..2d06a8876ae 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server;
import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.provision.Provisioner;
import com.yahoo.config.provision.TenantName;
+import com.yahoo.vespa.config.server.http.CompressedApplicationInputStream;
import com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
import com.yahoo.vespa.config.server.http.v2.ApplicationApiHandler;
@@ -85,7 +86,9 @@ public class ApplicationRepositoryTest {
private PrepareResult createAndPrepareAndActivateApp() throws IOException {
File file = CompressedApplicationInputStreamTest.createTarFile();
- return applicationRepository.deploy(tenant, new FileInputStream(file), ApplicationApiHandler.APPLICATION_X_GZIP,
+ return applicationRepository.deploy(tenant,
+ CompressedApplicationInputStream.createFromCompressedStream(
+ new FileInputStream(file), ApplicationApiHandler.APPLICATION_X_GZIP),
prepareParams(), false, false, Instant.now());
}