Search in sources :

Example 41 with ProgramId

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));
}
Also used : AuditMessage(co.cask.cdap.proto.audit.AuditMessage) StreamId(co.cask.cdap.proto.id.StreamId) ArrayList(java.util.ArrayList) StreamProperties(co.cask.cdap.proto.StreamProperties) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ProgramId(co.cask.cdap.proto.id.ProgramId) AccessPayload(co.cask.cdap.proto.audit.payload.access.AccessPayload) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 42 with ProgramId

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);
}
Also used : AuditMessage(co.cask.cdap.proto.audit.AuditMessage) Table(co.cask.cdap.api.dataset.table.Table) ArrayList(java.util.ArrayList) AuthenticationTestContext(co.cask.cdap.security.auth.context.AuthenticationTestContext) NoOpAuthorizer(co.cask.cdap.security.spi.authorization.NoOpAuthorizer) NoOpUsageRegistry(co.cask.cdap.data2.registry.NoOpUsageRegistry) ProgramId(co.cask.cdap.proto.id.ProgramId) LineageWriterDatasetFramework(co.cask.cdap.data2.metadata.writer.LineageWriterDatasetFramework) LineageWriterDatasetFramework(co.cask.cdap.data2.metadata.writer.LineageWriterDatasetFramework) InMemoryTableModule(co.cask.cdap.data2.dataset2.module.lib.inmemory.InMemoryTableModule) AccessPayload(co.cask.cdap.proto.audit.payload.access.AccessPayload) NoOpLineageWriter(co.cask.cdap.data2.metadata.writer.NoOpLineageWriter) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 43 with ProgramId

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());
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) HashMap(java.util.HashMap) DatasetMeta(co.cask.cdap.proto.DatasetMeta) NotFoundException(co.cask.cdap.common.NotFoundException) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 44 with ProgramId

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()));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) HTable(org.apache.hadoop.hbase.client.HTable) Table(com.google.common.collect.Table) ProgramId(co.cask.cdap.proto.id.ProgramId) TransactionNotInProgressException(org.apache.tephra.TransactionNotInProgressException) TransactionFailureException(org.apache.tephra.TransactionFailureException) NotFoundException(co.cask.cdap.common.NotFoundException) SimpleQueueSpecificationGenerator(co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator) SimpleQueueSpecificationGenerator(co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator) QueueSpecificationGenerator(co.cask.cdap.app.queue.QueueSpecificationGenerator) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) QueueSpecification(co.cask.cdap.app.queue.QueueSpecification) ApplicationId(co.cask.cdap.proto.id.ApplicationId)

Example 45 with ProgramId

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());
}
Also used : Trigger(co.cask.cdap.api.schedule.Trigger) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) ProgramId(co.cask.cdap.proto.id.ProgramId)

Aggregations

ProgramId (co.cask.cdap.proto.id.ProgramId)259 Test (org.junit.Test)104 ApplicationId (co.cask.cdap.proto.id.ApplicationId)96 Path (javax.ws.rs.Path)62 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)45 DatasetId (co.cask.cdap.proto.id.DatasetId)40 RunId (org.apache.twill.api.RunId)40 NotFoundException (co.cask.cdap.common.NotFoundException)35 ProgramType (co.cask.cdap.proto.ProgramType)35 NamespaceId (co.cask.cdap.proto.id.NamespaceId)35 StreamId (co.cask.cdap.proto.id.StreamId)32 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)28 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 POST (javax.ws.rs.POST)24 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)23 GET (javax.ws.rs.GET)22 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)21 HttpResponse (org.apache.http.HttpResponse)20 HashMap (java.util.HashMap)19