Search in sources :

Example 6 with WorkflowAction

use of org.apache.oozie.client.WorkflowAction in project oozie by apache.

the class TestJavaActionExecutor method submitAction.

protected String submitAction(Context context, JavaActionExecutor javaActionExecutor) throws ActionExecutorException {
    WorkflowAction action = context.getAction();
    javaActionExecutor.prepareActionDir(getFileSystem(), context);
    javaActionExecutor.submitLauncher(getFileSystem(), context, action);
    String jobId = action.getExternalId();
    String jobTracker = action.getTrackerUri();
    String consoleUrl = action.getConsoleUrl();
    assertNotNull(jobId);
    assertNotNull(jobTracker);
    assertNotNull(consoleUrl);
    return jobId;
}
Also used : WorkflowAction(org.apache.oozie.client.WorkflowAction)

Example 7 with WorkflowAction

use of org.apache.oozie.client.WorkflowAction in project oozie by apache.

the class TestDistCpActionExecutor method testDistCpFile.

public void testDistCpFile() throws Exception {
    Path inputPath = new Path(getFsTestCaseDir(), "input.txt");
    final Path outputPath = new Path(getFsTestCaseDir(), "output.txt");
    byte[] content = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes();
    OutputStream os = getFileSystem().create(inputPath);
    os.write(content);
    os.close();
    String actionXml = "<distcp>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<arg>" + inputPath + "</arg>" + "<arg>" + outputPath + "</arg>" + "</distcp>";
    Context context = createContext(actionXml);
    final String launcherId = submitAction(context);
    waitUntilYarnAppDoneAndAssertSuccess(launcherId);
    waitFor(60 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return getFileSystem().exists(outputPath);
        }
    });
    assertTrue(getFileSystem().exists(outputPath));
    byte[] readContent = new byte[content.length];
    InputStream is = getFileSystem().open(outputPath);
    int offset = 0;
    while (offset < readContent.length) {
        int numRead = is.read(readContent, offset, readContent.length);
        if (numRead == -1) {
            break;
        }
        offset += numRead;
    }
    assertEquals(is.read(), -1);
    is.close();
    offset = 0;
    while (offset < readContent.length) {
        assertEquals(readContent[offset], content[offset]);
        offset++;
    }
    // Check for external ids
    DistcpActionExecutor ae = new DistcpActionExecutor();
    WorkflowAction wfAction = context.getAction();
    ae.check(context, wfAction);
    ae.end(context, wfAction);
    assertEquals("SUCCEEDED", wfAction.getExternalStatus());
    String externalIds = wfAction.getExternalChildIDs();
    assertNotNull(externalIds);
    assertNotSame("", externalIds);
    // check for the expected prefix of hadoop jobIDs
    assertTrue(externalIds.contains("job_"));
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Example 8 with WorkflowAction

use of org.apache.oozie.client.WorkflowAction in project oozie by apache.

the class TestFsActionExecutor method testSubmitWithNameNode.

