Java Code Examples for org.apache.helix.tools.ClusterSetup#addCluster()

The following examples show how to use org.apache.helix.tools.ClusterSetup#addCluster() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelixVcrPopulateToolTest.java    From ambry with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  srcZkInfo = new com.github.ambry.utils.TestUtils.ZkInfo(TestUtils.getTempDir("helixVcr"), "DC1", (byte) 1,
      SRC_ZK_SERVER_PORT, true);

  HelixZkClient zkClient =
      SharedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(SRC_ZK_CONNECT_STRING));
  zkClient.setZkSerializer(new ZNRecordSerializer());
  ClusterSetup clusterSetup = new ClusterSetup(zkClient);
  clusterSetup.addCluster(SRC_CLUSTER_NAME, true);
  srcHelixAdmin = new HelixAdminFactory().getHelixAdmin(SRC_ZK_CONNECT_STRING);

  String resourceName = "1";
  Set<String> partitionSet = new HashSet<>();
  for (int i = 0; i < 100; i++) {
    partitionSet.add(Integer.toString(i));
  }
  IdealState idealState = HelixVcrPopulateTool.buildIdealState(resourceName, partitionSet);
  srcHelixAdmin.addResource(SRC_CLUSTER_NAME, resourceName, idealState);
}
 
Example 2
Source File: HelixVcrPopulateTool.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Create a helix cluster with given information.
 * @param destZkString the cluster's zk string
 * @param destClusterName the cluster's name
 */
static void createCluster(String destZkString, String destClusterName) {
  HelixZkClient destZkClient = getHelixZkClient(destZkString);
  HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
  if (ZKUtil.isClusterSetup(destClusterName, destZkClient)) {
    errorAndExit("Failed to create cluster because " + destClusterName + " already exist.");
  }
  ClusterSetup clusterSetup = new ClusterSetup.Builder().setZkAddress(destZkString).build();
  clusterSetup.addCluster(destClusterName, true);

  // set ALLOW_PARTICIPANT_AUTO_JOIN
  HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).
      forCluster(destClusterName).build();
  Map<String, String> helixClusterProperties = new HashMap<>();
  helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
  destAdmin.setConfig(configScope, helixClusterProperties);

  setClusterConfig(destZkClient, destClusterName, false);
  System.out.println("Cluster " + destClusterName + " is created successfully!");
}
 
Example 3
Source File: TestZkConnectionLost.java    From helix with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void beforeClass() throws Exception {
  ZkServer zkServer = TestHelper.startZkServer(_zkAddr);
  _zkServerRef.set(zkServer);
  _zkClient = SharedZkClientFactory.getInstance()
      .buildZkClient(new HelixZkClient.ZkConnectionConfig(_zkAddr));
  _zkClient.setZkSerializer(new ZNRecordSerializer());
  _setupTool = new ClusterSetup(_zkClient);
  _participants = new MockParticipantManager[_numNodes];
  _setupTool.addCluster(CLUSTER_NAME, true);
  setupParticipants(_setupTool);
  setupDBs(_setupTool);
  createManagers(_zkAddr, CLUSTER_NAME);

  // start controller
  String controllerName = CONTROLLER_PREFIX + "_0";
  _controller = new ClusterControllerManager(_zkAddr, CLUSTER_NAME, controllerName);
  _controller.syncStart();

  ZkHelixClusterVerifier clusterVerifier =
      new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(_zkAddr).build();
  Assert.assertTrue(clusterVerifier.verifyByPolling());
}
 
Example 4
Source File: HelixUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Helix cluster for the Gobblin Cluster application.
 *
 * @param zkConnectionString the ZooKeeper connection string
 * @param clusterName the Helix cluster name
 * @param overwrite true to overwrite exiting cluster, false to reuse existing cluster
 */
public static void createGobblinHelixCluster(String zkConnectionString, String clusterName, boolean overwrite) {
  ClusterSetup clusterSetup = new ClusterSetup(zkConnectionString);
  // Create the cluster and overwrite if it already exists
  clusterSetup.addCluster(clusterName, overwrite);
  // Helix 0.6.x requires a configuration property to have the form key=value.
  String autoJoinConfig = ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN + "=true";
  clusterSetup.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName, autoJoinConfig);
}
 
