@Bean(destroyMethod = "close")
  @ConditionalOnMissingBean
  @SneakyThrows
  public CuratorFramework curatorFramework(
      RetryPolicy retryPolicy, ZookeeperDiscoveryProperties properties) {
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    if (ensembleProvider != null) {
      builder.ensembleProvider(ensembleProvider);
    }
    CuratorFramework curator =
        builder
            .retryPolicy(retryPolicy)
            .connectString(zookeeperProperties.getConnectString())
            .build();
    curator.start();

    log.trace(
        "blocking until connected to zookeeper for "
            + properties.getBlockUntilConnectedWait()
            + properties.getBlockUntilConnectedUnit());
    curator.blockUntilConnected(
        properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
    log.trace("connected to zookeeper");
    return curator;
  }
  @Before
  public void setUp() throws Exception {
    sfb = new ZKServerFactoryBean();
    delete(sfb.getDataDir());
    delete(sfb.getDataLogDir());
    sfb.afterPropertiesSet();

    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")).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")).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();

    DefaultRuntimeProperties sysprops = new DefaultRuntimeProperties();
    sysprops.setProperty(SystemProperties.KARAF_DATA, "target/data");
    FabricGitServiceImpl gitService = new FabricGitServiceImpl();
    gitService.bindRuntimeProperties(sysprops);
    gitService.activate();
    gitService.setGitForTesting(git);

    DataStoreTemplateRegistry registrationHandler = new DataStoreTemplateRegistry();
    registrationHandler.activateComponent();

    dataStore = new CachingGitDataStore();
    dataStore.bindCurator(curator);
    dataStore.bindGitService(gitService);
    dataStore.bindRegistrationHandler(registrationHandler);
    dataStore.bindRuntimeProperties(sysprops);
    dataStore.bindConfigurer(
        new Configurer() {
          @Override
          public <T> void configure(Map<String, ?> configuration, T target) throws Exception {}
        });
    Map<String, String> datastoreProperties = new HashMap<String, String>();
    datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
    dataStore.activate(datastoreProperties);
  }
Example #3
0
  public static CuratorFramework newCurator(
      Map conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth) {
    List<String> serverPorts = new ArrayList<String>();
    for (String zkServer : (List<String>) servers) {
      serverPorts.add(zkServer + ":" + Utils.getInt(port));
    }
    String zkStr = StringUtils.join(serverPorts, ",") + root;
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();

    setupBuilder(builder, zkStr, conf, auth);

    return builder.build();
  }
Example #4
0
  protected static void setupBuilder(
      CuratorFrameworkFactory.Builder builder, String zkStr, Map conf, ZookeeperAuthInfo auth) {
    builder
        .connectString(zkStr)
        .connectionTimeoutMs(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT)))
        .sessionTimeoutMs(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)))
        .retryPolicy(
            new StormBoundedExponentialBackoffRetry(
                Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL)),
                Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL_CEILING)),
                Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES))));

    if (auth != null && auth.scheme != null && auth.payload != null) {
      builder = builder.authorization(auth.scheme, auth.payload);
    }
  }