Search in sources :

Example 36 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class TestCoordChangeXCommand method testCoordStatus_Failed.

// Status change from failed- successful
public void testCoordStatus_Failed() throws Exception {
    Date start = new Date();
    // 5 hrs
    Date end = new Date(start.getTime() + (5 * HOURS_IN_MS));
    String status = "status=RUNNING";
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.FAILED, start, end, end, true, false, 4);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
    try {
        new CoordChangeXCommand(job.getId(), status).call();
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
        CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
        assertEquals(coordJob.getStatusStr(), "RUNNING");
    } catch (CommandException e) {
        e.printStackTrace();
        if (e.getErrorCode() != ErrorCode.E1022) {
            fail("Error code should be E1022");
        }
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 37 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class TestCoordMaterializeTransitionXCommand method testActionMaterForHcatalogIncorrectURI.

public void testActionMaterForHcatalogIncorrectURI() throws Exception {
    Services.get().destroy();
    Services services = super.setupServicesForHCatalog();
    services.init();
    Date startTime = DateUtils.parseDateOozieTZ("2009-03-06T010:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2009-03-11T10:00Z");
    CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-job-for-matd-neg-hcat.xml", CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
    try {
        new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
        fail("Expected Command exception but didn't catch any");
    } catch (CommandException e) {
        e.printStackTrace();
        job = services.get(JPAService.class).execute(new CoordJobGetJPAExecutor(job.getId()));
        assertEquals(CoordinatorJob.Status.FAILED, job.getStatus());
        assertEquals(ErrorCode.E1012, e.getErrorCode());
    } catch (Exception e) {
        fail("Unexpected exception " + e.getMessage());
    }
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ParseException(java.text.ParseException) CommandException(org.apache.oozie.command.CommandException)

Example 38 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class TestBundleSubmitXCommand method testMultipleCoordSubmit.

public void testMultipleCoordSubmit() throws Exception {
    final XConfiguration jobConf = setUpBundle();
    jobConf.set("coordName1", "coord1");
    jobConf.set("coordName2", "coord2");
    jobConf.set("coord1.starttime", "2009-02-01T00:00Z");
    BundleSubmitXCommand command = new BundleSubmitXCommand(jobConf);
    final BundleJobBean bundleBean = (BundleJobBean) command.getJob();
    bundleBean.setStartTime(new Date());
    bundleBean.setEndTime(new Date());
    final String jobId = command.call();
    sleep(2000);
    new BundleStartXCommand(jobId).call();
    waitFor(2000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
            return actions.get(0).getStatus().equals(Job.Status.RUNNING);
        }
    });
    List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
    assertEquals(actions.size(), 2);
    assertEquals(actions.get(0).getCoordName(), "coord1");
    assertEquals(actions.get(1).getCoordName(), "coord2");
    try {
        new BundleCoordSubmitXCommand(jobConf, jobId, "coord1").call();
        fail("Should fail. Coord job is already created");
    } catch (CommandException e) {
        assertEquals(e.getErrorCode(), ErrorCode.E1304);
    }
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
    assertEquals(actions.size(), 2);
    assertEquals(actions.get(0).getStatusStr(), "RUNNING");
    assertEquals(actions.get(1).getStatusStr(), "RUNNING");
}
Also used : CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XConfiguration(org.apache.oozie.util.XConfiguration) BundleJobBean(org.apache.oozie.BundleJobBean) List(java.util.List) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 39 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class TestCoordActionInputCheckXCommand method addRecordToCoordJobTable.