Example 5
Source File: VcrTestUtil.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Populate info on ZooKeeper server and start {@link HelixControllerManager}.
 * @param zkConnectString zk connect string to zk server.
 * @param vcrClusterName the vcr cluster name.
 * @param clusterMap the {@link ClusterMap} to use.
 * @return the created {@link HelixControllerManager}.
 */
public static HelixControllerManager populateZkInfoAndStartController(String zkConnectString, String vcrClusterName,
    ClusterMap clusterMap) {
  HelixZkClient zkClient = DedicatedZkClientFactory.getInstance()
      .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkConnectString), new HelixZkClient.ZkClientConfig());
  try {
    zkClient.setZkSerializer(new ZNRecordSerializer());
    ClusterSetup clusterSetup = new ClusterSetup(zkClient);
    clusterSetup.addCluster(vcrClusterName, true);
    HelixAdmin admin = new ZKHelixAdmin(zkClient);
    // set ALLOW_PARTICIPANT_AUTO_JOIN
    HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).
        forCluster(vcrClusterName).build();
    Map<String, String> helixClusterProperties = new HashMap<>();
    helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
    admin.setConfig(configScope, helixClusterProperties);
    // set PersistBestPossibleAssignment
    ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
    ClusterConfig clusterConfig = configAccessor.getClusterConfig(vcrClusterName);
    clusterConfig.setPersistBestPossibleAssignment(true);
    configAccessor.setClusterConfig(vcrClusterName, clusterConfig);

    FullAutoModeISBuilder builder = new FullAutoModeISBuilder(helixResource);
    builder.setStateModel(LeaderStandbySMD.name);
    for (PartitionId partitionId : clusterMap.getAllPartitionIds(null)) {
      builder.add(partitionId.toPathString());
    }
    builder.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
    IdealState idealState = builder.build();
    admin.addResource(vcrClusterName, helixResource, idealState);
    admin.rebalance(vcrClusterName, helixResource, 3, "", "");
    HelixControllerManager helixControllerManager = new HelixControllerManager(zkConnectString, vcrClusterName);
    helixControllerManager.syncStart();
    return helixControllerManager;
  } finally {
    zkClient.close();
  }
}
 
Example 6
Source File: ClustersResource.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new Helix cluster
 * <p>
 * Usage: <code> curl -d 'jsonParameters={"command":"addCluster","clusterName":"{clusterName}"}' -H
 * "Content-Type: application/json" http://{host:port}/clusters
 */
@Override
public Representation post(Representation entity) {
  try {
    JsonParameters jsonParameters = new JsonParameters(entity);
    String command = jsonParameters.getCommand();

    if (command == null) {
      throw new HelixException("Could NOT find 'command' in parameterMap: "
          + jsonParameters._parameterMap);
    } else if (command.equalsIgnoreCase(ClusterSetup.addCluster)) {
      jsonParameters.verifyCommand(ClusterSetup.addCluster);

      ZkClient zkClient =
          ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
      ClusterSetup setupTool = new ClusterSetup(zkClient);
      setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME), false);
    } else {
      throw new HelixException("Unsupported command: " + command + ". Should be one of ["
          + ClusterSetup.addCluster + "]");
    }

    getResponse().setEntity(getClustersRepresentation());
    getResponse().setStatus(Status.SUCCESS_OK);
  } catch (Exception e) {
    getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
        MediaType.APPLICATION_JSON);
    getResponse().setStatus(Status.SUCCESS_OK);
    LOG.error("Error in posting " + entity, e);
  }
  return null;
}
 
Example 7
Source File: ClustersResource.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new Helix cluster
 * <p>
 * Usage: <code> curl -d 'jsonParameters={"command":"addCluster","clusterName":"{clusterName}"}' -H
 * "Content-Type: application/json" http://{host:port}/clusters
 */
