Java Code Examples for org.apache.helix.model.InstanceConfig#setDomain()

The following examples show how to use org.apache.helix.model.InstanceConfig#setDomain() . 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: TestWagedRebalanceTopologyAware.java    From helix with Apache License 2.0 6 votes vote down vote up
protected void addInstanceConfig(String storageNodeName, int seqNo, int zoneCount, int tagCount) {
  _gSetupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
  String zone = "zone-" + seqNo % zoneCount;
  String tag = "tag-" + seqNo % tagCount;

  InstanceConfig config =
      _gSetupTool.getClusterManagementTool().getInstanceConfig(CLUSTER_NAME, storageNodeName);
  config.setDomain(
      String.format("DOMAIN=%s,ZONE=%s,INSTANCE=%s", DOMAIN_NAME, zone, storageNodeName));
  config.addTag(tag);
  _gSetupTool.getClusterManagementTool().setInstanceConfig(CLUSTER_NAME, storageNodeName, config);

  _nodeToZoneMap.put(storageNodeName, zone);
  _nodeToTagMap.put(storageNodeName, tag);
  _nodes.add(storageNodeName);
}
 
Example 2
Source File: TestAssignableNode.java    From helix with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseFaultZoneNotFound() throws IOException {
  ResourceControllerDataProvider testCache = setupClusterDataCache();

  ClusterConfig testClusterConfig = new ClusterConfig("testClusterConfigId");
  testClusterConfig.setFaultZoneType("zone");
  testClusterConfig.setTopologyAwareEnabled(true);
  testClusterConfig.setTopology("/zone/");
  when(testCache.getClusterConfig()).thenReturn(testClusterConfig);

  InstanceConfig testInstanceConfig = new InstanceConfig("testInstanceConfigId");
  testInstanceConfig.setDomain("instance=testInstance");
  Map<String, InstanceConfig> instanceConfigMap = new HashMap<>();
  instanceConfigMap.put(_testInstanceId, testInstanceConfig);
  when(testCache.getInstanceConfigMap()).thenReturn(instanceConfigMap);

  AssignableNode node = new AssignableNode(testCache.getClusterConfig(),
      testCache.getInstanceConfigMap().get(_testInstanceId), _testInstanceId);
  Assert.assertEquals(node.getFaultZone(), "Default_zone");
}
 
Example 3
Source File: TestClusterAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
@Test(dependsOnMethods = "testGetClusters")
public void testGetClusterTopology() {
  System.out.println("Start test :" + TestHelper.getTestMethodName());
  String cluster = "TestCluster_1";
  String instance = cluster + "localhost_12920";
  // set the fake zone id in instance configuration
  HelixDataAccessor helixDataAccessor = new ZKHelixDataAccessor(cluster, _baseAccessor);
  InstanceConfig instanceConfig =
      helixDataAccessor.getProperty(helixDataAccessor.keyBuilder().instanceConfig(instance));
  instanceConfig.setDomain("helixZoneId=123");
  helixDataAccessor.setProperty(helixDataAccessor.keyBuilder().instanceConfig(instance),
      instanceConfig);

  String response = new JerseyUriRequestBuilder("clusters/{}/topology").format(cluster).get(this);

  Assert.assertEquals(response,
      "{\"id\":\"TestCluster_1\",\"zones\":[{\"id\":\"123\",\"instances\":[{\"id\":\"TestCluster_1localhost_12920\"}]}],"
          + "\"allInstances\":[\"TestCluster_1localhost_12918\",\"TestCluster_1localhost_12919\",\"TestCluster_1localhost_12924\","
          + "\"TestCluster_1localhost_12925\",\"TestCluster_1localhost_12926\",\"TestCluster_1localhost_12927\",\"TestCluster_1localhost_12920\","
          + "\"TestCluster_1localhost_12921\",\"TestCluster_1localhost_12922\",\"TestCluster_1localhost_12923\"]}");
  System.out.println("End test :" + TestHelper.getTestMethodName());
}
 
