Package org.apache.helix

Examples of org.apache.helix.HelixException


    {
      mapper.writeValue(sw, data);

      if (sw.toString().getBytes().length > ZNRecord.SIZE_LIMIT)
      {
        throw new HelixException("Data size larger than 1M. Write empty string to zk.");
      }
      return sw.toString().getBytes();

    }
    catch (Exception e)
View Full Code Here


      Map<String, String> existingStat, Map<String, String> incomingStat)
      throws HelixException
  {
    if (existingStat == null)
    {
      throw new HelixException("existing stat for merge is null");
    }
    if (incomingStat == null)
    {
      throw new HelixException("incoming stat for merge is null");
    }
    // get agg type and arguments, then get agg object
    String aggTypeStr = ExpressionParser.getAggregatorStr(statName);
    String[] aggArgs = ExpressionParser.getAggregatorArgs(statName);
    Aggregator agg = ExpressionParser.getAggregator(aggTypeStr);
    // XXX: some of below lines might fail with null exceptions

    // get timestamps, values out of zk maps
    String existingTime = existingStat.get(TIMESTAMP_NAME);
    String existingVal = existingStat.get(VALUE_NAME);
    String incomingTime = incomingStat.get(TIMESTAMP_NAME);
    String incomingVal = incomingStat.get(VALUE_NAME);
    // parse values into tuples, if the values exist. else, tuples are null
    Tuple<String> existingTimeTuple = (existingTime != null) ? Tuple
        .fromString(existingTime) : null;
    Tuple<String> existingValueTuple = (existingVal != null) ? Tuple
        .fromString(existingVal) : null;
    Tuple<String> incomingTimeTuple = (incomingTime != null) ? Tuple
        .fromString(incomingTime) : null;
    Tuple<String> incomingValueTuple = (incomingVal != null) ? Tuple
        .fromString(incomingVal) : null;

    // dp merge
    agg.merge(existingValueTuple, incomingValueTuple, existingTimeTuple,
        incomingTimeTuple, aggArgs);
    // put merged tuples back in map
    Map<String, String> mergedMap = new HashMap<String, String>();
    if (existingTimeTuple.size() == 0)
    {
      throw new HelixException("merged time tuple has size zero");
    }
    if (existingValueTuple.size() == 0)
    {
      throw new HelixException("merged value tuple has size zero");
    }

    mergedMap.put(TIMESTAMP_NAME, existingTimeTuple.toString());
    mergedMap.put(VALUE_NAME, existingValueTuple.toString());
    return mergedMap;
View Full Code Here

    double mergedVal;
    double mergedTime;
   
    if (currValTup == null || newValTup == null || currTimeTup == null ||
        newTimeTup == null) {
      throw new HelixException("Tuples cannot be null");
    }
   
    //old tuples may be empty, indicating no value/time exist
    if (currValTup.size() > 0 && currTimeTup.size() > 0) {
      currVal = Double.parseDouble(currValTup.iterator().next());
View Full Code Here

                                       stateModelDefRef,
                                       mode);
      }
      else
      {
        throw new HelixException("Unsupported command: " + command
            + ". Should be one of [" + ClusterSetup.addResource + "]");

      }

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

                                           String instanceName,
                                           Map<String, String> taskResultMap)
  {
    if (srcMessage.getCorrelationId() == null)
    {
      throw new HelixException("Message " + srcMessage.getMsgId()
          + " does not contain correlation id");
    }
    Message replyMessage =
        new Message(MessageType.TASK_REPLY, UUID.randomUUID().toString());
    replyMessage.setCorrelationId(srcMessage.getCorrelationId());
View Full Code Here

  {
    if (!(data instanceof ZNRecord))
    {
      // null is NOT an instance of any class
      logger.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 + ")");
    }

    ZNRecord record = (ZNRecord) data;
   
    // apply retention policy
    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));
        }
      }
    }

    // do serialization
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    serializationConfig.set(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
    serializationConfig.set(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
    StringWriter sw = new StringWriter();
    try
    {
      mapper.writeValue(sw, data);
    } catch (Exception e)
    {
      logger.error("Exception during data serialization. Will not write to zk. Data (first 1k): "
          + sw.toString().substring(0, 1024), e);
      throw new HelixException(e);
    }
   
    if (sw.toString().getBytes().length > ZNRecord.SIZE_LIMIT)
    {
      logger.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

    {
      String type = _message.getMsgType();
      HelixTaskResult result = new HelixTaskResult();
      if (!type.equals(MessageType.SCHEDULER_MSG.toString()))
      {
        throw new HelixException("Unexpected msg type for message "
            + _message.getMsgId() + " type:" + _message.getMsgType());
      }
      // Parse timeout value
      int timeOut = -1;
      if (_message.getRecord().getSimpleFields().containsKey("TIMEOUT"))
View Full Code Here

      }
    }

    if (nextIters.size() != 1)
    {
      throw new HelixException("operator pipeline produced " + nextIters.size()
          + " tuple sets instead of exactly 1");
    }

    return nextIters.get(0);
  }
View Full Code Here

    {
      aggComponent = matcher.group();
      aggComponent = aggComponent.substring(1, aggComponent.length() - 1);
      if (aggComponent.contains(")") || aggComponent.contains("("))
      {
        throw new HelixException(expression
            + " has invalid aggregate component");
      }
    }
    else
    {
      throw new HelixException(expression + " has invalid aggregate component");
    }
    if (matcher.find())
    {
      statComponent = matcher.group();
      statComponent = statComponent.substring(1, statComponent.length() - 1);
      // statComponent must have at least 1 arg between paren
      if (statComponent.contains(")") || statComponent.contains("(")
          || statComponent.length() == 0)
      {
        throw new HelixException(expression + " has invalid stat component");
      }
      lastMatchEnd = matcher.end();
    }
    else
    {
      throw new HelixException(expression + " has invalid stat component");
    }
    if (matcher.find())
    {
      throw new HelixException(expression
          + " has too many parenthesis components");
    }

    if (expression.length() >= lastMatchEnd + 1)
    { // lastMatchEnd is pos 1 past the pattern. check if there are paren there
      if (expression.substring(lastMatchEnd).contains("(")
          || expression.substring(lastMatchEnd).contains(")"))
      {
        throw new HelixException(expression + " has extra parenthesis");
      }
    }

    // check wildcard locations. each part can have at most 1 wildcard, and must
    // be at end
    // String expStatNamePart = expression.substring(expression.)
    StringTokenizer fieldTok = new StringTokenizer(statComponent,
        statFieldDelim);
    while (fieldTok.hasMoreTokens())
    {
      String currTok = fieldTok.nextToken();
      if (currTok.contains(wildcardChar))
      {
        if (currTok.indexOf(wildcardChar) != currTok.length() - 1
            || currTok.lastIndexOf(wildcardChar) != currTok.length() - 1)
        {
          throw new HelixException(currTok
              + " is illegal stat name.  Single wildcard must appear at end.");
        }
      }
    }
  }
View Full Code Here

  {
    aggStr = aggStr.toUpperCase();
    Aggregator agg = aggregatorMap.get(aggStr);
    if (agg == null)
    {
      throw new HelixException("Unknown aggregator type " + aggStr);
    }
    return agg;
  }
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.