Search in sources :

Example 1 with DatasetId

use of io.cdap.cdap.proto.id.DatasetId in project cdap by caskdata.

the class RemotePermissionsTestBase method testVisibility.

@Test
public void testVisibility() throws Exception {
    ApplicationId app1 = NS.app("app1");
    ProgramId program1 = app1.program(ProgramType.SERVICE, "service1");
    ApplicationId app2 = NS.app("app2");
    ProgramId program2 = app2.program(ProgramType.MAPREDUCE, "service2");
    DatasetId ds = NS.dataset("ds");
    DatasetId ds1 = NS.dataset("ds1");
    DatasetId ds2 = NS.dataset("ds2");
    // Grant permissions on non-numbered entities to ALICE
    permissionManager.grant(Authorizable.fromEntityId(PROGRAM), ALICE, Collections.singleton(ApplicationPermission.EXECUTE));
    permissionManager.grant(Authorizable.fromEntityId(ds), ALICE, EnumSet.of(StandardPermission.GET, StandardPermission.UPDATE));
    // Grant permissions on entities ending with 2 to BOB
    permissionManager.grant(Authorizable.fromEntityId(program2), BOB, Collections.singleton(StandardPermission.UPDATE));
    permissionManager.grant(Authorizable.fromEntityId(ds2), BOB, EnumSet.of(StandardPermission.GET, StandardPermission.UPDATE));
    Set<? extends EntityId> allEntities = ImmutableSet.of(NS, APP, PROGRAM, ds, app1, program1, ds1, app2, program2, ds2);
    Assert.assertEquals(ImmutableSet.of(NS, APP, PROGRAM, ds), accessEnforcer.isVisible(allEntities, ALICE));
    Assert.assertEquals(ImmutableSet.of(NS, app2, program2, ds2), accessEnforcer.isVisible(allEntities, BOB));
    Assert.assertEquals(ImmutableSet.of(), accessEnforcer.isVisible(allEntities, CAROL));
    Assert.assertEquals(ImmutableSet.of(), accessEnforcer.isVisible(ImmutableSet.<EntityId>of(), ALICE));
    Assert.assertEquals(ImmutableSet.of(ds, APP), accessEnforcer.isVisible(ImmutableSet.of(ds, APP), ALICE));
    for (EntityId entityId : allEntities) {
        permissionManager.revoke(Authorizable.fromEntityId(entityId));
    }
}
Also used : EntityId(io.cdap.cdap.proto.id.EntityId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 2 with DatasetId

use of io.cdap.cdap.proto.id.DatasetId in project cdap by caskdata.

the class DescribeDatasetInstanceCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    DatasetMeta meta = datasetClient.get(instance);
    Table table = Table.builder().setHeader("hive table", "spec", "type", "principal").setRows(ImmutableList.of(meta), new RowMaker<DatasetMeta>() {

        @Override
        public List<?> makeRow(DatasetMeta object) {
            return Lists.newArrayList(object.getHiveTableName(), GSON.toJson(object.getSpec()), GSON.toJson(object.getType()), object.getOwnerPrincipal());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 3 with DatasetId

use of io.cdap.cdap.proto.id.DatasetId in project cdap by caskdata.

the class GetDatasetInstancePropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    Map<String, String> properties = datasetClient.getProperties(instance);
    Table table = Table.builder().setHeader("property", "value").setRows(Iterables.transform(properties.entrySet(), new Function<Map.Entry<String, String>, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(Map.Entry<String, String> entry) {
            return ImmutableList.of(entry.getKey(), entry.getValue());
        }
    })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Nullable(javax.annotation.Nullable) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 4 with DatasetId

use of io.cdap.cdap.proto.id.DatasetId in project cdap by caskdata.

the class DeleteDatasetInstanceCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId dataset = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    datasetClient.delete(dataset);
    output.printf("Successfully deleted dataset instance '%s'\n", dataset.getEntityName());
}
Also used : DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 5 with DatasetId

use of io.cdap.cdap.proto.id.DatasetId in project cdap by caskdata.

the class SetDatasetInstancePropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    Map<String, String> properties = ArgumentParser.parseMap(arguments.get(ArgumentName.DATASET_PROPERTIES.toString()), ArgumentName.DATASET_PROPERTIES.toString());
    datasetClient.updateExisting(instance, properties);
    output.printf("Successfully updated properties for dataset instance '%s' to %s", instance.getEntityName(), GSON.toJson(properties));
}
Also used : DatasetId(io.cdap.cdap.proto.id.DatasetId)

Aggregations

DatasetId (io.cdap.cdap.proto.id.DatasetId)184 Test (org.junit.Test)106 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)35 Path (javax.ws.rs.Path)27 ProgramId (io.cdap.cdap.proto.id.ProgramId)21 TransactionExecutor (org.apache.tephra.TransactionExecutor)21 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)19 QueryResult (io.cdap.cdap.proto.QueryResult)18 HashMap (java.util.HashMap)17 ColumnDesc (io.cdap.cdap.proto.ColumnDesc)16 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)16 Map (java.util.Map)16 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)15 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)15 HashSet (java.util.HashSet)15 Set (java.util.Set)15 Table (io.cdap.cdap.api.dataset.table.Table)14 POST (javax.ws.rs.POST)14 TransactionFailureException (org.apache.tephra.TransactionFailureException)14 Location (org.apache.twill.filesystem.Location)14