use of io.cdap.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 io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DefaultDatasetTypeService method getModule.
/**
* Returns the {@link DatasetModuleMeta metadata} of the specified {@link DatasetModuleId}.
*/
@Override
public DatasetModuleMeta getModule(DatasetModuleId datasetModuleId) throws Exception {
ensureNamespaceExists(datasetModuleId.getParent());
DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
if (moduleMeta == null) {
throw new DatasetModuleNotFoundException(datasetModuleId);
}
return moduleMeta;
}
use of io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeTable method getTypeMeta.
private DatasetTypeMeta getTypeMeta(NamespaceId namespaceId, String typeName, DatasetModuleMeta moduleMeta) throws IOException {
List<DatasetModuleMeta> modulesToLoad = Lists.newArrayList();
// adding first all modules we depend on, then myself
for (String usedModule : moduleMeta.getUsesModules()) {
// Try to find module in the specified namespace first, then the system namespace
DatasetModuleMeta usedModuleMeta = getModuleWithFallback(namespaceId.datasetModule(usedModule));
// Module could not be found in either user or system namespace, bail out
Preconditions.checkState(usedModuleMeta != null, String.format("Unable to find metadata about module %s that module %s uses.", usedModule, moduleMeta.getName()));
modulesToLoad.add(usedModuleMeta);
}
modulesToLoad.add(moduleMeta);
return new DatasetTypeMeta(typeName, modulesToLoad);
}
use of io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeManager method deleteModules.
/**
* Deletes all modules in a namespace, other than system.
* Presumes that the namespace has already been checked to be non-system.
*
* @param namespaceId the {@link NamespaceId} to delete modules from.
*/
public void deleteModules(final NamespaceId namespaceId) throws DatasetModuleConflictException {
Preconditions.checkArgument(namespaceId != null && !NamespaceId.SYSTEM.equals(namespaceId), "Cannot delete modules from system namespace");
LOG.info("Deleting all modules from namespace {}", namespaceId);
try {
TransactionRunners.run(transactionRunner, context -> {
final DatasetTypeTable datasetTypeTable = DatasetTypeTable.create(context);
final DatasetInstanceTable datasetInstanceTable = new DatasetInstanceTable(context);
final Set<String> typesToDelete = new HashSet<String>();
final List<Location> moduleLocations = new ArrayList<>();
final Collection<DatasetModuleMeta> modules = datasetTypeTable.getModules(namespaceId);
try {
impersonator.doAs(namespaceId, new Callable<Void>() {
@Override
public Void call() throws Exception {
for (DatasetModuleMeta module : modules) {
typesToDelete.addAll(module.getTypes());
moduleLocations.add(Locations.getLocationFromAbsolutePath(locationFactory, module.getJarLocationPath()));
}
return null;
}
});
} catch (Exception e) {
// the callable throws no checked exceptions
throw Throwables.propagate(e);
}
// check if there are any instances that use types of these modules?
Collection<DatasetSpecification> instances = datasetInstanceTable.getByTypes(namespaceId, typesToDelete);
// cannot delete when there's instance that uses it
if (!instances.isEmpty()) {
throw new DatasetModuleConflictException("Cannot delete all modules: existing dataset instances depend on it. Delete them first");
}
datasetTypeTable.deleteModules(namespaceId);
// Delete module locations
for (Location moduleLocation : moduleLocations) {
if (!moduleLocation.delete()) {
LOG.debug("Could not delete dataset module archive - {}", moduleLocation);
}
}
});
} catch (RuntimeException e) {
for (Throwable cause : Throwables.getCausalChain(e)) {
if (cause instanceof DatasetModuleConflictException) {
throw (DatasetModuleConflictException) cause;
}
}
LOG.error("Failed to delete all modules from namespace {}", namespaceId);
throw Throwables.propagate(e);
} catch (Exception e) {
LOG.error("Operation failed", e);
throw Throwables.propagate(e);
}
}
use of io.cdap.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());
accessEnforcer.enforce(datasetModuleId, principal, StandardPermission.DELETE);
}
delegate.deleteAll(namespaceId);
}
Aggregations