Example usage for org.apache.hadoop.mapred RunningJob isSuccessful

List of usage examples for org.apache.hadoop.mapred RunningJob isSuccessful

Introduction

In this page you can find the example usage for org.apache.hadoop.mapred RunningJob isSuccessful.

Prototype

public boolean isSuccessful() throws IOException;

Source Link

Document

Check if the job completed successfully.

Usage

From source file:org.apache.oozie.action.hadoop.TestHive2ActionExecutor.java

License:Apache License

@SuppressWarnings("deprecation")
public void testHive2Action() throws Exception {
    setupHiveServer2();// w  w  w.  jav a 2s  .co m
    Path inputDir = new Path(getFsTestCaseDir(), INPUT_DIRNAME);
    Path outputDir = new Path(getFsTestCaseDir(), OUTPUT_DIRNAME);
    FileSystem fs = getFileSystem();

    {
        String query = getHive2Script(inputDir.toString(), outputDir.toString());
        Writer dataWriter = new OutputStreamWriter(fs.create(new Path(inputDir, DATA_FILENAME)));
        dataWriter.write(SAMPLE_DATA_TEXT);
        dataWriter.close();
        Context context = createContext(getQueryActionXml(query));
        final RunningJob launcherJob = submitAction(context,
                Namespace.getNamespace("uri:oozie:hive2-action:0.2"));
        String launcherId = context.getAction().getExternalId();
        waitFor(200 * 1000, new Predicate() {
            @Override
            public boolean evaluate() throws Exception {
                return launcherJob.isComplete();
            }
        });
        assertTrue(launcherJob.isSuccessful());
        Configuration conf = new XConfiguration();
        conf.set("user.name", getTestUser());
        Map<String, String> actionData = LauncherMapperHelper.getActionData(getFileSystem(),
                context.getActionDir(), conf);
        assertFalse(LauncherMapperHelper.hasIdSwap(actionData));
        Hive2ActionExecutor ae = new Hive2ActionExecutor();
        ae.check(context, context.getAction());
        assertTrue(launcherId.equals(context.getAction().getExternalId()));
        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
        ae.end(context, context.getAction());
        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
        assertNotNull(context.getAction().getData());
        Properties outputData = new Properties();
        outputData.load(new StringReader(context.getAction().getData()));
        assertTrue(outputData.containsKey(LauncherMain.HADOOP_JOBS));
        assertEquals(outputData.get(LauncherMain.HADOOP_JOBS), context.getExternalChildIDs());
        assertTrue(fs.exists(outputDir));
        assertTrue(fs.isDirectory(outputDir));
    }
    {
        Path script = new Path(getAppPath(), HIVE_SCRIPT_FILENAME);
        Writer scriptWriter = new OutputStreamWriter(fs.create(script));
        scriptWriter.write(getHive2Script(inputDir.toString(), outputDir.toString()));
        scriptWriter.close();

        Writer dataWriter = new OutputStreamWriter(fs.create(new Path(inputDir, DATA_FILENAME)));
        dataWriter.write(SAMPLE_DATA_TEXT);
        dataWriter.close();
        Context context = createContext(getScriptActionXml());
        final RunningJob launcherJob = submitAction(context,
                Namespace.getNamespace("uri:oozie:hive2-action:0.1"));
        String launcherId = context.getAction().getExternalId();
        waitFor(200 * 1000, new Predicate() {
            @Override
            public boolean evaluate() throws Exception {
                return launcherJob.isComplete();
            }
        });
        assertTrue(launcherJob.isSuccessful());
        Configuration conf = new XConfiguration();
        conf.set("user.name", getTestUser());
        Map<String, String> actionData = LauncherMapperHelper.getActionData(getFileSystem(),
                context.getActionDir(), conf);
        assertFalse(LauncherMapperHelper.hasIdSwap(actionData));
        Hive2ActionExecutor ae = new Hive2ActionExecutor();
        ae.check(context, context.getAction());
        assertTrue(launcherId.equals(context.getAction().getExternalId()));
        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
        ae.end(context, context.getAction());
        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
        assertNotNull(context.getAction().getData());
        Properties outputData = new Properties();
        outputData.load(new StringReader(context.getAction().getData()));
        assertTrue(outputData.containsKey(LauncherMain.HADOOP_JOBS));
        assertEquals(outputData.get(LauncherMain.HADOOP_JOBS), context.getExternalChildIDs());
        assertTrue(fs.exists(outputDir));
        assertTrue(fs.isDirectory(outputDir));
    }
}

