/** * Execute all steps in the loaded bootstrap config without skipping any of them. * * @return the result of executing the bootstrap steps. * @throws IllegalStateException if bootstrapping is already in progress * @throws InterruptedException if bootstrapping was interrupted */ public BootstrapResult bootstrap() throws InterruptedException { return bootstrap(x -> false); }
/** * Execute all steps in the loaded bootstrap config without skipping any of them. * * @return the result of executing the bootstrap steps. * @throws IllegalStateException if bootstrapping is already in progress * @throws InterruptedException if bootstrapping was interrupted */ public BootstrapResult bootstrap() throws InterruptedException { return bootstrap(x -> false); }
@POST @Path("/bootstrap") public void bootstrap(HttpRequest request, HttpResponder responder) throws InterruptedException { bootstrapService.reload(); bootstrapService.bootstrap(); responder.sendStatus(HttpResponseStatus.OK); } }
@POST @Path("/bootstrap") public void bootstrap(HttpRequest request, HttpResponder responder) throws InterruptedException { bootstrapService.reload(); bootstrapService.bootstrap(); responder.sendStatus(HttpResponseStatus.OK); } }
@Override protected void startUp() { LOG.info("Starting {}", getClass().getSimpleName()); config = bootstrapConfigProvider.getConfig(); executorService = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("bootstrap-service")); executorService.execute(() -> { try { if (isBootstrappedWithRetries()) { // if the system is already bootstrapped, skip any bootstrap step that is supposed to only run once bootstrap(step -> step.getRunCondition() == BootstrapStep.RunCondition.ONCE); } else { bootstrap(); } } catch (InterruptedException e) { LOG.info("Bootstrapping could not complete due to interruption. It will be re-run the next time CDAP starts."); } }); LOG.info("Started {}", getClass().getSimpleName()); }
@Override protected void startUp() { LOG.info("Starting {}", getClass().getSimpleName()); config = bootstrapConfigProvider.getConfig(); executorService = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("bootstrap-service")); executorService.execute(() -> { try { if (isBootstrappedWithRetries()) { // if the system is already bootstrapped, skip any bootstrap step that is supposed to only run once bootstrap(step -> step.getRunCondition() == BootstrapStep.RunCondition.ONCE); } else { bootstrap(); } } catch (InterruptedException e) { LOG.info("Bootstrapping could not complete due to interruption. It will be re-run the next time CDAP starts."); } }); LOG.info("Started {}", getClass().getSimpleName()); }
@Test public void testNoConcurrentBootstrap() throws Exception { CountDownLatch runningLatch = new CountDownLatch(1); CountDownLatch waitingLatch = new CountDownLatch(1); EXECUTOR1.setLatches(runningLatch, waitingLatch); Thread t = new Thread(() -> { try { bootstrapService.bootstrap(); } catch (InterruptedException e) { runningLatch.countDown(); } }); t.start(); runningLatch.await(); try { bootstrapService.bootstrap(); Assert.fail("BootstrapService should not allow concurrent bootstrap operations"); } catch (IllegalStateException e) { // expected } finally { waitingLatch.countDown(); } }
Thread t = new Thread(() -> { try { bootstrapService.bootstrap(); } catch (InterruptedException e) {
@Test public void testRetries() throws Exception { EXECUTOR1.setNumRetryableFailures(3); BootstrapResult result = bootstrapService.bootstrap(); List<BootstrapStepResult> expectedStepResults = new ArrayList<>(); for (BootstrapStep step : bootstrapConfig.getSteps()) { expectedStepResults.add(new BootstrapStepResult(step.getLabel(), BootstrapStepResult.Status.SUCCEEDED)); } BootstrapResult expected = new BootstrapResult(expectedStepResults); Assert.assertEquals(expected, result); }
@Test public void testRunCondition() throws Exception { BootstrapResult result = bootstrapService.bootstrap(step -> step.getRunCondition() == BootstrapStep.RunCondition.ONCE); List<BootstrapStepResult> stepResults = new ArrayList<>(3); stepResults.add(new BootstrapStepResult(STEP1.getLabel(), BootstrapStepResult.Status.SKIPPED)); stepResults.add(new BootstrapStepResult(STEP2.getLabel(), BootstrapStepResult.Status.SUCCEEDED)); stepResults.add(new BootstrapStepResult(STEP3.getLabel(), BootstrapStepResult.Status.SKIPPED)); Assert.assertEquals(new BootstrapResult(stepResults), result); }
@Test public void testContinuesAfterFailures() throws Exception { EXECUTOR1.shouldFail(); BootstrapResult result = bootstrapService.bootstrap(); List<BootstrapStepResult> stepResults = new ArrayList<>(3); stepResults.add(new BootstrapStepResult(STEP1.getLabel(), BootstrapStepResult.Status.FAILED)); stepResults.add(new BootstrapStepResult(STEP2.getLabel(), BootstrapStepResult.Status.SUCCEEDED)); stepResults.add(new BootstrapStepResult(STEP3.getLabel(), BootstrapStepResult.Status.SUCCEEDED)); BootstrapResult expected = new BootstrapResult(stepResults); Assert.assertEquals(expected, result); }
@Test public void testAllSuccess() throws Exception { BootstrapResult result = bootstrapService.bootstrap(); List<BootstrapStepResult> expectedStepResults = new ArrayList<>(); for (BootstrapStep step : bootstrapConfig.getSteps()) { expectedStepResults.add(new BootstrapStepResult(step.getLabel(), BootstrapStepResult.Status.SUCCEEDED)); } BootstrapResult expected = new BootstrapResult(expectedStepResults); Assert.assertEquals(expected, result); Assert.assertTrue(bootstrapService.isBootstrapped()); }