Package org.apache.helix

Examples of org.apache.helix.HelixException


    try {
      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.addCluster)) {
        jsonParameters.verifyCommand(ClusterSetup.addCluster);

        ZkClient zkClient =
            (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkClient);
        setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME), false);
      } else {
        throw new HelixException("Unsupported command: " + command + ". Should be one of ["
            + ClusterSetup.addCluster + "]");
      }

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


        accessor.setProperty(accessor.keyBuilder().stateModelDef(newStateModel.getId()),
            new StateModelDefinition(newStateModel));
        getResponse().setEntity(getStateModelsRepresentation());
      } else {
        throw new HelixException("Unsupported command: " + command + ". Should be one of ["
            + ClusterSetup.addStateModelDef + "]");
      }

      getResponse().setStatus(Status.SUCCESS_OK);
    } catch (Exception e) {
View Full Code Here

        ZkClient zkClient =
            (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkClient);
        setupTool.getClusterManagementTool().removeInstanceTag(clusterName, instanceName, tag);
      } else {
        throw new HelixException("Unsupported command: " + command + ". Should be one of ["
            + ClusterSetup.enableInstance + ", " + ClusterSetup.enablePartition + ", "
            + ClusterSetup.resetInstance + "]");
      }

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

  public void verifyCommand(String command) {

    // 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.addInstanceTag)) {
      if (!_parameterMap.containsKey(ClusterSetup.instanceGroupTag)) {
        throw new HelixException("Missing Json parameters: '" + ClusterSetup.instanceGroupTag + "'");
      }
    } else if (command.equalsIgnoreCase(ClusterSetup.removeInstanceTag)) {
      if (!_parameterMap.containsKey(ClusterSetup.instanceGroupTag)) {
        throw new HelixException("Missing Json parameters: '" + ClusterSetup.instanceGroupTag + "'");
      }
    } 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) 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.");
      }
      HelixDataAccessor accessor =
          ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
      LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
      if (leader == null) {
        throw new HelixException("There is no leader for the cluster " + clusterName);
      }

      Message schedulerMessage =
          new Message(MessageType.SCHEDULER_MSG, UUID.randomUUID().toString());
      schedulerMessage.getRecord().getSimpleFields().put(CRITERIA, criteriaString);
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

            ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);

        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);
    } catch (Exception e) {
View Full Code Here

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

  @Override
  public MessageHandler createHandler(Message message, NotificationContext context) {
    String type = message.getMsgType();

    if (!type.equals(getMessageType())) {
      throw new HelixException("Unexpected msg type for message " + message.getMsgId() + " type:"
          + message.getMsgType());
    }

    return new DefaultParticipantErrorMessageHandler(message, context, _manager);
  }
View Full Code Here

  @Override
  public MessageHandler createHandler(Message message, NotificationContext context) {
    String type = message.getMsgType();

    if (!type.equals(getMessageType())) {
      throw new HelixException("Unexpected msg type for message " + message.getMsgId() + " type:"
          + message.getMsgType());
    }

    return new DefaultControllerMessageHandler(message, context);
  }
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.