diff options
author | Harald Musum <musum@yahooinc.com> | 2022-04-28 16:01:16 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-04-28 16:01:16 +0200 |
commit | db7d8655a40949f30421d9f9b217199fb388ea49 (patch) | |
tree | f451d39425cda48b14560eb46d0c8582d3d696ec /configserver | |
parent | d5a2caa23b848a18352127b502f4817aa9bfc45d (diff) |
Log with deploy logger, users will get console notifications
Diffstat (limited to 'configserver')
6 files changed, 54 insertions, 40 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 e4b1bf8ae58..82950d62dad 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 @@ -86,7 +86,6 @@ import com.yahoo.vespa.defaults.Defaults; import com.yahoo.vespa.flags.FlagSource; import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.orchestrator.Orchestrator; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -362,7 +361,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye private PrepareResult deploy(File applicationDir, PrepareParams prepareParams, DeployHandlerLogger logger) { ApplicationId applicationId = prepareParams.getApplicationId(); - long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), applicationDir); + long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), applicationDir, logger); Deployment deployment = prepare(sessionId, prepareParams, logger); if ( ! prepareParams.isDryRun()) @@ -428,7 +427,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout); SessionRepository sessionRepository = tenant.getSessionRepository(); DeployLogger logger = new SilentDeployLogger(); - Session newSession = sessionRepository.createSessionFromExisting(activeSession.get(), true, timeoutBudget); + Session newSession = sessionRepository.createSessionFromExisting(activeSession.get(), true, timeoutBudget, logger); return Optional.of(Deployment.unprepared(newSession, this, hostProvisioner, tenant, logger, timeout, clock, false /* don't validate as this is already deployed */, bootstrap)); @@ -511,7 +510,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye * Deletes an application * * @return true if the application was found and deleted, false if it was not present - * @throws RuntimeException if the delete transaction fails. This method is exception safe. + * @throws RuntimeException if deleting the application fails. This method is exception safe. */ public boolean delete(ApplicationId applicationId) { Tenant tenant = getTenant(applicationId); @@ -861,12 +860,14 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye throw new IllegalArgumentException("Session not prepared: " + sessionId); } - public long createSessionFromExisting(ApplicationId applicationId, boolean internalRedeploy, TimeoutBudget timeoutBudget) { + public long createSessionFromExisting(ApplicationId applicationId, + boolean internalRedeploy, + TimeoutBudget timeoutBudget, + DeployLogger deployLogger) { Tenant tenant = getTenant(applicationId); SessionRepository sessionRepository = tenant.getSessionRepository(); Session fromSession = getExistingSession(tenant, applicationId); - Session session = sessionRepository.createSessionFromExisting(fromSession, internalRedeploy, timeoutBudget); - return session.getSessionId(); + return sessionRepository.createSessionFromExisting(fromSession, internalRedeploy, timeoutBudget, deployLogger).getSessionId(); } public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, InputStream in, @@ -874,16 +875,16 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye File tempDir = uncheck(() -> Files.createTempDirectory("deploy")).toFile(); long sessionId; try { - sessionId = createSession(applicationId, timeoutBudget, decompressApplication(in, contentType, tempDir)); + sessionId = createSession(applicationId, timeoutBudget, decompressApplication(in, contentType, tempDir), logger); } finally { cleanupTempDirectory(tempDir, logger); } return sessionId; } - public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, File applicationDirectory) { + public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, File applicationDirectory, DeployLogger deployLogger) { SessionRepository sessionRepository = getTenant(applicationId).getSessionRepository(); - Session session = sessionRepository.createSessionFromApplicationPackage(applicationDirectory, applicationId, timeoutBudget); + Session session = sessionRepository.createSessionFromApplicationPackage(applicationDirectory, applicationId, timeoutBudget, deployLogger); return session.getSessionId(); } 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 5708cf30c89..392ea01d7f4 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 @@ -56,7 +56,7 @@ public class SessionCreateHandler extends SessionHandler { if (request.hasProperty("from")) { ApplicationId applicationId = getFromApplicationId(request); logger = DeployHandlerLogger.forApplication(applicationId, verbose); - sessionId = applicationRepository.createSessionFromExisting(applicationId, false, timeoutBudget); + sessionId = applicationRepository.createSessionFromExisting(applicationId, false, timeoutBudget, logger); } else { validateDataAndHeader(request, List.of(ApplicationApiHandler.APPLICATION_ZIP, ApplicationApiHandler.APPLICATION_X_GZIP)); logger = DeployHandlerLogger.forTenant(tenantName, verbose); @@ -70,17 +70,17 @@ public class SessionCreateHandler extends SessionHandler { static ApplicationId getFromApplicationId(HttpRequest request) { String from = request.getProperty("from"); - if (from == null || "".equals(from)) { + if (from == null || "".equals(from)) throw new BadRequestException("Parameter 'from' has illegal value '" + from + "'"); - } + return getAndValidateFromParameter(URI.create(from)); } private static ApplicationId getAndValidateFromParameter(URI from) { UriPattern.Match match = new UriPattern(fromPattern).match(from); - if (match == null || match.groupCount() < 7) { + if (match == null || match.groupCount() < 7) throw new BadRequestException("Parameter 'from' has illegal value '" + from + "'"); - } + return new ApplicationId.Builder() .tenant(match.group(2)) .applicationName(match.group(3)) @@ -88,18 +88,18 @@ public class SessionCreateHandler extends SessionHandler { } static void validateDataAndHeader(HttpRequest request, List<String> supportedContentTypes) { - if (request.getData() == null) { + if (request.getData() == null) throw new BadRequestException("Request contains no data"); - } + String header = request.getHeader(ApplicationApiHandler.contentTypeHeader); - if (header == null) { + if (header == null) throw new BadRequestException("Request contains no " + ApplicationApiHandler.contentTypeHeader + " header"); - } else { - ContentType contentType = ContentType.parse(header); - if (!supportedContentTypes.contains(contentType.getMimeType())) { - throw new BadRequestException("Request contains invalid " + ApplicationApiHandler.contentTypeHeader + " header (" + contentType.getMimeType() + "), only '[" - + String.join(", ", supportedContentTypes) + "]' are supported"); - } - } + + ContentType contentType = ContentType.parse(header); + if ( ! supportedContentTypes.contains(contentType.getMimeType())) + throw new BadRequestException("Request contains invalid " + ApplicationApiHandler.contentTypeHeader + + " header (" + contentType.getMimeType() + "), only '[" + + String.join(", ", supportedContentTypes) + "]' are supported"); } + } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java index 96a81d04c81..c31acbd8b68 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java @@ -266,10 +266,11 @@ public class SessionRepository { */ public LocalSession createSessionFromExisting(Session existingSession, boolean internalRedeploy, - TimeoutBudget timeoutBudget) { + TimeoutBudget timeoutBudget, + DeployLogger deployLogger) { ApplicationId existingApplicationId = existingSession.getApplicationId(); File existingApp = getSessionAppDir(existingSession.getSessionId()); - LocalSession session = createSessionFromApplication(existingApp, existingApplicationId, internalRedeploy, timeoutBudget); + LocalSession session = createSessionFromApplication(existingApp, existingApplicationId, internalRedeploy, timeoutBudget, deployLogger); // Note: Setters below need to be kept in sync with calls in SessionPreparer.writeStateToZooKeeper() session.setApplicationId(existingApplicationId); session.setApplicationPackageReference(existingSession.getApplicationPackageReference()); @@ -289,9 +290,12 @@ public class SessionRepository { * @param timeoutBudget Timeout for creating session and waiting for other servers. * @return a new session */ - public LocalSession createSessionFromApplicationPackage(File applicationDirectory, ApplicationId applicationId, TimeoutBudget timeoutBudget) { + public LocalSession createSessionFromApplicationPackage(File applicationDirectory, + ApplicationId applicationId, + TimeoutBudget timeoutBudget, + DeployLogger deployLogger) { applicationRepo.createApplication(applicationId); - return createSessionFromApplication(applicationDirectory, applicationId, false, timeoutBudget); + return createSessionFromApplication(applicationDirectory, applicationId, false, timeoutBudget, deployLogger); } /** @@ -300,7 +304,7 @@ public class SessionRepository { */ private void createLocalSession(File applicationFile, ApplicationId applicationId, long sessionId) { try { - ApplicationPackage applicationPackage = createApplicationPackage(applicationFile, applicationId, sessionId, false); + ApplicationPackage applicationPackage = createApplicationPackage(applicationFile, applicationId, sessionId, false, Optional.empty()); createLocalSession(sessionId, applicationPackage); } catch (Exception e) { throw new RuntimeException("Error creating session " + sessionId, e); @@ -669,7 +673,8 @@ public class SessionRepository { ApplicationId applicationId, long sessionId, Optional<Long> currentlyActiveSessionId, - boolean internalRedeploy) { + boolean internalRedeploy, + Optional<DeployLogger> deployLogger) { long deployTimestamp = System.currentTimeMillis(); String user = System.getenv("USER"); if (user == null) { @@ -683,19 +688,21 @@ public class SessionRepository { } catch (IllegalArgumentException e) { if (failDeploymentForFilesWithUnknownExtension.value()) throw e; - log.log(Level.INFO, e.getMessage()); + deployLogger.ifPresent(logger -> logger.logApplicationPackage(Level.INFO, e.getMessage())); } + return app; } private LocalSession createSessionFromApplication(File applicationDirectory, ApplicationId applicationId, boolean internalRedeploy, - TimeoutBudget timeoutBudget) { + TimeoutBudget timeoutBudget, + DeployLogger deployLogger) { long sessionId = getNextSessionId(); try { ensureSessionPathDoesNotExist(sessionId); - ApplicationPackage app = createApplicationPackage(applicationDirectory, applicationId, sessionId, internalRedeploy); + ApplicationPackage app = createApplicationPackage(applicationDirectory, applicationId, sessionId, internalRedeploy, Optional.of(deployLogger)); log.log(Level.FINE, () -> TenantRepository.logPre(tenantName) + "Creating session " + sessionId + " in ZooKeeper"); SessionZooKeeperClient sessionZKClient = createSessionZooKeeperClient(sessionId); sessionZKClient.createNewSession(clock.instant()); @@ -712,7 +719,8 @@ public class SessionRepository { private ApplicationPackage createApplicationPackage(File applicationDirectory, ApplicationId applicationId, long sessionId, - boolean internalRedeploy) throws IOException { + boolean internalRedeploy, + Optional<DeployLogger> deployLogger) throws IOException { // Synchronize to avoid threads trying to create an application package concurrently // (e.g. a maintainer and an external deployment) synchronized (monitor) { @@ -724,7 +732,8 @@ public class SessionRepository { applicationId, sessionId, activeSessionId, - internalRedeploy); + internalRedeploy, + deployLogger); applicationPackage.writeMetaData(); return applicationPackage; } 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 ce44fade2f0..26e993c3028 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 @@ -8,6 +8,7 @@ import com.yahoo.config.ConfigInstance; import com.yahoo.config.SimpletypesConfig; import com.yahoo.config.application.api.ApplicationMetaData; import com.yahoo.config.model.NullConfigModelRegistry; +import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ApplicationId; @@ -834,11 +835,11 @@ public class ApplicationRepositoryTest { } private long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, File app) { - return applicationRepository.createSession(applicationId, timeoutBudget, app); + return applicationRepository.createSession(applicationId, timeoutBudget, app, new BaseDeployLogger()); } private long createSessionFromExisting(ApplicationId applicationId, TimeoutBudget timeoutBudget) { - return applicationRepository.createSessionFromExisting(applicationId, false, timeoutBudget); + return applicationRepository.createSessionFromExisting(applicationId, false, timeoutBudget, new BaseDeployLogger()); } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java index f279d327a52..8638a29cf75 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server.http.v2; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; import com.yahoo.config.application.api.ApplicationMetaData; +import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; @@ -131,7 +132,8 @@ public class SessionActiveHandlerTest { void invoke() { long sessionId = applicationRepository.createSession(applicationId(), new TimeoutBudget(clock, Duration.ofSeconds(10)), - testApp); + testApp, + new BaseDeployLogger()); applicationRepository.prepare(sessionId, new PrepareParams.Builder().applicationId(applicationId()).build()); actResponse = handler.handle(createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, sessionId, subPath)); Tenant tenant = applicationRepository.getTenant(applicationId()); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java index cb4b0e9d5bd..edcb9a0fd4b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.config.server.http.v2; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.concurrent.UncheckedTimeoutException; +import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationLockException; import com.yahoo.config.provision.ApplicationName; @@ -329,7 +330,7 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { } private long createSession(ApplicationId applicationId) { - return applicationRepository.createSession(applicationId, timeoutBudget, app); + return applicationRepository.createSession(applicationId, timeoutBudget, app, new BaseDeployLogger()); } private static class FailingSessionPrepareHandler extends SessionPrepareHandler { |