use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class WritableDatasetTestRun method multipleInsertsTest.
@Test
public void multipleInsertsTest() throws Exception {
DatasetId myTable1 = NAMESPACE_ID.dataset("my_table_1");
DatasetId myTable2 = NAMESPACE_ID.dataset("my_table_2");
DatasetId myTable3 = NAMESPACE_ID.dataset("my_table_3");
String myTable1HiveName = getDatasetHiveName(myTable1);
String myTable2HiveName = getDatasetHiveName(myTable2);
String myTable3HiveName = getDatasetHiveName(myTable3);
try {
initKeyValueTable(MY_TABLE, true);
initKeyValueTable(myTable1, false);
initKeyValueTable(myTable2, false);
initKeyValueTable(myTable3, false);
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(NAMESPACE_ID, String.format("from %s insert into table %s select * where key='1' " + "insert into table %s select * where key='2' " + "insert into table %s select *", MY_TABLE_NAME, myTable1HiveName, myTable2HiveName, myTable3HiveName));
ExploreExecutionResult result = future.get();
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + myTable2HiveName).get();
Assert.assertEquals("2_2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + myTable1HiveName).get();
Assert.assertEquals("1_2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + myTable3HiveName).get();
Assert.assertEquals("1_2", result.next().getColumns().get(0).toString());
Assert.assertEquals("2_2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
} finally {
datasetFramework.deleteInstance(MY_TABLE);
datasetFramework.deleteInstance(myTable1);
datasetFramework.deleteInstance(myTable2);
datasetFramework.deleteInstance(myTable3);
}
}
use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class ProtoTriggerCodecTest method testObjectContainingTrigger.
@Test
public void testObjectContainingTrigger() {
ScheduleDetail sched1 = new ScheduleDetail("sched1", "one partition schedule", new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "ww"), ImmutableMap.of("prop3", "abc"), new ProtoTrigger.PartitionTrigger(new DatasetId("test1", "pdfs1"), 1), ImmutableList.<Constraint>of(), null);
ScheduleDetail sched2 = new ScheduleDetail("schedone", "one time schedule", new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "wf112"), ImmutableMap.of("prop", "all"), new ProtoTrigger.TimeTrigger("* * * 1 1"), ImmutableList.<Constraint>of(), null);
Assert.assertEquals(sched1, GSON.fromJson(GSON.toJson(sched1), ScheduleDetail.class));
Assert.assertEquals(sched2, GSON.fromJson(GSON.toJson(sched2), ScheduleDetail.class));
}
use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class AuthorizerTest method testHierarchy.
@Test
// TODO: Enable when hierarchy is supported
@Ignore
public void testHierarchy() throws Exception {
Authorizer authorizer = get();
DatasetId dataset = namespace.dataset("bar");
verifyAuthFailure(namespace, user, Action.READ);
authorizer.grant(namespace, user, Collections.singleton(Action.READ));
authorizer.enforce(dataset, user, Action.READ);
authorizer.grant(dataset, user, Collections.singleton(Action.WRITE));
verifyAuthFailure(namespace, user, Action.WRITE);
authorizer.revoke(namespace, user, Collections.singleton(Action.READ));
authorizer.revoke(dataset);
verifyAuthFailure(namespace, user, Action.READ);
}
use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class AuthorizationTest method testPrograms.
@Test
public void testPrograms() throws Exception {
createAuthNamespace();
final ApplicationManager dummyAppManager = deployApplication(AUTH_NAMESPACE, DummyApp.class);
ArtifactSummary dummyArtifactSummary = dummyAppManager.getInfo().getArtifact();
ArtifactId dummyArtifact = AUTH_NAMESPACE.artifact(dummyArtifactSummary.getName(), dummyArtifactSummary.getVersion());
ApplicationId appId = AUTH_NAMESPACE.app(DummyApp.class.getSimpleName());
final ProgramId serviceId = appId.service(DummyApp.Greeting.SERVICE_NAME);
DatasetId dsId = AUTH_NAMESPACE.dataset("whom");
StreamId streamId = AUTH_NAMESPACE.stream("who");
assertAllAccess(ALICE, AUTH_NAMESPACE, dummyArtifact, appId, serviceId, dsId, streamId);
// alice should be able to start and stop programs in the app she deployed
dummyAppManager.startProgram(serviceId.toId());
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return dummyAppManager.isRunning(serviceId.toId());
}
}, 5, TimeUnit.SECONDS);
ServiceManager greetingService = dummyAppManager.getServiceManager(serviceId.getProgram());
// alice should be able to set instances for the program
greetingService.setInstances(2);
Assert.assertEquals(2, greetingService.getProvisionedInstances());
// alice should also be able to save runtime arguments for all future runs of the program
Map<String, String> args = ImmutableMap.of("key", "value");
greetingService.setRuntimeArgs(args);
// Alice should be able to get runtime arguments as she has ADMIN on it
Assert.assertEquals(args, greetingService.getRuntimeArgs());
dummyAppManager.stopProgram(serviceId.toId());
Tasks.waitFor(false, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return dummyAppManager.isRunning(serviceId.toId());
}
}, 5, TimeUnit.SECONDS);
// Bob should not be able to start programs in dummy app because he does not have privileges on it
SecurityRequestContext.setUserId(BOB.getName());
try {
dummyAppManager.startProgram(serviceId.toId());
Assert.fail("Bob should not be able to start the service because he does not have admin privileges on it.");
} catch (RuntimeException expected) {
//noinspection ThrowableResultOfMethodCallIgnored
Assert.assertTrue(Throwables.getRootCause(expected) instanceof UnauthorizedException);
}
try {
dummyAppManager.getInfo();
Assert.fail("Bob should not be able to read the app info with out privileges");
} catch (Exception expected) {
// expected
}
// setting instances should fail because Bob does not have admin privileges on the program
try {
greetingService.setInstances(3);
Assert.fail("Setting instances should have failed because bob does not have admin privileges on the service.");
} catch (RuntimeException expected) {
//noinspection ThrowableResultOfMethodCallIgnored
Assert.assertTrue(Throwables.getRootCause(expected) instanceof UnauthorizedException);
}
try {
greetingService.setRuntimeArgs(args);
Assert.fail("Setting runtime arguments should have failed because bob does not have admin privileges on the " + "service");
} catch (UnauthorizedException expected) {
// expected
}
try {
greetingService.getRuntimeArgs();
Assert.fail("Getting runtime arguments should have failed because bob does not have READ privileges on the " + "service");
} catch (UnauthorizedException expected) {
// expected
}
SecurityRequestContext.setUserId(ALICE.getName());
dummyAppManager.delete();
assertNoAccess(appId);
}
use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowLocalDatasets.
@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/localdatasets")
public void getWorkflowLocalDatasets(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException, DatasetManagementException {
WorkflowSpecification workflowSpec = getWorkflowSpecForValidRun(namespaceId, applicationId, workflowId, runId);
Map<String, DatasetSpecificationSummary> localDatasetSummaries = new HashMap<>();
for (Map.Entry<String, DatasetCreationSpec> localDatasetEntry : workflowSpec.getLocalDatasetSpecs().entrySet()) {
String mappedDatasetName = localDatasetEntry.getKey() + "." + runId;
String datasetType = localDatasetEntry.getValue().getTypeName();
Map<String, String> datasetProperties = localDatasetEntry.getValue().getProperties().getProperties();
if (datasetFramework.hasInstance(new DatasetId(namespaceId, mappedDatasetName))) {
localDatasetSummaries.put(localDatasetEntry.getKey(), new DatasetSpecificationSummary(mappedDatasetName, datasetType, datasetProperties));
}
}
responder.sendJson(HttpResponseStatus.OK, localDatasetSummaries);
}
Aggregations