Search in sources :

Example 76 with DatasetId

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

the class UsageHandlerTestRun method testMapReduceUsage.

@Test
public void testMapReduceUsage() throws Exception {
    final ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
    final ProgramId program = app.mr(AllProgramsApp.NoOpMR.NAME);
    final StreamId stream = NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME);
    final DatasetId dataset = NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME);
    Assert.assertEquals(0, getAppStreamUsage(app).size());
    Assert.assertEquals(0, getProgramStreamUsage(program).size());
    Assert.assertEquals(0, getStreamProgramUsage(stream).size());
    Assert.assertEquals(0, getAppDatasetUsage(app).size());
    Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
    deployApp(AllProgramsApp.class);
    // now that we only support dynamic dataset instantiation in initialize (and not in configure as before),
    // we must run the mapreduce program to register its usage
    startProgram(program);
    waitState(program, ProgramStatus.STOPPED);
    try {
        Assert.assertTrue(getAppStreamUsage(app).contains(stream));
        Assert.assertTrue(getProgramStreamUsage(program).contains(stream));
        Assert.assertTrue(getStreamProgramUsage(stream).contains(program));
        Assert.assertTrue(getProgramDatasetUsage(program).contains(dataset));
        Assert.assertTrue(getAppDatasetUsage(app).contains(dataset));
        Assert.assertTrue(getDatasetProgramUsage(dataset).contains(program));
    } finally {
        deleteApp(app);
        Assert.assertEquals(0, getAppStreamUsage(app).size());
        Assert.assertEquals(0, getProgramStreamUsage(program).size());
        Assert.assertEquals(0, getStreamProgramUsage(stream).size());
        Assert.assertEquals(0, getAppDatasetUsage(app).size());
        Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 77 with DatasetId

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

the class UsageHandlerTestRun method testWorkerUsage.

@Test
public void testWorkerUsage() throws Exception {
    final ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
    final ProgramId program = app.worker(AllProgramsApp.NoOpWorker.NAME);
    final StreamId stream = NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME);
    final DatasetId dataset = NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME);
    Assert.assertEquals(0, getAppStreamUsage(app).size());
    Assert.assertEquals(0, getProgramStreamUsage(program).size());
    Assert.assertEquals(0, getStreamProgramUsage(stream).size());
    Assert.assertEquals(0, getAppDatasetUsage(app).size());
    Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
    deployApp(AllProgramsApp.class);
    try {
        startProgram(program);
        // Wait for the worker to run and then stop.
        waitState(program, ProgramStatus.RUNNING);
        waitState(program, ProgramStatus.STOPPED);
        Assert.assertTrue(getAppStreamUsage(app).contains(stream));
        Assert.assertTrue(getProgramStreamUsage(program).contains(stream));
        Assert.assertTrue(getStreamProgramUsage(stream).contains(program));
        Assert.assertTrue(getProgramDatasetUsage(program).contains(dataset));
        Assert.assertTrue(getAppDatasetUsage(app).contains(dataset));
        Assert.assertTrue(getDatasetProgramUsage(dataset).contains(program));
    } finally {
        deleteApp(app);
        Assert.assertEquals(0, getAppStreamUsage(app).size());
        Assert.assertEquals(0, getProgramStreamUsage(program).size());
        Assert.assertEquals(0, getStreamProgramUsage(stream).size());
        Assert.assertEquals(0, getAppDatasetUsage(app).size());
        Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 78 with DatasetId

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

the class UsageHandlerTestRun method testServiceUsage.

@Test
public void testServiceUsage() throws Exception {
    final ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
    final ProgramId program = app.service(AllProgramsApp.NoOpService.NAME);
    final DatasetId dataset = NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME);
    Assert.assertEquals(0, getAppDatasetUsage(app).size());
    Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
    deployApp(AllProgramsApp.class);
    try {
        Assert.assertTrue(getProgramDatasetUsage(program).contains(dataset));
        Assert.assertTrue(getAppDatasetUsage(app).contains(dataset));
        Assert.assertTrue(getDatasetProgramUsage(dataset).contains(program));
    } finally {
        deleteApp(app);
        Assert.assertEquals(0, getAppDatasetUsage(app).size());
        Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
    }
}
Also used : ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 79 with DatasetId

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