@Override
public Representation post(Representation entity) {
  try {
    JsonParameters jsonParameters = new JsonParameters(entity);
    String command = jsonParameters.getCommand();

    if (command == null) {
      throw new HelixException("Could NOT find 'command' in parameterMap: "
          + jsonParameters._parameterMap);
    } else if (command.equalsIgnoreCase(ClusterSetup.addCluster)) {
      jsonParameters.verifyCommand(ClusterSetup.addCluster);

      ZkClient zkClient =
          ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
      ClusterSetup setupTool = new ClusterSetup(zkClient);
      setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME), false);
    } else {
      throw new HelixException("Unsupported command: " + command + ". Should be one of ["
          + ClusterSetup.addCluster + "]");
    }

    getResponse().setEntity(getClustersRepresentation());
    getResponse().setStatus(Status.SUCCESS_OK);
  } catch (Exception e) {
    getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
        MediaType.APPLICATION_JSON);
    getResponse().setStatus(Status.SUCCESS_OK);
    LOG.error("Error in posting " + entity, e);
  }
  return null;
}
 
Example 8
Source File: ClusterAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
@PUT
@Path("{clusterId}")
public Response createCluster(@PathParam("clusterId") String clusterId,
    @DefaultValue("false") @QueryParam("recreate") String recreate,
    @DefaultValue("false") @QueryParam("addCloudConfig") String addCloudConfig,
    String cloudConfigManifest) {

  boolean recreateIfExists = Boolean.parseBoolean(recreate);
  boolean cloudConfigIncluded = Boolean.parseBoolean(addCloudConfig);

  ClusterSetup clusterSetup = getClusterSetup();

  CloudConfig cloudConfig = null;
  if (cloudConfigIncluded) {
    ZNRecord record;
    try {
      record = toZNRecord(cloudConfigManifest);
      cloudConfig = new CloudConfig.Builder(record).build();
    } catch (IOException | HelixException e) {
      String errMsg = "Failed to generate a valid CloudConfig from " + cloudConfigManifest;
      LOG.error(errMsg, e);
      return badRequest(errMsg + " Exception: " + e.getMessage());
    }
  }

  try {
    clusterSetup.addCluster(clusterId, recreateIfExists, cloudConfig);
  } catch (Exception ex) {
    LOG.error("Failed to create cluster {}. Exception: {}.", clusterId, ex);
    return serverError(ex);
  }
  return created();
}
 
Example 9
Source File: TestHelper.java    From helix with Apache License 2.0 5 votes vote down vote up
public static void setupCluster(String clusterName, String zkAddr, int startPort,
    String participantNamePrefix, String resourceNamePrefix, int resourceNb, int partitionNb,
    int nodesNb, int replica, String stateModelDef, RebalanceMode mode, boolean doRebalance)
    throws Exception {
  HelixZkClient zkClient = SharedZkClientFactory.getInstance()
      .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr));
  if (zkClient.exists("/" + clusterName)) {
    LOG.warn("Cluster already exists:" + clusterName + ". Deleting it");
    zkClient.deleteRecursively("/" + clusterName);
  }

  ClusterSetup setupTool = new ClusterSetup(zkAddr);
  setupTool.addCluster(clusterName, true);

  for (int i = 0; i < nodesNb; i++) {
    int port = startPort + i;
    setupTool.addInstanceToCluster(clusterName, participantNamePrefix + "_" + port);
  }

  for (int i = 0; i < resourceNb; i++) {
    String resourceName = resourceNamePrefix + i;
    setupTool.addResourceToCluster(clusterName, resourceName, partitionNb, stateModelDef,
        mode.toString());
    if (doRebalance) {
      setupTool.rebalanceStorageCluster(clusterName, resourceName, replica);
    }
  }
  zkClient.close();
}
 
Example 10
Source File: TestClusterAggregateMetrics.java    From helix with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void beforeClass() throws Exception {
  System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));

  _setupTool = new ClusterSetup(ZK_ADDR);
  // setup storage cluster
  _setupTool.addCluster(CLUSTER_NAME, true);
  _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, NUM_PARTITIONS, STATE_MODEL);

  for (int i = 0; i < NUM_PARTICIPANTS; i++) {
    String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
    _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
  }
  _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, NUM_REPLICAS);

  // start dummy participants
  for (int i = 0; i < NUM_PARTICIPANTS; i++) {
    String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
    _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
    _participants[i].syncStart();
  }

  // start controller
  String controllerName = CONTROLLER_PREFIX + "_0";
  _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
  _controller.syncStart();

  boolean result = ClusterStateVerifier.verifyByPolling(
      new ClusterStateVerifier.MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME), 10000, 100);
  Assert.assertTrue(result);

  result = ClusterStateVerifier.verifyByPolling(
      new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME), 10000, 100);
  Assert.assertTrue(result);

  // create cluster manager
  _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin",
      InstanceType.ADMINISTRATOR, ZK_ADDR);
  _manager.connect();
}
 
