Search in sources :

Example 26 with DatasetId

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);
    }
}
Also used : ExploreExecutionResult(co.cask.cdap.explore.client.ExploreExecutionResult) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 27 with DatasetId

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));
}
Also used : ScheduleProgramInfo(co.cask.cdap.api.workflow.ScheduleProgramInfo) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 28 with DatasetId

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);
}
Also used : DatasetId(co.cask.cdap.proto.id.DatasetId) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with DatasetId

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);
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) StreamId(co.cask.cdap.proto.id.StreamId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ProgramId(co.cask.cdap.proto.id.ProgramId) TimeoutException(java.util.concurrent.TimeoutException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DatasetId(co.cask.cdap.proto.id.DatasetId) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ServiceManager(co.cask.cdap.test.ServiceManager) DummyApp(co.cask.cdap.test.app.DummyApp) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 30 with DatasetId

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);
}
Also used : HashMap(java.util.HashMap) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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