Package org.apache.helix

Examples of org.apache.helix.HelixException


        setupTool.getClusterManagementTool().resetInstance(clusterName,
                                                           Arrays.asList(instanceName));
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.enableInstance + ", "
            + ClusterSetup.enablePartition + ", " + ClusterSetup.resetInstance + "]");
      }

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


  {

    // verify command itself
    if (_parameterMap.isEmpty())
    {
      throw new HelixException("'" + JSON_PARAMETERS + "' in the POST body is empty");
    }

    if (!_parameterMap.containsKey(MANAGEMENT_COMMAND))
    {
      throw new HelixException("Missing management paramater '" + MANAGEMENT_COMMAND
          + "'");
    }

    if (!_parameterMap.get(MANAGEMENT_COMMAND).equalsIgnoreCase(command)
        && !(CLUSTERSETUP_COMMAND_ALIASES.get(command) != null && CLUSTERSETUP_COMMAND_ALIASES.get(command)
                                                                                              .contains(_parameterMap.get(MANAGEMENT_COMMAND))))
    {
      throw new HelixException(MANAGEMENT_COMMAND + " must be '" + command + "'");
    }

    // verify command parameters
    if (command.equalsIgnoreCase(ClusterSetup.enableInstance))
    {
      if (!_parameterMap.containsKey(ENABLED))
      {
        throw new HelixException("Missing Json parameters: '" + ENABLED + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.enablePartition))
    {
      if (!_parameterMap.containsKey(ENABLED))
      {
        throw new HelixException("Missing Json parameters: '" + ENABLED + "'");
      }

      if (!_parameterMap.containsKey(PARTITION))
      {
        throw new HelixException("Missing Json parameters: '" + PARTITION + "'");
      }

      if (!_parameterMap.containsKey(RESOURCE))
      {
        throw new HelixException("Missing Json parameters: '" + RESOURCE + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.resetPartition))
    {
      if (!_parameterMap.containsKey(PARTITION))
      {
        throw new HelixException("Missing Json parameters: '" + PARTITION + "'");
      }

      if (!_parameterMap.containsKey(RESOURCE))
      {
        throw new HelixException("Missing Json parameters: '" + RESOURCE + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.resetInstance))
    {
      // nothing
    }
    else if (command.equalsIgnoreCase(ClusterSetup.activateCluster))
    {
      if (!_parameterMap.containsKey(GRAND_CLUSTER))
      {
        throw new HelixException("Missing Json parameters: '" + GRAND_CLUSTER + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.setConfig))
    {
      if (!_parameterMap.containsKey(CONFIGS))
      {
        throw new HelixException("Missing Json parameters: '" + CONFIGS + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.removeConfig))
    {
      if (!_parameterMap.containsKey(CONFIGS))
      {
        throw new HelixException("Missing Json parameters: '" + CONFIGS + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.addCluster))
    {
      if (!_parameterMap.containsKey(CLUSTER_NAME))
      {
        throw new HelixException("Missing Json parameters: '" + CLUSTER_NAME + "'");
      }
    }
    else if (command.equalsIgnoreCase(ClusterSetup.addResource))
    {
      if (!_parameterMap.containsKey(RESOURCE_GROUP_NAME))
      {
        throw new HelixException("Missing Json paramaters: '" + RESOURCE_GROUP_NAME + "'");
      }

      if (!_parameterMap.containsKey(PARTITIONS))
      {
        throw new HelixException("Missing Json paramaters: '" + PARTITIONS + "'");
      }

      if (!_parameterMap.containsKey(STATE_MODEL_DEF_REF))
      {
        throw new HelixException("Missing Json paramaters: '" + STATE_MODEL_DEF_REF + "'");
      }

    }
  }
View Full Code Here

      ZkClient zkClient = (ZkClient)getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
     
      String msgTemplateString = ClusterRepresentationUtil.getFormJsonParameterString(form, MESSAGETEMPLATE);
      if(msgTemplateString == null)
      {
        throw new HelixException("SchedulerTasksResource need to have MessageTemplate specified.");
      }
      Map<String, String> messageTemplate = ClusterRepresentationUtil.getFormJsonParameters(form, MESSAGETEMPLATE);
     
      String criteriaString = ClusterRepresentationUtil.getFormJsonParameterString(form, CRITERIA);
      if(criteriaString == null)
      {
        throw new HelixException("SchedulerTasksResource need to have Criteria specified.");
      }
     
      Message schedulerMessage = new Message(MessageType.SCHEDULER_MSG, UUID.randomUUID().toString());
      schedulerMessage.getRecord().getSimpleFields().put(CRITERIA, criteriaString);
     
View Full Code Here

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

      JsonParameters jsonParameters = new JsonParameters(entity);
      String command = jsonParameters.getCommand();

      if (command == null)
      {
        throw new HelixException("Could NOT find 'command' in parameterMap: "
            + jsonParameters._parameterMap);
      }
      else if (command.equalsIgnoreCase(ClusterSetup.enableCluster))
      {
        boolean enabled =
            Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));

        setupTool.getClusterManagementTool().enableCluster(clusterName, enabled);
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.enableCluster + "]");
      }

      getResponse().setEntity(getControllerRepresentation(clusterName));
      getResponse().setStatus(Status.SUCCESS_OK);
View Full Code Here

  @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

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.