the class PartitionedFileSetAdmin method truncate.

@Override
public void truncate() throws IOException {
    super.truncate();
    // should fix this.
    if (FileSetProperties.isExploreEnabled(spec.getProperties())) {
        ExploreFacade exploreFacade = exploreFacadeProvider.get();
        if (exploreFacade != null) {
            DatasetId instanceId = new DatasetId(context.getNamespaceId(), spec.getName());
            try {
                exploreFacade.disableExploreDataset(instanceId, spec);
                exploreFacade.enableExploreDataset(instanceId, spec, true);
            } catch (Exception e) {
                throw new DataSetException(String.format("Unable to reset explore on dataset %s", instanceId), e);
            }
        }
    }
}
Also used : DataSetException(co.cask.cdap.api.dataset.DataSetException) ExploreFacade(co.cask.cdap.explore.client.ExploreFacade) IOException(java.io.IOException) DataSetException(co.cask.cdap.api.dataset.DataSetException) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 80 with DatasetId

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

the class DatasetServiceAuthorizationTest method testNotFound.

@Test
public void testNotFound() throws Exception {
    String namespace = NamespaceId.DEFAULT.getNamespace();
    final DatasetId nonExistingInstance = NamespaceId.DEFAULT.dataset("notfound");
    final DatasetModuleId nonExistingModule = NamespaceId.DEFAULT.datasetModule("notfound");
    final DatasetTypeId nonExistingType = NamespaceId.DEFAULT.datasetType("notfound");
    Assert.assertNull(dsFramework.getDatasetSpec(nonExistingInstance));
    Assert.assertFalse(dsFramework.hasInstance(nonExistingInstance));
    assertNotFound(new DatasetOperationExecutor() {

        @Override
        public void execute() throws Exception {
            dsFramework.updateInstance(nonExistingInstance, DatasetProperties.EMPTY);
        }
    }, String.format("Expected %s to not exist", nonExistingInstance));
    assertNotFound(new DatasetOperationExecutor() {

        @Override
        public void execute() throws Exception {
            dsFramework.deleteInstance(nonExistingInstance);
        }
    }, String.format("Expected %s to not exist", nonExistingInstance));
    assertNotFound(new DatasetOperationExecutor() {

        @Override
        public void execute() throws Exception {
            dsFramework.truncateInstance(nonExistingInstance);
        }
    }, String.format("Expected %s to not exist", nonExistingInstance));
    assertNotFound(new DatasetOperationExecutor() {

        @Override
        public void execute() throws Exception {
            dsFramework.deleteModule(nonExistingModule);
        }
    }, String.format("Expected %s to not exist", nonExistingModule));
    Assert.assertNull(String.format("Expected %s to not exist", nonExistingType), dsFramework.getTypeInfo(nonExistingType));
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) IOException(java.io.IOException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Aggregations

DatasetId (co.cask.cdap.proto.id.DatasetId)180 Test (org.junit.Test)96 ProgramId (co.cask.cdap.proto.id.ProgramId)34 StreamId (co.cask.cdap.proto.id.StreamId)34 Path (javax.ws.rs.Path)34 TransactionExecutor (org.apache.tephra.TransactionExecutor)31 NamespaceId (co.cask.cdap.proto.id.NamespaceId)25 ApplicationId (co.cask.cdap.proto.id.ApplicationId)23 IOException (java.io.IOException)19 POST (javax.ws.rs.POST)17 TransactionFailureException (org.apache.tephra.TransactionFailureException)17 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)16 QueryResult (co.cask.cdap.proto.QueryResult)16 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)15 ColumnDesc (co.cask.cdap.proto.ColumnDesc)14 Map (java.util.Map)13 NoSuchElementException (java.util.NoSuchElementException)13 Table (co.cask.cdap.api.dataset.table.Table)12 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)11 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11