From source file:org.apache.oozie.action.hadoop.TestHiveActionExecutor.java

License:Apache License

public void testHiveAction() throws Exception {
    Path inputDir = new Path(getFsTestCaseDir(), INPUT_DIRNAME);
    Path outputDir = new Path(getFsTestCaseDir(), OUTPUT_DIRNAME);
    String hiveScript = getHiveScript(inputDir.toString(), outputDir.toString());
    FileSystem fs = getFileSystem();

    {/*from   ww w.ja  v a 2  s .  c  o m*/
        Path script = new Path(getAppPath(), HIVE_SCRIPT_FILENAME);
        Writer scriptWriter = new OutputStreamWriter(fs.create(script));
        scriptWriter.write(hiveScript);
        scriptWriter.close();
        Writer dataWriter = new OutputStreamWriter(fs.create(new Path(inputDir, DATA_FILENAME)));
        dataWriter.write(SAMPLE_DATA_TEXT);
        dataWriter.close();
        Context context = createContext(getActionScriptXml());
        Namespace ns = Namespace.getNamespace("uri:oozie:hive-action:0.2");
        final RunningJob launcherJob = submitAction(context, ns);
        String launcherId = context.getAction().getExternalId();
        waitFor(200 * 1000, new Predicate() {
            public boolean evaluate() throws Exception {
                return launcherJob.isComplete();
            }
        });
        assertTrue(launcherJob.isSuccessful());
        Configuration conf = new XConfiguration();
        conf.set("user.name", getTestUser());
        Map<String, String> actionData = LauncherMapperHelper.getActionData(getFileSystem(),
                context.getActionDir(), conf);
        assertFalse(LauncherMapperHelper.hasIdSwap(actionData));
        HiveActionExecutor ae = new HiveActionExecutor();
        ae.check(context, context.getAction());
        assertTrue(launcherId.equals(context.getAction().getExternalId()));
        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
        assertNotNull(context.getAction().getData());
        ae.end(context, context.getAction());
        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
        assertNotNull(context.getAction().getData());
        Properties outputData = new Properties();
        outputData.load(new StringReader(context.getAction().getData()));
        assertTrue(outputData.containsKey(LauncherMain.HADOOP_JOBS));
        assertEquals(outputData.get(LauncherMain.HADOOP_JOBS), context.getExternalChildIDs());
        //while this works in a real cluster, it does not with miniMR
        //assertTrue(outputData.getProperty(LauncherMain.HADOOP_JOBS).trim().length() > 0);
        //assertTrue(!actionData.get(LauncherMapper.ACTION_DATA_EXTERNAL_CHILD_IDS).isEmpty());
        assertTrue(fs.exists(outputDir));
        assertTrue(fs.isDirectory(outputDir));
    }
    {
        Context context = createContext(getActionQueryXml(hiveScript));
        Namespace ns = Namespace.getNamespace("uri:oozie:hive-action:0.6");
        final RunningJob launcherJob = submitAction(context, ns);
        String launcherId = context.getAction().getExternalId();
        waitFor(200 * 1000, new Predicate() {
            public boolean evaluate() throws Exception {
                return launcherJob.isComplete();
            }
        });
        assertTrue(launcherJob.isSuccessful());
        Configuration conf = new XConfiguration();
        conf.set("user.name", getTestUser());
        Map<String, String> actionData = LauncherMapperHelper.getActionData(getFileSystem(),
                context.getActionDir(), conf);
        assertFalse(LauncherMapperHelper.hasIdSwap(actionData));
        HiveActionExecutor ae = new HiveActionExecutor();
        ae.check(context, context.getAction());
        assertTrue(launcherId.equals(context.getAction().getExternalId()));
        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
        assertNotNull(context.getAction().getData());
        ae.end(context, context.getAction());
        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
        assertNotNull(context.getAction().getData());
        Properties outputData = new Properties();
        outputData.load(new StringReader(context.getAction().getData()));
        assertTrue(outputData.containsKey(LauncherMain.HADOOP_JOBS));
        assertEquals(outputData.get(LauncherMain.HADOOP_JOBS), context.getExternalChildIDs());
        //while this works in a real cluster, it does not with miniMR
        //assertTrue(outputData.getProperty(LauncherMain.HADOOP_JOBS).trim().length() > 0);
        //assertTrue(!actionData.get(LauncherMapper.ACTION_DATA_EXTERNAL_CHILD_IDS).isEmpty());
        assertTrue(fs.exists(outputDir));
        assertTrue(fs.isDirectory(outputDir));
    }
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testSimpestSleSubmitOK() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "</java>";
    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override//from   w w  w  .j  av  a  2  s  .  c  o m
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testOutputSubmitOK() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "<arg>out</arg>" + "<capture-output/>" + "</java>";
    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override//  ww w .j av  a  2 s. c  om
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
    assertNotNull(context.getAction().getData());
    StringReader sr = new StringReader(context.getAction().getData());
    Properties props = new Properties();
    props.load(sr);
    assertEquals("A", props.get("a"));

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testIdSwapSubmitOK() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "<arg>id</arg>" + "<capture-output/>" + "</java>";
    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override//from  ww  w. jav a 2s  .com
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    ActionExecutor ae = new JavaActionExecutor();
    try {
        ae.check(context, context.getAction());
    } catch (ActionExecutorException ex) {
        if (!ex.getMessage().contains("IDSWAP")) {
            fail();
        }
    }
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testAdditionalJarSubmitOK() throws Exception {
    Path appJarPath = new Path("test-extra.jar");

    File jarFile = IOUtils.createJar(new File(getTestCaseDir()), appJarPath.getName(),
            LauncherMainTester2.class);
    InputStream is = new FileInputStream(jarFile);
    OutputStream os = getFileSystem().create(new Path(getAppPath(), appJarPath.toString()));
    IOUtils.copyStream(is, os);//  w  ww .j  a  v a2s.  c  o  m

    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester2.class.getName()
            + "</main-class>" + "<file>" + appJarPath.toString() + "</file>" + "</java>";

    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    ActionExecutor ae = new JavaActionExecutor();
    assertFalse(ae.isCompleted(context.getAction().getExternalStatus()));
    waitFor(60 * 1000, new Predicate() {
        @Override
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    ae.check(context, context.getAction());
    assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testExit0SubmitOK() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "<arg>exit0</arg>" + "</java>";

    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override/*from   w  ww.  j  a va2s. com*/
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertTrue(ae.isCompleted(context.getAction().getExternalStatus()));
    assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testExit1SubmitError() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "<arg>exit1</arg>" + "</java>";

    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override/*from ww  w.  j a  v a  2  s  .  co m*/
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    assertFalse(LauncherMapperHelper.isMainSuccessful(runningJob));
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertTrue(ae.isCompleted(context.getAction().getExternalStatus()));
    assertEquals("FAILED/KILLED", context.getAction().getExternalStatus());
    assertEquals("1", context.getAction().getErrorCode());
    assertNull(context.getAction().getData());

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.ERROR, context.getAction().getStatus());
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testExceptionSubmitException() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "<arg>exception</arg>" + "</java>";

    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override/* ww w . ja  va  2 s  .  com*/
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    assertFalse(LauncherMapperHelper.isMainSuccessful(runningJob));
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertTrue(ae.isCompleted(context.getAction().getExternalStatus()));
    assertEquals("FAILED/KILLED", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.ERROR, context.getAction().getStatus());
}

From source file:org.apache.oozie.action.hadoop.TestJavaActionExecutor.java

License:Apache License

public void testExceptionSubmitThrowable() throws Exception {
    String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
            + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName()
            + "</main-class>" + "<arg>throwable</arg>" + "</java>";

    Context context = createContext(actionXml, null);
    final RunningJob runningJob = submitAction(context);
    waitFor(60 * 1000, new Predicate() {
        @Override//from ww  w  .  java2  s  .  c  o  m
        public boolean evaluate() throws Exception {
            return runningJob.isComplete();
        }
    });
    assertTrue(runningJob.isSuccessful());
    assertFalse(LauncherMapperHelper.isMainSuccessful(runningJob));
    ActionExecutor ae = new JavaActionExecutor();
    ae.check(context, context.getAction());
    assertTrue(ae.isCompleted(context.getAction().getExternalStatus()));
    assertEquals("FAILED/KILLED", context.getAction().getExternalStatus());
    assertNull(context.getAction().getData());

    ae.end(context, context.getAction());
    assertEquals(WorkflowAction.Status.ERROR, context.getAction().getStatus());
}