use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestSshActionExecutor method testNoArgsNorArg.
public void testNoArgsNorArg() throws Exception {
String baseDir = getTestCaseDir();
Path appPath = new Path(getNameNodeUri(), baseDir);
Path script = new Path(baseDir, "script.sh");
FileSystem fs = FileSystem.getLocal(createJobConf());
Writer w = new OutputStreamWriter(fs.create(script));
w.write("echo \"prop1=something\"");
w.close();
XConfiguration protoConf = new XConfiguration();
protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
XConfiguration wfConf = new XConfiguration();
wfConf.set(OozieClient.APP_PATH, appPath.toString());
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setConf(wfConf.toXmlString());
workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
workflow.setProtoActionConf(protoConf.toXmlString());
workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
final WorkflowActionBean action = new WorkflowActionBean();
action.setId("actionId");
action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>localhost</host>" + "<command>" + script.toString() + "</command>" + "<capture-output/>" + "</ssh>");
action.setName("ssh");
final SshActionExecutor ssh = new SshActionExecutor();
final Context context = new Context(workflow, action);
ssh.start(context, action);
waitFor(30 * 1000, new Predicate() {
@Override
public boolean evaluate() throws Exception {
ssh.check(context, action);
return Status.DONE == action.getStatus();
}
});
ssh.end(context, action);
assertEquals(Status.OK, action.getStatus());
assertEquals("something", PropertiesUtils.stringToProperties(action.getData()).getProperty("prop1"));
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestJsonWorkflowJob method createWorkflow.
static WorkflowJobBean createWorkflow() {
WorkflowJobBean wf = new WorkflowJobBean();
wf.setAppPath("a");
wf.setAppName("b");
wf.setId("c");
wf.setConf("cc");
wf.setStatus(WorkflowJob.Status.PREP);
wf.setCreatedTime(JsonUtils.parseDateRfc822(CREATED_TIME));
wf.setStartTime(JsonUtils.parseDateRfc822(START_TIME));
wf.setEndTime(JsonUtils.parseDateRfc822(END_TIME));
wf.setUser("d");
wf.setGroup("e");
wf.setRun(2);
wf.setConsoleUrl("cu");
return wf;
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestJsonWorkflowJob method testProperties.
public void testProperties() {
WorkflowJobBean wf = createWorkflow();
assertEquals("a", wf.getAppPath());
assertEquals("b", wf.getAppName());
assertEquals("c", wf.getId());
assertEquals("cc", wf.getConf());
assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
assertEquals(JsonUtils.parseDateRfc822(CREATED_TIME), wf.getCreatedTime());
assertEquals(JsonUtils.parseDateRfc822(START_TIME), wf.getStartTime());
assertEquals(JsonUtils.parseDateRfc822(END_TIME), wf.getEndTime());
assertEquals("d", wf.getUser());
assertEquals("e", wf.getGroup());
assertEquals(2, wf.getRun());
assertEquals("cu", wf.getConsoleUrl());
assertEquals(0, wf.getActions().size());
wf.setActions(Arrays.asList((WorkflowActionBean) TestJsonWorkflowAction.createNode()));
assertEquals(1, wf.getActions().size());
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class WorkflowJobQueryExecutor method getList.
@Override
public List<WorkflowJobBean> getList(WorkflowJobQuery namedQuery, Object... parameters) throws JPAExecutorException {
JPAService jpaService = Services.get().get(JPAService.class);
EntityManager em = jpaService.getEntityManager();
Query query = getSelectQuery(namedQuery, em, parameters);
List<?> retList = (List<?>) jpaService.executeGetList(namedQuery.name(), query, em);
List<WorkflowJobBean> beanList = new ArrayList<WorkflowJobBean>();
if (retList != null) {
for (Object ret : retList) {
beanList.add(constructBean(namedQuery, ret, parameters));
}
}
return beanList;
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class WorkflowJobQueryExecutor method constructBean.
private WorkflowJobBean constructBean(WorkflowJobQuery namedQuery, Object ret, Object... parameters) throws JPAExecutorException {
WorkflowJobBean bean;
Object[] arr;
switch(namedQuery) {
case GET_WORKFLOW:
bean = (WorkflowJobBean) ret;
break;
case GET_WORKFLOW_STARTTIME:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[1]));
break;
case GET_WORKFLOW_START_END_TIME:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[1]));
bean.setEndTime(DateUtils.toDate((Timestamp) arr[2]));
break;
case GET_WORKFLOW_USER_GROUP:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setUser((String) arr[0]);
bean.setGroup((String) arr[1]);
break;
case GET_WORKFLOW_SUSPEND:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setUser((String) arr[1]);
bean.setGroup((String) arr[2]);
bean.setAppName((String) arr[3]);
bean.setStatusStr((String) arr[4]);
bean.setParentId((String) arr[5]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[6]));
bean.setEndTime(DateUtils.toDate((Timestamp) arr[7]));
bean.setLogToken((String) arr[8]);
bean.setWfInstanceBlob((BinaryBlob) (arr[9]));
break;
case GET_WORKFLOW_ACTION_OP:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setUser((String) arr[1]);
bean.setGroup((String) arr[2]);
bean.setAppName((String) arr[3]);
bean.setAppPath((String) arr[4]);
bean.setStatusStr((String) arr[5]);
bean.setRun((Integer) arr[6]);
bean.setParentId((String) arr[7]);
bean.setLogToken((String) arr[8]);
bean.setWfInstanceBlob((BinaryBlob) (arr[9]));
bean.setProtoActionConfBlob((StringBlob) arr[10]);
break;
case GET_WORKFLOW_RERUN:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setUser((String) arr[1]);
bean.setGroup((String) arr[2]);
bean.setAppName((String) arr[3]);
bean.setStatusStr((String) arr[4]);
bean.setRun((Integer) arr[5]);
bean.setLogToken((String) arr[6]);
bean.setWfInstanceBlob((BinaryBlob) (arr[7]));
bean.setParentId((String) arr[8]);
break;
case GET_WORKFLOW_DEFINITION:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setUser((String) arr[1]);
bean.setGroup((String) arr[2]);
bean.setAppName((String) arr[3]);
bean.setLogToken((String) arr[4]);
bean.setWfInstanceBlob((BinaryBlob) (arr[5]));
break;
case GET_WORKFLOW_KILL:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setUser((String) arr[1]);
bean.setGroup((String) arr[2]);
bean.setAppName((String) arr[3]);
bean.setAppPath((String) arr[4]);
bean.setStatusStr((String) arr[5]);
bean.setParentId((String) arr[6]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[7]));
bean.setEndTime(DateUtils.toDate((Timestamp) arr[8]));
bean.setLogToken((String) arr[9]);
bean.setWfInstanceBlob((BinaryBlob) (arr[10]));
bean.setSlaXmlBlob((StringBlob) arr[11]);
bean.setProtoActionConfBlob((StringBlob) arr[12]);
break;
case GET_WORKFLOW_RESUME:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setUser((String) arr[1]);
bean.setGroup((String) arr[2]);
bean.setAppName((String) arr[3]);
bean.setAppPath((String) arr[4]);
bean.setStatusStr((String) arr[5]);
bean.setParentId((String) arr[6]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[7]));
bean.setEndTime(DateUtils.toDate((Timestamp) arr[8]));
bean.setLogToken((String) arr[9]);
bean.setWfInstanceBlob((BinaryBlob) (arr[10]));
bean.setProtoActionConfBlob((StringBlob) arr[11]);
break;
case GET_WORKFLOW_STATUS:
bean = new WorkflowJobBean();
bean.setId((String) parameters[0]);
bean.setStatusStr((String) ret);
break;
case GET_WORKFLOWS_PARENT_COORD_RERUN:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setStatusStr((String) arr[1]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[2]));
bean.setEndTime(DateUtils.toDate((Timestamp) arr[3]));
break;
case GET_COMPLETED_COORD_WORKFLOWS_OLDER_THAN:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setParentId((String) arr[1]);
break;
case GET_WORKFLOW_FOR_SLA:
bean = new WorkflowJobBean();
arr = (Object[]) ret;
bean.setId((String) arr[0]);
bean.setStatusStr((String) arr[1]);
bean.setStartTime(DateUtils.toDate((Timestamp) arr[2]));
bean.setEndTime(DateUtils.toDate((Timestamp) arr[3]));
break;
default:
throw new JPAExecutorException(ErrorCode.E0603, "QueryExecutor cannot construct job bean for " + namedQuery.name());
}
return bean;
}
Aggregations