Package com.linkedin.helix

Examples of com.linkedin.helix.HelixException


  @Override
  public void addInstance(String clusterName, InstanceConfig instanceConfig)
  {
    if (!ZKUtil.isClusterSetup(clusterName, _zkClient))
    {
      throw new HelixException("cluster " + clusterName + " is not setup yet");
    }
    String instanceConfigsPath =
        PropertyPathConfig.getPath(PropertyType.CONFIGS,
                                   clusterName,
                                   ConfigScopeProperty.PARTICIPANT.toString());
    String nodeId = instanceConfig.getId();
    String instanceConfigPath = instanceConfigsPath + "/" + nodeId;

    if (_zkClient.exists(instanceConfigPath))
    {
      throw new HelixException("Node " + nodeId + " already exists in cluster "
          + clusterName);
    }

    ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord());
View Full Code Here


    String instanceConfigPath = instanceConfigsPath + "/" + nodeId;
    String instancePath = HelixUtil.getInstancePath(clusterName, nodeId);

    if (!_zkClient.exists(instanceConfigPath))
    {
      throw new HelixException("Node " + nodeId
          + " does not exist in config for cluster " + clusterName);
    }

    if (!_zkClient.exists(instancePath))
    {
      throw new HelixException("Node " + nodeId
          + " does not exist in instances for cluster " + clusterName);
    }

    // delete config path
    ZKUtil.dropChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord());
View Full Code Here

                                   clusterName,
                                   ConfigScopeProperty.PARTICIPANT.toString(),
                                   instanceName);
    if (!_zkClient.exists(instanceConfigPath))
    {
      throw new HelixException("instance" + instanceName + " does not exist in cluster "
          + clusterName);
    }

    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
View Full Code Here

    ZkBaseDataAccessor<ZNRecord> baseAccessor =
        new ZkBaseDataAccessor<ZNRecord>(_zkClient);
    if (!baseAccessor.exists(path, 0))
    {
      throw new HelixException("Cluster " + clusterName + ", instance: " + instanceName
          + ", instance config does not exist");
    }

    baseAccessor.update(path, new DataUpdater<ZNRecord>()
    {
      @Override
      public ZNRecord update(ZNRecord currentData)
      {
        if (currentData == null)
        {
          throw new HelixException("Cluster: " + clusterName + ", instance: "
              + instanceName + ", participant config is null");
        }

        InstanceConfig config = new InstanceConfig(currentData);
        config.setInstanceEnabled(enabled);
View Full Code Here

        new ZkBaseDataAccessor<ZNRecord>(_zkClient);

    // check instanceConfig exists
    if (!baseAccessor.exists(path, 0))
    {
      throw new HelixException("Cluster: " + clusterName + ", instance: " + instanceName
          + ", instance config does not exist");
    }

    // check resource exists
    String idealStatePath =
        PropertyPathConfig.getPath(PropertyType.IDEALSTATES, clusterName, resourceName);

    ZNRecord idealStateRecord = null;
    try
    {
      idealStateRecord = baseAccessor.get(idealStatePath, null, 0);
    }
    catch (ZkNoNodeException e)
    {
      // OK.
    }

    if (idealStateRecord == null)
    {
      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");
      }
    }

    // update participantConfig
    // could not use ZNRecordUpdater since it doesn't do listField merge/subtract
    baseAccessor.update(path, new DataUpdater<ZNRecord>()
    {
      @Override
      public ZNRecord update(ZNRecord currentData)
      {
        if (currentData == null)
        {
          throw new HelixException("Cluster: " + clusterName + ", instance: "
              + instanceName + ", participant config is null");
        }

        // TODO: merge with InstanceConfig.setInstanceEnabledForPartition
        List<String> list =
View Full Code Here

    // check the instance is alive
    LiveInstance liveInstance =
        accessor.getProperty(keyBuilder.liveInstance(instanceName));
    if (liveInstance == null)
    {
      throw new HelixException("Can't reset state for " + resourceName + "/"
          + 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;
View Full Code Here

      {
        _zkClient.deleteRecursive(root);
      }
      else
      {
        throw new HelixException("Cluster " + clusterName + " already exists");
      }
    }

    _zkClient.createPersistent(root);
View Full Code Here

                          String idealStateMode,
                          int bucketSize)
  {
    if (!ZKUtil.isClusterSetup(clusterName, _zkClient))
    {
      throw new HelixException("cluster " + clusterName + " is not setup yet");
    }

    IdealStateModeProperty mode = IdealStateModeProperty.AUTO;
    try
    {
      mode = IdealStateModeProperty.valueOf(idealStateMode);
    }
    catch (Exception e)
    {
      logger.error("", e);
    }
    IdealState idealState = new IdealState(resourceName);
    idealState.setNumPartitions(partitions);
    idealState.setStateModelDefRef(stateModelRef);
    idealState.setIdealStateMode(mode.toString());
    idealState.setReplicas("" + 0);
    idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);

    if (bucketSize > 0)
    {
      idealState.setBucketSize(bucketSize);
    }

    String stateModelDefPath =
        PropertyPathConfig.getPath(PropertyType.STATEMODELDEFS,
                                   clusterName,
                                   stateModelRef);
    if (!_zkClient.exists(stateModelDefPath))
    {
      throw new HelixException("State model " + stateModelRef
          + " not found in the cluster STATEMODELDEFS path");
    }

    String idealStatePath = HelixUtil.getIdealStatePath(clusterName);
    String dbIdealStatePath = idealStatePath + "/" + resourceName;
    if (_zkClient.exists(dbIdealStatePath))
    {
      throw new HelixException("Skip the operation. DB ideal state directory exists:"
          + dbIdealStatePath);
    }

    ZKUtil.createChildren(_zkClient, idealStatePath, idealState.getRecord());
  }
View Full Code Here

                               String stateModelDef,
                               StateModelDefinition stateModel)
  {
    if (!ZKUtil.isClusterSetup(clusterName, _zkClient))
    {
      throw new HelixException("cluster " + clusterName + " is not setup yet");
    }
    String stateModelDefPath = HelixUtil.getStateModelDefinitionPath(clusterName);
    String stateModelPath = stateModelDefPath + "/" + stateModelDef;
    if (_zkClient.exists(stateModelPath))
    {
      logger.warn("Skip the operation.State Model directory exists:" + stateModelPath);
      throw new HelixException("State model path " + stateModelPath + " already exists.");
    }

    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
View Full Code Here

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

    String persistentStatsPath =
        PropertyPathConfig.getPath(PropertyType.PERSISTENTSTATS, clusterName);
    ZkBaseDataAccessor<ZNRecord> baseAccessor =
View Full Code Here

TOP

Related Classes of com.linkedin.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.