Example 4
Source File: TestClusterService.java    From helix with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClusterTopology_whenMultiZones() {
  InstanceConfig instanceConfig1 = new InstanceConfig("instance0");
  instanceConfig1.setDomain("helixZoneId=zone0");
  InstanceConfig instanceConfig2 = new InstanceConfig("instance1");
  instanceConfig2.setDomain("helixZoneId=zone1");
  List<HelixProperty> instanceConfigs = (List) ImmutableList.of(instanceConfig1, instanceConfig2);

  Mock mock = new Mock();
  when(mock.dataAccessor.keyBuilder()).thenReturn(new PropertyKey.Builder(TEST_CLUSTER));
  when(mock.dataAccessor.getChildValues(any(PropertyKey.class), anyBoolean())).thenReturn(instanceConfigs);

  ClusterTopology clusterTopology = mock.clusterService.getClusterTopology(TEST_CLUSTER);

  Assert.assertEquals(clusterTopology.getZones().size(), 2);
  Assert.assertEquals(clusterTopology.getClusterId(), TEST_CLUSTER);
}
 
Example 5
Source File: TestClusterService.java    From helix with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClusterTopology_whenZoneHasMultiInstances() {
  InstanceConfig instanceConfig1 = new InstanceConfig("instance0");
  instanceConfig1.setDomain("helixZoneId=zone0");
  InstanceConfig instanceConfig2 = new InstanceConfig("instance1");
  instanceConfig2.setDomain("helixZoneId=zone0");
  List<HelixProperty> instanceConfigs = (List) ImmutableList.of(instanceConfig1, instanceConfig2);

  Mock mock = new Mock();
  when(mock.dataAccessor.keyBuilder()).thenReturn(new PropertyKey.Builder(TEST_CLUSTER));
  when(mock.dataAccessor.getChildValues(any(PropertyKey.class), anyBoolean()))
      .thenReturn(instanceConfigs);

  ClusterTopology clusterTopology = mock.clusterService.getClusterTopology(TEST_CLUSTER);

  Assert.assertEquals(clusterTopology.getZones().size(), 1);
  Assert.assertEquals(clusterTopology.getZones().get(0).getInstances().size(), 2);
  Assert.assertEquals(clusterTopology.getClusterId(), TEST_CLUSTER);
}
 
Example 6
Source File: TestCrushAutoRebalanceNonRack.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()));

  _gSetupTool.addCluster(CLUSTER_NAME, true);

  ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
  ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
  clusterConfig.setTopology("/instance");
  clusterConfig.setFaultZoneType("instance");
  configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);

  for (int i = 0; i < NUM_NODE; i++) {
    String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
    _gSetupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    _nodes.add(storageNodeName);
    String tag = "tag-" + i % 2;
    _gSetupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, storageNodeName, tag);
    _nodeToTagMap.put(storageNodeName, tag);
    InstanceConfig instanceConfig =
        configAccessor.getInstanceConfig(CLUSTER_NAME, storageNodeName);
    instanceConfig.setDomain("instance=" + storageNodeName);
    configAccessor.setInstanceConfig(CLUSTER_NAME, storageNodeName, instanceConfig);
  }

  // start dummy participants
  for (String node : _nodes) {
    MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, node);
    participant.syncStart();
    _participants.add(participant);
  }

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

  enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
}
 
Example 7
Source File: TestAlertingRebalancerFailure.java    From helix with Apache License 2.0 4 votes vote down vote up
private void setDomainId(String instanceName, ConfigAccessor configAccessor) {
  String domain = String.format("Rack=%s, Instance=%s", instanceName, instanceName);
  InstanceConfig instanceConfig = configAccessor.getInstanceConfig(CLUSTER_NAME, instanceName);
  instanceConfig.setDomain(domain);
  configAccessor.setInstanceConfig(CLUSTER_NAME, instanceName, instanceConfig);
}
 
