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;
}
});
}
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);
}
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));
}
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);
}
}
}
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());
}
}
Aggregations