Search in sources :

Example 1 with ComponentConfigurer

use of io.fabric8.service.ComponentConfigurer in project fabric8 by jboss-fuse.

the class GitDataStoreImplTestSupport method createGitDataStore.

protected GitDataStoreImpl createGitDataStore() throws Exception {
    RuntimeProperties runtimeProperties = createMockRuntimeProperties();
    CreateEnsembleOptions ensembleOptions = CreateEnsembleOptions.builder().zookeeperPassword("admin").build();
    recursiveDelete(runtimeProperties.getDataPath().toFile());
    BootstrapConfiguration.DataStoreOptions options = new BootstrapConfiguration.DataStoreOptions("root", new File("target/test-container"), zkURL, ensembleOptions);
    runtimeProperties.putRuntimeAttribute(DataStoreTemplate.class, new DataStoreBootstrapTemplate(options));
    FabricGitServiceImpl fabricGitService = new FabricGitServiceImpl();
    fabricGitService.bindRuntimeProperties(runtimeProperties);
    fabricGitService.activate();
    ComponentConfigurer componentConfigurer = new ComponentConfigurer();
    componentConfigurer.activate(null);
    ZkDataStoreImpl zkDataStore = new ZkDataStoreImpl() {

        @Override
        public String getDefaultVersion() {
            return "1.0";
        }
    };
    zkDataStore.bindCurator(curator);
    zkDataStore.bindRuntimeProperties(runtimeProperties);
    zkDataStore.activateComponent();
    final GitDataStoreImpl gitDataStore = new GitDataStoreImpl();
    gitDataStore.bindConfigurer(componentConfigurer);
    gitDataStore.bindGitService(fabricGitService);
    gitDataStore.bindRuntimeProperties(runtimeProperties);
    gitDataStore.bindGitProxyService(new GitProxyRegistrationHandler());
    gitDataStore.bindCurator(curator);
    gitDataStore.bindDataStore(zkDataStore);
    gitDataStore.activate(new HashMap<String, Object>());
    return gitDataStore;
}
Also used : BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) ZkDataStoreImpl(io.fabric8.service.ZkDataStoreImpl) ComponentConfigurer(io.fabric8.service.ComponentConfigurer) DataStoreBootstrapTemplate(io.fabric8.zookeeper.bootstrap.DataStoreBootstrapTemplate) AbstractRuntimeProperties(io.fabric8.api.scr.AbstractRuntimeProperties)

Example 2 with ComponentConfigurer

use of io.fabric8.service.ComponentConfigurer in project fabric8 by jboss-fuse.

the class PlaceholderResolverHelpersTest method curatorConfiguration.

