Search in sources :

Example 51 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project helix by apache.

the class ZkUnitTestBase method verifyEnabled.

public void verifyEnabled(ZkClient zkClient, String clusterName, String instance, boolean wantEnabled) {
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instance));
    AssertJUnit.assertEquals(wantEnabled, config.getInstanceEnabled());
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) Builder(org.apache.helix.PropertyKey.Builder) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor)

Example 52 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project helix by apache.

the class BaseStageTest method setupInstances.

protected void setupInstances(int numInstances) {
    // setup liveInstances
    for (int i = 0; i < numInstances; i++) {
        String instance = HOSTNAME_PREFIX + i;
        InstanceConfig config = new InstanceConfig(instance);
        config.setHostName(instance);
        config.setPort("12134");
        admin.addInstance(manager.getClusterName(), config);
    }
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig)

Example 53 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project helix by apache.

the class TestHelixInstanceTag method testInstanceTag.

@Test
public void testInstanceTag() throws Exception {
    HelixManager manager = _controller;
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    String DB2 = "TestDB2";
    int partitions = 100;
    String DB2tag = "TestDB2_tag";
    int replica = 2;
    for (int i = 0; i < 2; i++) {
        String instanceName = "localhost_" + (12918 + i);
        _setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, instanceName, DB2tag);
    }
    _setupTool.addResourceToCluster(CLUSTER_NAME, DB2, partitions, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, DB2, DB2tag, replica);
    boolean result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME)));
    Assert.assertTrue(result, "Cluster verification fails");
    ExternalView ev = accessor.getProperty(accessor.keyBuilder().externalView(DB2));
    Set<String> hosts = new HashSet<String>();
    for (String p : ev.getPartitionSet()) {
        for (String hostName : ev.getStateMap(p).keySet()) {
            InstanceConfig config = accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
            Assert.assertTrue(config.containsTag(DB2tag));
            hosts.add(hostName);
        }
    }
    Assert.assertEquals(hosts.size(), 2);
    String DB3 = "TestDB3";
    String DB3Tag = "TestDB3_tag";
    partitions = 10;
    replica = 3;
    for (int i = 1; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        _setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, instanceName, DB3Tag);
    }
    _setupTool.addResourceToCluster(CLUSTER_NAME, DB3, partitions, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, DB3, DB3Tag, replica);
    result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME)));
    Assert.assertTrue(result, "Cluster verification fails");
    ev = accessor.getProperty(accessor.keyBuilder().externalView(DB3));
    hosts = new HashSet<String>();
    for (String p : ev.getPartitionSet()) {
        for (String hostName : ev.getStateMap(p).keySet()) {
            InstanceConfig config = accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
            Assert.assertTrue(config.containsTag(DB3Tag));
            hosts.add(hostName);
        }
    }
    Assert.assertEquals(hosts.size(), 4);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HelixManager(org.apache.helix.HelixManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) HelixDataAccessor(org.apache.helix.HelixDataAccessor) InstanceConfig(org.apache.helix.model.InstanceConfig) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 54 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project helix by apache.

the class TestTopology method testCreateClusterTopologyWithDefaultTopology.

@Test
public void testCreateClusterTopologyWithDefaultTopology() {
    ClusterConfig clusterConfig = new ClusterConfig("Test_Cluster");
    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 zoneId = "rack_" + i / 10;
        config.setZoneId(zoneId);
        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(zoneId)) {
            nodeToWeightMap.put(zoneId, 0);
        }
        nodeToWeightMap.put(zoneId, nodeToWeightMap.get(zoneId) + weight);
    }
    Topology topo = new Topology(allNodes, liveNodes, instanceConfigMap, clusterConfig);
    Assert.assertTrue(topo.getEndNodeType().equals(Topology.Types.INSTANCE.name()));
    Assert.assertTrue(topo.getFaultZoneType().equals(Topology.Types.ZONE.name()));
    List<Node> faultZones = topo.getFaultZones();
    Assert.assertEquals(faultZones.size(), 10);
    Node root = topo.getRootNode();
    Assert.assertEquals(root.getChildrenCount(Topology.Types.ZONE.name()), 10);
    Assert.assertEquals(root.getChildrenCount(topo.getEndNodeType()), 100);
    // validate weights.
    for (Node rack : root.getChildren()) {
        Assert.assertEquals(rack.getWeight(), (long) nodeToWeightMap.get(rack.getName()));
    }
}
Also used : HashMap(java.util.HashMap) Node(org.apache.helix.controller.rebalancer.topology.Node) ArrayList(java.util.ArrayList) Topology(org.apache.helix.controller.rebalancer.topology.Topology) InstanceConfig(org.apache.helix.model.InstanceConfig) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 55 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project helix by apache.

the class TestTopology method testCreateClusterTopology.

@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()));
        }
    }
}
Also used : HashMap(java.util.HashMap) Node(org.apache.helix.controller.rebalancer.topology.Node) ArrayList(java.util.ArrayList) Topology(org.apache.helix.controller.rebalancer.topology.Topology) InstanceConfig(org.apache.helix.model.InstanceConfig) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Aggregations

InstanceConfig (org.apache.helix.model.InstanceConfig)149 ArrayList (java.util.ArrayList)40 Test (org.testng.annotations.Test)35 HashMap (java.util.HashMap)32 HashSet (java.util.HashSet)28 ZNRecord (org.apache.helix.ZNRecord)26 IdealState (org.apache.helix.model.IdealState)24 ExternalView (org.apache.helix.model.ExternalView)23 Map (java.util.Map)21 HelixException (org.apache.helix.HelixException)21 HelixAdmin (org.apache.helix.HelixAdmin)20 List (java.util.List)19 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)19 HelixDataAccessor (org.apache.helix.HelixDataAccessor)17 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)15 Test (org.junit.Test)15 Set (java.util.Set)13 VerifiableProperties (com.github.ambry.config.VerifiableProperties)12 IOException (java.io.IOException)12 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)12