Example 11
Source File: TestPreferenceListAsQueue.java    From helix with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void beforeMethod() {
  _instanceList = Lists.newLinkedList();
  _clusterSetup = new ClusterSetup(ZK_ADDR);
  _admin = _clusterSetup.getClusterManagementTool();
  _prefListHistory = Lists.newLinkedList();

  // Create cluster
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  _clusterName = className + "_" + methodName;
  _clusterSetup.addCluster(_clusterName, true);
}
 
Example 12
Source File: HelixUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Helix cluster for the Gobblin Cluster application.
 *
 * @param zkConnectionString the ZooKeeper connection string
 * @param clusterName the Helix cluster name
 * @param overwrite true to overwrite exiting cluster, false to reuse existing cluster
 */
public static void createGobblinHelixCluster(
    String zkConnectionString,
    String clusterName,
    boolean overwrite) {
  ClusterSetup clusterSetup = new ClusterSetup(zkConnectionString);
  // Create the cluster and overwrite if it already exists
  clusterSetup.addCluster(clusterName, overwrite);
  // Helix 0.6.x requires a configuration property to have the form key=value.
  String autoJoinConfig = ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN + "=true";
  clusterSetup.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName, autoJoinConfig);
}
 
Example 13
Source File: TerrapinControllerHandler.java    From terrapin with Apache License 2.0 5 votes vote down vote up
private void setUpHelixCluster(String zookeeperQuorum, String clusterName) {
  ZkClient zkClient = ZKClientPool.getZkClient(zookeeperQuorum);
  HelixAdmin helixAdmin = new ZKHelixAdmin(zkClient);
  try {
    if(!ImmutableSet.copyOf(helixAdmin.getClusters()).contains(clusterName)) {
      ClusterSetup helixClusterSetUp = new ClusterSetup(zkClient);
      helixClusterSetUp.addCluster(clusterName, false);
      helixClusterSetUp.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName,
          "allowParticipantAutoJoin=true");
    }
  } finally {
    zkClient.close();
  }
}
 
Example 14
Source File: TestConfigAccessor.java    From helix with Apache License 2.0 4 votes vote down vote up
public void testUpdateCloudConfig() throws Exception {
  ClusterSetup _clusterSetup = new ClusterSetup(ZK_ADDR);
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;


  CloudConfig.Builder cloudConfigInitBuilder = new CloudConfig.Builder();
  cloudConfigInitBuilder.setCloudEnabled(true);
  cloudConfigInitBuilder.setCloudID("TestCloudID");
  List<String> sourceList = new ArrayList<String>();
  sourceList.add("TestURL");
  cloudConfigInitBuilder.setCloudInfoSources(sourceList);
  cloudConfigInitBuilder.setCloudInfoProcessorName("TestProcessor");
  cloudConfigInitBuilder.setCloudProvider(CloudProvider.CUSTOMIZED);
  CloudConfig cloudConfigInit = cloudConfigInitBuilder.build();

  _clusterSetup.addCluster(clusterName, false, cloudConfigInit);

  // Read CloudConfig from Zookeeper and check the content
  ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR);
  CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
  Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
  Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
  List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
  Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
  Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
  Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());

  // Change the processor name and check if processor name has been changed in Zookeeper.
  CloudConfig.Builder cloudConfigToUpdateBuilder = new CloudConfig.Builder();
  cloudConfigToUpdateBuilder.setCloudInfoProcessorName("TestProcessor2");
  CloudConfig cloudConfigToUpdate = cloudConfigToUpdateBuilder.build();
  _configAccessor.updateCloudConfig(clusterName, cloudConfigToUpdate);

  cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
  Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
  Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
  listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
  Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
  Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor2");
  Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
}
 
