Package com.linkedin.helix.model

Examples of com.linkedin.helix.model.IdealState


                            true); // do rebalance
   
    // enable group message
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
    idealState.setGroupMessageMode(true);
    accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);

    // registry a message listener so we know how many message generated
    TestZkChildListener listener = new TestZkChildListener();
    _gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
View Full Code Here


    }
   
    // enable group message
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
    idealState.setGroupMessageMode(true);
    accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);

    // registry a message listener so we know how many message generated
    TestZkChildListener listener = new TestZkChildListener();
    _gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
View Full Code Here

    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();
    ExternalView externalView =
        helixDataAccessor.getProperty(keyBuilder.externalView(_dbName));
    IdealState idealState = helixDataAccessor.getProperty(keyBuilder.idealStates(_dbName));

    monitor.updateExternalView(externalView, idealState);

    AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), 0);
    AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), 0);
View Full Code Here

        {
          return (T) new ExternalView(_externalView);
        }
        else if (type == PropertyType.IDEALSTATES)
        {
          return (T) new IdealState(_idealState);
        }
        return null;
      }
View Full Code Here

    zkClient.waitUntilConnected(10, TimeUnit.SECONDS);
    BaseDataAccessor baseDataAccessor = new ZkBaseDataAccessor(zkClient);
    HelixDataAccessor accessor =
        new ZKHelixDataAccessor("test-cluster", baseDataAccessor);
    Builder builder = new PropertyKey.Builder("test-cluster");
    HelixProperty value = new IdealState("test-resource");
    accessor.createProperty(builder.idealStates("test-resource"), value);
  }
