Package org.apache.helix

Examples of org.apache.helix.HelixAdmin


//    String clusterName = getValue("clusterName");

    ZkClient zkClient =
        (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    HelixAdmin admin = setupTool.getClusterManagementTool();
    ZNRecord record = new ZNRecord(scopeProperty + " Config");

    HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
    List<String> configKeys = admin.getConfigKeys(scope);
    Map<String, String> configs = admin.getConfig(scope, configKeys);
    record.setSimpleFields(configs);

    representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                                 MediaType.APPLICATION_JSON);
View Full Code Here


  }
 
  private List<ExternalView> getExternalViews() {
    String clusterName = helixManager.getClusterName();
    List<ExternalView> externalViewList = new ArrayList<ExternalView>();
    HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
    List<String> resourcesInCluster = helixAdmin.getResourcesInCluster(clusterName);
    for(String resourceName : resourcesInCluster) {
      ExternalView ev = helixManager.getClusterManagmentTool().getResourceExternalView(clusterName, resourceName);
      if(ev != null) {
        externalViewList.add(ev);
      }
View Full Code Here

            }, "test"
    );

    String resourceName = "test-resource";
    LOG.info("Ideal state assignment");
    HelixAdmin helixAdmin = participant.getClusterManagmentTool();
    helixAdmin.addResource(clusterName, resourceName, 1, "OnlineOffline",
        IdealState.IdealStateModeProperty.CUSTOMIZED.toString());

    IdealState idealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
    idealState.setReplicas("1");
    idealState.setStateModelFactoryName("test");
    idealState.setPartitionState(resourceName + "_0", instanceId, "ONLINE");

    LOG.info("Shutdown ZK server");
    TestHelper.stopZkServer(zkServerRef.get());
    Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {

        @Override
        public void run() {
            try {
                LOG.info("Restart ZK server");
                // zkServer.set(TestUtils.startZookeeper(zkDir, zkPort));
                zkServerRef.set(TestHelper.startZkSever(zkAddr, null, false));
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }, 2L, TimeUnit.SECONDS);

    // future.get();
   
    LOG.info("Before update ideal state");
    helixAdmin.setResourceIdealState(clusterName, resourceName, idealState);
    LOG.info("After update ideal state");

    LOG.info("Wait for OFFLINE->ONLINE state transition");
    try {
        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
View Full Code Here

public class TestInvalidAutoIdealState extends ZkUnitTestBase {
    // TODO Disable this test, need refactor it for testing message generation based on state priority
    // @Test
    void testInvalidReplica2() throws Exception
    {
        HelixAdmin admin = new ZKHelixAdmin(ZK_ADDR);
       
        // create cluster
      String className = TestHelper.getTestClassName();
      String methodName = TestHelper.getTestMethodName();
      String clusterName = className + "_" + methodName;
      String db = "TestDB";

      System.out.println("START " + clusterName + " at "
          + new Date(System.currentTimeMillis()));

        // System.out.println("Creating cluster: " + clusterName);
        admin.addCluster(clusterName, true);

        // add MasterSlave state mode definition
        admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(
                StateModelConfigGenerator.generateConfigForMasterSlave()));

        // Add nodes to the cluster
      int n = 3;
        System.out.println("Adding " + n + " participants to the cluster");
        for (int i = 0; i < n; i++) {
          int port = 12918 + i;
            InstanceConfig instanceConfig = new InstanceConfig("localhost_" + port);
            instanceConfig.setHostName("localhost");
            instanceConfig.setPort("" + port);
            instanceConfig.setInstanceEnabled(true);
            admin.addInstance(clusterName, instanceConfig);
            // System.out.println("\t Added participant: " + instanceConfig.getInstanceName());
        }

        // construct ideal-state manually
        IdealState idealState = new IdealState(db);
        idealState.setIdealStateMode(IdealStateModeProperty.AUTO.toString());
        idealState.setNumPartitions(2);
        idealState.setReplicas("" + 2)// should be 3
        idealState.setStateModelDefRef("MasterSlave");
        idealState.getRecord().setListField("TestDB_0", Arrays.asList("localhost_12918", "localhost_12919", "localhost_12920"));
        idealState.getRecord().setListField("TestDB_1", Arrays.asList("localhost_12919", "localhost_12918", "localhost_12920"));
       
        admin.setResourceIdealState(clusterName, "TestDB", idealState);

      // start participants
      MockParticipant[] participants = new MockParticipant[n];
      for (int i = 0; i < n; i++)
      {
View Full Code Here

                            "MasterSlave",
                            true); // do rebalance

    // setup message constraint
    // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,CONSTRAINT_VALUE=1";
    HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
    ConstraintItemBuilder builder = new ConstraintItemBuilder();
    builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION")
           .addConstraintAttribute("INSTANCE", ".*")
           .addConstraintAttribute("CONSTRAINT_VALUE", "1");
   
//    Map<String, String> constraints = new TreeMap<String, String>();
//    constraints.put("MESSAGE_TYPE", "STATE_TRANSITION");
//    // constraints.put("TRANSITION", "OFFLINE-SLAVE");
//    constraints.put("CONSTRAINT_VALUE", "1");
//    constraints.put("INSTANCE", ".*");
    admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1", builder.build());
   

    final ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));

View Full Code Here

    TestHelper.setupEmptyCluster(_gZkClient, clusterName);

    admin.connect();
    AssertJUnit.assertTrue(admin.isConnected());

    HelixAdmin adminTool = admin.getClusterManagmentTool();
//    ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName)
//        .forResource("testResource").forPartition("testPartition").build();
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTITION)
                                      .forCluster(clusterName)
                                      .forResource("testResource")
                                      .forPartition("testPartition")
                                      .build();

    Map<String, String> properties = new HashMap<String, String>();
    properties.put("pKey1", "pValue1");
    properties.put("pKey2", "pValue2");
    adminTool.setConfig(scope, properties);

    properties = adminTool.getConfig(scope, Arrays.asList("pKey1", "pKey2"));
    Assert.assertEquals(properties.size(), 2);
    Assert.assertEquals(properties.get("pKey1"), "pValue1");
    Assert.assertEquals(properties.get("pKey2"), "pValue2");

    admin.disconnect();
View Full Code Here

  void disablePartition() {
    String instanceName = _manager.getInstanceName();
    String resourceName = _message.getResourceName();
    String partitionName = _message.getPartitionName();
    String clusterName = _manager.getClusterName();
    HelixAdmin admin = _manager.getClusterManagmentTool();
    admin.enablePartition(false, clusterName, instanceName, resourceName, Arrays.asList(partitionName));
    logger.info("error in transit from ERROR to " + _message.getToState()
          + " for partition: " + partitionName + ". disable it on " + instanceName);

  }
View Full Code Here

TOP

Related Classes of org.apache.helix.HelixAdmin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.