@Test public void shouldNotComplainWhenConfiguredCorrectly() throws Exception { environmentHelper.setEnv(new HashMap<String, String>() {{ put("PORT", "50555"); put("LOG_LEVEL", "ERROR"); put("VERIFY_ENVIRONMENT", "COMPLIANCE_TOOL"); put("MSA_METADATA_URL", "some-msa-metadata-url"); put("MSA_ENTITY_ID", "some-msa-entity-id"); put("SERVICE_ENTITY_IDS", "[\"http://some-service-entity-id\"]"); put("SAML_SIGNING_KEY", TEST_RP_PRIVATE_SIGNING_KEY); put("SAML_PRIMARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY); put("SAML_SECONDARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY); put("CLOCK_SKEW", "PT5s"); }}); factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false) ), "verify-service-provider.yml" ); }
@Override public RestlerConfig getConfiguration() { ObjectMapper objectMapper = Jackson.newObjectMapper(); ValidatorFactory validatorFactory = Validation .byProvider(HibernateValidator.class) .configure() .addValidatedValueHandler(new OptionalValidatedValueUnwrapper()) .buildValidatorFactory(); final ConfigurationFactory<RestlerConfig> configurationFactory = new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw"); try { return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE); } catch (Exception e) { throw new RuntimeException("Cannot get test configuration", e); } }
@Test public void testName() throws Exception { MutableSchedulerConfiguration mutable = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); mutable.getCassandraConfig().getApplication().writeDaemonConfiguration(Paths.get(".").resolve("cassandra.yaml")); final ServiceConfig serviceConfig = mutable.getServiceConfig(); final ServiceConfig updated = ServiceConfig.create("yo", serviceConfig.getId(), serviceConfig.getVersion(), serviceConfig.getUser(), serviceConfig.getCluster(), serviceConfig.getRole(), serviceConfig.getPrincipal(), serviceConfig.getFailoverTimeoutS(), serviceConfig.getSecret(), serviceConfig.isCheckpoint()); mutable.setServiceConfig(updated); final ConfigValidator configValidator = new ConfigValidator(); final List<ConfigValidationError> validate = configValidator.validate( configuration.createConfig(), mutable.createConfig()); Assert.assertTrue(validate.size() == 1); }
@Test public void testCluster() throws Exception { MutableSchedulerConfiguration mutable = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); final ServiceConfig serviceConfig = mutable.getServiceConfig(); final ServiceConfig updated = ServiceConfig.create(serviceConfig.getName(), serviceConfig.getId(), serviceConfig.getVersion(), serviceConfig.getUser(), serviceConfig.getCluster() + "1234", serviceConfig.getRole(), serviceConfig.getPrincipal(), serviceConfig.getFailoverTimeoutS(), serviceConfig.getSecret(), serviceConfig.isCheckpoint()); mutable.setServiceConfig(updated); final ConfigValidator configValidator = new ConfigValidator(); final List<ConfigValidationError> validate = configValidator.validate(configuration.createConfig(), mutable.createConfig()); Assert.assertTrue(validate.size() == 1); }
@Test public void testPrincipal() throws Exception { MutableSchedulerConfiguration mutable = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); final ServiceConfig serviceConfig = mutable.getServiceConfig(); final ServiceConfig updated = ServiceConfig.create(serviceConfig.getName(), serviceConfig.getId(), serviceConfig.getVersion(), serviceConfig.getUser(), serviceConfig.getCluster(), serviceConfig.getRole(), serviceConfig.getPrincipal() + "asdf", serviceConfig.getFailoverTimeoutS(), serviceConfig.getSecret(), serviceConfig.isCheckpoint()); mutable.setServiceConfig(updated); final ConfigValidator configValidator = new ConfigValidator(); final List<ConfigValidationError> validate = configValidator.validate(configuration.createConfig(), mutable.createConfig()); Assert.assertTrue(validate.size() == 1); }
@Test public void testRole() throws Exception { MutableSchedulerConfiguration mutable = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); final ServiceConfig serviceConfig = mutable.getServiceConfig(); final ServiceConfig updated = ServiceConfig.create(serviceConfig.getName(), serviceConfig.getId(), serviceConfig.getVersion(), serviceConfig.getUser(), serviceConfig.getCluster(), serviceConfig.getRole() + "qwerty", serviceConfig.getPrincipal(), serviceConfig.getFailoverTimeoutS(), serviceConfig.getSecret(), serviceConfig.isCheckpoint()); mutable.setServiceConfig(updated); final ConfigValidator configValidator = new ConfigValidator(); final List<ConfigValidationError> validate = configValidator.validate(configuration.createConfig(),mutable.createConfig()); Assert.assertTrue(validate.size() == 1); }
@Before public void beforeEach() throws Exception { factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule(new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); configuration = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); }
@Test public void loadAndPersistConfiguration() throws Exception { final String configFilePath = Resources.getResource("scheduler.yml").getFile(); MutableSchedulerConfiguration mutableConfig = configurationFactory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), configFilePath); final CassandraSchedulerConfiguration original = mutableConfig.createConfig(); final CuratorFrameworkConfig curatorConfig = mutableConfig.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); StateStore stateStore = new CuratorStateStore( original.getServiceConfig().getName(), server.getConnectString(), retryPolicy); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, original.getServiceConfig().getName(), connectString, original, new ConfigValidator(), stateStore); ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager); CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig(); assertEquals("cassandra", original.getServiceConfig().getName()); assertEquals("cassandra-role", original.getServiceConfig().getRole()); assertEquals("cassandra-cluster", original.getServiceConfig().getCluster()); assertEquals("cassandra-principal", original.getServiceConfig().getPrincipal()); assertEquals("", original.getServiceConfig().getSecret()); manager.start(); assertEquals(original.getCassandraConfig(), targetConfig.getCassandraConfig()); assertEquals(original.getExecutorConfig(), targetConfig.getExecutorConfig()); assertEquals(original.getServers(), targetConfig.getServers()); assertEquals(original.getSeeds(), targetConfig.getSeeds()); }
@Test public void serializeDeserializeExecutorConfig() throws Exception { MutableSchedulerConfiguration mutable = configurationFactory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); final CassandraSchedulerConfiguration original = mutable.createConfig(); final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig(); mutable.setCassandraConfig( mutable.getCassandraConfig() .mutable().setJmxPort(8000).setCpus(0.6).setMemoryMb(10000).build()); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); StateStore stateStore = new CuratorStateStore( original.getServiceConfig().getName(), server.getConnectString(), retryPolicy); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, original.getServiceConfig().getName(), connectString, original, new ConfigValidator(), stateStore); configurationManager.store(original); ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager); CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig(); ExecutorConfig expectedExecutorConfig = new ExecutorConfig( "export LD_LIBRARY_PATH=$MESOS_SANDBOX/libmesos-bundle/lib:$LD_LIBRARY_PATH && export MESOS_NATIVE_JAVA_LIBRARY=$(ls $MESOS_SANDBOX/libmesos-bundle/lib/libmesos-*.so) && ./executor/bin/cassandra-executor server executor/conf/executor.yml", new ArrayList<>(), 0.1, 768, 512, 9000, "./jre", URI.create("https://downloads.mesosphere.com/java/jre-8u121-linux-x64.tar.gz"), URI.create("https://s3-us-west-2.amazonaws.com/cassandra-framework-dev/testing/executor.zip"), URI.create("https://s3-us-west-2.amazonaws.com/cassandra-framework-dev/testing/apache-cassandra-2.2.5-bin.tar.gz"), URI.create("http://downloads.mesosphere.com/libmesos-bundle/libmesos-bundle-1.8.8-1.0.3-rc1-1.tar.gz"), false); manager.start(); assertEquals(original.getCassandraConfig(), targetConfig.getCassandraConfig()); assertEquals(expectedExecutorConfig, targetConfig.getExecutorConfig()); manager.stop(); }
@Test public void failOnBadServersCount() throws Exception { MutableSchedulerConfiguration mutable = configurationFactory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); CassandraSchedulerConfiguration originalConfig = mutable.createConfig(); final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); StateStore stateStore = new CuratorStateStore( originalConfig.getServiceConfig().getName(), server.getConnectString(), retryPolicy); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, originalConfig.getServiceConfig().getName(), connectString, originalConfig, new ConfigValidator(), stateStore); ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager); CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig(); manager.start(); assertEquals(originalConfig.getCassandraConfig(), targetConfig.getCassandraConfig()); assertEquals(originalConfig.getExecutorConfig(), targetConfig.getExecutorConfig()); assertEquals(originalConfig.getServers(), targetConfig.getServers()); assertEquals(originalConfig.getSeeds(), targetConfig.getSeeds()); manager.stop(); int updatedServers = originalConfig.getServers() - 1; mutable.setServers(updatedServers); configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, originalConfig.getServiceConfig().getName(), connectString, mutable.createConfig(), new ConfigValidator(), stateStore); manager = new ConfigurationManager(taskFactory, configurationManager); manager.start(); assertEquals(1, configurationManager.getErrors().size()); }
@Test public void failOnBadSeedsCount() throws Exception { MutableSchedulerConfiguration mutableSchedulerConfiguration = configurationFactory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); CassandraSchedulerConfiguration originalConfig = mutableSchedulerConfiguration.createConfig(); final CuratorFrameworkConfig curatorConfig = mutableSchedulerConfiguration.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); StateStore stateStore = new CuratorStateStore( originalConfig.getServiceConfig().getName(), server.getConnectString(), retryPolicy); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, originalConfig.getServiceConfig().getName(), connectString, originalConfig, new ConfigValidator(), stateStore); ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager); CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig(); manager.start(); assertEquals(originalConfig.getCassandraConfig(), targetConfig.getCassandraConfig()); assertEquals(originalConfig.getExecutorConfig(), targetConfig.getExecutorConfig()); assertEquals(originalConfig.getServers(), targetConfig.getServers()); assertEquals(originalConfig.getSeeds(), targetConfig.getSeeds()); manager.stop(); int updatedSeeds = originalConfig.getServers() + 1; mutableSchedulerConfiguration.setSeeds(updatedSeeds); configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, originalConfig.getServiceConfig().getName(), connectString, mutableSchedulerConfiguration.createConfig(), new ConfigValidator(), stateStore); manager = new ConfigurationManager(taskFactory, configurationManager); manager.start(); assertEquals(1, configurationManager.getErrors().size()); }
@Before public void beforeEach() throws Exception { server = new TestingServer(); server.start(); final ConfigurationFactory<MutableSchedulerConfiguration> factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); config = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); ServiceConfig initial = config.createConfig().getServiceConfig(); final CassandraSchedulerConfiguration targetConfig = config.createConfig(); clusterTaskConfig = targetConfig.getClusterTaskConfig(); final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); stateStore = new CuratorStateStore( targetConfig.getServiceConfig().getName(), server.getConnectString(), retryPolicy); stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build()); identity = new IdentityManager( initial,stateStore); identity.register("test_id"); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, config.createConfig().getServiceConfig().getName(), server.getConnectString(), config.createConfig(), new ConfigValidator(), stateStore); Capabilities mockCapabilities = Mockito.mock(Capabilities.class); when(mockCapabilities.supportsNamedVips()).thenReturn(true); configuration = new ConfigurationManager( new CassandraDaemonTask.Factory(mockCapabilities), configurationManager); cassandraState = new CassandraState( configuration, clusterTaskConfig, stateStore); }
@BeforeClass public static void beforeAll() throws Exception { server = new TestingServer(); server.start(); final ConfigurationFactory<MutableSchedulerConfiguration> factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); config = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); stateStore = new CuratorStateStore( config.createConfig().getServiceConfig().getName(), server.getConnectString(), retryPolicy); final CassandraSchedulerConfiguration configuration = config.createConfig(); try { final ConfigValidator configValidator = new ConfigValidator(); final DefaultConfigurationManager defaultConfigurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, configuration.getServiceConfig().getName(), server.getConnectString(), configuration, configValidator, stateStore); Capabilities mockCapabilities = Mockito.mock(Capabilities.class); when(mockCapabilities.supportsNamedVips()).thenReturn(true); configurationManager = new ConfigurationManager( new CassandraDaemonTask.Factory(mockCapabilities), defaultConfigurationManager); } catch (ConfigStoreException e) { throw new RuntimeException(e); } }
@BeforeClass public static void beforeAll() throws Exception { server = new TestingServer(); server.start(); final ConfigurationFactory<MutableSchedulerConfiguration> factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); MutableSchedulerConfiguration mutable = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); config = mutable.createConfig(); final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); StateStore stateStore = new CuratorStateStore( config.getServiceConfig().getName(), server.getConnectString(), retryPolicy); configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, config.getServiceConfig().getName(), server.getConnectString(), config, new ConfigValidator(), stateStore); config = (CassandraSchedulerConfiguration) configurationManager.getTargetConfig(); }
private void beforeHelper(String configName) throws Exception { MockitoAnnotations.initMocks(this); mesosConfig = Mockito.mock(MesosConfig.class); client = Mockito.mock(SchedulerClient.class); Mockito.when(mockFuture.get()).thenReturn(true); Mockito.when(mockStage.toCompletableFuture()).thenReturn(mockFuture); backup = Mockito.mock(BackupManager.class); restore = Mockito.mock(RestoreManager.class); cleanup = Mockito.mock(CleanupManager.class); repair = Mockito.mock(RepairManager.class); upgrade = Mockito.mock(UpgradeSSTableManager.class); seeds = Mockito.mock(SeedsManager.class); capabilities = Mockito.mock(Capabilities.class); executorService = Executors.newSingleThreadScheduledExecutor(); frameworkId = TestUtils.generateFrameworkId(); factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); config = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource(configName).getFile()); stateStore = new CuratorStateStore( "/" + config.getServiceConfig().getName(), server.getConnectString()); DefaultConfigurationManager defaultConfigurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, "/" + config.createConfig().getServiceConfig().getName(), server.getConnectString(), config.createConfig(), new ConfigValidator(), stateStore); Capabilities mockCapabilities = Mockito.mock(Capabilities.class); when(mockCapabilities.supportsNamedVips()).thenReturn(true); configurationManager = new ConfigurationManager( new CassandraDaemonTask.Factory(mockCapabilities), defaultConfigurationManager); cassandraState = new CassandraState( configurationManager, configurationManager.getTargetConfig().getClusterTaskConfig(), stateStore); offerRequirementProvider = new PersistentOfferRequirementProvider(defaultConfigurationManager); scheduler = new CassandraScheduler( configurationManager, mesosConfig, offerRequirementProvider, cassandraState, client, backup, restore, cleanup, repair, upgrade, true, seeds, executorService, stateStore, defaultConfigurationManager, capabilities); masterInfo = TestUtils.generateMasterInfo(); driver = new QueuedSchedulerDriver(); scheduler.setSchedulerDriver(driver); scheduler.registered(driver, frameworkId, masterInfo); }
@Before public void beforeEach() throws Exception { MockitoAnnotations.initMocks(this); server = new TestingServer(); server.start(); Capabilities mockCapabilities = mock(Capabilities.class); when(mockCapabilities.supportsNamedVips()).thenReturn(true); taskFactory = new CassandraDaemonTask.Factory(mockCapabilities); final ConfigurationFactory<MutableSchedulerConfiguration> factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); config = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); final CassandraSchedulerConfiguration targetConfig = config.createConfig(); clusterTaskConfig = targetConfig.getClusterTaskConfig(); final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); stateStore = new CuratorStateStore( targetConfig.getServiceConfig().getName(), server.getConnectString(), retryPolicy); stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build()); configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, config.createConfig().getServiceConfig().getName(), server.getConnectString(), config.createConfig(), new ConfigValidator(), stateStore); cassandraState = new CassandraState( new ConfigurationManager(taskFactory, configurationManager), clusterTaskConfig, stateStore); }
@BeforeClass public static void beforeAll() throws Exception { server = new TestingServer(); server.start(); final ConfigurationFactory<MutableSchedulerConfiguration> factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); MutableSchedulerConfiguration mutable = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); config = mutable.createConfig(); ServiceConfig initial = config.getServiceConfig(); clusterTaskConfig = config.getClusterTaskConfig(); final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); stateStore = new CuratorStateStore( config.getServiceConfig().getName(), server.getConnectString(), retryPolicy); stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build()); identity = new IdentityManager( initial,stateStore); identity.register("test_id"); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, config.getServiceConfig().getName(), server.getConnectString(), config, new ConfigValidator(), stateStore); Capabilities mockCapabilities = Mockito.mock(Capabilities.class); when(mockCapabilities.supportsNamedVips()).thenReturn(true); configuration = new ConfigurationManager( new CassandraDaemonTask.Factory(mockCapabilities), configurationManager); provider = new ClusterTaskOfferRequirementProvider(); }
@Before public void beforeEach() throws Exception { MockitoAnnotations.initMocks(this); server = new TestingServer(); server.start(); final ConfigurationFactory<MutableSchedulerConfiguration> factory = new ConfigurationFactory<>( MutableSchedulerConfiguration.class, BaseValidator.newValidator(), Jackson.newObjectMapper().registerModule( new GuavaModule()) .registerModule(new Jdk8Module()), "dw"); config = factory.build( new SubstitutingSourceProvider( new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false, true)), Resources.getResource("scheduler.yml").getFile()); ServiceConfig initial = config.createConfig().getServiceConfig(); final CassandraSchedulerConfiguration targetConfig = config.createConfig(); clusterTaskConfig = targetConfig.getClusterTaskConfig(); final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig(); RetryPolicy retryPolicy = (curatorConfig.getOperationTimeout().isPresent()) ? new RetryUntilElapsed( curatorConfig.getOperationTimeoutMs() .get() .intValue() , (int) curatorConfig.getBackoffMs()) : new RetryForever((int) curatorConfig.getBackoffMs()); stateStore = new CuratorStateStore( targetConfig.getServiceConfig().getName(), server.getConnectString(), retryPolicy); stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build()); identity = new IdentityManager(initial,stateStore); identity.register("test_id"); DefaultConfigurationManager configurationManager = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class, config.createConfig().getServiceConfig().getName(), server.getConnectString(), config.createConfig(), new ConfigValidator(), stateStore); Capabilities mockCapabilities = Mockito.mock(Capabilities.class); when(mockCapabilities.supportsNamedVips()).thenReturn(true); configuration = new ConfigurationManager( new CassandraDaemonTask.Factory(mockCapabilities), configurationManager); cassandraState = new CassandraState( configuration, clusterTaskConfig, stateStore); taskFactory = new CassandraTaskFactory(executorDriver); }