Package org.apache.helix

Examples of org.apache.helix.ZNRecord


    // test async create
    List<String> createPaths =
        Arrays.asList("/test/child1/child1", "/test/child2/child2");
    List<ZNRecord> createRecords =
        Arrays.asList(new ZNRecord("child1"), new ZNRecord("child2"));

    boolean[] needCreate = new boolean[createPaths.size()];
    Arrays.fill(needCreate, true);
    List<List<String>> pathsCreated =
        new ArrayList<List<String>>(Collections.<List<String>> nCopies(createPaths.size(),
                                                                       null));
    accessor.create(createPaths,
                    createRecords,
                    needCreate,
                    pathsCreated,
                    AccessOption.PERSISTENT);
    System.out.println("pathsCreated: " + pathsCreated);

    // test async set
    List<String> setPaths =
        Arrays.asList("/test/setChild1/setChild1", "/test/setChild2/setChild2");
    List<ZNRecord> setRecords =
        Arrays.asList(new ZNRecord("setChild1"), new ZNRecord("setChild2"));

    pathsCreated =
        new ArrayList<List<String>>(Collections.<List<String>> nCopies(setPaths.size(),
                                                                       null));
    boolean[] success =
        accessor.set(setPaths, setRecords, pathsCreated, null, AccessOption.PERSISTENT);
    System.out.println("pathsCreated: " + pathsCreated);
    System.out.println("setSuccess: " + Arrays.toString(success));

    // test async update
    List<String> updatePaths =
        Arrays.asList("/test/updateChild1/updateChild1", "/test/setChild2/setChild2");
    class TestUpdater implements DataUpdater<ZNRecord>
    {
      final ZNRecord _newData;

      public TestUpdater(ZNRecord newData)
      {
        _newData = newData;
      }

      @Override
      public ZNRecord update(ZNRecord currentData)
      {
        return _newData;

      }
    }
    List<DataUpdater<ZNRecord>> updaters =
        Arrays.asList((DataUpdater<ZNRecord>) new TestUpdater(new ZNRecord("updateChild1")),
                      (DataUpdater<ZNRecord>) new TestUpdater(new ZNRecord("updateChild2")));

    pathsCreated =
        new ArrayList<List<String>>(Collections.<List<String>> nCopies(updatePaths.size(),
                                                                       null));
View Full Code Here


  public void persistAggStats(HelixManager manager)
  {
    Map<String, String> report = _aggStatsProvider.getRecentHealthReport();
    Map<String, Map<String, String>> partitionReport =
        _aggStatsProvider.getRecentPartitionHealthReport();
    ZNRecord record = new ZNRecord(_aggStatsProvider.getReportName());
    if (report != null)
    {
      record.setSimpleFields(report);
    }
    if (partitionReport != null)
    {
      record.setMapFields(partitionReport);
    }

//    DataAccessor accessor = manager.getDataAccessor();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
//    boolean retVal = accessor.setProperty(PropertyType.PERSISTENTSTATS, record);
View Full Code Here

      HelixDataAccessor accessor = manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();

      HelixProperty property = accessor.getProperty(keyBuilder.alertHistory());
      ZNRecord alertFiredHistory;
      if(property == null)
      {
        alertFiredHistory = new ZNRecord(PropertyType.ALERT_HISTORY.toString());
      }
      else
      {
        alertFiredHistory = property.getRecord();
      }
      while(alertFiredHistory.getMapFields().size() >= ALERT_HISTORY_SIZE)
      {
        // ZNRecord uses TreeMap which is sorted ascending internally
        String firstKey = (String)(alertFiredHistory.getMapFields().keySet().toArray()[0]);
        alertFiredHistory.getMapFields().remove(firstKey);
      }
      alertFiredHistory.setMapField(date, delta);
//      manager.getDataAccessor().setProperty(PropertyType.ALERT_HISTORY, alertFiredHistory);
      accessor.setProperty(keyBuilder.alertHistory(), new AlertHistory(alertFiredHistory));
      _alertBeanCollection.setAlertHistory(alertFiredHistory);
    }
  }
View Full Code Here

    ;
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    List<String> hostedEntities =
        setupTool.getClusterManagementTool().getResourcesInCluster(clusterName);

    ZNRecord hostedEntitiesRecord = new ZNRecord("ResourceGroups");
    hostedEntitiesRecord.setListField("ResourceGroups", hostedEntities);

    StringRepresentation representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord),
                                 MediaType.APPLICATION_JSON);