Example 15
Source File: TestConfigAccessor.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteCloudConfig() throws Exception {
  ClusterSetup _clusterSetup = new ClusterSetup(ZK_ADDR);
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;

  CloudConfig.Builder cloudConfigInitBuilder = new CloudConfig.Builder();
  cloudConfigInitBuilder.setCloudEnabled(true);
  cloudConfigInitBuilder.setCloudID("TestCloudID");
  List<String> sourceList = new ArrayList<String>();
  sourceList.add("TestURL");
  cloudConfigInitBuilder.setCloudInfoSources(sourceList);
  cloudConfigInitBuilder.setCloudInfoProcessorName("TestProcessor");
  cloudConfigInitBuilder.setCloudProvider(CloudProvider.AZURE);
  CloudConfig cloudConfigInit = cloudConfigInitBuilder.build();

  _clusterSetup.addCluster(clusterName, false, cloudConfigInit);

  // Read CloudConfig from Zookeeper and check the content
  ConfigAccessor _configAccessor = new ConfigAccessor(ZK_ADDR);
  CloudConfig cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
  Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
  Assert.assertEquals(cloudConfigFromZk.getCloudID(), "TestCloudID");
  List<String> listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
  Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
  Assert.assertEquals(cloudConfigFromZk.getCloudInfoProcessorName(), "TestProcessor");
  Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.AZURE.name());

  // Change the processor name and check if processor name has been changed in Zookeeper.
  CloudConfig.Builder cloudConfigBuilderToDelete = new CloudConfig.Builder();
  cloudConfigBuilderToDelete.setCloudInfoProcessorName("TestProcessor");
  cloudConfigBuilderToDelete.setCloudID("TestCloudID");
  CloudConfig cloudConfigToDelete = cloudConfigBuilderToDelete.build();

  _configAccessor.deleteCloudConfigFields(clusterName, cloudConfigToDelete);

  cloudConfigFromZk = _configAccessor.getCloudConfig(clusterName);
  Assert.assertTrue(cloudConfigFromZk.isCloudEnabled());
  Assert.assertNull(cloudConfigFromZk.getCloudID());
  listUrlFromZk = cloudConfigFromZk.getCloudInfoSources();
  Assert.assertEquals(listUrlFromZk.get(0), "TestURL");
  Assert.assertNull(cloudConfigFromZk.getCloudInfoProcessorName());
  Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.AZURE.name());
}
 
Example 16
Source File: TestDriver.java    From helix with Apache License 2.0 4 votes vote down vote up
public static void setupCluster(String uniqClusterName, String zkAddr, int numResources,
    int numPartitionsPerResource, int numInstances, int replica, boolean doRebalance)
    throws Exception {
  HelixZkClient zkClient = SharedZkClientFactory.getInstance()
      .buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR));

  try {
    zkClient.setZkSerializer(new ZNRecordSerializer());

    // String clusterName = CLUSTER_PREFIX + "_" + uniqClusterName;
    String clusterName = uniqClusterName;
    if (zkClient.exists("/" + clusterName)) {
      LOG.warn("test cluster already exists:" + clusterName + ", test name:" + uniqClusterName + " is not unique or test has been run without cleaning up zk; deleting it");
      zkClient.deleteRecursively("/" + clusterName);
    }

    if (_testInfoMap.containsKey(uniqClusterName)) {
      LOG.warn("test info already exists:" + uniqClusterName + " is not unique or test has been run without cleaning up test info map; removing it");
      _testInfoMap.remove(uniqClusterName);
    }
    TestInfo testInfo =
        new TestInfo(clusterName, zkClient, numResources, numPartitionsPerResource, numInstances,
            replica);
    _testInfoMap.put(uniqClusterName, testInfo);

    ClusterSetup setupTool = new ClusterSetup(zkAddr);
    setupTool.addCluster(clusterName, true);

    for (int i = 0; i < numInstances; i++) {
      int port = START_PORT + i;
      setupTool.addInstanceToCluster(clusterName, PARTICIPANT_PREFIX + "_" + port);
    }

    for (int i = 0; i < numResources; i++) {
      String dbName = TEST_DB_PREFIX + i;
      setupTool.addResourceToCluster(clusterName, dbName, numPartitionsPerResource, STATE_MODEL);
      if (doRebalance) {
        setupTool.rebalanceStorageCluster(clusterName, dbName, replica);

        // String idealStatePath = "/" + clusterName + "/" +
        // PropertyType.IDEALSTATES.toString() + "/"
        // + dbName;
        // ZNRecord idealState = zkClient.<ZNRecord> readData(idealStatePath);
        // testInfo._idealStateMap.put(dbName, idealState);
      }
    }
  } finally {
    zkClient.close();
  }
}
 
