Search in sources :

Example 21 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class LineageDataset method getEntitiesForRun.

/**
   * @return a set of entities (program and data it accesses) associated with a program run.
   */
public Set<NamespacedEntityId> getEntitiesForRun(ProgramRunId run) {
    ImmutableSet.Builder<NamespacedEntityId> recordBuilder = ImmutableSet.builder();
    byte[] startKey = getRunScanStartKey(run);
    try (Scanner scanner = accessRegistryTable.scan(startKey, Bytes.stopKeyForPrefix(startKey))) {
        Row row;
        while ((row = scanner.next()) != null) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Got row key = {}", Bytes.toString(row.getRow()));
            }
            RowKey rowKey = parseRow(row);
            if (run.getEntityName().equals(rowKey.getRunId().getId())) {
                recordBuilder.add(rowKey.getProgram());
                recordBuilder.add(rowKey.getData());
            }
        }
    }
    return recordBuilder.build();
}
Also used : Scanner(co.cask.cdap.api.dataset.table.Scanner) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) ImmutableSet(com.google.common.collect.ImmutableSet) Row(co.cask.cdap.api.dataset.table.Row)

Example 22 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class LineageDataset method toRelation.

private Relation toRelation(Row row) {
    Map<Character, EntityId> rowInfo = new HashMap<>(4);
    MDSKey.Splitter splitter = new MDSKey(row.getRow()).split();
    char marker = (char) splitter.getInt();
    LOG.trace("Got marker {}", marker);
    EntityId id1 = toEntityId(splitter, marker);
    LOG.trace("Got id1 {}", id1);
    rowInfo.put(marker, id1);
    // inverted time - not required for relation
    splitter.skipLong();
    marker = (char) splitter.getInt();
    LOG.trace("Got marker {}", marker);
    EntityId id2 = toEntityId(splitter, marker);
    LOG.trace("Got id2 {}", id1);
    rowInfo.put(marker, id2);
    RunId runId = RunIds.fromString(splitter.getString());
    LOG.trace("Got runId {}", runId);
    AccessType accessType = AccessType.fromType((char) splitter.getInt());
    LOG.trace("Got access type {}", accessType);
    DatasetId datasetInstance = (DatasetId) rowInfo.get(DATASET_MARKER);
    LOG.trace("Got datasetInstance {}", datasetInstance);
    StreamId stream = (StreamId) rowInfo.get(STREAM_MARKER);
    LOG.trace("Got stream {}", stream);
    ProgramId program = (ProgramId) rowInfo.get(PROGRAM_MARKER);
    LOG.trace("Got program {}", program);
    NamespacedEntityId component = toComponent(splitter, program);
    LOG.trace("Got component {}", component);
    if (stream == null) {
        return new Relation(datasetInstance, program, accessType, runId, component == null ? ImmutableSet.<NamespacedEntityId>of() : ImmutableSet.of((NamespacedEntityId) component));
    }
    return new Relation(stream, program, accessType, runId, component == null ? ImmutableSet.<NamespacedEntityId>of() : ImmutableSet.of((NamespacedEntityId) component));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) HashMap(java.util.HashMap) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) EntityId(co.cask.cdap.proto.id.EntityId) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) RunId(org.apache.twill.api.RunId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId)

Example 23 with NamespacedEntityId

use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.

the class MetadataStoreTest method testPublishing.

@Test
public void testPublishing() throws InterruptedException {
    generateMetadataUpdates();
    // Audit messages for metadata changes
    List<AuditMessage> actualAuditMessages = new ArrayList<>();
    for (AuditMessage auditMessage : auditPublisher.popMessages()) {
        // Ignore system audit messages
        if (auditMessage.getEntityId() instanceof NamespacedEntityId) {
            String systemNs = NamespaceId.SYSTEM.getNamespace();
            if (!((NamespacedEntityId) auditMessage.getEntityId()).getNamespace().equals(systemNs)) {
                actualAuditMessages.add(auditMessage);
            }
        }
    }
    Assert.assertEquals(expectedAuditMessages, actualAuditMessages);
}
Also used : AuditMessage(co.cask.cdap.proto.audit.AuditMessage) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

NamespacedEntityId (co.cask.cdap.proto.id.NamespacedEntityId)23 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)9 ProgramId (co.cask.cdap.proto.id.ProgramId)6 HashMap (java.util.HashMap)6 StreamId (co.cask.cdap.proto.id.StreamId)5 HashSet (java.util.HashSet)5 RunId (org.apache.twill.api.RunId)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Row (co.cask.cdap.api.dataset.table.Row)3 Scanner (co.cask.cdap.api.dataset.table.Scanner)3 Metadata (co.cask.cdap.data2.metadata.dataset.Metadata)3 AuditMessage (co.cask.cdap.proto.audit.AuditMessage)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Collection (java.util.Collection)3 LinkedHashSet (java.util.LinkedHashSet)3 Test (org.junit.Test)3 MethodArgument (co.cask.cdap.common.internal.remote.MethodArgument)2 MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)2