Package org.apache.helix.model

Examples of org.apache.helix.model.IdealState$AutoModeBuilder


      logger.debug("Processing resource:" + resourceName);

      Resource resource = resourceMap.get(resourceName);
      // Ideal state may be gone. In that case we need to get the state model name
      // from the current state
      IdealState idealState = cache.getIdealState(resourceName);

      if (idealState == null) {
        // if ideal state is deleted, use an empty one
        logger.info("resource:" + resourceName + " does not exist anymore");
        idealState = new IdealState(resourceName);
      }

      Rebalancer rebalancer = null;
      MappingCalculator mappingCalculator = null;
      if (idealState.getRebalanceMode() == RebalanceMode.USER_DEFINED
          && idealState.getRebalancerClassName() != null) {
        String rebalancerClassName = idealState.getRebalancerClassName();
        logger
            .info("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName);
        try {
          rebalancer =
              (Rebalancer) (HelixUtil.loadClass(getClass(), rebalancerClassName).newInstance());
          mappingCalculator = new SemiAutoRebalancer();
        } catch (Exception e) {
          logger.warn("Exception while invoking custom rebalancer class:" + rebalancerClassName, e);
        }
      }
      if (rebalancer == null) {
        if (idealState.getRebalanceMode() == RebalanceMode.FULL_AUTO) {
          rebalancer = new AutoRebalancer();
          mappingCalculator = new AutoRebalancer();
        } else if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
          rebalancer = new SemiAutoRebalancer();
          mappingCalculator = new SemiAutoRebalancer();
        } else {
          rebalancer = new CustomRebalancer();
          mappingCalculator = new CustomRebalancer();
View Full Code Here


    if (LOG.isInfoEnabled()) {
      LOG.info("newMapping: " + newMapping);
    }

    IdealState newIdealState = new IdealState(resourceName);
    newIdealState.getRecord().setSimpleFields(currentIdealState.getRecord().getSimpleFields());
    newIdealState.setRebalanceMode(RebalanceMode.FULL_AUTO);
    newIdealState.getRecord().setListFields(newMapping.getListFields());
    return newIdealState;
  }
View Full Code Here

    Assert.assertTrue(nMbeansUnregistered == listener._nMbeansUnregistered - 7);
    Assert.assertTrue(nMbeansRegistered == listener._nMbeansRegistered - 7);

    // Add a resource, one more mbean registered
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("TestDB00"));

    setupTool.addResourceToCluster(_firstClusterName, "TestDB1", idealState.getNumPartitions(),
        "MasterSlave");
    setupTool.rebalanceResource(_firstClusterName, "TestDB1",
        Integer.parseInt(idealState.getReplicas()));

    Thread.sleep(1000);
    Assert.assertTrue(nMbeansUnregistered == listener._nMbeansUnregistered - 7);
    Assert.assertTrue(nMbeansRegistered == listener._nMbeansRegistered - 8);
View Full Code Here

      _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 3);

    // Set the timeout values
    IdealState idealState =
        _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, TEST_DB);
    String stateTransition = "SLAVE" + "-" + "MASTER" + "_" + Message.Attributes.TIMEOUT;
    idealState.getRecord().setSimpleField(stateTransition, "300");

    String command =
        "-zkSvr " + ZK_ADDR + " -addResourceProperty " + CLUSTER_NAME + " " + TEST_DB + " "
            + stateTransition + " 200";
    ClusterSetup.processCommandLineArgs(command.split(" "));
