diff options
author | Valerij Fredriksen <freva@users.noreply.github.com> | 2018-04-17 12:25:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-17 12:25:26 +0200 |
commit | 6b9f956080484c22e894ee0ccd2692c2f442a333 (patch) | |
tree | 677feacbacb4d374c2ee7b7a88e3efcced8a7b3f | |
parent | 7372bbaffe35c46640c6bf6ff81db986c2c88ad8 (diff) | |
parent | 5fb8eac120cdcefb86875afa75366248d60776bf (diff) |
Merge pull request #5601 from vespa-engine/hmusum/reorder-and-arrange-methods
Reorder and arrange methods by operations. No functional changes
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java | 269 |
1 files changed, 131 insertions, 138 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 ad52de5eede..636ac7e7070 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 @@ -123,6 +123,41 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye this.fileDistributionStatus = fileDistributionStatus; } + // ---------------- Deploying ---------------------------------------------------------------- + + public PrepareResult prepare(Tenant tenant, long sessionId, PrepareParams prepareParams, Instant now) { + validateThatLocalSessionIsNotActive(tenant, sessionId); + LocalSession session = getLocalSession(tenant, sessionId); + ApplicationId applicationId = prepareParams.getApplicationId(); + Optional<ApplicationSet> currentActiveApplicationSet = getCurrentActiveApplicationSet(tenant, applicationId); + Slime deployLog = createDeployLog(); + DeployLogger logger = new DeployHandlerLogger(deployLog.get().setArray("log"), prepareParams.isVerbose(), applicationId); + ConfigChangeActions actions = session.prepare(logger, prepareParams, currentActiveApplicationSet, tenant.getPath(), now); + logConfigChangeActions(actions, logger); + log.log(LogLevel.INFO, Tenants.logPre(applicationId) + "Session " + sessionId + " prepared successfully. "); + return new PrepareResult(sessionId, actions, deployLog); + } + + public PrepareResult prepareAndActivate(Tenant tenant, long sessionId, PrepareParams prepareParams, + boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) { + PrepareResult result = prepare(tenant, sessionId, prepareParams, now); + activate(tenant, sessionId, prepareParams.getTimeoutBudget(), ignoreLockFailure, ignoreSessionStaleFailure); + return result; + } + + 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) { + 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); + } + /** * Creates a new deployment from the active application, if available. * @@ -157,25 +192,29 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye // Keep manually deployed applications on the latest version, don't change version otherwise Version version = environment.isManuallyDeployed() ? Vtag.currentVersion : newSession.getVespaVersion(); - return Optional.of(Deployment.unprepared(newSession, - this, - hostProvisioner, - tenant, - timeout, - clock, - false, // don't validate as this is already deployed - version)); + return Optional.of(Deployment.unprepared(newSession, this, hostProvisioner,tenant, timeout, clock, + false /* don't validate as this is already deployed */, version)); + } + + public ApplicationId activate(Tenant tenant, + long sessionId, + TimeoutBudget timeoutBudget, + boolean ignoreLockFailure, + boolean ignoreSessionStaleFailure) { + LocalSession localSession = getLocalSession(tenant, sessionId); + Deployment deployment = deployFromPreparedSession(localSession, tenant, timeoutBudget.timeLeft()); + deployment.setIgnoreLockFailure(ignoreLockFailure); + deployment.setIgnoreSessionStaleFailure(ignoreSessionStaleFailure); + deployment.activate(); + return localSession.getApplicationId(); } private Deployment deployFromPreparedSession(LocalSession session, Tenant tenant, Duration timeout) { - return Deployment.prepared(session, - this, - hostProvisioner, - tenant, - timeout, - clock); + return Deployment.prepared(session, this, hostProvisioner, tenant,timeout, clock); } + // ---------------- Application operations ---------------------------------------------------------------- + /** * Removes a previously deployed application * @@ -212,21 +251,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return true; } - public HttpResponse serviceConvergenceCheck(Tenant tenant, ApplicationId applicationId, String hostname, URI uri) { - Application application = getApplication(tenant, applicationId); - return convergeChecker.serviceConvergenceCheck(application, hostname, uri); - } - - public HttpResponse serviceListToCheckForConfigConvergence(Tenant tenant, ApplicationId applicationId, URI uri) { - Application application = getApplication(tenant, applicationId); - return convergeChecker.serviceListToCheckForConfigConvergence(application, uri); - } - - public HttpResponse clusterControllerStatusPage( - Tenant tenant, - ApplicationId applicationId, - String hostName, - String pathSuffix) { + public HttpResponse clusterControllerStatusPage(Tenant tenant, ApplicationId applicationId, String hostName, String pathSuffix) { Application application = getApplication(tenant, applicationId); // WARNING: pathSuffix may be given by the external user. Make sure no security issues arise... @@ -242,37 +267,89 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return getApplication(tenant, applicationId).getApplicationGeneration(); } + public void restart(ApplicationId applicationId, HostFilter hostFilter) { + hostProvisioner.ifPresent(provisioner -> provisioner.restart(applicationId, hostFilter)); + } + + public HttpResponse filedistributionStatus(Tenant tenant, ApplicationId applicationId, Duration timeout) { + Application application = getApplication(tenant, applicationId); + return fileDistributionStatus.status(application, timeout); + } + + public ApplicationFile getApplicationFileFromSession(TenantName tenantName, long sessionId, String path, LocalSession.Mode mode) { + Tenant tenant = tenants.getTenant(tenantName); + return getLocalSession(tenant, sessionId).getApplicationFile(Path.fromString(path), mode); + } + private Application getApplication(Tenant tenant, ApplicationId applicationId) { long sessionId = getSessionIdForApplication(tenant, applicationId); RemoteSession session = tenant.getRemoteSessionRepo().getSession(sessionId, 0); return session.ensureApplicationLoaded().getForVersionOrLatest(Optional.empty(), clock.instant()); } + // ---------------- Convergence ---------------------------------------------------------------- + + public HttpResponse serviceConvergenceCheck(Tenant tenant, ApplicationId applicationId, String hostname, URI uri) { + Application application = getApplication(tenant, applicationId); + return convergeChecker.serviceConvergenceCheck(application, hostname, uri); + } + + public HttpResponse serviceListToCheckForConfigConvergence(Tenant tenant, ApplicationId applicationId, URI uri) { + Application application = getApplication(tenant, applicationId); + return convergeChecker.serviceListToCheckForConfigConvergence(application, uri); + } + + // ---------------- Session operations ---------------------------------------------------------------- + + /** + * Gets the active Session for the given application id. + * + * @return the active session, or null if there is no active session for the given application id. + */ + public LocalSession getActiveSession(ApplicationId applicationId) { + return getActiveSession(tenants.getTenant(applicationId.tenant()), applicationId); + } + public long getSessionIdForApplication(Tenant tenant, ApplicationId applicationId) { return tenant.getApplicationRepo().getSessionIdForApplication(applicationId); } - private LocalSession getLocalSession(Tenant tenant, long sessionId) { - LocalSession session = tenant.getLocalSessionRepo().getSession(sessionId); - if (session == null) throw new NotFoundException("Session " + sessionId + " was not found"); - - return session; + public void validateThatRemoteSessionIsNotActive(Tenant tenant, long sessionId) { + RemoteSession session = getRemoteSession(tenant, sessionId); + if (Session.Status.ACTIVATE.equals(session.getStatus())) { + throw new IllegalStateException("Session is active: " + sessionId); + } } - private RemoteSession getRemoteSession(Tenant tenant, long sessionId) { - RemoteSession session = tenant.getRemoteSessionRepo().getSession(sessionId); - if (session == null) throw new NotFoundException("Session " + sessionId + " was not found"); + public void validateThatRemoteSessionIsPrepared(Tenant tenant, long sessionId) { + RemoteSession session = getRemoteSession(tenant, sessionId); + if (!Session.Status.PREPARE.equals(session.getStatus())) + throw new IllegalStateException("Session not prepared: " + sessionId); + } - return session; + public long createSessionFromExisting(Tenant tenant, DeployLogger logger, + TimeoutBudget timeoutBudget, ApplicationId applicationId) { + LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo(); + SessionFactory sessionFactory = tenant.getSessionFactory(); + LocalSession fromSession = getExistingSession(tenant, applicationId); + LocalSession session = sessionFactory.createSessionFromExisting(fromSession, logger, timeoutBudget); + localSessionRepo.addSession(session); + return session.getSessionId(); } - public void restart(ApplicationId applicationId, HostFilter hostFilter) { - hostProvisioner.ifPresent(provisioner -> provisioner.restart(applicationId, hostFilter)); + public long createSession(Tenant tenant, TimeoutBudget timeoutBudget, InputStream in, String contentType, String applicationName) { + File tempDir = Files.createTempDir(); + long sessionId = createSession(tenant, timeoutBudget, decompressApplication(in, contentType, tempDir), applicationName); + cleanupApplicationDirectory(tempDir, logger); + return sessionId; } - public HttpResponse filedistributionStatus(Tenant tenant, ApplicationId applicationId, Duration timeout) { - Application application = getApplication(tenant, applicationId); - return fileDistributionStatus.status(application, timeout); + public long createSession(Tenant tenant, TimeoutBudget timeoutBudget, File applicationDirectory, String applicationName) { + LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo(); + SessionFactory sessionFactory = tenant.getSessionFactory(); + LocalSession session = sessionFactory.createSession(applicationDirectory, applicationName, timeoutBudget); + localSessionRepo.addSession(session); + return session.getSessionId(); } public Tenant verifyTenantAndApplication(ApplicationId applicationId) { @@ -288,41 +365,29 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return tenant; } - public ApplicationId activate(Tenant tenant, - long sessionId, - TimeoutBudget timeoutBudget, - boolean ignoreLockFailure, - boolean ignoreSessionStaleFailure) { - LocalSession localSession = getLocalSession(tenant, sessionId); - Deployment deployment = deployFromPreparedSession(localSession, tenant, timeoutBudget.timeLeft()); - deployment.setIgnoreLockFailure(ignoreLockFailure); - deployment.setIgnoreSessionStaleFailure(ignoreSessionStaleFailure); - deployment.activate(); - return localSession.getApplicationId(); - } - public ApplicationMetaData getMetadataFromSession(Tenant tenant, long sessionId) { return getLocalSession(tenant, sessionId).getMetaData(); } - public void validateThatLocalSessionIsNotActive(Tenant tenant, long sessionId) { + private void validateThatLocalSessionIsNotActive(Tenant tenant, long sessionId) { LocalSession session = getLocalSession(tenant, sessionId); if (Session.Status.ACTIVATE.equals(session.getStatus())) { throw new IllegalStateException("Session is active: " + sessionId); } } - public void validateThatRemoteSessionIsNotActive(Tenant tenant, long sessionId) { - RemoteSession session = getRemoteSession(tenant, sessionId); - if (Session.Status.ACTIVATE.equals(session.getStatus())) { - throw new IllegalStateException("Session is active: " + sessionId); - } + private LocalSession getLocalSession(Tenant tenant, long sessionId) { + LocalSession session = tenant.getLocalSessionRepo().getSession(sessionId); + if (session == null) throw new NotFoundException("Session " + sessionId + " was not found"); + + return session; } - public void validateThatRemoteSessionIsPrepared(Tenant tenant, long sessionId) { - RemoteSession session = getRemoteSession(tenant, sessionId); - if (!Session.Status.PREPARE.equals(session.getStatus())) - throw new IllegalStateException("Session not prepared: " + sessionId); + private RemoteSession getRemoteSession(Tenant tenant, long sessionId) { + RemoteSession session = tenant.getRemoteSessionRepo().getSession(sessionId); + if (session == null) throw new NotFoundException("Session " + sessionId + " was not found"); + + return session; } private Optional<ApplicationSet> getCurrentActiveApplicationSet(Tenant tenant, ApplicationId appId) { @@ -340,39 +405,6 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return currentActiveApplicationSet; } - public PrepareResult prepare(Tenant tenant, long sessionId, PrepareParams prepareParams, Instant now) { - validateThatLocalSessionIsNotActive(tenant, sessionId); - LocalSession session = getLocalSession(tenant, sessionId); - ApplicationId applicationId = prepareParams.getApplicationId(); - Optional<ApplicationSet> currentActiveApplicationSet = getCurrentActiveApplicationSet(tenant, applicationId); - Slime deployLog = createDeployLog(); - DeployLogger logger = new DeployHandlerLogger(deployLog.get().setArray("log"), prepareParams.isVerbose(), applicationId); - ConfigChangeActions actions = session.prepare(logger, prepareParams, currentActiveApplicationSet, tenant.getPath(), now); - logConfigChangeActions(actions, logger); - log.log(LogLevel.INFO, Tenants.logPre(applicationId) + "Session " + sessionId + " prepared successfully. "); - return new PrepareResult(sessionId, actions, deployLog); - } - - public PrepareResult prepareAndActivate(Tenant tenant, long sessionId, PrepareParams prepareParams, - boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) { - PrepareResult result = prepare(tenant, sessionId, prepareParams, now); - activate(tenant, sessionId, prepareParams.getTimeoutBudget(), ignoreLockFailure, ignoreSessionStaleFailure); - return result; - } - - 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) { - 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)) { @@ -395,31 +427,6 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return applicationRepo.listApplications(); } - public long createSessionFromExisting(Tenant tenant, DeployLogger logger, - TimeoutBudget timeoutBudget, ApplicationId applicationId) { - LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo(); - SessionFactory sessionFactory = tenant.getSessionFactory(); - LocalSession fromSession = getExistingSession(tenant, applicationId); - LocalSession session = sessionFactory.createSessionFromExisting(fromSession, logger, timeoutBudget); - localSessionRepo.addSession(session); - return session.getSessionId(); - } - - public long createSession(Tenant tenant, TimeoutBudget timeoutBudget, InputStream in, String contentType, String applicationName) { - File tempDir = Files.createTempDir(); - long sessionId = createSession(tenant, timeoutBudget, decompressApplication(in, contentType, tempDir), applicationName); - cleanupApplicationDirectory(tempDir, logger); - return sessionId; - } - - public long createSession(Tenant tenant, TimeoutBudget timeoutBudget, File applicationDirectory, String applicationName) { - LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo(); - SessionFactory sessionFactory = tenant.getSessionFactory(); - LocalSession session = sessionFactory.createSession(applicationDirectory, applicationName, timeoutBudget); - localSessionRepo.addSession(session); - return session.getSessionId(); - } - private static void cleanupApplicationDirectory(File tempDir, DeployLogger logger) { logger.log(LogLevel.DEBUG, "Deleting tmp dir '" + tempDir + "'"); if (!IOUtils.recursiveDeleteDir(tempDir)) { @@ -447,25 +454,11 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye executor.awaitTermination(365, TimeUnit.DAYS); // Timeout should never happen } - public ApplicationFile getApplicationFileFromSession(TenantName tenantName, long sessionId, String path, LocalSession.Mode mode) { - Tenant tenant = tenants.getTenant(tenantName); - return getLocalSession(tenant, sessionId).getApplicationFile(Path.fromString(path), mode); - } - private LocalSession getExistingSession(Tenant tenant, ApplicationId applicationId) { TenantApplications applicationRepo = tenant.getApplicationRepo(); return getLocalSession(tenant, applicationRepo.getSessionIdForApplication(applicationId)); } - /** - * Gets the active Session for the given application id. - * - * @return the active session, or null if there is no active session for the given application id. - */ - public LocalSession getActiveSession(ApplicationId applicationId) { - return getActiveSession(tenants.getTenant(applicationId.tenant()), applicationId); - } - private LocalSession getActiveSession(Tenant tenant, ApplicationId applicationId) { TenantApplications applicationRepo = tenant.getApplicationRepo(); if (applicationRepo.listApplications().contains(applicationId)) { |