diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-05-26 13:20:32 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-05-26 13:20:32 +0200 |
commit | c7a626140e5af1df91d3363e073519d673bb093a (patch) | |
tree | 725ada9735464e3f77667108ff61079c8410b0bb /configserver | |
parent | 3efc3e5da971281d17db5cdc264b4b9ea69a1e91 (diff) |
Set status failed when we do not get a deployment when bootstrapping applications
If we for some reason don't get a Deployment the deployment of the
app should be retried
Diffstat (limited to 'configserver')
6 files changed, 30 insertions, 24 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 d1cf011d33a..937f9c05033 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 @@ -408,7 +408,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye Tenant tenant = tenantRepository.getTenant(application.tenant()); if (tenant == null) return Optional.empty(); - Session activeSession = getActiveLocalSession(tenant, application); + Session activeSession = getActiveLocalSession(application); if (activeSession == null) return Optional.empty(); TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout); SessionRepository sessionRepository = tenant.getSessionRepository(); @@ -1063,6 +1063,12 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return null; } + public Session getActiveLocalSession(ApplicationId applicationId) { + Tenant tenant = tenantRepository.getTenant(applicationId.tenant()); + if (tenant == null) throw new IllegalArgumentException("Unknown tenant " + applicationId.tenant()); + return getActiveLocalSession(tenant, applicationId); + } + public double getQuotaUsageRate(ApplicationId applicationId) { var application = getApplication(applicationId); return application.getModel().provisioned().all().values().stream() diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java index 772c2bf5125..8c674fd1856 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -226,13 +227,22 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable ExecutorService executor = Executors.newFixedThreadPool(configserverConfig.numRedeploymentThreads(), new DaemonThreadFactory("redeploy-apps-")); // Keep track of deployment status per application - Map<ApplicationId, Future<?>> deployments = new HashMap<>(); + Map<ApplicationId, Future<DeploymentStatus>> deployments = new HashMap<>(); log.log(Level.INFO, () -> "Redeploying " + applicationIds.size() + " apps: " + applicationIds); applicationIds.forEach(appId -> deployments.put(appId, executor.submit(() -> { log.log(Level.INFO, () -> "Starting redeployment of " + appId); - applicationRepository.deployFromLocalActive(appId, true /* bootstrap */) - .ifPresent(Deployment::activate); - log.log(Level.INFO, () -> appId + " redeployed"); + Optional<Deployment> deployment = applicationRepository.deployFromLocalActive(appId, true /* bootstrap */); + if (deployment.isPresent()) { + deployment.get().activate(); + log.log(Level.INFO, () -> appId + " redeployed"); + return DeploymentStatus.done; + } else { + // For some reason a deployment is not present, which should not be possible when bootstrapping + log.log(Level.INFO, () -> "Deployment failed for " + appId + + ", unable to get a deployment, active local session is " + + applicationRepository.getActiveLocalSession(appId)); + return DeploymentStatus.failed; + } }))); List<ApplicationId> failedDeployments = checkDeployments(deployments); @@ -245,7 +255,7 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable private enum DeploymentStatus { inProgress, done, failed}; - private List<ApplicationId> checkDeployments(Map<ApplicationId, Future<?>> deployments) { + private List<ApplicationId> checkDeployments(Map<ApplicationId, Future<DeploymentStatus>> deployments) { int applicationCount = deployments.size(); Set<ApplicationId> failedDeployments = new LinkedHashSet<>(); Set<ApplicationId> finishedDeployments = new LinkedHashSet<>(); @@ -279,10 +289,9 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable return new ArrayList<>(failedDeployments); } - private DeploymentStatus getDeploymentStatus(ApplicationId applicationId, Future<?> future) { + private DeploymentStatus getDeploymentStatus(ApplicationId applicationId, Future<DeploymentStatus> future) { try { - future.get(1, TimeUnit.MILLISECONDS); - return DeploymentStatus.done; + return future.get(1, TimeUnit.MILLISECONDS); } catch (ExecutionException | InterruptedException e) { if (e.getCause() instanceof TransientException) { log.log(Level.INFO, "Redeploying " + applicationId + 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 eff663588a9..736940366e8 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 @@ -154,8 +154,7 @@ public class ApplicationRepositoryTest { assertTrue(result.configChangeActions().getReindexActions().isEmpty()); assertTrue(result.configChangeActions().getRestartActions().isEmpty()); - Tenant tenant = applicationRepository.getTenant(applicationId()); - Session session = applicationRepository.getActiveLocalSession(tenant, applicationId()); + Session session = applicationRepository.getActiveLocalSession(applicationId()); session.getAllocatedHosts(); } @@ -227,8 +226,7 @@ public class ApplicationRepositoryTest { long secondSessionId = result2.sessionId(); assertNotEquals(firstSessionId, secondSessionId); - Tenant tenant = applicationRepository.getTenant(applicationId()); - Session session = applicationRepository.getActiveLocalSession(tenant, applicationId()); + Session session = applicationRepository.getActiveLocalSession(applicationId()); assertEquals(firstSessionId, session.getMetaData().getPreviousActiveGeneration()); } @@ -531,8 +529,7 @@ public class ApplicationRepositoryTest { public void require_that_provision_info_can_be_read() { prepareAndActivate(testAppJdiscOnly); - Tenant tenant = applicationRepository.getTenant(applicationId()); - Session session = applicationRepository.getActiveLocalSession(tenant, applicationId()); + Session session = applicationRepository.getActiveLocalSession(applicationId()); List<NetworkPorts.Allocation> list = new ArrayList<>(); list.add(new NetworkPorts.Allocation(8080, "container", "container/container.0", "http")); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java index 1142c756f94..561c726bad0 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java @@ -14,7 +14,6 @@ import com.yahoo.vespa.config.server.application.OrchestratorMock; import com.yahoo.vespa.config.server.http.ContentHandlerTestBase; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.session.Session; -import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; @@ -105,8 +104,7 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase { @Test public void require_that_get_does_not_set_write_flag() throws IOException { - Tenant tenant1 = applicationRepository.getTenant(appId1); - Session session = applicationRepository.getActiveLocalSession(tenant1, appId1); + Session session = applicationRepository.getActiveLocalSession(appId1); assertContent("/test.txt", "foo\n"); assertThat(session.getStatus(), is(Session.Status.ACTIVATE)); } 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 a51346148d2..c3196fdeaa6 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 @@ -20,7 +20,6 @@ import com.yahoo.vespa.config.server.model.TestModelFactory; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.session.Session; -import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.model.VespaModelFactory; @@ -138,8 +137,7 @@ public class SessionActiveHandlerTest { testApp); 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()); - Session session = applicationRepository.getActiveLocalSession(tenant, applicationId()); + Session session = applicationRepository.getActiveLocalSession(applicationId()); metaData = session.getMetaData(); this.sessionId = sessionId; } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java index 0d4af43d3ba..3e7addedddc 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java @@ -16,7 +16,6 @@ import com.yahoo.vespa.config.server.application.OrchestratorMock; import com.yahoo.vespa.config.server.http.ContentHandlerTestBase; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.session.PrepareParams; -import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; @@ -69,8 +68,7 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { .withConfigserverConfig(configserverConfig) .build(); applicationRepository.deploy(testApp, new PrepareParams.Builder().applicationId(applicationId()).build()); - Tenant tenant = applicationRepository.getTenant(applicationId()); - sessionId = applicationRepository.getActiveLocalSession(tenant, applicationId()).getSessionId(); + sessionId = applicationRepository.getActiveLocalSession(applicationId()).getSessionId(); handler = createHandler(); pathPrefix = "/application/v2/tenant/" + tenantName + "/session/"; |