/** * Execute the steps in the loaded bootstrap config. * * @param shouldSkip predicate that determines whether to skip a step * @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(Predicate<BootstrapStep> shouldSkip) throws InterruptedException { List<BootstrapStepResult> results = new ArrayList<>(config.getSteps().size()); if (!bootstrapping.compareAndSet(false, true)) { throw new IllegalStateException("Bootstrap already in progress."); } try { for (BootstrapStep step : config.getSteps()) { results.add(executeStep(step, shouldSkip)); } if (!config.getSteps().isEmpty()) { bootstrapStore.bootstrapped(); } return new BootstrapResult(results); } finally { bootstrapping.set(false); } }
@BeforeClass public static void setupClass() { Map<BootstrapStep.Type, BootstrapStepExecutor> executors = new HashMap<>(); executors.put(STEP1.getType(), EXECUTOR1); executors.put(STEP2.getType(), EXECUTOR2); executors.put(STEP3.getType(), EXECUTOR3); List<BootstrapStep> steps = new ArrayList<>(3); steps.add(STEP1); steps.add(STEP2); steps.add(STEP3); bootstrapConfig = new BootstrapConfig(steps); BootstrapConfigProvider bootstrapConfigProvider = new InMemoryBootstrapConfigProvider(bootstrapConfig); bootstrapStore = AppFabricTestHelper.getInjector().getInstance(BootstrapStore.class); bootstrapService = new BootstrapService(bootstrapConfigProvider, bootstrapStore, executors); bootstrapService.reload(); }
/** * Execute the steps in the loaded bootstrap config. * * @param shouldSkip predicate that determines whether to skip a step * @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(Predicate<BootstrapStep> shouldSkip) throws InterruptedException { List<BootstrapStepResult> results = new ArrayList<>(config.getSteps().size()); if (!bootstrapping.compareAndSet(false, true)) { throw new IllegalStateException("Bootstrap already in progress."); } try { for (BootstrapStep step : config.getSteps()) { results.add(executeStep(step, shouldSkip)); } if (!config.getSteps().isEmpty()) { bootstrapStore.bootstrapped(); } return new BootstrapResult(results); } finally { bootstrapping.set(false); } }
@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 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()); }