Search in sources :

Example 1 with Configurer

use of io.fabric8.api.scr.Configurer in project fabric8 by jboss-fuse.

the class ProjectDeployerTest method setUp.

@Before
public void setUp() throws Exception {
    URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
    basedir = System.getProperty("basedir", ".");
    String karafRoot = basedir + "/target/karaf";
    System.setProperty("karaf.root", karafRoot);
    System.setProperty("karaf.data", karafRoot + "/data");
    sfb = new ZKServerFactoryBean();
    delete(sfb.getDataDir());
    delete(sfb.getDataLogDir());
    sfb.setPort(9123);
    sfb.afterPropertiesSet();
    int zkPort = sfb.getClientPortAddress().getPort();
    LOG.info("Connecting to ZK on port: " + zkPort);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
    curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    // setup a local and remote git repo
    File root = new File(basedir + "/target/git").getCanonicalFile();
    delete(root);
    new File(root, "remote").mkdirs();
    remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
    remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
    new File(root, "local").mkdirs();
    git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
    git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", remoteUrl);
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.save();
    runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
    EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
    EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
    EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
    EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))).andReturn("").anyTimes();
    EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
    EasyMock.replay(runtimeProperties);
    FabricGitServiceImpl gitService = new FabricGitServiceImpl();
    gitService.bindRuntimeProperties(runtimeProperties);
    gitService.activate();
    gitService.setGitForTesting(git);
    /*
        dataStore = new GitDataStoreImpl();
        dataStore.bindCurator(curator);
        dataStore.bindGitService(gitService);
        dataStore.bindRuntimeProperties(runtimeProperties);
        dataStore.bindConfigurer(new Configurer() {
        

            @Override
            public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
                return null;
            }

            @Override
            public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
                return null;
            }
        });
        Map<String, Object> datastoreProperties = new HashMap<String, Object>();
        datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
        dataStore.activate(datastoreProperties);
        */
    fabricService = new FabricServiceImpl();
    // fabricService.bindDataStore(dataStore);
    fabricService.bindRuntimeProperties(runtimeProperties);
    fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port"));
    fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk"));
    fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver());
    fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver());
    fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver());
    fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver());
    fabricService.activateComponent();
    projectDeployer = new ProjectDeployerImpl();
    projectDeployer.bindFabricService(fabricService);
    projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer());
    // dataStore.getDefaultVersion();
    String defaultVersion = null;
    assertEquals("defaultVersion", "1.0", defaultVersion);
    // now lets import some data - using the old non-git file layout...
    String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import";
    assertFolderExists(importPath);
    dataStore.importFromFileSystem(importPath);
    assertHasVersion(defaultVersion);
}
Also used : ProfilePropertyPointerResolver(io.fabric8.service.ProfilePropertyPointerResolver) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) FabricGitServiceImpl(io.fabric8.git.internal.FabricGitServiceImpl) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) VersionPropertyPointerResolver(io.fabric8.service.VersionPropertyPointerResolver) EnvPlaceholderResolver(io.fabric8.service.EnvPlaceholderResolver) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) StoredConfig(org.eclipse.jgit.lib.StoredConfig) DataStoreTemplate(io.fabric8.api.DataStoreTemplate) ChecksumPlaceholderResolver(io.fabric8.service.ChecksumPlaceholderResolver) File(java.io.File) RuntimeProperties(io.fabric8.api.RuntimeProperties) Before(org.junit.Before)

Example 2 with Configurer

use of io.fabric8.api.scr.Configurer in project fabric8 by jboss-fuse.

the class CachingGitDataStoreTest method setUp.

@Before
public void setUp() throws Exception {
    sfb = new ZKServerFactoryBean();
    delete(sfb.getDataDir());
    delete(sfb.getDataLogDir());
    sfb.afterPropertiesSet();
    runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
    EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
    EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
    EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
    EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
    EasyMock.replay(runtimeProperties);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + sfb.getClientPortAddress().getPort()).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
    curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    // setup a local and remote git repo
    basedir = System.getProperty("basedir", ".");
    File root = new File(basedir + "/target/git").getCanonicalFile();
    delete(root);
    new File(root, "remote").mkdirs();
    remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
    remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
    new File(root, "local").mkdirs();
    git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
    git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", remoteUrl);
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.save();
    FabricGitServiceImpl gitService = new FabricGitServiceImpl();
    gitService.bindRuntimeProperties(runtimeProperties);
    gitService.activate();
    gitService.setGitForTesting(git);
    dataStore = new GitDataStoreImpl();
    dataStore.bindCurator(curator);
    dataStore.bindGitService(gitService);
    dataStore.bindRuntimeProperties(runtimeProperties);
    dataStore.bindConfigurer(new Configurer() {

        @Override
        public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
            return null;
        }

        @Override
        public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
            return null;
        }
    });
    Map<String, Object> datastoreProperties = new HashMap<String, Object>();
    // datastoreProperties.put(GitDataStoreImpl.GIT_REMOTE_URL, remoteUrl);
    dataStore.activate(datastoreProperties);
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) HashMap(java.util.HashMap) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) IOException(java.io.IOException) StoredConfig(org.eclipse.jgit.lib.StoredConfig) DataStoreTemplate(io.fabric8.api.DataStoreTemplate) Configurer(io.fabric8.api.scr.Configurer) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) RuntimeProperties(io.fabric8.api.RuntimeProperties) Before(org.junit.Before)

Example 3 with Configurer

use of io.fabric8.api.scr.Configurer 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

DataStoreTemplate (io.fabric8.api.DataStoreTemplate)2 RuntimeProperties (io.fabric8.api.RuntimeProperties)2 ZKServerFactoryBean (io.fabric8.zookeeper.spring.ZKServerFactoryBean)2 File (java.io.File)2 HashMap (java.util.HashMap)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2 RetryOneTime (org.apache.curator.retry.RetryOneTime)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 Before (org.junit.Before)2 Configurer (io.fabric8.api.scr.Configurer)1 FabricGitServiceImpl (io.fabric8.git.internal.FabricGitServiceImpl)1 ChecksumPlaceholderResolver (io.fabric8.service.ChecksumPlaceholderResolver)1 ComponentConfigurer (io.fabric8.service.ComponentConfigurer)1 EnvPlaceholderResolver (io.fabric8.service.EnvPlaceholderResolver)1 FabricServiceImpl (io.fabric8.service.FabricServiceImpl)1 ProfilePropertyPointerResolver (io.fabric8.service.ProfilePropertyPointerResolver)1 VersionPropertyPointerResolver (io.fabric8.service.VersionPropertyPointerResolver)1 CuratorConfig (io.fabric8.zookeeper.curator.CuratorConfig)1 IOException (java.io.IOException)1 Map (java.util.Map)1