use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetServiceAuthorizationTest method testNotFound.
@Test
public void testNotFound() throws Exception {
String namespace = NamespaceId.DEFAULT.getNamespace();
final DatasetId nonExistingInstance = NamespaceId.DEFAULT.dataset("notfound");
final DatasetModuleId nonExistingModule = NamespaceId.DEFAULT.datasetModule("notfound");
final DatasetTypeId nonExistingType = NamespaceId.DEFAULT.datasetType("notfound");
Assert.assertNull(dsFramework.getDatasetSpec(nonExistingInstance));
Assert.assertFalse(dsFramework.hasInstance(nonExistingInstance));
assertNotFound(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.updateInstance(nonExistingInstance, DatasetProperties.EMPTY);
}
}, String.format("Expected %s to not exist", nonExistingInstance));
assertNotFound(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.deleteInstance(nonExistingInstance);
}
}, String.format("Expected %s to not exist", nonExistingInstance));
assertNotFound(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.truncateInstance(nonExistingInstance);
}
}, String.format("Expected %s to not exist", nonExistingInstance));
assertNotFound(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.deleteModule(nonExistingModule);
}
}, String.format("Expected %s to not exist", nonExistingModule));
Assert.assertNull(String.format("Expected %s to not exist", nonExistingType), dsFramework.getTypeInfo(nonExistingType));
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetServiceAuthorizationTest method testDatasetTypes.
@Test
public void testDatasetTypes() throws Exception {
final DatasetModuleId module1 = NamespaceId.DEFAULT.datasetModule("module1");
final DatasetModuleId module2 = NamespaceId.DEFAULT.datasetModule("module2");
final DatasetTypeId type1 = NamespaceId.DEFAULT.datasetType("datasetType1");
DatasetTypeId type1x = NamespaceId.DEFAULT.datasetType("datasetType1x");
final DatasetTypeId type2 = NamespaceId.DEFAULT.datasetType("datasetType2");
SecurityRequestContext.setUserId(ALICE.getName());
final Location moduleJar = createModuleJar(TestModule1x.class);
assertAuthorizationFailure(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.addModule(module1, new TestModule1x(), moduleJar);
}
}, String.format("Expected module add operation to fail for %s because she does not have %s on %s", ALICE, Action.WRITE, NamespaceId.DEFAULT));
// grant alice WRITE on the namespace
grantAndAssertSuccess(NamespaceId.DEFAULT, ALICE, EnumSet.of(Action.WRITE));
dsFramework.addModule(module1, new TestModule1x(), moduleJar);
// all operations on module1 should succeed as alice
Assert.assertNotNull(dsFramework.getTypeInfo(type1));
Assert.assertNotNull(dsFramework.getTypeInfo(type1x));
// should be able to use the type from the module to add an instance as well
dsFramework.addInstance(type1x.getType(), NamespaceId.DEFAULT.dataset("succeed"), DatasetProperties.EMPTY);
// but should fail as Bob
SecurityRequestContext.setUserId(BOB.getName());
assertAuthorizationFailure(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.addInstance(type1.getType(), NamespaceId.DEFAULT.dataset("fail"), DatasetProperties.EMPTY);
}
}, String.format("Creating an instance of a type from %s should fail as %s does not have any privileges on it.", module1, BOB));
// granting WRITE on the namespace, BOB should now be able to create the dataset type
grantAndAssertSuccess(NamespaceId.DEFAULT, BOB, EnumSet.of(Action.WRITE));
// adding a module should now succeed as bob though, because bob has write privileges on the namespace
dsFramework.addModule(module2, new TestModule2(), createModuleJar(TestModule2.class));
// all operations on module2 should succeed as Bob
Assert.assertNotNull(dsFramework.getTypeInfo(type2));
// but should fail as Alice after revoking Alice rights to the namespace
SecurityRequestContext.setUserId(ALICE.getName());
authorizer.revoke(NamespaceId.DEFAULT, ALICE, EnumSet.allOf(Action.class));
assertAuthorizationFailure(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.addInstance(type2.getType(), NamespaceId.DEFAULT.dataset("fail"), DatasetProperties.EMPTY);
}
}, String.format("Creating an instance of a type from %s should fail as %s does not have any privileges on it.", module2, ALICE));
assertAuthorizationFailure(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.deleteModule(module2);
}
}, String.format("Deleting module %s should fail as %s does not have any privileges on it.", module2, ALICE));
SecurityRequestContext.setUserId(BOB.getName());
assertAuthorizationFailure(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.deleteModule(module1);
}
}, String.format("Deleting module %s should fail as %s does not have any privileges on it.", module1, BOB));
assertAuthorizationFailure(new DatasetOperationExecutor() {
@Override
public void execute() throws Exception {
dsFramework.deleteAllModules(NamespaceId.DEFAULT);
}
}, String.format("Deleting all modules in %s should fail as %s does not have ADMIN privileges on it.", NamespaceId.DEFAULT, BOB));
// Grant all permission for cleanup
grantAndAssertSuccess(NamespaceId.DEFAULT, ALICE, EnumSet.allOf(Action.class));
grantAndAssertSuccess(NamespaceId.DEFAULT, BOB, EnumSet.allOf(Action.class));
// delete all instances so modules can be deleted
dsFramework.deleteAllInstances(NamespaceId.DEFAULT);
SecurityRequestContext.setUserId(ALICE.getName());
dsFramework.deleteAllInstances(NamespaceId.DEFAULT);
SecurityRequestContext.setUserId(BOB.getName());
// After granting admin on the default namespace, deleting all modules should succeed
grantAndAssertSuccess(NamespaceId.DEFAULT, BOB, EnumSet.of(Action.ADMIN));
dsFramework.deleteAllModules(NamespaceId.DEFAULT);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetClientTestRun method testAll.
@Test
public void testAll() throws Exception {
DatasetModuleId module = TEST_NAMESPACE.datasetModule(StandaloneDatasetModule.NAME);
DatasetTypeId type = TEST_NAMESPACE.datasetType(StandaloneDataset.class.getName());
DatasetModuleId moduleInOtherNamespace = OTHER_NAMESPACE.datasetModule(StandaloneDatasetModule.NAME);
DatasetTypeId typeInOtherNamespace = OTHER_NAMESPACE.datasetType(StandaloneDataset.class.getName());
int numBaseModules = moduleClient.list(TEST_NAMESPACE).size();
int numBaseTypes = typeClient.list(TEST_NAMESPACE).size();
LOG.info("Adding Dataset module");
File moduleJarFile = createAppJarFile(StandaloneDatasetModule.class);
moduleClient.add(TEST_NAMESPACE.datasetModule(StandaloneDatasetModule.NAME), StandaloneDatasetModule.class.getName(), moduleJarFile);
Assert.assertEquals(numBaseModules + 1, moduleClient.list(TEST_NAMESPACE).size());
Assert.assertEquals(numBaseTypes + 2, typeClient.list(TEST_NAMESPACE).size());
LOG.info("Checking that the new Dataset module exists");
DatasetModuleMeta datasetModuleMeta = moduleClient.get(module);
Assert.assertNotNull(datasetModuleMeta);
Assert.assertEquals(StandaloneDatasetModule.NAME, datasetModuleMeta.getName());
LOG.info("Checking that the new Dataset module does not exist in a different namespace");
try {
moduleClient.get(moduleInOtherNamespace);
Assert.fail("datasetModule found in namespace other than one in which it was expected");
} catch (DatasetModuleNotFoundException expected) {
// expected
}
LOG.info("Checking that the new Dataset type exists");
DatasetTypeMeta datasetTypeMeta = typeClient.get(type);
Assert.assertNotNull(datasetTypeMeta);
Assert.assertEquals(type.getType(), datasetTypeMeta.getName());
datasetTypeMeta = typeClient.get(type);
Assert.assertNotNull(datasetTypeMeta);
Assert.assertEquals(StandaloneDataset.class.getName(), datasetTypeMeta.getName());
LOG.info("Checking that the new Dataset type does not exist in a different namespace");
try {
typeClient.get(typeInOtherNamespace);
Assert.fail("datasetType found in namespace other than one in which it was expected");
} catch (DatasetTypeNotFoundException expected) {
// expected
}
LOG.info("Creating, truncating, and deleting dataset of new Dataset type");
// Before creating dataset, there are some system datasets already exist
int numBaseDataset = datasetClient.list(TEST_NAMESPACE).size();
DatasetId instance = TEST_NAMESPACE.dataset("testDataset");
String description = "test description";
datasetClient.create(instance, new DatasetInstanceConfiguration(StandaloneDataset.TYPE_NAME, Collections.<String, String>emptyMap(), description, null));
Assert.assertEquals(numBaseDataset + 1, datasetClient.list(TEST_NAMESPACE).size());
// Assert dataset summary for the newly created dataset
DatasetSpecificationSummary expectedSpec = new DatasetSpecificationSummary(instance.getDataset(), StandaloneDataset.TYPE_NAME, description, Collections.<String, String>emptyMap());
Assert.assertEquals(expectedSpec, getSpecForDataset(instance, datasetClient.list(TEST_NAMESPACE)));
datasetClient.truncate(instance);
DatasetMeta metaBefore = datasetClient.get(instance);
Assert.assertEquals(0, metaBefore.getSpec().getProperties().size());
datasetClient.update(instance, ImmutableMap.of("sdf", "foo", "abc", "123"));
DatasetMeta metaAfter = datasetClient.get(instance);
Assert.assertEquals(2, metaAfter.getSpec().getProperties().size());
Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("sdf"));
Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("abc"));
Assert.assertEquals("foo", metaAfter.getSpec().getProperties().get("sdf"));
Assert.assertEquals("123", metaAfter.getSpec().getProperties().get("abc"));
datasetClient.updateExisting(instance, ImmutableMap.of("sdf", "fzz"));
metaAfter = datasetClient.get(instance);
Assert.assertEquals(2, metaAfter.getSpec().getProperties().size());
Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("sdf"));
Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("abc"));
Assert.assertEquals("fzz", metaAfter.getSpec().getProperties().get("sdf"));
Assert.assertEquals("123", metaAfter.getSpec().getProperties().get("abc"));
datasetClient.delete(instance);
Assert.assertEquals(numBaseDataset, datasetClient.list(TEST_NAMESPACE).size());
LOG.info("Creating and deleting multiple Datasets");
for (int i = 1; i <= 3; i++) {
datasetClient.create(TEST_NAMESPACE.dataset("testDataset" + i), StandaloneDataset.TYPE_NAME);
}
Assert.assertEquals(numBaseDataset + 3, datasetClient.list(TEST_NAMESPACE).size());
for (int i = 1; i <= 3; i++) {
datasetClient.delete(TEST_NAMESPACE.dataset("testDataset" + i));
}
Assert.assertEquals(numBaseDataset, datasetClient.list(TEST_NAMESPACE).size());
LOG.info("Deleting Dataset module");
moduleClient.delete(module);
Assert.assertEquals(numBaseModules, moduleClient.list(TEST_NAMESPACE).size());
Assert.assertEquals(numBaseTypes, typeClient.list(TEST_NAMESPACE).size());
LOG.info("Adding Dataset module and then deleting all Dataset modules");
moduleClient.add(TEST_NAMESPACE.datasetModule("testModule1"), StandaloneDatasetModule.class.getName(), moduleJarFile);
Assert.assertEquals(numBaseModules + 1, moduleClient.list(TEST_NAMESPACE).size());
Assert.assertEquals(numBaseTypes + 2, typeClient.list(TEST_NAMESPACE).size());
moduleClient.deleteAll(TEST_NAMESPACE);
Assert.assertEquals(numBaseModules, moduleClient.list(TEST_NAMESPACE).size());
Assert.assertEquals(numBaseTypes, typeClient.list(TEST_NAMESPACE).size());
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class HiveExploreServiceTestRun method testDeployNotRecordScannable.
@Test
public void testDeployNotRecordScannable() throws Exception {
// Try to deploy a dataset that is not record scannable, when explore is enabled.
// This should be processed with no exception being thrown
DatasetModuleId module2 = NAMESPACE_ID.datasetModule("module2");
DatasetId myTableNotRecordScannable = NAMESPACE_ID.dataset("my_table_not_record_scannable");
datasetFramework.addModule(module2, new NotRecordScannableTableDefinition.NotRecordScannableTableModule());
datasetFramework.addInstance("NotRecordScannableTableDef", myTableNotRecordScannable, DatasetProperties.EMPTY);
datasetFramework.deleteInstance(myTableNotRecordScannable);
datasetFramework.deleteModule(module2);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class HiveExploreStructuredRecordTestRun method start.
@BeforeClass
public static void start() throws Exception {
initialize(tmpFolder);
DatasetModuleId moduleId = NAMESPACE_ID.datasetModule("email");
datasetFramework.addModule(moduleId, new EmailTableDefinition.EmailTableModule());
datasetFramework.addInstance("email", MY_TABLE, DatasetProperties.EMPTY);
// Accessing dataset instance to perform data operations
EmailTableDefinition.EmailTable table = datasetFramework.getDataset(MY_TABLE, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx1 = transactionManager.startShort(100);
table.startTx(tx1);
table.writeEmail("email1", "this is the subject", "this is the body", "sljackson@boss.com");
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx1, table.getTxChanges());
transactionManager.commit(tx1);
table.postTxCommit();
datasetFramework.addModule(NAMESPACE_ID.datasetModule("TableWrapper"), new TableWrapperDefinition.Module());
}
Aggregations