public void testSubmitWithNameNode() throws Exception {
    FsActionExecutor ae = new FsActionExecutor();
    FileSystem fs = getFileSystem();
    Path mkdir = new Path(getFsTestCaseDir(), "mkdir");
    Path mkdirX = new Path(mkdir.toUri().getPath());
    Path delete = new Path(getFsTestCaseDir(), "delete");
    Path deleteX = new Path(delete.toUri().getPath());
    fs.mkdirs(delete);
    Path source = new Path(getFsTestCaseDir(), "source");
    Path sourceX = new Path(source.toUri().getPath());
    fs.mkdirs(source);
    Path target = new Path(new Path(getFsTestCaseDir(), "target").toUri().getPath());
    Path chmod1 = new Path(getFsTestCaseDir(), "chmod1");
    Path chmod1X = new Path(chmod1.toUri().getPath());
    fs.mkdirs(chmod1);
    Path child1 = new Path(chmod1, "child1");
    fs.mkdirs(child1);
    Path chmod2 = new Path(getFsTestCaseDir(), "chmod2");
    Path chmod2X = new Path(chmod2.toUri().getPath());
    fs.mkdirs(chmod2);
    Path child2 = new Path(chmod2, "child2");
    fs.mkdirs(child2);
    Path newFile1 = new Path(mkdir + "newFile1");
    Path newFile1X = new Path(newFile1.toUri().getPath());
    Path newFile2 = new Path(mkdir + "newFile2");
    Path newFile2X = new Path(newFile2.toUri().getPath());
    fs.createNewFile(newFile1);
    String actionXml = MessageFormat.format("<fs><name-node>{0}</name-node>" + "<mkdir path=''{1}''/>" + "<delete path=''{2}''/>" + "<move source=''{3}'' target=''{4}''/>" + "<chmod path=''{5}'' permissions=''-rwxrwxrwx''/>" + "<chmod path=''{6}'' permissions=''-rwxrwx---'' dir-files=''false''/>" + "<touchz path=''{7}''/>" + "<touchz path=''{8}''/>" + "</fs>", getNameNodeUri(), mkdirX, deleteX, sourceX, target, chmod1X, chmod2X, newFile1X, newFile2X);
    Context context = createContext(actionXml);
    WorkflowAction action = context.getAction();
    assertFalse(fs.exists(ae.getRecoveryPath(context)));
    ae.start(context, action);
    assertTrue(fs.exists(ae.getRecoveryPath(context)));
    ae.check(context, context.getAction());
    assertEquals("OK", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());
    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
    assertFalse(fs.exists(ae.getRecoveryPath(context)));
    assertTrue(fs.exists(mkdir));
    assertFalse(fs.exists(delete));
    assertFalse(fs.exists(source));
    assertTrue(fs.exists(target));
    assertTrue(fs.exists(newFile1));
    assertTrue(fs.exists(newFile2));
    assertEquals("rwxrwxrwx", fs.getFileStatus(chmod1).getPermission().toString());
    assertNotSame("rwxrwxrwx", fs.getFileStatus(child1).getPermission().toString());
    assertEquals("rwxrwx---", fs.getFileStatus(chmod2).getPermission().toString());
    assertNotSame("rwxrwx---", fs.getFileStatus(child2).getPermission().toString());
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 9 with WorkflowAction

use of org.apache.oozie.client.WorkflowAction in project oozie by apache.

the class TestFsActionExecutor method testSubmit.

public void testSubmit() throws Exception {
    FsActionExecutor ae = new FsActionExecutor();
    FileSystem fs = getFileSystem();
    Path mkdir = new Path(getFsTestCaseDir(), "mkdir");
    Path delete = new Path(getFsTestCaseDir(), "delete");
    fs.mkdirs(delete);
    Path source = new Path(getFsTestCaseDir(), "source");
    fs.mkdirs(source);
    Path target = new Path(new Path(getFsTestCaseDir(), "target").toUri().getPath());
    Path chmod1 = new Path(getFsTestCaseDir(), "chmod1");
    fs.mkdirs(chmod1);
    Path child1 = new Path(chmod1, "child1");
    fs.mkdirs(child1);
    Path chmod2 = new Path(getFsTestCaseDir(), "chmod2");
    fs.mkdirs(chmod2);
    Path child2 = new Path(chmod2, "child2");
    fs.mkdirs(child2);
    Path newFile1 = new Path(mkdir + "newFile1");
    Path newFile2 = new Path(mkdir + "newFile2");
    fs.createNewFile(newFile1);
    String actionXml = MessageFormat.format("<fs><mkdir path=''{0}''/>" + "<delete path=''{1}''/>" + "<move source=''{2}'' target=''{3}''/>" + "<chmod path=''{4}'' permissions=''-rwxrwxrwx''/>" + "<chmod path=''{5}'' permissions=''-rwxrwx---'' dir-files=''false''/>" + "<touchz path=''{6}''/>" + "<touchz path=''{7}''/>" + "</fs>", mkdir, delete, source, target, chmod1, chmod2, newFile1, newFile2);
    Context context = createContext(actionXml);
    WorkflowAction action = context.getAction();
    assertFalse(fs.exists(ae.getRecoveryPath(context)));
    ae.start(context, action);
    assertTrue(fs.exists(ae.getRecoveryPath(context)));
    ae.check(context, context.getAction());
    assertEquals("OK", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());
    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
    assertFalse(fs.exists(ae.getRecoveryPath(context)));
    assertTrue(fs.exists(mkdir));
    assertFalse(fs.exists(delete));
    assertFalse(fs.exists(source));
    assertTrue(fs.exists(target));
    assertTrue(fs.exists(newFile1));
    assertTrue(fs.exists(newFile2));
    assertEquals("rwxrwxrwx", fs.getFileStatus(chmod1).getPermission().toString());
    assertNotSame("rwxrwxrwx", fs.getFileStatus(child1).getPermission().toString());
    assertEquals("rwxrwx---", fs.getFileStatus(chmod2).getPermission().toString());
    assertNotSame("rwxrwx---", fs.getFileStatus(child2).getPermission().toString());
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 10 with WorkflowAction

use of org.apache.oozie.client.WorkflowAction in project oozie by apache.

the class TestFsActionExecutor method testRecovery.

public void testRecovery() throws Exception {
    FsActionExecutor ae = new FsActionExecutor();
    FileSystem fs = getFileSystem();
    Path mkdir = new Path(getFsTestCaseDir(), "mkdir");
    Path delete = new Path(getFsTestCaseDir(), "delete");
    fs.mkdirs(delete);
    Path source = new Path(getFsTestCaseDir(), "source");
    fs.mkdirs(source);
    Path target = new Path(new Path(getFsTestCaseDir(), "target").toUri().getPath());
    Path chmod1 = new Path(getFsTestCaseDir(), "chmod1");
    fs.mkdirs(chmod1);
    Path child1 = new Path(chmod1, "child1");
    fs.mkdirs(child1);
    Path chmod2 = new Path(getFsTestCaseDir(), "chmod2");
    fs.mkdirs(chmod2);
    Path child2 = new Path(chmod2, "child2");
    fs.mkdirs(child2);
    String actionXml = MessageFormat.format("<fs>" + "<mkdir path=''{0}''/>" + "<delete path=''{1}''/>" + "<move source=''{2}'' target=''{3}''/>" + "<chmod path=''{4}'' permissions=''111''/>" + "<chmod path=''{5}'' permissions=''222'' dir-files=''false''/>" + "</fs>", mkdir, delete, source.toUri().getPath(), target, chmod1, chmod2);
    String id = "ID" + System.currentTimeMillis();
    Context context = createContext(actionXml);
    ((WorkflowJobBean) context.getWorkflow()).setId(id);
    ((WorkflowActionBean) context.getWorkflow().getActions().get(0)).setJobId(id);
    ((WorkflowActionBean) context.getWorkflow().getActions().get(0)).setId(id + "-FS");
    WorkflowAction action = context.getAction();
    assertFalse(fs.exists(ae.getRecoveryPath(context)));
    try {
        ae.start(context, action);
    } catch (ActionExecutorException ex) {
        if (!ex.getErrorCode().equals("FS001")) {
            throw ex;
        }
    }
    assertTrue(fs.exists(mkdir));
    assertFalse(fs.exists(delete));
    assertTrue(fs.exists(ae.getRecoveryPath(context)));
    actionXml = MessageFormat.format("<fs>" + "<mkdir path=''{0}''/>" + "<delete path=''{1}''/>" + "<move source=''{2}'' target=''{3}''/>" + "<chmod path=''{4}'' permissions=''-rwxrwxrwx''/>" + "<chmod path=''{5}'' permissions=''-rwxrwx---'' dir-files=''false''/>" + "</fs>", mkdir, delete, source, target, chmod1, chmod2);
    context = createContext(actionXml);
    ((WorkflowJobBean) context.getWorkflow()).setId(id);
    ((WorkflowActionBean) context.getWorkflow().getActions().get(0)).setJobId(id);
    ((WorkflowActionBean) context.getWorkflow().getActions().get(0)).setId(id + "-FS");
    action = context.getAction();
    ae.start(context, action);
    ae.check(context, context.getAction());
    assertEquals("OK", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());
    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
    assertFalse(fs.exists(ae.getRecoveryPath(context)));
    assertTrue(fs.exists(mkdir));
    assertFalse(fs.exists(delete));
    assertFalse(fs.exists(source));
    assertTrue(fs.exists(target));
    assertEquals("rwxrwxrwx", fs.getFileStatus(chmod1).getPermission().toString());
    assertNotSame("rwxrwxrwx", fs.getFileStatus(child1).getPermission().toString());
    assertEquals("rwxrwx---", fs.getFileStatus(chmod2).getPermission().toString());
    assertNotSame("rwxrwx---", fs.getFileStatus(child2).getPermission().toString());
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Aggregations

WorkflowAction (org.apache.oozie.client.WorkflowAction)41 FileSystem (org.apache.hadoop.fs.FileSystem)9 Path (org.apache.hadoop.fs.Path)8 IOException (java.io.IOException)6 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)6 WorkflowJob (org.apache.oozie.client.WorkflowJob)6 Writer (java.io.Writer)5 Properties (java.util.Properties)5 OozieClient (org.apache.oozie.client.OozieClient)5 XConfiguration (org.apache.oozie.util.XConfiguration)5 OutputStreamWriter (java.io.OutputStreamWriter)4 Configuration (org.apache.hadoop.conf.Configuration)3 Element (org.jdom.Element)3 File (java.io.File)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 URISyntaxException (java.net.URISyntaxException)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)2