All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.singularity.client.SingularityClusterManager Maven / Gradle / Ivy

The newest version!
package com.hubspot.singularity.client;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.KeeperException;

public class SingularityClusterManager {
  private final CuratorFramework curator;
  private final String contextPath;

  private final SingularityClientProvider clientProvider;

  static final String LEADER_PATH = "/leader";

  @Inject
  public SingularityClusterManager(
    @Named(SingularityClientModule.CONTEXT_PATH) String contextPath,
    @Named(SingularityClientModule.CURATOR_NAME) CuratorFramework curator,
    SingularityClientProvider clientProvider
  ) {
    this.contextPath = contextPath;
    this.curator = curator;
    this.clientProvider = clientProvider;
  }

  public List getClusterNames() {
    try {
      return curator.getChildren().forPath("");
    } catch (KeeperException.NoNodeException e) {
      throw new RuntimeException("Singularity cluster not set up yet?");
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public String getClusterMembers(String cluster) {
    return SingularityClientProvider.getClusterMembers(curator);
  }

  @SuppressWarnings("deprecation")
  public SingularityClient getClusterClient(String cluster) {
    return clientProvider
      .setContextPath(contextPath)
      .setHosts(getClusterMembers(cluster))
      .get();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy