use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class StreamAdminTest method testAuditPublish.
@Test
public void testAuditPublish() throws Exception {
// clear existing all messages
getInMemoryAuditPublisher().popMessages();
final List<AuditMessage> expectedMessages = new ArrayList<>();
StreamAdmin streamAdmin = getStreamAdmin();
StreamId stream1 = FOO_NAMESPACE.stream("stream1");
grantAndAssertSuccess(stream1, USER, EnumSet.of(Action.ADMIN));
streamAdmin.create(stream1);
expectedMessages.add(new AuditMessage(0, stream1, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
StreamId stream2 = FOO_NAMESPACE.stream("stream2");
grantAndAssertSuccess(stream2, USER, EnumSet.of(Action.ADMIN));
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));
// clean up privilege
revokeAndAssertSuccess(stream1, USER, EnumSet.of(Action.ADMIN));
revokeAndAssertSuccess(stream2, USER, EnumSet.of(Action.ADMIN));
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class AbstractDatasetFrameworkTest method testAuditPublish.
@Test
public void testAuditPublish() throws Exception {
// Clear all audit messages
inMemoryAuditPublisher.popMessages();
List<AuditMessage> expectedMessages = new ArrayList<>();
// Adding modules
DatasetFramework framework = getFramework();
framework.addModule(IN_MEMORY, new InMemoryTableModule());
// Creating instances
framework.addInstance(Table.class.getName(), MY_TABLE, DatasetProperties.EMPTY);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
framework.addInstance(Table.class.getName(), MY_TABLE2, DatasetProperties.EMPTY);
expectedMessages.add(new AuditMessage(0, MY_TABLE2, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
// Update instance
framework.updateInstance(MY_TABLE, DatasetProperties.EMPTY);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.UPDATE, AuditPayload.EMPTY_PAYLOAD));
// Access instance
ProgramRunId runId = new ProgramId("ns", "app", ProgramType.FLOW, "flow").run(RunIds.generate().getId());
LineageWriterDatasetFramework lineageFramework = new LineageWriterDatasetFramework(framework, new NoOpLineageWriter(), new NoOpUsageRegistry(), new AuthenticationTestContext(), new NoOpAuthorizer());
lineageFramework.setContext(new TestProgramContext(runId));
lineageFramework.setAuditPublisher(inMemoryAuditPublisher);
lineageFramework.getDataset(MY_TABLE, ImmutableMap.<String, String>of(), getClass().getClassLoader());
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.ACCESS, new AccessPayload(AccessType.UNKNOWN, runId)));
// Truncate instance
framework.truncateInstance(MY_TABLE);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.TRUNCATE, AuditPayload.EMPTY_PAYLOAD));
// Delete instance
framework.deleteInstance(MY_TABLE);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
// Delete all instances in a namespace
framework.deleteAllInstances(MY_TABLE2.getParent());
expectedMessages.add(new AuditMessage(0, MY_TABLE2, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
Assert.assertEquals(expectedMessages, inMemoryAuditPublisher.popMessages());
// cleanup
framework.deleteModule(IN_MEMORY);
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class DatasetInstanceServiceTest method testInstanceMetaCache.
@Test
public void testInstanceMetaCache() throws Exception {
// deploy a dataset
instanceService.create(NamespaceId.DEFAULT.getEntityName(), "testds", new DatasetInstanceConfiguration("table", new HashMap<String, String>()));
// get the dataset meta for two different owners, assert it is the same
DatasetMeta meta = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow1")));
DatasetMeta met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertSame(meta, met2);
// update the dataset
instanceService.update(NamespaceId.DEFAULT.dataset("testds"), ImmutableMap.of("ttl", "12345678"));
// get the dataset meta, validate it changed
met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertNotSame(meta, met2);
Assert.assertEquals("12345678", met2.getSpec().getProperty("ttl"));
// delete the dataset
instanceService.drop(NamespaceId.DEFAULT.dataset("testds"));
// get the dataset meta, validate not found
try {
instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow2")));
Assert.fail("get() should have thrown NotFoundException");
} catch (NotFoundException e) {
// expected
}
// recreate the dataset
instanceService.create(NamespaceId.DEFAULT.getNamespace(), "testds", new DatasetInstanceConfiguration("table", new HashMap<String, String>()));
// get the dataset meta, validate it is up to date
met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertEquals(meta.getSpec(), met2.getSpec());
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class HBaseQueueDebugger method scanQueues.
private void scanQueues(List<NamespaceMeta> namespaceMetas) throws Exception {
final QueueStatistics totalStats = new QueueStatistics();
for (NamespaceMeta namespaceMeta : namespaceMetas) {
final NamespaceId namespaceId = new NamespaceId(namespaceMeta.getName());
final Collection<ApplicationSpecification> apps = store.getAllApplications(namespaceId);
for (final ApplicationSpecification app : apps) {
ApplicationId appId = new ApplicationId(namespaceMeta.getName(), app.getName(), app.getAppVersion());
Collection<FlowSpecification> flows = app.getFlows().values();
for (final FlowSpecification flow : flows) {
final ProgramId flowId = appId.program(ProgramType.FLOW, flow.getName());
impersonator.doAs(flowId, new Callable<Void>() {
@Override
public Void call() throws Exception {
SimpleQueueSpecificationGenerator queueSpecGenerator = new SimpleQueueSpecificationGenerator(flowId.getParent());
Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> table = queueSpecGenerator.create(flow);
for (Table.Cell<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> cell : table.cellSet()) {
if (cell.getRowKey().getType() == FlowletConnection.Type.FLOWLET) {
for (QueueSpecification queue : cell.getValue()) {
QueueStatistics queueStats = scanQueue(queue.getQueueName(), null);
totalStats.add(queueStats);
}
}
}
return null;
}
});
}
}
}
System.out.printf("Total results for all queues: %s\n", totalStats.getReport(showTxTimestampOnly()));
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class DeleteAndCreateSchedulesStage method toProgramSchedule.
private ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleCreationSpec scheduleCreationSpec) {
ProgramId programId = appId.workflow(scheduleCreationSpec.getProgramName());
Trigger trigger = scheduleCreationSpec.getTrigger();
return new ProgramSchedule(scheduleCreationSpec.getName(), scheduleCreationSpec.getDescription(), programId, scheduleCreationSpec.getProperties(), trigger, scheduleCreationSpec.getConstraints(), scheduleCreationSpec.getTimeoutMillis());
}
Aggregations