Search in sources :

Example 11 with URIHandler

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);
}
Also used : Path(org.apache.hadoop.fs.Path) HCatURIHandler(org.apache.oozie.dependency.HCatURIHandler) URIHandler(org.apache.oozie.dependency.URIHandler) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) URI(java.net.URI) Test(org.junit.Test)

Example 12 with URIHandler

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()));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) HCatURIHandler(org.apache.oozie.dependency.HCatURIHandler) URIHandler(org.apache.oozie.dependency.URIHandler) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) URI(java.net.URI)

Example 13 with URIHandler

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();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) URI(java.net.URI) Trash(org.apache.hadoop.fs.Trash) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException) UserGroupInformationService(org.apache.oozie.service.UserGroupInformationService) FileSystem(org.apache.hadoop.fs.FileSystem) URIHandler(org.apache.oozie.dependency.URIHandler) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 14 with URIHandler

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);
        }
    }
}
Also used : URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) URI(java.net.URI) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ElException(org.apache.oozie.coord.ElException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 15 with URIHandler

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);
        }
    }
}
Also used : URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) URI(java.net.URI) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ElException(org.apache.oozie.coord.ElException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Aggregations

URIHandler (org.apache.oozie.dependency.URIHandler)22 URI (java.net.URI)15 URIHandlerService (org.apache.oozie.service.URIHandlerService)13 FSURIHandler (org.apache.oozie.dependency.FSURIHandler)9 IOException (java.io.IOException)5 CommandException (org.apache.oozie.command.CommandException)5 Configuration (org.apache.hadoop.conf.Configuration)4 Path (org.apache.hadoop.fs.Path)4 LauncherURIHandler (org.apache.oozie.action.hadoop.LauncherURIHandler)4 HCatURIHandler (org.apache.oozie.dependency.HCatURIHandler)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 ELEvaluator (org.apache.oozie.util.ELEvaluator)4 Element (org.jdom.Element)4 PreconditionException (org.apache.oozie.command.PreconditionException)3 ElException (org.apache.oozie.coord.ElException)3 Context (org.apache.oozie.dependency.URIHandler.Context)3 XConfiguration (org.apache.oozie.util.XConfiguration)3 XLog (org.apache.oozie.util.XLog)3 URISyntaxException (java.net.URISyntaxException)2 Calendar (java.util.Calendar)2