@Test
public void curatorConfiguration() throws Exception {
    ComponentConfigurer configurer = new ComponentConfigurer();
    CuratorConfig cc = new CuratorConfig();
    BundleContext context = mock(BundleContext.class);
    configurer.activate(context);
    Map<String, String> configuration = new HashMap<>();
    configurer.configure(configuration, cc);
    // empty config
    assertNull(cc.getZookeeperUrl());
    assertNull(cc.getZookeeperPassword());
    assertThat(cc.getZookeeperConnectionTimeOut(), equalTo(Constants.DEFAULT_CONNECTION_TIMEOUT_MS));
    assertThat(cc.getZookeeperSessionTimeout(), equalTo(Constants.DEFAULT_SESSION_TIMEOUT_MS));
    assertThat(cc.getZookeeperRetryInterval(), equalTo(Constants.DEFAULT_RETRY_INTERVAL));
    assertThat(cc.getZookeeperRetryMax(), equalTo(Constants.MAX_RETRIES_LIMIT));
    // default config from SCR component
    cc = new CuratorConfig();
    context = mock(BundleContext.class);
    when(context.getProperty("zookeeper.url")).thenReturn("url");
    when(context.getProperty("zookeeper.password")).thenReturn("password");
    when(context.getProperty("zookeeper.retry.max")).thenReturn("42");
    when(context.getProperty("zookeeper.retry.interval")).thenReturn("43");
    when(context.getProperty("zookeeper.connection.timeout")).thenReturn("44");
    when(context.getProperty("zookeeper.session.timeout")).thenReturn("45");
    configurer.activate(context);
    configuration.clear();
    configuration.put(Constants.ZOOKEEPER_URL, "${zookeeper.url}");
    configuration.put(Constants.ZOOKEEPER_PASSWORD, "${zookeeper.password}");
    configuration.put(Constants.RETRY_POLICY_MAX_RETRIES, "${zookeeper.retry.max}");
    configuration.put(Constants.RETRY_POLICY_INTERVAL_MS, "${zookeeper.retry.interval}");
    configuration.put(Constants.CONNECTION_TIMEOUT, "${zookeeper.connection.timeout}");
    configuration.put(Constants.SESSION_TIMEOUT, "${zookeeper.session.timeout}");
    configurer.configure(configuration, cc);
    assertThat(cc.getZookeeperUrl(), equalTo("url"));
    assertThat(cc.getZookeeperPassword(), equalTo("password"));
    assertThat(cc.getZookeeperConnectionTimeOut(), equalTo(44));
    assertThat(cc.getZookeeperSessionTimeout(), equalTo(45));
    assertThat(cc.getZookeeperRetryInterval(), equalTo(43));
    assertThat(cc.getZookeeperRetryMax(), equalTo(42));
    // mixed placeholder and value configuration
    cc = new CuratorConfig();
    context = mock(BundleContext.class);
    when(context.getProperty("zookeeper.password")).thenReturn("password");
    when(context.getProperty("zookeeper.retry.max")).thenReturn("42");
    when(context.getProperty("zookeeper.retry.interval")).thenReturn("43");
    when(context.getProperty("zookeeper.connection.timeout")).thenReturn("44");
    when(context.getProperty("zookeeper.session.timeout")).thenReturn("45");
    configurer.activate(context);
    configuration.clear();
    configuration.put(Constants.ZOOKEEPER_URL, "url2");
    configuration.put(Constants.ZOOKEEPER_PASSWORD, "${zookeeper.password}");
    configuration.put(Constants.RETRY_POLICY_MAX_RETRIES, "${zookeeper.retry.max}");
    configuration.put(Constants.RETRY_POLICY_INTERVAL_MS, "${zookeeper.retry.interval}");
    configuration.put(Constants.CONNECTION_TIMEOUT, "444");
    configuration.put(Constants.SESSION_TIMEOUT, "${zookeeper.session.timeout}");
    configurer.configure(configuration, cc);
    assertThat(cc.getZookeeperUrl(), equalTo("url2"));
    assertThat(cc.getZookeeperPassword(), equalTo("password"));
    assertThat(cc.getZookeeperConnectionTimeOut(), equalTo(444));
    assertThat(cc.getZookeeperSessionTimeout(), equalTo(45));
    assertThat(cc.getZookeeperRetryInterval(), equalTo(43));
    assertThat(cc.getZookeeperRetryMax(), equalTo(42));
}
Also used : HashMap(java.util.HashMap) ComponentConfigurer(io.fabric8.service.ComponentConfigurer) CuratorConfig(io.fabric8.zookeeper.curator.CuratorConfig) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

ComponentConfigurer (io.fabric8.service.ComponentConfigurer)2 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)1 ZkDataStoreImpl (io.fabric8.service.ZkDataStoreImpl)1 BootstrapConfiguration (io.fabric8.zookeeper.bootstrap.BootstrapConfiguration)1 DataStoreBootstrapTemplate (io.fabric8.zookeeper.bootstrap.DataStoreBootstrapTemplate)1 CuratorConfig (io.fabric8.zookeeper.curator.CuratorConfig)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1