use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestActionErrors method _testErrorWithUserRetry.
/**
* Provides functionality to test user retry
*
* @param errorType the error type. (start.non-transient, end.non-transient)
* @param externalStatus the external status to set.
* @param signalValue the signal value to set.
* @throws Exception
*/
private void _testErrorWithUserRetry(String errorType, String externalStatus, String signalValue) throws Exception {
String workflowPath = getTestCaseFileUri("workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid-user-retry.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("error", errorType);
conf.set("external-status", externalStatus);
conf.set("signal-value", signalValue);
final String jobId = engine.submitJob(conf, true);
final JPAService jpaService = Services.get().get(JPAService.class);
final WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
return (action != null && action.getUserRetryCount() == 2);
}
});
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
assertEquals(2, action.getUserRetryCount());
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestActionErrors method _testError.
/**
* Provides functionality to test errors
*
* @param errorType the error type. (start.non-transient, end.non-transient)
* @param externalStatus the external status to set.
* @param signalValue the signal value to set.
* @throws Exception
*/
private void _testError(String errorType, String externalStatus, String signalValue) throws Exception {
String workflowPath = getTestCaseFileUri("workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("error", errorType);
conf.set("external-status", externalStatus);
conf.set("signal-value", signalValue);
final String jobId = engine.submitJob(conf, true);
final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
store.beginTrx();
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowJobBean bean = store.getWorkflow(jobId, false);
return (bean.getWorkflowInstance().getStatus() == WorkflowInstance.Status.KILLED);
}
});
assertEquals(WorkflowJob.Status.KILLED, engine.getJob(jobId).getStatus());
store.commitTrx();
store.closeTrx();
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestActionErrors method _testTransient.
/**
* Provides functionality to test transient failures.
*
* @param errorType the error type. (start.transient, end.transient)
* @param expStatus1 expected status after the first step (START_RETRY, END_RETRY)
* @param expStatus2 expected status after the second step (START_MANUAL, END_MANUAL)
* @param expErrorMsg the expected error message.
* @throws Exception
*/
private void _testTransient(String errorType, WorkflowActionBean.Status expStatus1, final WorkflowActionBean.Status expStatus2, String expErrorMsg) throws Exception {
String workflowPath = getTestCaseFileUri("workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final int maxRetries = 2;
final int retryInterval = 10;
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("signal-value", "OK");
conf.set("external-status", "ok");
conf.set("error", errorType);
conf.setInt(OozieClient.ACTION_MAX_RETRIES, maxRetries);
conf.setInt(OozieClient.ACTION_RETRY_INTERVAL, retryInterval);
final String jobId = engine.submitJob(conf, true);
int retryCount = 1;
WorkflowActionBean.Status expectedStatus = expStatus1;
int expectedRetryCount = 2;
Thread.sleep(20000);
String aId = null;
final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
store.beginTrx();
while (retryCount <= maxRetries) {
List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
aId = action.getId();
assertEquals(expectedStatus, action.getStatus());
assertEquals(expectedRetryCount, action.getRetries());
assertEquals("TEST_ERROR", action.getErrorCode());
assertEquals(expErrorMsg, action.getErrorMessage());
if (action.getRetries() == maxRetries) {
expectedRetryCount = 0;
expectedStatus = expStatus2;
break;
} else {
expectedRetryCount++;
}
Thread.sleep(retryInterval * 1000);
retryCount++;
}
store.commitTrx();
store.closeTrx();
Thread.sleep(5000);
final String actionId = aId;
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getWorkflowAction(actionId).getStatus() == expStatus2);
}
});
final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
store2.beginTrx();
WorkflowActionBean action = engine.getWorkflowAction(actionId);
assertEquals("TEST_ERROR", action.getErrorCode());
assertEquals(expErrorMsg, action.getErrorMessage());
assertEquals(expStatus2, action.getStatus());
assertTrue(action.isPending() == false);
assertEquals(WorkflowJob.Status.SUSPENDED, engine.getJob(jobId).getStatus());
store2.commitTrx();
store2.closeTrx();
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestActionStartXCommand method testActionReuseWfJobAppPath.
public void testActionReuseWfJobAppPath() throws Exception {
JPAService jpaService = Services.get().get(JPAService.class);
WorkflowJobBean job = this.addRecordToWfJobTableWithCustomAppPath(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
WorkflowActionBean action = this.addRecordToWfActionTableWithAppPathConfig(job.getId(), "1", WorkflowAction.Status.PREP);
WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
new ActionStartXCommand(action.getId(), "map-reduce").call();
action = jpaService.execute(wfActionGetCmd);
assertNotNull(action.getExternalId());
Element actionXml = XmlUtils.parseXml(action.getConf());
Namespace ns = actionXml.getNamespace();
Element configElem = actionXml.getChild("configuration", ns);
String strConf = XmlUtils.prettyPrint(configElem).toString();
XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
String workDir = inlineConf.get("work.dir", null);
assertNotNull(workDir);
assertFalse(workDir.contains("workflow.xml"));
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestActionUserRetry method testUserRetryPolicy.
public void testUserRetryPolicy() throws JPAExecutorException, IOException, CommandException {
Configuration conf = new XConfiguration();
String workflowUri = getTestCaseFileUri("workflow.xml");
// @formatter:off
String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"1\" retry-policy=\"exponential\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
// @Formatter:on
writeToFile(appXml, workflowUri);
conf.set(OozieClient.APP_PATH, workflowUri);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("error", "start.error");
conf.set("external-status", "error");
conf.set("signal-value", "based_on_action_status");
SubmitXCommand sc = new SubmitXCommand(conf);
final String jobId = sc.call();
new StartXCommand(jobId).call();
final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
final JPAService jpaService = Services.get().get(JPAService.class);
// set a timeout for exponential retry of action with respect to given
// retry-interval and retry-max.
// If retry-interval is 1 then, for first retry, delay will be 1 min,
// for second retry it will be 2 min, 4, 8, 16 & so on.
int timeout = (1 + 2) * 60 * 1000;
waitFor(timeout, new Predicate() {
public boolean evaluate() throws Exception {
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
return (action != null && action.getUserRetryCount() == 2);
}
});
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
assertEquals(2, action.getUserRetryCount());
}
Aggregations