use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.
the class LineageAdmin method getMetadataForRun.
/**
* @return metadata associated with a run
*/
public Set<MetadataRecord> getMetadataForRun(ProgramRunId run) throws NotFoundException {
entityExistenceVerifier.ensureExists(run);
Set<NamespacedEntityId> runEntities = new HashSet<>(lineageStoreReader.getEntitiesForRun(run));
// No entities associated with the run, but run exists.
if (runEntities.isEmpty()) {
return ImmutableSet.of();
}
RunId runId = RunIds.fromString(run.getRun());
// The entities returned by lineageStore does not contain application
ApplicationId application = run.getParent().getParent();
runEntities.add(application);
return metadataStore.getSnapshotBeforeTime(MetadataScope.USER, runEntities, RunIds.getTime(runId, TimeUnit.MILLISECONDS));
}
use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.
the class LineageAdmin method getRollupRelations.
private Multimap<RelationKey, Relation> getRollupRelations(Multimap<RelationKey, Relation> relations, Map<ProgramRunId, RunRecordMeta> runRecordMap, Map<String, ProgramRunId> workflowIdMap) throws NotFoundException {
Multimap<RelationKey, Relation> relationsNew = HashMultimap.create();
for (Map.Entry<RelationKey, Collection<Relation>> entry : relations.asMap().entrySet()) {
for (Relation relation : entry.getValue()) {
ProgramRunId workflowProgramRunId = getWorkflowProgramRunid(relation, runRecordMap, workflowIdMap);
if (workflowProgramRunId == null) {
relationsNew.put(entry.getKey(), relation);
} else {
ProgramId workflowProgramId = new ProgramId(workflowProgramRunId.getNamespace(), workflowProgramRunId.getApplication(), workflowProgramRunId.getType(), workflowProgramRunId.getProgram());
Relation workflowRelation;
NamespacedEntityId data = relation.getData();
if (data instanceof DatasetId) {
workflowRelation = new Relation((DatasetId) data, workflowProgramId, relation.getAccess(), RunIds.fromString(workflowProgramRunId.getRun()));
} else {
workflowRelation = new Relation((StreamId) data, workflowProgramId, relation.getAccess(), RunIds.fromString(workflowProgramRunId.getRun()));
}
relationsNew.put(entry.getKey(), workflowRelation);
}
}
}
return relationsNew;
}
use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchMetadata.
@Test
public void testSearchMetadata() throws Exception {
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(AllProgramsApp.class));
Map<NamespacedEntityId, Metadata> expectedUserMetadata = new HashMap<>();
// Add metadata to app
Map<String, String> props = ImmutableMap.of("key1", "value1");
Set<String> tags = ImmutableSet.of("tag1", "tag2");
ApplicationId appId = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
addProperties(appId, props);
addTags(appId, tags);
expectedUserMetadata.put(appId, new Metadata(props, tags));
// Add metadata to stream
props = ImmutableMap.of("key10", "value10", "key11", "value11");
tags = ImmutableSet.of("tag11");
StreamId streamId = NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME);
addProperties(streamId, props);
addTags(streamId, tags);
expectedUserMetadata.put(streamId, new Metadata(props, tags));
Set<MetadataSearchResultRecord> results = super.searchMetadata(NamespaceId.DEFAULT, "value*", ImmutableSet.<EntityTypeSimpleName>of());
// Verify results
Assert.assertEquals(expectedUserMetadata.keySet(), getEntities(results));
for (MetadataSearchResultRecord result : results) {
// User metadata has to match exactly since we know what we have set
Assert.assertEquals(expectedUserMetadata.get(result.getEntityId()), result.getMetadata().get(MetadataScope.USER));
// Make sure system metadata is returned, we cannot check for exact match since we haven't set it
Metadata systemMetadata = result.getMetadata().get(MetadataScope.SYSTEM);
Assert.assertNotNull(systemMetadata);
Assert.assertFalse(systemMetadata.getProperties().isEmpty());
Assert.assertFalse(systemMetadata.getTags().isEmpty());
}
}
use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.
the class StreamAdminTest method testAuditPublish.
@Test
public void testAuditPublish() throws Exception {
grantAndAssertSuccess(FOO_NAMESPACE, USER, EnumSet.allOf(Action.class));
// clear existing all messages
getInMemoryAuditPublisher().popMessages();
final List<AuditMessage> expectedMessages = new ArrayList<>();
StreamAdmin streamAdmin = getStreamAdmin();
StreamId stream1 = FOO_NAMESPACE.stream("stream1");
streamAdmin.create(stream1);
expectedMessages.add(new AuditMessage(0, stream1, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
StreamId stream2 = FOO_NAMESPACE.stream("stream2");
streamAdmin.create(stream2);
expectedMessages.add(new AuditMessage(0, stream2, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
streamAdmin.truncate(stream1);
expectedMessages.add(new AuditMessage(0, stream1, "", AuditType.TRUNCATE, AuditPayload.EMPTY_PAYLOAD));
streamAdmin.updateConfig(stream1, new StreamProperties(100L, new FormatSpecification("f", null), 100));
expectedMessages.add(new AuditMessage(0, stream1, "", AuditType.UPDATE, AuditPayload.EMPTY_PAYLOAD));
ProgramRunId run = new ProgramId("ns1", "app", ProgramType.FLOW, "flw").run(RunIds.generate().getId());
streamAdmin.addAccess(run, stream1, AccessType.READ);
expectedMessages.add(new AuditMessage(0, stream1, "", AuditType.ACCESS, new AccessPayload(co.cask.cdap.proto.audit.payload.access.AccessType.READ, run)));
streamAdmin.drop(stream1);
expectedMessages.add(new AuditMessage(0, stream1, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
streamAdmin.dropAllInNamespace(FOO_NAMESPACE);
expectedMessages.add(new AuditMessage(0, stream2, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
// Ignore audit messages for system namespace (creation of system datasets, etc)
final String systemNs = NamespaceId.SYSTEM.getNamespace();
final Iterable<AuditMessage> actualMessages = Iterables.filter(getInMemoryAuditPublisher().popMessages(), new Predicate<AuditMessage>() {
@Override
public boolean apply(AuditMessage input) {
return !(input.getEntityId() instanceof NamespacedEntityId && ((NamespacedEntityId) input.getEntityId()).getNamespace().equals(systemNs));
}
});
Assert.assertEquals(expectedMessages, Lists.newArrayList(actualMessages));
}
use of co.cask.cdap.proto.id.NamespacedEntityId in project cdap by caskdata.
the class RemoteLineageWriterHandler method addStreamAccess.
@POST
@Path("/addStreamAccess")
public void addStreamAccess(HttpRequest request, HttpResponder responder) throws Exception {
Iterator<MethodArgument> arguments = parseArguments(request);
ProgramRunId run = deserializeNext(arguments);
StreamId stream = deserializeNext(arguments);
AccessType accessType = deserializeNext(arguments);
NamespacedEntityId component = deserializeNext(arguments);
lineageWriter.addAccess(run, stream, accessType, component);
responder.sendStatus(HttpResponseStatus.OK);
}
Aggregations