private CoordinatorJobBean addRecordToCoordJobTable(String jobId, Date start, Date end, String dataInType) throws CommandException {
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(jobId);
    coordJob.setAppName("testApp");
    coordJob.setAppPath("testAppPath");
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    coordJob.setCreatedTime(new Date());
    coordJob.setLastModifiedTime(new Date());
    coordJob.setUser("testUser");
    coordJob.setGroup("testGroup");
    coordJob.setTimeZone("UTC");
    coordJob.setTimeUnit(Timeunit.DAY);
    coordJob.setMatThrottling(2);
    try {
        coordJob.setStartTime(start);
        coordJob.setEndTime(end);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not set Date/time");
    }
    String testDir = getTestCaseDir();
    XConfiguration jobConf = new XConfiguration();
    jobConf.set(OozieClient.USER_NAME, getTestUser());
    String confStr = jobConf.toXmlString(false);
    coordJob.setConf(confStr);
    String appXml = "<coordinator-app xmlns='uri:oozie:coordinator:0.2' name='NAME' frequency=\"1\" start='2009-02-01T01:00" + TZ + "' end='2009-02-03T23:59" + TZ + "' timezone='UTC' freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<controls>";
    appXml += "<timeout>10</timeout>";
    appXml += "<concurrency>2</concurrency>";
    appXml += "<execution>LIFO</execution>";
    appXml += "</controls>";
    appXml += "<input-events>";
    appXml += "<data-in name='A' dataset='a'>";
    appXml += "<dataset name='a' frequency='7' initial-instance='2009-01-01T01:00" + TZ + "' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    if (dataInType.equals("future")) {
        appXml += "<start-instance>${coord:" + dataInType + "(0,5)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(3,5)}</end-instance>";
    } else if (dataInType.equals("latest")) {
        appXml += "<start-instance>${coord:" + dataInType + "(-3)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(0)}</end-instance>";
    } else if (dataInType.equals("current")) {
        appXml += "<start-instance>${coord:" + dataInType + "(-3)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(1)}</end-instance>";
    }
    appXml += "</data-in>";
    appXml += "</input-events>";
    appXml += "<output-events>";
    appXml += "<data-out name='LOCAL_A' dataset='local_a'>";
    appXml += "<dataset name='local_a' frequency='7' initial-instance='2009-01-01T01:00" + TZ + "' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    appXml += "<start-instance>${coord:current(-3)}</start-instance>";
    appXml += "<instance>${coord:current(0)}</instance>";
    appXml += "</data-out>";
    appXml += "</output-events>";
    appXml += "<action>";
    appXml += "<workflow>";
    appXml += "<app-path>hdfs:///tmp/workflows/</app-path>";
    appXml += "<configuration>";
    appXml += "<property>";
    appXml += "<name>inputA</name>";
    appXml += "<value>${coord:dataIn('A')}</value>";
    appXml += "</property>";
    appXml += "<property>";
    appXml += "<name>inputB</name>";
    appXml += "<value>${coord:dataOut('LOCAL_A')}</value>";
    appXml += "</property>";
    appXml += "</configuration>";
    appXml += "</workflow>";
    appXml += "</action>";
    appXml += "</coordinator-app>";
    coordJob.setJobXml(appXml);
    coordJob.setLastActionNumber(0);
    coordJob.setFrequency("1");
    coordJob.setExecutionOrder(Execution.FIFO);
    coordJob.setConcurrency(1);
    JPAService jpaService = Services.get().get(JPAService.class);
    if (jpaService != null) {
        try {
            jpaService.execute(new CoordJobInsertJPAExecutor(coordJob));
        } catch (JPAExecutorException e) {
            throw new CommandException(e);
        }
    } else {
        fail("Unable to insert the test job record to table");
    }
    return coordJob;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 40 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class TestBundleKillXCommand method testBundleKill3.

/**
 * Test : Kill bundle job
 *
 * @throws Exception
 */
public void testBundleKill3() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(job.getConf()));
    } catch (IOException ioe) {
        log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe);
    }
    Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    BundleSubmitXCommand submitCmd = new BundleSubmitXCommand(jobConf);
    submitCmd.call();
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.PREP, job.getStatus());
    new BundleKillXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.KILLED, job.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) BundleJobBean(org.apache.oozie.BundleJobBean) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Aggregations

CommandException (org.apache.oozie.command.CommandException)225 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)85 XConfiguration (org.apache.oozie.util.XConfiguration)62 Date (java.util.Date)59 IOException (java.io.IOException)57 Configuration (org.apache.hadoop.conf.Configuration)56 JPAService (org.apache.oozie.service.JPAService)56 XException (org.apache.oozie.XException)42 PreconditionException (org.apache.oozie.command.PreconditionException)35 ArrayList (java.util.ArrayList)26 StringReader (java.io.StringReader)25 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)24 List (java.util.List)23 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)23 Element (org.jdom.Element)23 JDOMException (org.jdom.JDOMException)20 File (java.io.File)16 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)16 WorkflowException (org.apache.oozie.workflow.WorkflowException)16 URISyntaxException (java.net.URISyntaxException)14