use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeService method getModule.
/**
* Returns the {@link DatasetModuleMeta metadata} of the specified {@link DatasetModuleId}.
*/
DatasetModuleMeta getModule(DatasetModuleId datasetModuleId) throws Exception {
ensureNamespaceExists(datasetModuleId.getParent());
DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
if (moduleMeta == null) {
throw new DatasetModuleNotFoundException(datasetModuleId);
}
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
if (!filter.apply(datasetModuleId)) {
throw new UnauthorizedException(principal, datasetModuleId);
}
return moduleMeta;
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeService method listModules.
/**
* Returns all {@link DatasetModuleMeta dataset modules} in the specified {@link NamespaceId namespace}.
*/
List<DatasetModuleMeta> listModules(final NamespaceId namespaceId) throws Exception {
ensureNamespaceExists(namespaceId);
// Sorting by name for convenience
List<DatasetModuleMeta> allModules = Lists.newArrayList(typeManager.getModules(namespaceId));
Collections.sort(allModules, new Comparator<DatasetModuleMeta>() {
@Override
public int compare(DatasetModuleMeta o1, DatasetModuleMeta o2) {
return o1.getName().compareTo(o2.getName());
}
});
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
Iterable<DatasetModuleMeta> authorizedDatasetModules = Iterables.filter(allModules, new com.google.common.base.Predicate<DatasetModuleMeta>() {
@Override
public boolean apply(DatasetModuleMeta datasetModuleMeta) {
return authFilter.apply(namespaceId.datasetModule(datasetModuleMeta.getName()));
}
});
return Lists.newArrayList(authorizedDatasetModules);
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class GenerateClientUsageExample method datasetModuleClient.
public void datasetModuleClient() throws Exception {
// Construct the client used to interact with CDAP
DatasetModuleClient datasetModuleClient = new DatasetModuleClient(clientConfig);
// Add a dataset module
File moduleJarFile = createAppJarFile(SomeDatasetModule.class);
DatasetModuleId datasetModuleId = NamespaceId.DEFAULT.datasetModule("someDatasetModule");
datasetModuleClient.add(datasetModuleId, SomeDatasetModule.class.getName(), moduleJarFile);
// Fetch the dataset module information
DatasetModuleMeta datasetModuleMeta = datasetModuleClient.get(datasetModuleId);
// Delete all dataset modules
datasetModuleClient.deleteAll(NamespaceId.DEFAULT);
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeHandlerTest method testBundledJarModule.
// Tests that a module can be deployed from a jar that is embedded in a bundle jar. This verifies class loading.
@Test
public void testBundledJarModule() throws Exception {
// Get jar of TestModule1
Location module1Jar = createModuleJar(TestModule1.class);
// Create bundle jar with TestModule2 and TestModule1 inside it, request for deploy is made for Module1.
Assert.assertEquals(200, deployModuleBundled("module1", TestModule1.class.getName(), TestModule2.class, module1Jar));
Assert.assertEquals(HttpStatus.SC_OK, deleteModules().getResponseCode());
List<DatasetModuleMeta> modules = getModules().getResponseObject();
Assert.assertEquals(0, modules.size());
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class AuthorizationDatasetTypeService method deleteAll.
@Override
public void deleteAll(NamespaceId namespaceId) throws Exception {
Principal principal = authenticationContext.getPrincipal();
for (DatasetModuleMeta meta : delegate.listModules(namespaceId)) {
DatasetModuleId datasetModuleId = namespaceId.datasetModule(meta.getName());
authorizationEnforcer.enforce(datasetModuleId, principal, Action.ADMIN);
}
delegate.deleteAll(namespaceId);
}
Aggregations