Search in sources :

Example 11 with KeyParser

use of org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser in project hadoop by apache.

the class RollingLevelDBTimelineStore method addRelatedEntity.

/**
   * Parses the related entity from the given key at the given offset and adds
   * it to the given entity.
   */
private static void addRelatedEntity(TimelineEntity entity, byte[] key, int offset) throws IOException {
    KeyParser kp = new KeyParser(key, offset);
    String type = kp.getNextString();
    String id = kp.getNextString();
    entity.addRelatedEntity(type, id);
}
Also used : KeyParser(org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser)

Example 12 with KeyParser

use of org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser in project hadoop by apache.

the class RollingLevelDBTimelineStore method getDomains.

@Override
public TimelineDomains getDomains(String owner) throws IOException {
    DBIterator iterator = null;
    try {
        byte[] prefix = KeyBuilder.newInstance().add(owner).getBytesForLookup();
        List<TimelineDomain> domains = new ArrayList<TimelineDomain>();
        for (iterator = ownerdb.iterator(), iterator.seek(prefix); iterator.hasNext(); ) {
            byte[] key = iterator.peekNext().getKey();
            if (!prefixMatches(prefix, prefix.length, key)) {
                break;
            }
            // Iterator to parse the rows of an individual domain
            KeyParser kp = new KeyParser(key, prefix.length);
            String domainId = kp.getNextString();
            byte[] prefixExt = KeyBuilder.newInstance().add(owner).add(domainId).getBytesForLookup();
            TimelineDomain domainToReturn = getTimelineDomain(iterator, domainId, prefixExt);
            if (domainToReturn != null) {
                domains.add(domainToReturn);
            }
        }
        // Sort the domains to return
        Collections.sort(domains, new Comparator<TimelineDomain>() {

            @Override
            public int compare(TimelineDomain domain1, TimelineDomain domain2) {
                int result = domain2.getCreatedTime().compareTo(domain1.getCreatedTime());
                if (result == 0) {
                    return domain2.getModifiedTime().compareTo(domain1.getModifiedTime());
                } else {
                    return result;
                }
            }
        });
        TimelineDomains domainsToReturn = new TimelineDomains();
        domainsToReturn.addDomains(domains);
        return domainsToReturn;
    } finally {
        IOUtils.cleanup(LOG, iterator);
    }
}
Also used : DBIterator(org.iq80.leveldb.DBIterator) TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains) ArrayList(java.util.ArrayList) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) KeyParser(org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser)

Aggregations

KeyParser (org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser)12 IOException (java.io.IOException)6 KeyBuilder (org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyBuilder)3 LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 LRUMap (org.apache.commons.collections.map.LRUMap)2 GenericObjectMapper.readReverseOrderedLong (org.apache.hadoop.yarn.server.timeline.GenericObjectMapper.readReverseOrderedLong)2 GenericObjectMapper.writeReverseOrderedLong (org.apache.hadoop.yarn.server.timeline.GenericObjectMapper.writeReverseOrderedLong)2 DBIterator (org.iq80.leveldb.DBIterator)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TimelineDomain (org.apache.hadoop.yarn.api.records.timeline.TimelineDomain)1 TimelineDomains (org.apache.hadoop.yarn.api.records.timeline.TimelineDomains)1 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)1 DB (org.iq80.leveldb.DB)1