Search in sources :

Example 66 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestFsActionExecutor method testChgrpRelativePath.

public void testChgrpRelativePath() throws Exception {
    String testUser = getTestUser();
    String testGroup = getTestGroup();
    String testGroup2 = getTestGroup2();
    FsActionExecutor ae = new FsActionExecutor();
    FileSystem fs = getFileSystem();
    Context context = createContext("<fs/>");
    Path basePath = new Path(getFsTestCaseDir(), "2010");
    createTestDirForChgrp(basePath, fs);
    Path globPath = new Path(basePath + "/1[0-1]");
    Path relativePath = new Path(globPath.toUri().getPath());
    Path nameNode = new Path(globPath.toUri().getScheme() + "://" + globPath.toUri().getAuthority());
    ae.chgrp(context, null, nameNode, relativePath, testUser, testGroup2, false, false);
    assertEquals(testGroup2, fs.getFileStatus(new Path(basePath, "10")).getGroup().toString());
    assertEquals(testGroup2, fs.getFileStatus(new Path(basePath, "11")).getGroup().toString());
    assertEquals(testGroup, fs.getFileStatus(new Path(basePath, "12")).getGroup().toString());
    assertEquals(testGroup, fs.getFileStatus(new Path(basePath + "/10/dir1")).getGroup().toString());
    assertEquals(testGroup, fs.getFileStatus(new Path(basePath + "/10/dir2")).getGroup().toString());
    assertEquals(testGroup, fs.getFileStatus(new Path(basePath + "/11/dir3")).getGroup().toString());
    assertEquals(testGroup, fs.getFileStatus(new Path(basePath + "/10/dir1/file1")).getGroup().toString());
    try {
        ae.chgrp(context, null, null, relativePath, testUser, testGroup2, false, false);
        fail();
    } catch (ActionExecutorException e) {
        assertEquals(e.getErrorCode(), "FS001");
    }
    fs.delete(basePath, true);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) ActionExecutorException(org.apache.oozie.action.ActionExecutorException)

Example 67 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestFsActionExecutor method testMoveWithGlob.

