@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 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); }