Package org.apache.helix

Examples of org.apache.helix.HelixException


  @Override
  public void addClusterToGrandCluster(String clusterName, String grandCluster)
  {
    if (!ZKUtil.isClusterSetup(grandCluster, _zkClient))
    {
      throw new HelixException("Grand cluster " + grandCluster + " is not setup yet");
    }

    if (!ZKUtil.isClusterSetup(clusterName, _zkClient))
    {
      throw new HelixException("Cluster " + clusterName + " is not setup yet");
    }

    IdealState idealState = new IdealState(clusterName);

    idealState.setNumPartitions(1);
    idealState.setStateModelDefRef("LeaderStandby");

    List<String> controllers = getInstancesInCluster(grandCluster);
    if (controllers.size() == 0)
    {
      throw new HelixException("Grand cluster " + grandCluster + " has no instances");
    }
    idealState.setReplicas(Integer.toString(controllers.size()));
    Collections.shuffle(controllers);
    idealState.getRecord().setListField(clusterName, controllers);
    idealState.setPartitionState(clusterName, controllers.get(0), "LEADER");
View Full Code Here


    Collections.sort(instanceNames);

    IdealState idealState = getResourceIdealState(clusterName, resourceName);
    if (idealState == null)
    {
      throw new HelixException("Resource: " + resourceName + " has NOT been added yet");
    }

    idealState.setReplicas(Integer.toString(replica));
    int partitions = idealState.getNumPartitions();
    String stateModelName = idealState.getStateModelDefRef();
    StateModelDefinition stateModDef = getStateModelDef(clusterName, stateModelName);

    if (stateModDef == null)
    {
      throw new HelixException("cannot find state model: " + stateModelName);
    }
    // StateModelDefinition def = new StateModelDefinition(stateModDef);

    List<String> statePriorityList = stateModDef.getStatesPriorityList();

    String masterStateValue = null;
    String slaveStateValue = null;
    replica--;

    for (String state : statePriorityList)
    {
      String count = stateModDef.getNumInstancesPerState(state);
      if (count.equals("1"))
      {
        if (masterStateValue != null)
        {
          throw new HelixException("Invalid or unsupported state model definition");
        }
        masterStateValue = state;
      }
      else if (count.equalsIgnoreCase("R"))
      {
        if (slaveStateValue != null)
        {
          throw new HelixException("Invalid or unsupported state model definition");
        }
        slaveStateValue = state;
      }
      else if (count.equalsIgnoreCase("N"))
      {
        if (!(masterStateValue == null && slaveStateValue == null))
        {
          throw new HelixException("Invalid or unsupported state model definition");
        }
        replica = instanceNames.size() - 1;
        masterStateValue = slaveStateValue = state;
      }
    }
    if (masterStateValue == null && slaveStateValue == null)
    {
      throw new HelixException("Invalid or unsupported state model definition");
    }

    if (masterStateValue == null)
    {
      masterStateValue = slaveStateValue;
View Full Code Here

    StateModelDefinition stateModDef =
        this.getStateModelDef(clusterName, currentIdealState.getStateModelDefRef());

    if (stateModDef == null)
    {
      throw new HelixException("cannot find state model: " + currentIdealState.getStateModelDefRef());
    }
    String[] states = RebalanceUtil.parseStates(clusterName, stateModDef);

    ZNRecord newIdealStateRecord =
        DefaultIdealStateCalculator.convertToZNRecord(balancedRecord,
View Full Code Here

          }
        }
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + JsonParameters.ZK_DELETE_CHILDREN + "]");
      }

      getResponse().setStatus(Status.SUCCESS_OK);
    }
View Full Code Here

        scopeKey1 = getValue("scopeKey1");
        String scopeKey2 = getValue("scopeKey2");
        if (scopeKey1 == null)
        {
          // path is "/clusters/{clusterName}/configs/partition"
          throw new HelixException("Missing resourceName");
        }
        else if (scopeKey2 == null)
        {
          // path is "/clusters/{clusterName}/configs/partition/resourceName"
          representation = getConfigKeys(scopeProperty, scopeKey1);
View Full Code Here

      setupTool.removeConfig(scopeStr, propertiesStr);
    }
    else
    {
      throw new HelixException("Unsupported command: " + command + ". Should be one of ["
          + ClusterSetup.setConfig + ", " + ClusterSetup.removeConfig + "]");

    }

    getResponse().setEntity(represent());
View Full Code Here

      case RESOURCE:
        String scopeKey1 = getValue("scopeKey1");

        if (scopeKey1 == null)
        {
          throw new HelixException("Missing resourceName|participantName");
        }
        else
        {
          scopeConfigStr =
              ConfigScopeProperty.CLUSTER.toString() + "=" + clusterName + ","
                  + scopeProperty.toString() + "=" + scopeKey1;

          setConfigs(entity, scopeConfigStr);
        }
        break;
      case PARTITION:
        scopeKey1 = getValue("scopeKey1");
        String scopeKey2 = getValue("scopeKey2");
        if (scopeKey1 == null || scopeKey2 == null)
        {
          throw new HelixException("Missing resourceName|partitionName");
        }
        else
        {
          scopeConfigStr =
              ConfigScopeProperty.CLUSTER.toString() + "=" + clusterName + ","
View Full Code Here

                                        parameterMap.get(key));
        }
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.addIdealState + ", "
            + ClusterSetup.rebalance + ", " + ClusterSetup.expandResource + ", "
            + ClusterSetup.addResourceProperty + "]");
      }
View Full Code Here

        accessor.setProperty(accessor.keyBuilder().stateModelDef(newStateModel.getId()),
                             new StateModelDefinition(newStateModel));
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.addStateModelDef + "]");
      }
      getResponse().setEntity(getStateModelRepresentation(clusterName, modelName));
      getResponse().setStatus(Status.SUCCESS_OK);
    }
View Full Code Here

  public <T extends HelixProperty> boolean setProperty(PropertyKey key, T value)
  {
    PropertyType type = key.getType();
    if (!value.isValid())
    {
      throw new HelixException("The ZNRecord for " + type + " is not valid.");
    }

    String path = key.getPath();
    int options = constructOptions(type);
View Full Code Here

TOP

Related Classes of org.apache.helix.HelixException

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.