Package org.apache.helix

Examples of org.apache.helix.HelixException


      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.activateCluster)
          || JsonParameters.CLUSTERSETUP_COMMAND_ALIASES.get(ClusterSetup.activateCluster)
                                                        .contains(command))
      {
        jsonParameters.verifyCommand(ClusterSetup.activateCluster);

        boolean enabled = true;
        if (jsonParameters.getParameter(JsonParameters.ENABLED) != null)
        {
          enabled =
              Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));
        }

        String grandCluster = jsonParameters.getParameter(JsonParameters.GRAND_CLUSTER);

        setupTool.activateCluster(clusterName, grandCluster, enabled);
      }
      else if (command.equalsIgnoreCase(ClusterSetup.expandCluster))
      {
        setupTool.expandCluster(clusterName);
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.activateCluster + ", "
            + ClusterSetup.expandCluster + "]");
      }
      getResponse().setEntity(getClusterRepresentation(clusterName));
      getResponse().setStatus(Status.SUCCESS_OK);
View Full Code Here


  {
    if (!(data instanceof ZNRecord))
    {
      // null is NOT an instance of any class
      LOG.error("Input object must be of type ZNRecord but it is " + data + ". Will not write to zk");
      throw new HelixException("Input object is not of type ZNRecord (was " + data + ")");
    }

    // apply retention policy on list field
    ZNRecord record = (ZNRecord) data;
    int max = getListFieldBound(record);
    if (max < Integer.MAX_VALUE)
    {
      Map<String, List<String>> listMap = record.getListFields();
      for (String key : listMap.keySet())
      {
        List<String> list = listMap.get(key);
        if (list.size() > max)
        {
          listMap.put(key, list.subList(0, max));
        }
      }
    }
   
    StringWriter sw = new StringWriter();
    try
    {
      JsonFactory f = new JsonFactory();
      JsonGenerator g = f.createJsonGenerator(sw);

      g.writeStartObject();

      // write id field
      g.writeRaw("\n  ");
      g.writeStringField("id", record.getId());

      // write simepleFields
      g.writeRaw("\n  ");
      g.writeObjectFieldStart("simpleFields");
      for (String key : record.getSimpleFields().keySet())
      {
        g.writeRaw("\n    ");
        g.writeStringField(key, record.getSimpleField(key));
      }
      g.writeRaw("\n  ");
      g.writeEndObject(); // for simpleFields

      // write listFields
      g.writeRaw("\n  ");
      g.writeObjectFieldStart("listFields");
      for (String key : record.getListFields().keySet())
      {
        // g.writeStringField(key, record.getListField(key).toString());

        // g.writeObjectFieldStart(key);
        g.writeRaw("\n    ");
        g.writeArrayFieldStart(key);
        List<String> list = record.getListField(key);
        for (String listValue : list)
        {
          g.writeString(listValue);
        }
        // g.writeEndObject();
        g.writeEndArray();

      }
      g.writeRaw("\n  ");
      g.writeEndObject(); // for listFields

      // write mapFields
      g.writeRaw("\n  ");
      g.writeObjectFieldStart("mapFields");
      for (String key : record.getMapFields().keySet())
      {
        // g.writeStringField(key, record.getMapField(key).toString());
        g.writeRaw("\n    ");
        g.writeObjectFieldStart(key);
        Map<String, String> map = record.getMapField(key);
        for (String mapKey : map.keySet())
        {
          g.writeRaw("\n      ");
          g.writeStringField(mapKey, map.get(mapKey));
        }
        g.writeRaw("\n    ");
        g.writeEndObject();

      }
      g.writeRaw("\n  ");
      g.writeEndObject(); // for mapFields

      g.writeRaw("\n");
      g.writeEndObject(); // for whole znrecord

      // important: will force flushing of output, close underlying output
      // stream
      g.close();
    }
    catch (Exception e)
    {
      LOG.error("Exception during data serialization. Will not write to zk. Data (first 1k): "
          + sw.toString().substring(0, 1024), e);
      throw new HelixException(e);
    }
   
    // check size
    if (sw.toString().getBytes().length > ZNRecord.SIZE_LIMIT)
    {
      LOG.error("Data size larger than 1M, ZNRecord.id: " + record.getId()
          + ". Will not write to zk. Data (first 1k): " + sw.toString().substring(0, 1024));
      throw new HelixException("Data size larger than 1M, ZNRecord.id: " + record.getId());
    }
   
    return sw.toString().getBytes();
  }
