use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.
the class DatasetTypeService method listTypes.
/**
* Lists all {@link DatasetType dataset types} in the specified {@link NamespaceId}.
*/
List<DatasetTypeMeta> listTypes(final NamespaceId namespaceId) throws Exception {
ensureNamespaceExists(namespaceId);
// Sorting by name for convenience
List<DatasetTypeMeta> allTypes = Lists.newArrayList(typeManager.getTypes(namespaceId));
Collections.sort(allTypes, new Comparator<DatasetTypeMeta>() {
@Override
public int compare(DatasetTypeMeta o1, DatasetTypeMeta o2) {
return o1.getName().compareTo(o2.getName());
}
});
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
Iterable<DatasetTypeMeta> authorizedDatasetTypes = Iterables.filter(allTypes, new com.google.common.base.Predicate<DatasetTypeMeta>() {
@Override
public boolean apply(DatasetTypeMeta datasetTypeMeta) {
DatasetTypeId datasetTypeId = namespaceId.datasetType(datasetTypeMeta.getName());
return authFilter.apply(datasetTypeId);
}
});
return Lists.newArrayList(authorizedDatasetTypes);
}
use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.
the class DatasetTypeService method revokeAllPrivilegesOnModule.
private void revokeAllPrivilegesOnModule(DatasetModuleId moduleId, @Nullable DatasetModuleMeta moduleMeta) throws Exception {
privilegesManager.revoke(moduleId);
moduleMeta = moduleMeta == null ? typeManager.getModule(moduleId) : moduleMeta;
if (moduleMeta == null) {
LOG.debug("Could not find metadata for module {}. Will not revoke privileges for its types.", moduleId);
return;
}
for (String type : moduleMeta.getTypes()) {
DatasetTypeId datasetTypeId = moduleId.getParent().datasetType(type);
privilegesManager.revoke(datasetTypeId);
}
}
use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.
the class DatasetModulesDeployer method deployModules.
/**
* Deploy the given dataset modules.
*
* @param namespaceId namespace to deploy to
* @param modules the dataset modules to deploy
* @param jarLocation the location of the jar file containing the modules
* @throws Exception if there was a problem deploying a module
*/
void deployModules(NamespaceId namespaceId, Map<String, String> modules, Location jarLocation, ClassLoader artifactClassLoader) throws Exception {
List<String> implicitModules = new ArrayList<>();
for (Map.Entry<String, String> moduleEntry : modules.entrySet()) {
String moduleName = moduleEntry.getKey();
String typeName = moduleEntry.getValue();
if (systemDatasetFramework.hasSystemType(typeName)) {
LOG.info("Not adding dataset type '{}' because it is defined by the system.", typeName);
continue;
}
// Filter out the implicit modules: They have to be deployed last.
if (moduleName.startsWith(".implicit.")) {
implicitModules.add(typeName);
continue;
}
loadAndDeployModule(artifactClassLoader, typeName, jarLocation, moduleName, namespaceId);
}
for (String typeName : implicitModules) {
DatasetTypeId typeId = namespaceId.datasetType(typeName);
DatasetTypeMeta typeMeta = datasetFramework.getTypeInfo(typeId);
if (typeMeta != null) {
String existingModule = Iterables.getLast(typeMeta.getModules()).getName();
if (modules.containsKey(existingModule)) {
// it was deployed already as part of one of the explicit deployModule() calls
continue;
}
}
loadAndDeployModule(artifactClassLoader, typeName, jarLocation, typeName, namespaceId);
}
}
use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.
the class DatasetModulesDeployer method loadAndDeployModule.
private void loadAndDeployModule(ClassLoader artifactClassLoader, String className, Location jarLocation, String moduleName, NamespaceId namespaceId) throws ClassNotFoundException, IllegalAccessException, InstantiationException, DatasetManagementException {
// note: using app class loader to load module class
@SuppressWarnings("unchecked") Class<Dataset> clazz = (Class<Dataset>) artifactClassLoader.loadClass(className);
try {
// note: we can deploy module or create module from Dataset class
// note: it seems dangerous to instantiate dataset module here, but this will be fine when we move deploy into
// isolated user's environment (e.g. separate yarn container)
DatasetModuleId moduleId = namespaceId.datasetModule(moduleName);
DatasetModule module;
if (DatasetModule.class.isAssignableFrom(clazz)) {
module = (DatasetModule) clazz.newInstance();
} else if (Dataset.class.isAssignableFrom(clazz)) {
if (systemDatasetFramework.hasSystemType(clazz.getName())) {
return;
}
DatasetTypeId typeId = namespaceId.datasetType(clazz.getName());
if (datasetFramework.hasType(typeId) && !allowDatasetUncheckedUpgrade) {
return;
}
module = new SingleTypeModule(clazz);
} else {
throw new IllegalArgumentException(String.format("Cannot use class %s to add dataset module: it must be of type DatasetModule or Dataset", clazz.getName()));
}
LOG.info("Adding module: {}", clazz.getName());
datasetFramework.addModule(moduleId, module, jarLocation);
} catch (ModuleConflictException e) {
LOG.info("Conflict while deploying module {}: {}", moduleName, e.getMessage());
throw e;
}
}
use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.
the class CLIMainTest method testDataset.
@Test
public void testDataset() throws Exception {
String datasetName = PREFIX + "sdf123lkj";
String ownedDatasetName = PREFIX + "owned";
DatasetTypeClient datasetTypeClient = new DatasetTypeClient(cliConfig.getClientConfig());
DatasetTypeMeta datasetType = datasetTypeClient.list(NamespaceId.DEFAULT).get(0);
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName + " \"a=1\"", "Successfully created dataset");
testCommandOutputContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
testCommandOutputContains(cli, "get dataset instance properties " + datasetName, "a,1");
// test dataset creation with owner
String commandOutput = getCommandOutput(cli, "create dataset instance " + datasetType.getName() + " " + ownedDatasetName + " \"a=1\"" + " " + "someDescription " + ArgumentName.PRINCIPAL + " alice/somehost.net@somekdc.net");
Assert.assertTrue(commandOutput.contains("Successfully created dataset"));
Assert.assertTrue(commandOutput.contains("alice/somehost.net@somekdc.net"));
// test describing the table returns the given owner information
testCommandOutputContains(cli, "describe dataset instance " + ownedDatasetName, "alice/somehost.net@somekdc.net");
NamespaceClient namespaceClient = new NamespaceClient(cliConfig.getClientConfig());
NamespaceId barspace = new NamespaceId("bar");
namespaceClient.create(new NamespaceMeta.Builder().setName(barspace).build());
cliConfig.setNamespace(barspace);
// list of dataset instances is different in 'foo' namespace
testCommandOutputNotContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
// also can not create dataset instances if the type it depends on exists only in a different namespace.
DatasetTypeId datasetType1 = barspace.datasetType(datasetType.getName());
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName, new DatasetTypeNotFoundException(datasetType1).getMessage());
testCommandOutputContains(cli, "use namespace default", "Now using namespace 'default'");
try {
testCommandOutputContains(cli, "truncate dataset instance " + datasetName, "Successfully truncated");
} finally {
testCommandOutputContains(cli, "delete dataset instance " + datasetName, "Successfully deleted");
}
String datasetName2 = PREFIX + "asoijm39485";
String description = "test-description-for-" + datasetName2;
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName2 + " \"a=1\"" + " " + description, "Successfully created dataset");
testCommandOutputContains(cli, "list dataset instances", description);
testCommandOutputContains(cli, "delete dataset instance " + datasetName2, "Successfully deleted");
testCommandOutputContains(cli, "delete dataset instance " + ownedDatasetName, "Successfully deleted");
}
Aggregations