/** * Reloads the bootstrap config. */ public void reload() { config = bootstrapConfigProvider.getConfig(); }
/** * Check that this is a valid config, throwing an exception if not. * * @throws IllegalArgumentException if the config is invalid */ public void validate() { for (BootstrapStep step : steps) { step.validate(); } } }
/** * 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); }
@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(); }
@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()); }
@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); }
/** * Clear bootstrap state. This should only be called in tests. */ @VisibleForTesting void clear() { Transactionals.execute(transactional, dsContext -> { MetadataStoreDataset ds = get(dsContext, datasetFramework); ds.delete(KEY); }); }
/** * @return whether the system is bootstrapped or not */ public boolean isBootstrapped() { return bootstrapStore.isBootstrapped(); }
FakeExecutor() { reset(); }
@After public void cleanupTest() { bootstrapStore.clear(); EXECUTOR1.reset(); EXECUTOR2.reset(); EXECUTOR3.reset(); }
/** * 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); }
/** * Clear bootstrap state. This should only be called in tests. */ @VisibleForTesting void clear() { Transactionals.execute(transactional, dsContext -> { MetadataStoreDataset ds = get(dsContext, datasetFramework); ds.delete(KEY); }); }
/** * Reloads the bootstrap config. */ public void reload() { config = bootstrapConfigProvider.getConfig(); }
/** * Check that this is a valid config, throwing an exception if not. * * @throws IllegalArgumentException if the config is invalid */ public void validate() { for (BootstrapStep step : steps) { step.validate(); } } }
/** * @return whether the system is bootstrapped or not */ public boolean isBootstrapped() { return bootstrapStore.isBootstrapped(); }
/** * @return whether the CDAP instance is bootstrapped. */ public boolean isBootstrapped() { return Transactionals.execute(transactional, dsContext -> { MetadataStoreDataset ds = get(dsContext, datasetFramework); return ds.exists(KEY); }); }
/** * Mark the CDAP instance as bootstrapped. */ public void bootstrapped() { Transactionals.execute(transactional, dsContext -> { MetadataStoreDataset ds = get(dsContext, datasetFramework); ds.write(KEY, Boolean.TRUE); }); }
/** * Mark the CDAP instance as bootstrapped. */ public void bootstrapped() { Transactionals.execute(transactional, dsContext -> { MetadataStoreDataset ds = get(dsContext, datasetFramework); ds.write(KEY, Boolean.TRUE); }); }
/** * @return whether the CDAP instance is bootstrapped. */ public boolean isBootstrapped() { return Transactionals.execute(transactional, dsContext -> { MetadataStoreDataset ds = get(dsContext, datasetFramework); return ds.exists(KEY); }); }