View Full Code Here

  @Test
  public void testStateTransitionTimeOut() throws Exception {
    Map<String, SleepStateModelFactory> factories = new HashMap<String, SleepStateModelFactory>();
    // MockParticipantManager[] participants = new MockParticipantManager[NODE_NR];
    IdealState idealState =
        _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, TEST_DB);
    for (int i = 0; i < NODE_NR; i++) {
      String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
      SleepStateModelFactory factory = new SleepStateModelFactory(1000);
      factories.put(instanceName, factory);
      for (String p : idealState.getPartitionSet()) {
        if (idealState.getPreferenceList(p).get(0).equals(instanceName)) {
          factory.addPartition(p);
        }
      }

      _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
      _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
      _participants[i].syncStart();
    }
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller =
        new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();

    boolean result =
        ClusterStateVerifier
            .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    HelixDataAccessor accessor = _participants[0].getHelixDataAccessor();

    Builder kb = accessor.keyBuilder();
    ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
    for (String p : idealState.getPartitionSet()) {
      String idealMaster = idealState.getPreferenceList(p).get(0);
      Assert.assertTrue(ev.getStateMap(p).get(idealMaster).equals("ERROR"));

      TimeOutStateModel model = factories.get(idealMaster).getStateModel(p);
      Assert.assertEquals(model._errorCallcount, 1);
      Assert.assertEquals(model._error.getCode(), ErrorCode.TIMEOUT);
View Full Code Here

        return false;
      }
      ClusterDataCache cache = new ClusterDataCache();
      cache.refresh(accessor);

      IdealState idealState = cache.getIdealState(_resourceName);
      if (idealState == null) {
        return false;
      }
      String masterValue =
          cache.getStateModelDef(idealState.getStateModelDefRef()).getStatesPriorityList().get(0);
      int replicas = Integer.parseInt(cache.getIdealState(_resourceName).getReplicas());
      String instanceGroupTag = cache.getIdealState(_resourceName).getInstanceGroupTag();
      int instances = 0;
      for (String liveInstanceName : cache.getLiveInstances().keySet()) {
        if (cache.getInstanceConfigMap().get(liveInstanceName).containsTag(instanceGroupTag)) {
View Full Code Here

    CurrentStateOutput currentStateOutput =
        event.getAttribute(AttributeName.CURRENT_STATE.toString());

    Map<String, IdealState> updatedIdealStates = new HashMap<String, IdealState>();
    for (String resourceName : idealStateMap.keySet()) {
      IdealState currentIdealState = idealStateMap.get(resourceName);
      if (currentIdealState.getRebalanceMode() == RebalanceMode.USER_DEFINED
          && currentIdealState.getRebalancerClassName() != null) {
        String rebalancerClassName = currentIdealState.getRebalancerClassName();
        LOG.info("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName);
        try {
          Rebalancer balancer =
              (Rebalancer) (HelixUtil.loadClass(getClass(), rebalancerClassName).newInstance());
          balancer.init(manager);
          IdealState newIdealState =
              balancer.computeNewIdealState(resourceName, idealStateMap.get(resourceName),
                  currentStateOutput, cache);
          updatedIdealStates.put(resourceName, newIdealState);
        } catch (Exception e) {
          LOG.error("Exception while invoking custom rebalancer class:" + rebalancerClassName, e);
View Full Code Here

      zkClient.setZkSerializer(new ZNRecordSerializer());
      HelixDataAccessor accessor =
          new ZKHelixDataAccessor(_manager.getClusterName(), new ZkBaseDataAccessor(zkClient));
      Builder keyBuilder = accessor.keyBuilder();

      IdealState idealState = new IdealState(_resourceName);
      idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
      idealState.setReplicas(StateModelToken.ANY_LIVEINSTANCE.toString());
      idealState.setNumPartitions(1);
      idealState.setStateModelDefRef(LEADER_STANDBY);
      idealState.setStateModelFactoryName(_resourceName);
      List<String> prefList =
          new ArrayList<String>(Arrays.asList(StateModelToken.ANY_LIVEINSTANCE.toString()));
      idealState.getRecord().setListField(_resourceName + "_0", prefList);

      List<String> idealStates = accessor.getChildNames(keyBuilder.idealStates());
      while (idealStates == null || !idealStates.contains(_resourceName)) {
        accessor.setProperty(keyBuilder.idealStates(_resourceName), idealState);
        idealStates = accessor.getChildNames(keyBuilder.idealStates());
View Full Code Here

      admin.addInstance(clusterName, config);
    }

    // add ideal-state according to ideal-state-mode
    String resourceName = "TestDB";
    IdealState idealState = null;
    switch (idealStateMode) {
    case SEMI_AUTO: {
      AutoModeISBuilder builder = new AutoModeISBuilder(resourceName);
      builder.setStateModel("MasterSlave").setNumPartitions(2).setNumReplica(2);
      builder.assignPreferenceList(buildPartitionName(resourceName, 0), "localhost_12918",
View Full Code Here

      if (command.equalsIgnoreCase(ClusterSetup.addIdealState)) {
        ZNRecord newIdealState = jsonParameters.getExtraParameter(JsonParameters.NEW_IDEAL_STATE);
        HelixDataAccessor accessor =
            ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);

        accessor.setProperty(accessor.keyBuilder().idealStates(resourceName), new IdealState(
            newIdealState));

      } else if (command.equalsIgnoreCase(ClusterSetup.rebalance)) {
        int replicas = Integer.parseInt(jsonParameters.getParameter(JsonParameters.REPLICAS));
        String keyPrefix = jsonParameters.getParameter(JsonParameters.RESOURCE_KEY_PREFIX);
View Full Code Here

TOP

Related Classes of org.apache.helix.model.IdealState$AutoModeBuilder

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.