use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeService method delete.
/**
* Deletes the specified {@link DatasetModuleId}
*/
void delete(DatasetModuleId datasetModuleId) throws Exception {
NamespaceId namespaceId = datasetModuleId.getParent();
if (NamespaceId.SYSTEM.equals(namespaceId)) {
throw new UnauthorizedException(String.format("Cannot delete module '%s' from '%s' namespace.", datasetModuleId.getModule(), datasetModuleId.getNamespace()));
}
ensureNamespaceExists(namespaceId);
DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
if (moduleMeta == null) {
throw new DatasetModuleNotFoundException(datasetModuleId);
}
Principal principal = authenticationContext.getPrincipal();
authorizationEnforcer.enforce(datasetModuleId, principal, Action.ADMIN);
try {
typeManager.deleteModule(datasetModuleId);
} catch (DatasetModuleConflictException e) {
throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage());
}
// revoke all privileges on the module to be deleted
revokeAllPrivilegesOnModule(datasetModuleId, moduleMeta);
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeService method deleteSystemModules.
private void deleteSystemModules() throws Exception {
final List<DatasetModuleMeta> toRevoke = new ArrayList<>();
Transactions.createTransactional(datasetCache).execute(60, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
DatasetTypeMDS datasetTypeMDS = datasetCache.getDataset(DatasetMetaTableUtil.META_TABLE_NAME);
Collection<DatasetModuleMeta> allDatasets = datasetTypeMDS.getModules(NamespaceId.SYSTEM);
for (DatasetModuleMeta ds : allDatasets) {
if (ds.getJarLocationPath() == null) {
LOG.debug("Deleting system dataset module: {}", ds.toString());
DatasetModuleId moduleId = NamespaceId.SYSTEM.datasetModule(ds.getName());
datasetTypeMDS.deleteModule(moduleId);
toRevoke.add(ds);
}
}
}
});
long startTime = System.currentTimeMillis();
LOG.trace("Revoking all privileges for {} system dataset modules. ", toRevoke.size());
for (DatasetModuleMeta ds : toRevoke) {
revokeAllPrivilegesOnModule(NamespaceId.SYSTEM.datasetModule(ds.getName()), ds);
}
long doneTime = System.currentTimeMillis();
float elapsedSeconds = doneTime == startTime ? 0.0F : ((float) doneTime - startTime) / 1000;
LOG.debug("Revoking all privileges for {} system dataset modules took {} seconds.", toRevoke.size(), elapsedSeconds);
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeMDS method writeModule.
public void writeModule(NamespaceId namespaceId, DatasetModuleMeta moduleMeta) {
DatasetModuleId datasetModuleId = namespaceId.datasetModule(moduleMeta.getName());
DatasetModuleMeta existing = getModule(datasetModuleId);
write(getModuleKey(namespaceId.getEntityName(), moduleMeta.getName()), moduleMeta);
for (String type : moduleMeta.getTypes()) {
writeTypeToModuleMapping(namespaceId.datasetType(type), datasetModuleId);
}
if (existing != null) {
Set<String> removed = new HashSet<>(existing.getTypes());
removed.removeAll(moduleMeta.getTypes());
for (String type : removed) {
deleteAll(getTypeKey(datasetModuleId.getNamespace(), type));
}
}
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetTypeHandlerTest method verifyAll.
private void verifyAll(Set<DatasetModuleMeta> expectedModules, Map<String, List<String>> typeDependencies) throws IOException {
Set<DatasetModuleMeta> actualModules = new HashSet<>(getModules().getResponseObject());
Assert.assertEquals(expectedModules, actualModules);
for (DatasetModuleMeta expectedModule : expectedModules) {
ObjectResponse<DatasetModuleMeta> response = getModule(expectedModule.getName());
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals(expectedModule, response.getResponseObject());
for (String type : expectedModule.getTypes()) {
ObjectResponse<DatasetTypeMeta> typeResponse = getType(type);
Assert.assertEquals(HttpStatus.SC_OK, typeResponse.getResponseCode());
verify(typeResponse.getResponseObject(), type, typeDependencies.get(type));
}
}
List<DatasetTypeMeta> actualTypes = getTypes().getResponseObject();
Assert.assertEquals(actualTypes.size(), typeDependencies.size());
Assert.assertTrue(Iterables.elementsEqual(typeDependencies.keySet(), Iterables.transform(actualTypes, new Function<DatasetTypeMeta, String>() {
@Nullable
@Override
public String apply(@Nullable DatasetTypeMeta input) {
return input == null ? null : input.getName();
}
})));
for (DatasetTypeMeta typeMeta : actualTypes) {
verify(typeMeta, typeMeta.getName(), typeDependencies.get(typeMeta.getName()));
}
}
use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.
the class DatasetModuleClient method get.
/**
* Gets information about a dataset module.
*
* @param module the dataset module
* @return {@link DatasetModuleMeta} of the dataset module
* @throws DatasetModuleNotFoundException if the dataset module with the specified name was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public DatasetModuleMeta get(DatasetModuleId module) throws DatasetModuleNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new DatasetModuleNotFoundException(module);
}
return ObjectResponse.fromJsonBody(response, DatasetModuleMeta.class).getResponseObject();
}
Aggregations