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