Example 8
Source File: TestNodeSwap.java    From helix with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void beforeClass() throws Exception {
  System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));

  _gSetupTool.addCluster(CLUSTER_NAME, true);

  ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
  ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
  clusterConfig.setTopology("/zone/instance");
  clusterConfig.setFaultZoneType("zone");
  configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);

  Set<String> nodes = new HashSet<>();
  for (int i = 0; i < NUM_NODE; i++) {
    String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
    _gSetupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    String zone = "zone-" + i % 3;
    String domain = String.format("zone=%s,instance=%s", zone, storageNodeName);

    InstanceConfig instanceConfig =
        configAccessor.getInstanceConfig(CLUSTER_NAME, storageNodeName);
    instanceConfig.setDomain(domain);
    _gSetupTool.getClusterManagementTool().setInstanceConfig(CLUSTER_NAME, storageNodeName,
        instanceConfig);
    nodes.add(storageNodeName);
  }

  // start dummy participants
  for (String node : nodes) {
    MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, node);
    participant.syncStart();
    _participants.add(participant);
  }

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

  enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
  enableTopologyAwareRebalance(_gZkClient, CLUSTER_NAME, true);
}
 
Example 9
Source File: TestTopology.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateClusterTopology() {
  ClusterConfig clusterConfig = new ClusterConfig("Test_Cluster");

  String topology = "/Rack/Sub-Rack/Host/Instance";
  clusterConfig.setTopology(topology);
  clusterConfig.setFaultZoneType("Sub-Rack");
  clusterConfig.setTopologyAwareEnabled(true);

  List<String> allNodes = new ArrayList<String>();
  List<String> liveNodes = new ArrayList<String>();
  Map<String, InstanceConfig> instanceConfigMap = new HashMap<String, InstanceConfig>();

  Map<String, Integer> nodeToWeightMap = new HashMap<String, Integer>();

  for (int i = 0; i < 100; i++) {
    String instance = "localhost_" + i;
    InstanceConfig config = new InstanceConfig(instance);
    String rack_id = "rack_" + i/25;
    String sub_rack_id = "subrack-" + i/5;

    String domain =
        String.format("Rack=%s, Sub-Rack=%s, Host=%s", rack_id, sub_rack_id, instance);
    config.setDomain(domain);
    config.setHostName(instance);
    config.setPort("9000");
    allNodes.add(instance);

    int weight = 0;
    if (i % 10 != 0) {
      liveNodes.add(instance);
      weight = 1000;
      if (i % 3 == 0) {
        // set random instance weight.
        weight = (i+1) * 100;
        config.setWeight(weight);
      }
    }

    instanceConfigMap.put(instance, config);

    if (!nodeToWeightMap.containsKey(rack_id)) {
      nodeToWeightMap.put(rack_id, 0);
    }
    nodeToWeightMap.put(rack_id, nodeToWeightMap.get(rack_id) + weight);
    if (!nodeToWeightMap.containsKey(sub_rack_id)) {
      nodeToWeightMap.put(sub_rack_id, 0);
    }
    nodeToWeightMap.put(sub_rack_id, nodeToWeightMap.get(sub_rack_id) + weight);
  }

  Topology topo = new Topology(allNodes, liveNodes, instanceConfigMap, clusterConfig);

  Assert.assertTrue(topo.getEndNodeType().equals("Instance"));
  Assert.assertTrue(topo.getFaultZoneType().equals("Sub-Rack"));

  List<Node> faultZones = topo.getFaultZones();
  Assert.assertEquals(faultZones.size(), 20);

  Node root = topo.getRootNode();

  Assert.assertEquals(root.getChildrenCount("Rack"), 4);
  Assert.assertEquals(root.getChildrenCount("Sub-Rack"), 20);
  Assert.assertEquals(root.getChildrenCount("Host"), 100);
  Assert.assertEquals(root.getChildrenCount("Instance"), 100);


  // validate weights.
  for (Node rack : root.getChildren()) {
    Assert.assertEquals(rack.getWeight(), (long)nodeToWeightMap.get(rack.getName()));
    for (Node subRack : rack.getChildren()) {
      Assert.assertEquals(subRack.getWeight(), (long)nodeToWeightMap.get(subRack.getName()));
    }
  }
}