Examples of IdealState


Examples of org.apache.helix.model.IdealState

    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(className, new ZkBaseDataAccessor(zkClient));
    Builder keyBuilder = accessor.keyBuilder();

//    ZNRecord statusUpdates = new ZNRecord("statusUpdates");
    IdealState idealState = new IdealState("currentState");
    idealState.setStateModelDefRef("MasterSlave");
    idealState.setIdealStateMode("AUTO");
    idealState.setNumPartitions(10);

    for (int i = 0; i < 1024; i++)
    {
      idealState.getRecord().setSimpleField(i + "", bufStr);
    }
    boolean succeed =
        accessor.setProperty(keyBuilder.idealStates("TestDB_1"),
                                                              idealState);
    Assert.assertFalse(succeed);
    HelixProperty property =
        accessor.getProperty(keyBuilder.idealStates("TestDB_1"));
    Assert.assertNull(property);

    // legal sized data gets written to zk
    idealState.getRecord().getSimpleFields().clear();
    idealState.setStateModelDefRef("MasterSlave");
    idealState.setIdealStateMode("AUTO");
    idealState.setNumPartitions(10);

    for (int i = 0; i < 900; i++)
    {
      idealState.getRecord().setSimpleField(i + "", bufStr);
    }
    succeed =
        accessor.setProperty(keyBuilder.idealStates("TestDB_2"),
                                                              idealState);
    Assert.assertTrue(succeed);
    record =
        accessor.getProperty(keyBuilder.idealStates("TestDB_2")).getRecord();
    Assert.assertTrue(serializer.serialize(record).length > 900 * 1024);

    // oversized data should not update existing data on zk
    idealState.getRecord().getSimpleFields().clear();
    idealState.setStateModelDefRef("MasterSlave");
    idealState.setIdealStateMode("AUTO");
    idealState.setNumPartitions(10);

    for (int i = 900; i < 1024; i++)
    {
      idealState.getRecord().setSimpleField(i + "", bufStr);
    }
    // System.out.println("record: " + idealState.getRecord());
    succeed =
        accessor.updateProperty(keyBuilder.idealStates("TestDB_2"),
                                                                 idealState);
View Full Code Here

Examples of org.apache.helix.model.IdealState

      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 (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

Examples of org.apache.helix.model.IdealState

      StateModelDefinition stateModelDef =
          cache.getStateModelDef(resource.getStateModelDefRef());

      Map<String, Integer> stateTransitionPriorities =
          getStateTransitionPriorityMap(stateModelDef);
      IdealState idealState = cache.getIdealState(resourceName);
      Map<String, Bounds> stateConstraints =
          computeStateConstraints(stateModelDef, idealState, cache);

      for (Partition partition : resource.getPartitions())
      {
View Full Code Here

Examples of org.apache.helix.model.IdealState

    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

Examples of org.apache.helix.model.IdealState

          } 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

Examples of org.apache.helix.model.IdealState

  {
    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
    Builder keyBuilder = accessor.keyBuilder();

    IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resource));
    for (String partitionName : idealState.getPartitionSet())
    {
      if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO)
      {
        AssertJUnit.assertEquals(repl, idealState.getPreferenceList(partitionName).size());
      }
      else if (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
      {
        AssertJUnit.assertEquals(repl, idealState.getInstanceStateMap(partitionName)
                                                 .size());
      }
    }
  }
View Full Code Here

Examples of org.apache.helix.model.IdealState

    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

Examples of org.apache.helix.model.IdealState

      instances.add("localhost_" + i);
    }

    for (String resourceName : resources)
    {
      IdealState idealState = new IdealState(resourceName);
      for (int p = 0; p < partitions; p++)
      {
        List<String> value = new ArrayList<String>();
        for (int r = 0; r < replicas; r++)
        {
          int n = nodes[(p + r) % nodes.length];
          value.add("localhost_" + n);
        }
        idealState.getRecord().setListField(resourceName + "_" + p, value);
      }

      idealState.setReplicas(Integer.toString(replicas));
      idealState.setStateModelDefRef("MasterSlave");
      idealState.setIdealStateMode(IdealStateModeProperty.AUTO.toString());
      idealState.setNumPartitions(partitions);
      idealStates.add(idealState);

      // System.out.println(idealState);
      accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
    }
View Full Code Here

Examples of org.apache.helix.model.IdealState

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

Examples of org.apache.helix.model.IdealState

    if(instances.size() % replica != 0)
    {
      throw new HelixException("Instances must be divided by replica");
    }
   
    IdealState result = new IdealState(resultRecordName);
    result.setNumPartitions(partitions.size());
    result.setReplicas("" + replica);
    result.setStateModelDefRef(stateModelName);
   
    int groups = instances.size() / replica;
    int remainder = instances.size() % replica;
   
    int remainder2 = partitions.size() % groups;
    int storageNodeGroupSize = partitions.size() / groups;
   
    for(int i = 0; i < groups; i++)
    {
      int relayStart = 0, relayEnd = 0, storageNodeStart = 0, storageNodeEnd = 0;
      if(i < remainder)
      {
        relayStart = (replica + 1) * i;
        relayEnd = (replica + 1) *(i + 1);
      }
      else
      {
        relayStart = (replica + 1) * remainder + replica * (i - remainder);
        relayEnd = relayStart + replica;
      }
      //System.out.println("relay start :" + relayStart + " relayEnd:" + relayEnd);
      if(i < remainder2)
      {
        storageNodeStart = (storageNodeGroupSize + 1) * i;
        storageNodeEnd = (storageNodeGroupSize + 1) *(i + 1);
      }
      else
      {
        storageNodeStart = (storageNodeGroupSize + 1) * remainder2 + storageNodeGroupSize * (i - remainder2);
        storageNodeEnd = storageNodeStart + storageNodeGroupSize;
      }

      //System.out.println("storageNodeStart :" + storageNodeStart + " storageNodeEnd:" + storageNodeEnd);
      List<String> snBatch = partitions.subList(storageNodeStart, storageNodeEnd);
      List<String> relayBatch = instances.subList(relayStart, relayEnd);
     
      Map<String, List<String>> sublistFields = calculateSubIdealState(snBatch, relayBatch, replica);
     
      result.getRecord().getListFields().putAll(sublistFields);
    }
   
    for(String snName : result.getRecord().getListFields().keySet())
    {
      Map<String, String> mapField = new TreeMap<String, String>();
      List<String> relayCandidates = result.getRecord().getListField(snName);
      mapField.put(relayCandidates.get(0), firstValue);
      for(int i = 1; i < relayCandidates.size(); i++)
      {
        mapField.put(relayCandidates.get(i), restValue);
      }
      result.getRecord().getMapFields().put(snName, mapField);
    }
    System.out.println();
    return result;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.