View Full Code Here

    this(type.toString(), msgId);
  }

  public Message(String type, String msgId)
  {
    super(new ZNRecord(msgId));
    _record.setSimpleField(Attributes.MSG_TYPE.toString(), type);
    setMsgId(msgId);
    setMsgState(MessageState.NEW);
    _record.setSimpleField(Attributes.CREATE_TIMESTAMP.toString(),
                           "" + new Date().getTime());
View Full Code Here

    _record.setSimpleField(Attributes.CREATE_TIMESTAMP.toString(), "" + timestamp);
  }

  public Message(ZNRecord record, String id)
  {
    super(new ZNRecord(record, id));
    setMsgId(id);
  }
View Full Code Here

    case EXTERNALVIEW:
      // check if bucketized
      if (value.getBucketSize() > 0)
      {
        // set parent node
        ZNRecord metaRecord = new ZNRecord(value.getId());
        metaRecord.setSimpleFields(value.getRecord().getSimpleFields());
        success = _baseDataAccessor.set(path, metaRecord, options);
        if (success)
        {
          ZNRecordBucketizer bucketizer = new ZNRecordBucketizer(value.getBucketSize());
View Full Code Here

    // check if bucketized
    for (int i = 0; i < keys.size(); i++)
    {
      PropertyKey key = keys.get(i);
      ZNRecord record = children.get(i);

      PropertyType type = key.getType();
      String path = key.getPath();
      int options = constructOptions(type);
      // ZNRecord record = null;

      switch (type)
      {
      case CURRENTSTATES:
      case IDEALSTATES:
      case EXTERNALVIEW:
        // check if bucketized
        if (record != null)
        {
          HelixProperty property = new HelixProperty(record);

          int bucketSize = property.getBucketSize();
          if (bucketSize > 0)
          {
            List<ZNRecord> childRecords =
                _baseDataAccessor.getChildren(path, null, options);
            ZNRecord assembledRecord = new ZNRecordAssembler().assemble(childRecords);

            // merge with parent node value
            if (assembledRecord != null)
            {
              record.getSimpleFields().putAll(assembledRecord.getSimpleFields());
              record.getListFields().putAll(assembledRecord.getListFields());
              record.getMapFields().putAll(assembledRecord.getMapFields());
            }
          }
        }
        break;
      default:
View Full Code Here

  public <T extends HelixProperty> T getProperty(PropertyKey key)
  {
    PropertyType type = key.getType();
    String path = key.getPath();
    int options = constructOptions(type);
    ZNRecord record = null;
    try
    {
      Stat stat = new Stat();
      record = _baseDataAccessor.get(path, stat, options);
      if (record != null)
      {
        record.setCreationTime(stat.getCtime());
        record.setModifiedTime(stat.getMtime());
      }
    }
    catch (ZkNoNodeException e)
    {
      // OK
    }

    switch (type)
    {
    case CURRENTSTATES:
    case IDEALSTATES:
    case EXTERNALVIEW:
      // check if bucketized
      if (record != null)
      {
        HelixProperty property = new HelixProperty(record);

        int bucketSize = property.getBucketSize();
        if (bucketSize > 0)
        {
          List<ZNRecord> childRecords =
              _baseDataAccessor.getChildren(path, null, options);
          ZNRecord assembledRecord = new ZNRecordAssembler().assemble(childRecords);

          // merge with parent node value
          if (assembledRecord != null)
          {
            record.getSimpleFields().putAll(assembledRecord.getSimpleFields());
            record.getListFields().putAll(assembledRecord.getListFields());
            record.getMapFields().putAll(assembledRecord.getMapFields());
          }
        }
      }
      break;
    default:
View Full Code Here

            {
              // TODO: fix this if record.id != pathName
              String childPath = parentPath + "/" + record.getId();
              List<ZNRecord> childRecords =
                  _baseDataAccessor.getChildren(childPath, null, options);
              ZNRecord assembledRecord = new ZNRecordAssembler().assemble(childRecords);

              // merge with parent node value
              if (assembledRecord != null)
              {
                record.getSimpleFields().putAll(assembledRecord.getSimpleFields());
                record.getListFields().putAll(assembledRecord.getListFields());
                record.getMapFields().putAll(assembledRecord.getMapFields());
              }
            }
          }

          break;
View Full Code Here

TOP

Related Classes of org.apache.helix.ZNRecord

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.