Example 17
Source File: TestGetSetUserContentStore.java    From helix with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void beforeClass() throws Exception {
  _participants = new MockParticipantManager[_numNodes];
  String namespace = "/" + CLUSTER_NAME;
  if (_gZkClient.exists(namespace)) {
    _gZkClient.deleteRecursively(namespace);
  }

  // Setup cluster and instances
  ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
  setupTool.addCluster(CLUSTER_NAME, true);
  for (int i = 0; i < _numNodes; i++) {
    String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
    setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
  }

  // start dummy participants
  for (int i = 0; i < _numNodes; i++) {
    final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i);

    // Set task callbacks
    Map<String, TaskFactory> taskFactoryReg = new HashMap<>();
    TaskFactory shortTaskFactory = WriteTask::new;
    taskFactoryReg.put("WriteTask", shortTaskFactory);

    _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);

    // Register a Task state model factory.
    StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
    stateMachine.registerStateModelFactory("Task",
        new TaskStateModelFactory(_participants[i], taskFactoryReg));
    _participants[i].syncStart();
  }

  // Start controller
  String controllerName = CONTROLLER_PREFIX + "_0";
  _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
  _controller.syncStart();

  // Start an admin connection
  _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin",
      InstanceType.ADMINISTRATOR, ZK_ADDR);
  _manager.connect();
  _driver = new TaskDriver(_manager);

  _jobCommandMap = new HashMap<>();
}
 
Example 18
Source File: TestBatchAddJobs.java    From helix with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void beforeClass() {
  _setupTool = new ClusterSetup(ZK_ADDR);
  _setupTool.addCluster(CLUSTER_NAME, true);
  _submitJobTasks = new ArrayList<>();
}
 
Example 19
Source File: TestQuotaBasedScheduling.java    From helix with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void beforeClass() throws Exception {
  _numNodes = 2; // For easier debugging by inspecting ZNodes

  _participants = new MockParticipantManager[_numNodes];
  String namespace = "/" + CLUSTER_NAME;
  if (_gZkClient.exists(namespace)) {
    _gZkClient.deleteRecursively(namespace);
  }

  // Setup cluster and instances
  ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
  setupTool.addCluster(CLUSTER_NAME, true);
  for (int i = 0; i < _numNodes; i++) {
    String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
    setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
  }

  // start dummy participants
  for (int i = 0; i < _numNodes; i++) {
    final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i);

    // Set task callbacks
    Map<String, TaskFactory> taskFactoryReg = new HashMap<>();
    TaskFactory shortTaskFactory = context -> new ShortTask(context, instanceName);
    TaskFactory longTaskFactory = context -> new LongTask(context, instanceName);
    TaskFactory failTaskFactory = context -> new FailTask(context, instanceName);
    taskFactoryReg.put("ShortTask", shortTaskFactory);
    taskFactoryReg.put("LongTask", longTaskFactory);
    taskFactoryReg.put("FailTask", failTaskFactory);

    _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);

    // Register a Task state model factory.
    StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
    stateMachine.registerStateModelFactory("Task",
        new TaskStateModelFactory(_participants[i], taskFactoryReg));
    _participants[i].syncStart();
  }

  // Start controller
  String controllerName = CONTROLLER_PREFIX + "_0";
  _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
  _controller.syncStart();

  // Start an admin connection
  _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin",
      InstanceType.ADMINISTRATOR, ZK_ADDR);
  _manager.connect();
  _driver = new TaskDriver(_manager);

  _jobCommandMap = Maps.newHashMap();
}
 
Example 20
Source File: TestMultiZkHelixJavaApis.java    From helix with Apache License 2.0 4 votes vote down vote up
private void createClusters(ClusterSetup clusterSetup) {
  // Create clusters
  for (String clusterName : CLUSTER_LIST) {
    clusterSetup.addCluster(clusterName, false);
  }
}