View Full Code Here

                                          jsonParameters.getParameter(JsonParameters.INSTANCE_NAMES)
                                                        .split(";"));
        }
        else
        {
          throw new HelixException("Missing Json paramaters: '"
              + JsonParameters.INSTANCE_NAME + "' or '" + JsonParameters.INSTANCE_NAMES
              + "' ");
        }
      }
      else if (command.equalsIgnoreCase(ClusterSetup.swapInstance))
      {
        if (jsonParameters.getParameter(JsonParameters.NEW_INSTANCE) == null
            || jsonParameters.getParameter(JsonParameters.OLD_INSTANCE) == null)
        {
          throw new HelixException("Missing Json paramaters: '"
              + JsonParameters.NEW_INSTANCE + "' or '" + JsonParameters.OLD_INSTANCE
              + "' ");
        }
        setupTool.swapInstance(clusterName,
                               jsonParameters.getParameter(JsonParameters.OLD_INSTANCE),
                               jsonParameters.getParameter(JsonParameters.NEW_INSTANCE));
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.addInstance + ", "
            + ClusterSetup.swapInstance + "]");
      }

      getResponse().setEntity(getInstancesRepresentation(clusterName));
View Full Code Here

        ClusterSetup setupTool = new ClusterSetup(zkClient);
        setupTool.getClusterManagementTool().resetResource(clusterName, Arrays.asList(resourceName));
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
                                 + ". Should be one of [" + ClusterSetup.resetResource + "]");
      }
    }
    catch (Exception e)
    {
View Full Code Here

    }
    if (lastPos <= 0)
    {
      String error = "Invalid storage Instance info format: " + InstanceAddress;
      _logger.warn(error);
      throw new HelixException(error);
    }
    String host = InstanceAddress.substring(0, lastPos);
    String portStr = InstanceAddress.substring(lastPos + 1);
    int port = Integer.parseInt(portStr);
    addInstanceToCluster(clusterName, host, port);
View Full Code Here

    }
    if (lastPos <= 0)
    {
      String error = "Invalid storage Instance info format: " + InstanceAddress;
      _logger.warn(error);
      throw new HelixException(error);
    }
    String host = InstanceAddress.substring(0, lastPos);
    String portStr = InstanceAddress.substring(lastPos + 1);
    int port = Integer.parseInt(portStr);
    dropInstanceFromCluster(clusterName, host, port);
View Full Code Here

    // ensure node is stopped
    LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceId));
    if (liveInstance != null)
    {
      throw new HelixException("Can't drop " + instanceId + ", please stop " + instanceId
          + " before drop it");
    }

    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceId));
    if (config == null)
    {
      String error = "Node " + instanceId + " does not exist, cannot drop";
      _logger.warn(error);
      throw new HelixException(error);
    }

    // ensure node is disabled, otherwise fail
    if (config.getInstanceEnabled())
    {
      String error = "Node " + instanceId + " is enabled, cannot drop";
      _logger.warn(error);
      throw new HelixException(error);
    }
    _admin.dropInstance(clusterName, config);
  }
View Full Code Here

        accessor.getProperty(keyBuilder.instanceConfig(oldInstanceName));
    if (oldConfig == null)
    {
      String error = "Old instance " + oldInstanceName + " does not exist, cannot swap";
      _logger.warn(error);
      throw new HelixException(error);
    }

    InstanceConfig newConfig =
        accessor.getProperty(keyBuilder.instanceConfig(newInstanceName));
    if (newConfig == null)
    {
      String error = "New instance " + newInstanceName + " does not exist, cannot swap";
      _logger.warn(error);
      throw new HelixException(error);
    }

    // ensure old instance is disabled, otherwise fail
    if (oldConfig.getInstanceEnabled())
    {
      String error =
          "Old instance " + oldInstanceName
              + " is enabled, it need to be disabled and turned off";
      _logger.warn(error);
      throw new HelixException(error);
    }
    // ensure old instance is down, otherwise fail
    List<String> liveInstanceNames =
        accessor.getChildNames(accessor.keyBuilder().liveInstances());

    if (liveInstanceNames.contains(oldInstanceName))
    {
      String error =
          "Old instance " + oldInstanceName
              + " is still on, it need to be disabled and turned off";
      _logger.warn(error);
      throw new HelixException(error);
    }

    dropInstanceFromCluster(clusterName, oldInstanceName);

    List<IdealState> existingIdealStates =
View Full Code Here

                                  String propertyVal)
  {
    IdealState idealState = _admin.getResourceIdealState(clusterName, resourceName);
    if (idealState == null)
    {
      throw new HelixException("Resource: " + resourceName + " has NOT been added yet");
    }
    idealState.getRecord().setSimpleField(propertyKey, propertyVal);
    _admin.setResourceIdealState(clusterName, resourceName, idealState);
  }
View Full Code Here

                                     String propertyKey)
  {
    IdealState idealState = _admin.getResourceIdealState(clusterName, resourceName);
    if (idealState == null)
    {
      throw new HelixException("Resource: " + resourceName + " has NOT been added yet");
    }
    idealState.getRecord().getSimpleFields().remove(propertyKey);
    _admin.setResourceIdealState(clusterName, resourceName, idealState);
  }
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.