View Full Code Here

          } else
          {
            Message message = createMessage(manager, resourceName, partition.getPartitionName(),
                instanceName, currentState, nextState, sessionIdMap.get(instanceName),
                stateModelDef.getId(), resource.getStateModelFactoryname(), bucketSize);
            IdealState idealState = cache.getIdealState(resourceName);
            // Set timeout of needed
            String stateTransition = currentState + "-" + nextState + "_"
                + Message.Attributes.TIMEOUT;
            if (idealState != null
                && idealState.getRecord().getSimpleField(stateTransition) != null)
            {
              try
              {
                int timeout = Integer.parseInt(idealState.getRecord().getSimpleField(
                    stateTransition));
                if (timeout > 0)
                {
                  message.setExecutionTimeout(timeout);
                }
View Full Code Here

      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);

      String stateModelDefName;

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

      StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
      if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO_REBALANCE)
      {
        calculateAutoBalancedIdealState(cache,
                                        idealState,
                                        stateModelDef,
                                        currentStateOutput);
      }

      // For idealstate that has rebalancing timer and is in AUTO mode, we will run jsql
      // queries to calculate the
      // preference list

      Map<String, List<String>> queryPartitionPriorityLists = null;
      if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO
          && idealState.getRebalanceTimerPeriod() > 0)
      {
        if (manager != null)
        {
          queryPartitionPriorityLists =
              calculatePartitionPriorityListWithQuery(manager, idealState);
        }
      }

      for (Partition partition : resource.getPartitions())
      {
        Map<String, String> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceName, partition);

        Map<String, String> bestStateForPartition;
        Set<String> disabledInstancesForPartition =
            cache.getDisabledInstancesForPartition(partition.toString());

        if (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
        {
          Map<String, String> idealStateMap =
              idealState.getInstanceStateMap(partition.getPartitionName());
          bestStateForPartition =
              computeCustomizedBestStateForPartition(cache,
                                                     stateModelDef,
                                                     idealStateMap,
                                                     currentStateMap,
View Full Code Here

   
    Map<String, Object> resultOriginal = IdealStateCalculatorForStorageNode.calculateInitialIdealState(instanceNames, partitions, replicas);
   
    ZNRecord idealState1 = IdealStateCalculatorForStorageNode.convertToZNRecord(resultOriginal, "TestDB", "MASTER", "SLAVE");
   
    Map<String, Object> result1 = ClusterSetup.buildInternalIdealState(new IdealState(idealState1));
   
    List<String> instanceNames2 = new ArrayList<String>();
    for(int i = 30;i < 35; i++)
    {
      instanceNames2.add("localhost:123" + i);
View Full Code Here

      throw new HelixException("Cluster: " + clusterName + ", resource: " + resourceName
          + ", ideal state does not exist");
    }

    // check partitions exist. warn if not
    IdealState idealState = new IdealState(idealStateRecord);
    for (String partitionName : partitionNames)
    {
      if ((idealState.getIdealStateMode() == IdealStateModeProperty.AUTO && idealState.getPreferenceList(partitionName) == null)
          || (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED && idealState.getInstanceStateMap(partitionName) == null))
      {
        logger.warn("Cluster: " + clusterName + ", resource: " + resourceName
            + ", partition: " + partitionName
            + ", partition does not exist in ideal state");
      }
View Full Code Here

          + partitionNames + " on " + instanceName + ", because " + instanceName
          + " is not alive");
    }

    // check resource group exists
    IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
    if (idealState == null)
    {
      throw new HelixException("Can't reset state for " + resourceName + "/"
          + partitionNames + " on " + instanceName + ", because " + resourceName
          + " is not added");
    }

    // check partition exists in resource group
    Set<String> resetPartitionNames = new HashSet<String>(partitionNames);
    if (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
    {
      Set<String> partitions =
          new HashSet<String>(idealState.getRecord().getMapFields().keySet());
      if (!partitions.containsAll(resetPartitionNames))
      {
        throw new HelixException("Can't reset state for " + resourceName + "/"
            + partitionNames + " on " + instanceName + ", because not all "
            + partitionNames + " exist");
      }
    }
    else
    {
      Set<String> partitions =
          new HashSet<String>(idealState.getRecord().getListFields().keySet());
      if (!partitions.containsAll(resetPartitionNames))
      {
        throw new HelixException("Can't reset state for " + resourceName + "/"
            + partitionNames + " on " + instanceName + ", because not all "
            + partitionNames + " exist");
      }
    }

    // check partition is in ERROR state
    String sessionId = liveInstance.getSessionId();
    CurrentState curState =
        accessor.getProperty(keyBuilder.currentState(instanceName,
                                                     sessionId,
                                                     resourceName));
    for (String partitionName : resetPartitionNames)
    {
      if (!curState.getState(partitionName).equals("ERROR"))
      {
        throw new HelixException("Can't reset state for " + resourceName + "/"
            + partitionNames + " on " + instanceName + ", because not all "
            + partitionNames + " are in ERROR state");
      }
    }

    // check stateModelDef exists and get initial state
    String stateModelDef = idealState.getStateModelDefRef();
    StateModelDefinition stateModel =
        accessor.getProperty(keyBuilder.stateModelDef(stateModelDef));
    if (stateModel == null)
    {
      throw new HelixException("Can't reset state for " + resourceName + "/"
          + partitionNames + " on " + instanceName + ", because " + stateModelDef
          + " is NOT found");
    }

    // check there is no pending messages for the partitions exist
    List<Message> messages = accessor.getChildValues(keyBuilder.messages(instanceName));
    for (Message message : messages)
    {
      if (!MessageType.STATE_TRANSITION.toString().equalsIgnoreCase(message.getMsgType())
          || !sessionId.equals(message.getTgtSessionId())
          || !resourceName.equals(message.getResourceName())
          || !resetPartitionNames.contains(message.getPartitionName()))
      {
        continue;
      }

      throw new HelixException("Can't reset state for " + resourceName + "/"
          + partitionNames + " on " + instanceName
          + ", because a pending message exists: " + message);
    }

    String adminName = null;
    try
    {
      adminName = InetAddress.getLocalHost().getCanonicalHostName() + "-ADMIN";
    }
    catch (UnknownHostException e)
    {
      // can ignore it
      logger.info("Unable to get host name. Will set it to UNKNOWN, mostly ignorable", e);
      adminName = "UNKNOWN";
    }

    List<Message> resetMessages = new ArrayList<Message>();
    List<PropertyKey> messageKeys = new ArrayList<PropertyKey>();
    for (String partitionName : resetPartitionNames)
    {
      // send ERROR to initialState message
      String msgId = UUID.randomUUID().toString();
      Message message = new Message(MessageType.STATE_TRANSITION, msgId);
      message.setSrcName(adminName);
      message.setTgtName(instanceName);
      message.setMsgState(MessageState.NEW);
      message.setPartitionName(partitionName);
      message.setResourceName(resourceName);
      message.setTgtSessionId(sessionId);
      message.setStateModelDef(stateModelDef);
      message.setFromState("ERROR");
      message.setToState(stateModel.getInitialState());
      message.setStateModelFactoryName(idealState.getStateModelFactoryName());

      resetMessages.add(message);
      messageKeys.add(keyBuilder.message(instanceName, message.getId()));
    }
View Full Code Here

TOP

Related Classes of com.linkedin.helix.model.IdealState

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.