use of org.apache.oozie.dependency.URIHandler in project oozie by apache.
the class TestLauncherHCatURIHandler method testDelete.
@Test
public void testDelete() throws Exception {
createTestTable();
String location1 = getPartitionDir(db, table, "year=2012;month=12;dt=02;country=us");
String location2 = getPartitionDir(db, table, "year=2012;month=12;dt=03;country=us");
createPartitionForTestDelete(true, true);
URI hcatURI = getHCatURI(db, table, "year=2012;month=12;dt=02;country=us");
URIHandler uriHandler = uriService.getURIHandler(hcatURI);
assertTrue(uriHandler.exists(hcatURI, conf, getTestUser()));
LauncherURIHandlerFactory uriHandlerFactory = new LauncherURIHandlerFactory(uriService.getLauncherConfig());
LauncherURIHandler handler = uriHandlerFactory.getURIHandler(hcatURI);
handler.delete(hcatURI, conf);
assertFalse(getFileSystem().exists(new Path(location1)));
assertTrue(getFileSystem().exists(new Path(location2)));
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=02;country=us").size());
assertEquals(1, getPartitions(db, table, "year=2012;month=12;dt=03;country=us").size());
createPartitionForTestDelete(true, false);
hcatURI = getHCatURI(db, table, "year=2012;month=12");
handler.delete(hcatURI, conf);
assertFalse(getFileSystem().exists(new Path(location1)));
assertFalse(getFileSystem().exists(new Path(location2)));
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=02;country=us").size());
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=03;country=us").size());
createPartitionForTestDelete(true, true);
hcatURI = getHCatURI(db, table, "month=12;country=us");
handler.delete(hcatURI, conf);
assertFalse(getFileSystem().exists(new Path(location1)));
assertFalse(getFileSystem().exists(new Path(location2)));
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=02;country=us").size());
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=03;country=us").size());
createPartitionForTestDelete(true, true);
hcatURI = getHCatURI(db, table, "country=us");
handler.delete(hcatURI, conf);
assertFalse(getFileSystem().exists(new Path(location1)));
assertFalse(getFileSystem().exists(new Path(location2)));
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=02;country=us").size());
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=03;country=us").size());
createPartitionForTestDelete(true, true);
hcatURI = getHCatURI(db, table, "dt=03");
handler.delete(hcatURI, conf);
assertTrue(getFileSystem().exists(new Path(location1)));
assertFalse(getFileSystem().exists(new Path(location2)));
assertEquals(1, getPartitions(db, table, "year=2012;month=12;dt=02;country=us").size());
assertEquals(0, getPartitions(db, table, "year=2012;month=12;dt=03;country=us").size());
createPartitionForTestDelete(false, true);
hcatURI = getHCatURI(db, table, "dt=09");
handler.delete(hcatURI, conf);
assertTrue(getFileSystem().exists(new Path(location1)));
assertTrue(getFileSystem().exists(new Path(location2)));
assertEquals(1, getPartitions(db, table, "year=2012;month=12;dt=02;country=us").size());
assertEquals(1, getPartitions(db, table, "year=2012;month=12;dt=03;country=us").size());
dropTestTable(false);
}
use of org.apache.oozie.dependency.URIHandler in project oozie by apache.
the class TestFsActionExecutor method testDeleteHcat.
public void testDeleteHcat() throws Exception {
// setting current user as test user because directory structure created by HCat have current user permissions (755).
setSystemProperty(XTestCase.TEST_USER1_PROP, System.getProperty("user.name"));
createTestTable();
addPartition(db, table, "year=2012;month=12;dt=02;country=us");
URI hcatURI = getHCatURI(db, table, "country=us;year=2012;month=12;dt=02");
URIHandler handler = uriService.getURIHandler(hcatURI);
FsActionExecutor ae = new FsActionExecutor();
Path path = new Path(hcatURI);
Path nameNodePath = new Path(getNameNodeUri());
Context context = createContext("<fs/>");
XConfiguration conf = new XConfiguration();
assertTrue(handler.exists(hcatURI, conf, getTestUser()));
ae.delete(context, conf, nameNodePath, path, true);
assertFalse(handler.exists(hcatURI, conf, getTestUser()));
}
use of org.apache.oozie.dependency.URIHandler in project oozie by apache.
the class FsActionExecutor method delete.
/**
* Delete path
*
* @param context
* @param fsConf
* @param nameNodePath
* @param path
* @param skipTrash flag to skip the trash.
* @throws ActionExecutorException
*/
public void delete(Context context, XConfiguration fsConf, Path nameNodePath, Path path, boolean skipTrash) throws ActionExecutorException {
LOG.info("Deleting [{0}]. Skipping trash: [{1}]", path, skipTrash);
URI uri = path.toUri();
URIHandler handler;
org.apache.oozie.dependency.URIHandler.Context hcatContext = null;
try {
handler = Services.get().get(URIHandlerService.class).getURIHandler(uri);
if (handler instanceof FSURIHandler) {
// Use legacy code to handle hdfs partition deletion
path = resolveToFullPath(nameNodePath, path, true);
final FileSystem fs = getFileSystemFor(path, context, fsConf);
Path[] pathArr = FileUtil.stat2Paths(fs.globStatus(path));
if (pathArr != null && pathArr.length > 0) {
checkGlobMax(pathArr);
for (final Path p : pathArr) {
if (fs.exists(p)) {
if (!skipTrash) {
// Moving directory/file to trash of user.
UserGroupInformationService ugiService = Services.get().get(UserGroupInformationService.class);
UserGroupInformation ugi = ugiService.getProxyUser(fs.getConf().get(OozieClient.USER_NAME));
ugi.doAs(new PrivilegedExceptionAction<FileSystem>() {
@Override
public FileSystem run() throws Exception {
Trash trash = new Trash(fs.getConf());
if (!trash.moveToTrash(p)) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS005", "Could not move path [{0}] to trash on delete", p);
}
return null;
}
});
} else if (!fs.delete(p, true)) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS005", "delete, path [{0}] could not delete path", p);
}
}
}
}
} else {
hcatContext = handler.getContext(uri, fsConf, context.getWorkflow().getUser(), false);
handler.delete(uri, hcatContext);
}
} catch (Exception ex) {
throw convertException(ex);
} finally {
if (hcatContext != null) {
hcatContext.destroy();
}
}
}
use of org.apache.oozie.dependency.URIHandler in project oozie by apache.
the class CoordPushDependencyCheckXCommand method registerForNotification.
private void registerForNotification(List<String> missingDeps, Configuration actionConf) {
URIHandlerService uriService = Services.get().get(URIHandlerService.class);
String user = actionConf.get(OozieClient.USER_NAME, OozieClient.USER_NAME);
for (String missingDep : missingDeps) {
try {
URI missingURI = new URI(missingDep);
URIHandler handler = uriService.getURIHandler(missingURI);
handler.registerForNotification(missingURI, actionConf, user, actionId);
LOG.debug("Registered uri [{0}] for notifications", missingURI);
} catch (Exception e) {
LOG.warn("Exception while registering uri [{0}] for notifications", missingDep, e);
}
}
}
use of org.apache.oozie.dependency.URIHandler in project oozie by apache.
the class CoordPushDependencyCheckXCommand method unregisterAvailableDependencies.
private void unregisterAvailableDependencies(List<String> availableDeps) {
URIHandlerService uriService = Services.get().get(URIHandlerService.class);
for (String availableDep : availableDeps) {
try {
URI availableURI = new URI(availableDep);
URIHandler handler = uriService.getURIHandler(availableURI);
if (handler.unregisterFromNotification(availableURI, actionId)) {
LOG.debug("Successfully unregistered uri [{0}] from notifications", availableURI);
} else {
LOG.warn("Unable to unregister uri [{0}] from notifications", availableURI);
}
} catch (Exception e) {
LOG.warn("Exception while unregistering uri [{0}] from notifications", availableDep, e);
}
}
}
Aggregations