public void testMoveWithGlob() throws Exception {
    FsActionExecutor ae = new FsActionExecutor();
    FileSystem fs = getFileSystem();
    Path source = new Path(getFsTestCaseDir(), "source");
    Path target = new Path(getFsTestCaseDir(), "target");
    Context context = createContext("<fs/>");
    // Test simple example of glob
    fs.mkdirs(source);
    fs.mkdirs(target);
    fs.createNewFile(new Path(source, "newfile1"));
    fs.createNewFile(new Path(source, "newfile2"));
    ae.move(context, new Path(source.toString() + "/*"), target, false);
    assertTrue(fs.exists(new Path(target, "newfile1")));
    assertTrue(fs.exists(new Path(target, "newfile2")));
    // Test another example of glob
    fs.delete(target, true);
    fs.mkdirs(target);
    fs.mkdirs(new Path(source + "/2010"));
    fs.mkdirs(new Path(source + "/2011"));
    fs.mkdirs(new Path(source + "/2012"));
    fs.mkdirs(new Path(source + "/2010/10"));
    fs.mkdirs(new Path(source + "/2010/11"));
    fs.createNewFile(new Path(source + "/2010/10/newfile1"));
    fs.createNewFile(new Path(source + "/2010/11/newfile2"));
    fs.mkdirs(new Path(source + "/2011/09"));
    fs.mkdirs(new Path(source + "/2011/10"));
    fs.createNewFile(new Path(source + "/2011/09/newfile3"));
    fs.createNewFile(new Path(source + "/2011/10/newfile4"));
    ae.move(context, new Path(source.toString() + "/201[0-1]/1{0,1}/*"), target, false);
    assertTrue(fs.exists(new Path(target.toString() + "/newfile1")));
    assertTrue(fs.exists(new Path(target.toString() + "/newfile2")));
    assertFalse(fs.exists(new Path(target.toString() + "/newfile3")));
    assertTrue(fs.exists(new Path(target.toString() + "/newfile4")));
    fs.delete(new Path(source + "/2010"), true);
    fs.delete(new Path(source + "/2011"), true);
    fs.delete(new Path(source + "/2012"), true);
    // Catch exception when trying to move multiple files (match glob) to
    // the same name which doesn't exist
    fs.delete(target, true);
    try {
        ae.move(context, new Path(source.toString() + "/*"), target, true);
    } catch (ActionExecutorException ex) {
        assertEquals("FS012", ex.getErrorCode());
    }
    // Catch exception when trying to move multiple files (match glob) to
    // the same file name which exists
    fs.delete(target, true);
    Path targetFile = new Path(target, "newfile1");
    fs.createNewFile(targetFile);
    try {
        ae.move(context, new Path(source.toString() + "/*"), targetFile, true);
    } catch (ActionExecutorException ex) {
        assertEquals("FS012", ex.getErrorCode());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) ActionExecutorException(org.apache.oozie.action.ActionExecutorException)

Example 68 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestJavaActionExecutor method testAddActionShareLib.

@Test
public void testAddActionShareLib() throws Exception {
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    Path systemLibPath = new Path(wps.getSystemLibPath(), ShareLibService.SHARE_LIB_PREFIX + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString());
    Path javaShareLibPath = new Path(systemLibPath, "java");
    getFileSystem().mkdirs(javaShareLibPath);
    Path jar1Path = new Path(javaShareLibPath, "jar1.jar");
    getFileSystem().create(jar1Path).close();
    Path jar2Path = new Path(javaShareLibPath, "jar2.jar");
    getFileSystem().create(jar2Path).close();
    Path hcatShareLibPath = new Path(systemLibPath, "hcat");
    getFileSystem().mkdirs(hcatShareLibPath);
    Path jar3Path = new Path(hcatShareLibPath, "jar3.jar");
    getFileSystem().create(jar3Path).close();
    Path jar4Path = new Path(hcatShareLibPath, "jar4.jar");
    getFileSystem().create(jar4Path).close();
    Path otherShareLibPath = new Path(systemLibPath, "other");
    getFileSystem().mkdirs(otherShareLibPath);
    Path jar5Path = new Path(otherShareLibPath, "jar5.jar");
    getFileSystem().create(jar5Path).close();
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<main-class>MAIN-CLASS</main-class>" + "</java>";
    Element eActionXml = XmlUtils.parseXml(actionXml);
    Context context = createContext(actionXml, null);
    Services.get().setService(ShareLibService.class);
    // Test oozie server action sharelib setting
    WorkflowJobBean workflow = (WorkflowJobBean) context.getWorkflow();
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
    wfConf.set(OozieClient.APP_PATH, new Path(getAppPath(), "workflow.xml").toString());
    wfConf.setBoolean(OozieClient.USE_SYSTEM_LIBPATH, true);
    workflow.setConf(XmlUtils.prettyPrint(wfConf).toString());
    ConfigurationService.set("oozie.action.sharelib.for.java", "java,hcat");
    JavaActionExecutor ae = new JavaActionExecutor();
    Configuration jobConf = ae.createBaseHadoopConf(context, eActionXml);
    ae.setupLauncherConf(jobConf, eActionXml, getAppPath(), context);
    try {
        ae.setLibFilesArchives(context, eActionXml, getAppPath(), jobConf);
        fail();
    } catch (ActionExecutorException aee) {
        assertEquals("EJ001", aee.getErrorCode());
        assertEquals("Could not locate Oozie sharelib", aee.getMessage());
    }
    Path launcherPath = new Path(systemLibPath, "oozie");
    getFileSystem().mkdirs(launcherPath);
    Path jar6Path = new Path(launcherPath, "jar6.jar");
    getFileSystem().create(jar6Path).close();
    Services.get().get(ShareLibService.class).updateShareLib();
    ae.setLibFilesArchives(context, eActionXml, getAppPath(), jobConf);
    URI[] cacheFiles = DistributedCache.getCacheFiles(jobConf);
    String cacheFilesStr = Arrays.toString(cacheFiles);
    assertTrue(cacheFilesStr.contains(jar1Path.toString()));
    assertTrue(cacheFilesStr.contains(jar2Path.toString()));
    assertTrue(cacheFilesStr.contains(jar3Path.toString()));
    assertTrue(cacheFilesStr.contains(jar4Path.toString()));
    assertFalse(cacheFilesStr.contains(jar5Path.toString()));
    assertTrue(cacheFilesStr.contains(jar6Path.toString()));
    // Test per workflow action sharelib setting
    workflow = (WorkflowJobBean) context.getWorkflow();
    wfConf = new XConfiguration();
    wfConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
    wfConf.set(OozieClient.APP_PATH, new Path(getAppPath(), "workflow.xml").toString());
    wfConf.setBoolean(OozieClient.USE_SYSTEM_LIBPATH, true);
    wfConf.set("oozie.action.sharelib.for.java", "other,hcat");
    workflow.setConf(XmlUtils.prettyPrint(wfConf).toString());
    ConfigurationService.set("oozie.action.sharelib.for.java", "java");
    ae = new JavaActionExecutor();
    jobConf = ae.createBaseHadoopConf(context, eActionXml);
    ae.setupLauncherConf(jobConf, eActionXml, getAppPath(), context);
    ae.setLibFilesArchives(context, eActionXml, getAppPath(), jobConf);
    cacheFiles = DistributedCache.getCacheFiles(jobConf);
    cacheFilesStr = Arrays.toString(cacheFiles);
    // The oozie server setting should have been overridden by workflow setting
    assertFalse(cacheFilesStr.contains(jar1Path.toString()));
    assertFalse(cacheFilesStr.contains(jar2Path.toString()));
    assertTrue(cacheFilesStr.contains(jar3Path.toString()));
    assertTrue(cacheFilesStr.contains(jar4Path.toString()));
    assertTrue(cacheFilesStr.contains(jar5Path.toString()));
    assertTrue(cacheFilesStr.contains(jar6Path.toString()));
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ShareLibService(org.apache.oozie.service.ShareLibService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) URI(java.net.URI) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 69 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestFsActionExecutor method testRetryOnAccessControlError.

public void testRetryOnAccessControlError() throws Exception {
    FsActionExecutor ae = new FsActionExecutor();
    FileSystem fs = getFileSystem();
    Path path = new Path(getFsTestCaseDir(), "dir");
    fs.mkdirs(path);
    fs.setPermission(path, FsPermission.valueOf("-rwx------"));
    // do FS operation using different user to cause permission error
    Context context = createContextWithUser("<fs/>", getTestUser2());
    try {
        ae.chmod(context, path, "-r--------", false, false);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof ActionExecutorException);
        assertEquals("FS014", ((ActionExecutorException) e).getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.ERROR, ((ActionExecutorException) e).getErrorType());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException)

Example 70 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestFsActionExecutor method testResolveToFullPath.

public void testResolveToFullPath() throws Exception {
    FsActionExecutor ae = new FsActionExecutor();
    assertEquals(new Path("hdfs://x/bla"), ae.resolveToFullPath(null, new Path("hdfs://x/bla"), true));
    assertEquals(new Path("bla"), ae.resolveToFullPath(null, new Path("bla"), false));
    assertEquals(new Path("hdfs://x/bla"), ae.resolveToFullPath(new Path("hdfs://x"), new Path("/bla"), true));
    assertEquals(new Path("hdfs://x/bla/[0-1]*"), ae.resolveToFullPath(new Path("hdfs://x"), new Path("/bla/[0-1]*"), true));
    assertEquals(new Path("hdfs://x/bla"), ae.resolveToFullPath(new Path("hdfs://x/ha"), new Path("/bla"), true));
    assertEquals(new Path("hdfs://x/bla"), ae.resolveToFullPath(new Path("hdfs://z"), new Path("hdfs://x/bla"), true));
    assertEquals(new Path("hdfs://x/bla/[0-1]*"), ae.resolveToFullPath(new Path("hdfs://z"), new Path("hdfs://x/bla/[0-1]*"), true));
    assertEquals(new Path("hdfs://x/bla"), ae.resolveToFullPath(new Path("hdfs://x"), new Path("hdfs://x/bla"), true));
    try {
        ae.resolveToFullPath(null, new Path("hdfs://x/bla"), false);
        fail();
    } catch (ActionExecutorException ex) {
        assertEquals("FS002", ex.getErrorCode());
    }
    try {
        ae.resolveToFullPath(null, new Path("bla"), true);
        fail();
    } catch (ActionExecutorException ex) {
        assertEquals("FS001", ex.getErrorCode());
    }
    Services.get().destroy();
    setSystemProperty(HadoopAccessorService.SUPPORTED_FILESYSTEMS, null);
    new Services().init();
    try {
        ae.resolveToFullPath(null, new Path("file://bla"), true);
        fail();
    } catch (ActionExecutorException ex) {
        assertTrue(ex.getMessage().contains("E0904"));
    }
    try {
        ae.resolveToFullPath(new Path("hdfs://z"), new Path("hdfs://x/bla"), false);
        fail();
    } catch (ActionExecutorException ex) {
        assertEquals("FS002", ex.getErrorCode());
    }
    try {
        ae.resolveToFullPath(new Path("hdfs://z"), new Path("bla"), true);
        fail();
    } catch (ActionExecutorException ex) {
        assertEquals("FS011", ex.getErrorCode());
    }
    try {
        ae.resolveToFullPath(new Path("hdfs://z"), new Path("file://bla"), true);
        fail();
    } catch (ActionExecutorException ex) {
        assertTrue(ex.getMessage().contains("E0904"));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Services(org.apache.oozie.service.Services) ActionExecutorException(org.apache.oozie.action.ActionExecutorException)

Aggregations

ActionExecutorException (org.apache.oozie.action.ActionExecutorException)75 Path (org.apache.hadoop.fs.Path)41 IOException (java.io.IOException)39 Element (org.jdom.Element)28 URISyntaxException (java.net.URISyntaxException)27 FileSystem (org.apache.hadoop.fs.FileSystem)25 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)24 XConfiguration (org.apache.oozie.util.XConfiguration)23 Configuration (org.apache.hadoop.conf.Configuration)20 AccessControlException (org.apache.hadoop.security.AccessControlException)20 Namespace (org.jdom.Namespace)13 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)12 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)12 JDOMException (org.jdom.JDOMException)12 FileNotFoundException (java.io.FileNotFoundException)10 ELEvaluationException (org.apache.oozie.util.ELEvaluationException)10 ConnectException (java.net.ConnectException)9 UnknownHostException (java.net.UnknownHostException)9 RemoteException (org.apache.hadoop.ipc.RemoteException)9 ArrayList (java.util.ArrayList)8