Search in sources :

Example 16 with DatasetId

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

the class ExploreExecutorHttpHandler method addPartition.

@POST
@Path("datasets/{dataset}/partitions")
public void addPartition(final HttpRequest request, final HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName, @HeaderParam(Constants.Security.Headers.PROGRAM_ID) String programId) throws Exception {
    final DatasetId datasetId = new DatasetId(namespace, datasetName);
    propagateUserId(request);
    impersonator.doAs(getEntityToImpersonate(datasetId, programId), new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            doAddPartition(request, responder, datasetId);
            return null;
        }
    });
}
Also used : BadRequestException(co.cask.cdap.common.BadRequestException) ExploreException(co.cask.cdap.explore.service.ExploreException) SQLException(java.sql.SQLException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) JsonSyntaxException(com.google.gson.JsonSyntaxException) UnsupportedTypeException(co.cask.cdap.api.data.schema.UnsupportedTypeException) IOException(java.io.IOException) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 17 with DatasetId

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

the class ExploreExecutorHttpHandler method enableDataset.

/**
   * Enable ad-hoc exploration of a dataset instance.
   */
@POST
@Path("datasets/{dataset}/enable")
public void enableDataset(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) {
    DatasetId datasetId = new DatasetId(namespace, datasetName);
    DatasetSpecification datasetSpec = retrieveDatasetSpec(responder, datasetId);
    if (datasetSpec == null) {
        // this means the spec could not be retrieved and retrievedDatasetSpec() already responded
        return;
    }
    enableDataset(responder, datasetId, datasetSpec, false);
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 18 with DatasetId

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

the class NamespaceHttpHandlerTest method testDeleteDatasetsOnly.

@Test
public void testDeleteDatasetsOnly() throws Exception {
    CConfiguration cConf = getInjector().getInstance(CConfiguration.class);
    // test deleting non-existent namespace
    assertResponseCode(200, createNamespace(NAME));
    assertResponseCode(200, getNamespace(NAME));
    NamespacedLocationFactory namespacedLocationFactory = getInjector().getInstance(NamespacedLocationFactory.class);
    Location nsLocation = namespacedLocationFactory.get(new NamespaceId(NAME));
    Assert.assertTrue(nsLocation.exists());
    DatasetFramework dsFramework = getInjector().getInstance(DatasetFramework.class);
    deploy(AppWithServices.class, Constants.Gateway.API_VERSION_3_TOKEN, NAME);
    deploy(AppWithDataset.class, Constants.Gateway.API_VERSION_3_TOKEN, NAME);
    DatasetId myDataset = new DatasetId(NAME, "myds");
    Assert.assertTrue(dsFramework.hasInstance(myDataset));
    Id.Program program = Id.Program.from(NAME_ID, "AppWithServices", ProgramType.SERVICE, "NoOpService");
    startProgram(program);
    boolean resetEnabled = cConf.getBoolean(Constants.Dangerous.UNRECOVERABLE_RESET);
    cConf.setBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, false);
    // because reset is not enabled
    assertResponseCode(403, deleteNamespaceData(NAME));
    Assert.assertTrue(nsLocation.exists());
    cConf.setBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, resetEnabled);
    // because service is running
    assertResponseCode(409, deleteNamespaceData(NAME));
    Assert.assertTrue(nsLocation.exists());
    stopProgram(program);
    assertResponseCode(200, deleteNamespaceData(NAME));
    Assert.assertTrue(nsLocation.exists());
    Assert.assertTrue(getAppList(NAME).size() == 2);
    Assert.assertTrue(getAppDetails(NAME, "AppWithServices").get("name").getAsString().equals("AppWithServices"));
    Assert.assertTrue(getAppDetails(NAME, AppWithDataset.class.getSimpleName()).get("name").getAsString().equals(AppWithDataset.class.getSimpleName()));
    assertResponseCode(200, getNamespace(NAME));
    Assert.assertFalse(dsFramework.hasInstance(myDataset));
    assertResponseCode(200, deleteNamespace(NAME));
    assertResponseCode(404, getNamespace(NAME));
}
Also used : DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) NamespaceId(co.cask.cdap.proto.id.NamespaceId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) StreamId(co.cask.cdap.proto.id.StreamId) DatasetId(co.cask.cdap.proto.id.DatasetId) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Location(org.apache.twill.filesystem.Location) DatasetId(co.cask.cdap.proto.id.DatasetId) AppWithDataset(co.cask.cdap.AppWithDataset) AppForUnrecoverableResetTest(co.cask.cdap.AppForUnrecoverableResetTest) Test(org.junit.Test)

Example 19 with DatasetId

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

the class QueryClientTest method testAll.

@Test
public void testAll() throws Exception {
    NamespaceId namespace = new NamespaceId("queryClientTestNamespace");
    NamespaceId otherNamespace = new NamespaceId("queryClientOtherNamespace");
    namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
    ApplicationId app = namespace.app(FakeApp.NAME);
    FlowId flow = app.flow(FakeFlow.NAME);
    DatasetId dataset = namespace.dataset(FakeApp.DS_NAME);
    appClient.deploy(namespace, createAppJarFile(FakeApp.class));
    try {
        programClient.start(flow);
        assertProgramRunning(programClient, flow);
        StreamId stream = namespace.stream(FakeApp.STREAM_NAME);
        streamClient.sendEvent(stream, "bob:123");
        streamClient.sendEvent(stream, "joe:321");
        Thread.sleep(3000);
        executeBasicQuery(namespace, FakeApp.DS_NAME);
        exploreClient.disableExploreDataset(dataset).get();
        try {
            queryClient.execute(namespace, "select * from " + FakeApp.DS_NAME).get();
            Assert.fail("Explore Query should have thrown an ExecutionException since explore is disabled");
        } catch (ExecutionException e) {
        // ignored
        }
        exploreClient.enableExploreDataset(dataset).get();
        executeBasicQuery(namespace, FakeApp.DS_NAME);
        try {
            queryClient.execute(otherNamespace, "show tables").get();
            Assert.fail("Explore Query should have thrown an ExecutionException since the database should not exist");
        } catch (ExecutionException e) {
        // expected
        }
    } finally {
        programClient.stop(flow);
        assertProgramStopped(programClient, flow);
        try {
            appClient.delete(app);
        } catch (Exception e) {
            LOG.error("Error deleting app {} during test cleanup.", e);
        }
    }
}
Also used : FlowId(co.cask.cdap.proto.id.FlowId) FakeApp(co.cask.cdap.client.app.FakeApp) StreamId(co.cask.cdap.proto.id.StreamId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 20 with DatasetId

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

the class UsageHandlerTestRun method testSparkUsage.

@Test
public void testSparkUsage() throws Exception {
    final ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
    final ProgramId program = app.spark(AllProgramsApp.NoOpSpark.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 {
        // the program will run and stop by itself.
        startProgram(program);
        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());
    }
    deployApp(AllProgramsApp.class);
    try {
        // the program will run and stop by itself.
        startProgram(program);
        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)

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