Repository: oozie Updated Branches: refs/heads/master 0e1a00044 -> 406183137
http://git-wip-us.apache.org/repos/asf/oozie/blob/40618313/core/src/test/java/org/apache/oozie/servlet/MockCoordinatorEngineService.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/servlet/MockCoordinatorEngineService.java b/core/src/test/java/org/apache/oozie/servlet/MockCoordinatorEngineService.java index 4fc8653..d771f29 100644 --- a/core/src/test/java/org/apache/oozie/servlet/MockCoordinatorEngineService.java +++ b/core/src/test/java/org/apache/oozie/servlet/MockCoordinatorEngineService.java @@ -38,12 +38,15 @@ import org.apache.oozie.XException; import org.apache.oozie.client.CoordinatorAction; import org.apache.oozie.client.CoordinatorJob; import org.apache.oozie.client.CoordinatorJob.Execution; +import org.apache.oozie.client.CoordinatorWfAction; import org.apache.oozie.client.rest.RestConstants; import org.apache.oozie.command.CommandException; import org.apache.oozie.dependency.ActionDependency; import org.apache.oozie.service.CoordinatorEngineService; import org.apache.oozie.util.DateUtils; import org.apache.oozie.util.Pair; +import org.apache.oozie.WorkflowActionBean; +import org.apache.oozie.CoordinatorWfActionBean; public class MockCoordinatorEngineService extends CoordinatorEngineService { public static final String JOB_ID = "coord-job-C-"; @@ -61,9 +64,13 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { public static Integer length = null; public static String order = null; public static String filter = null; + public static String wfActionName = null; public static List<CoordinatorJob> coordJobs; - public static List<Boolean> started; + public static List<CoordinatorWfActionBean> coordWfActions; + public static List<Boolean> startedCoordJobs; public static final int INIT_COORD_COUNT = 4; + public static final int INIT_WF_ACTION_COUNT = 2; + static { @@ -77,11 +84,17 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { order = null; filter = null; coordJobs = new ArrayList<CoordinatorJob>(); - started = new ArrayList<Boolean>(); + coordWfActions = new ArrayList<CoordinatorWfActionBean>(); + startedCoordJobs = new ArrayList<Boolean>(); for (int i = 0; i < INIT_COORD_COUNT; i++) { coordJobs.add(createDummyCoordinatorJob(i)); - started.add(false); + startedCoordJobs.add(false); + } + for(int i = 0; i < INIT_WF_ACTION_COUNT; i++) { + coordWfActions.add(createDummyCoordWfAction("actionTest", i+1)); } + String nullReason = CoordinatorWfAction.NullReason.ACTION_NULL.getNullReason("actionTest2", "wf1"); + coordWfActions.add(new CoordinatorWfActionBean(INIT_WF_ACTION_COUNT+1, null, nullReason)); } @Override @@ -108,7 +121,7 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { did = "submit"; int idx = coordJobs.size(); coordJobs.add(createDummyCoordinatorJob(idx, conf)); - started.add(startJob); + startedCoordJobs.add(startJob); return JOB_ID + idx; } @@ -117,7 +130,7 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { did = RestConstants.JOB_ACTION_DRYRUN; int idx = coordJobs.size(); coordJobs.add(createDummyCoordinatorJob(idx, conf)); - started.add(false); + startedCoordJobs.add(false); return JOB_ID + idx; } @@ -125,21 +138,21 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { public void resume(String jobId) throws CoordinatorEngineException { did = RestConstants.JOB_ACTION_RESUME; int idx = validateCoordinatorIdx(jobId); - started.set(idx, true); + startedCoordJobs.set(idx, true); } @Override public void suspend(String jobId) throws CoordinatorEngineException { did = RestConstants.JOB_ACTION_SUSPEND; int idx = validateCoordinatorIdx(jobId); - started.set(idx, false); + startedCoordJobs.set(idx, false); } @Override public void kill(String jobId) throws CoordinatorEngineException { did = RestConstants.JOB_ACTION_KILL; int idx = validateCoordinatorIdx(jobId); - started.set(idx, false); + startedCoordJobs.set(idx, false); } @Override @@ -147,7 +160,7 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { throws CoordinatorEngineException { did = RestConstants.JOB_ACTION_KILL; int idx = validateCoordinatorIdx(jobId); - started.set(idx, false); + startedCoordJobs.set(idx, false); List<CoordinatorAction> actions = coordJobs.get(idx).getActions(); List<CoordinatorActionBean> actionBeans = new ArrayList<CoordinatorActionBean>(); @@ -162,7 +175,7 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { public void change(String jobId, String changeValue) throws CoordinatorEngineException { did = RestConstants.JOB_ACTION_CHANGE; int idx = validateCoordinatorIdx(jobId); - started.set(idx, true); + startedCoordJobs.set(idx, true); } @Override @@ -174,7 +187,7 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { public CoordinatorActionInfo ignore(String jobId, String type, String scope) throws CoordinatorEngineException { did = RestConstants.JOB_ACTION_IGNORE; int idx = validateCoordinatorIdx(jobId); - started.set(idx, true); + startedCoordJobs.set(idx, true); return null; } @Override @@ -182,7 +195,7 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { boolean noCleanup, boolean failed, Configuration conf) throws BaseEngineException { did = RestConstants.JOB_COORD_ACTION_RERUN; int idx = validateCoordinatorIdx(jobId); - started.set(idx, true); + startedCoordJobs.set(idx, true); List<CoordinatorAction> actions = coordJobs.get(idx).getActions(); List<CoordinatorActionBean> actionBeans = new ArrayList<CoordinatorActionBean>(); for (CoordinatorAction action : actions) { @@ -296,6 +309,16 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { did = RestConstants.SLA_ENABLE_ALERT; } + @Override + public List<CoordinatorWfActionBean> getWfActionByJobIdAndName(String jobId, String wfActionName, int offset, int len) + throws CoordinatorEngineException { + did = RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD; + MockCoordinatorEngineService.offset = offset; + MockCoordinatorEngineService.length = len; + MockCoordinatorEngineService.wfActionName = wfActionName; + return coordWfActions; + } + private int validateCoordinatorIdx(String jobId) throws CoordinatorEngineException { int idx = -1; try { @@ -397,4 +420,12 @@ public class MockCoordinatorEngineService extends CoordinatorEngineService { return action; } + private static CoordinatorWfActionBean createDummyCoordWfAction(String name, int id) { + CoordinatorWfActionBean coordWfAction = null; + WorkflowActionBean wfAction = new WorkflowActionBean(); + wfAction.setName(name); + coordWfAction = new CoordinatorWfActionBean(id, wfAction, null); + return coordWfAction; + } + } http://git-wip-us.apache.org/repos/asf/oozie/blob/40618313/core/src/test/java/org/apache/oozie/servlet/TestV2JobServlet.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/servlet/TestV2JobServlet.java b/core/src/test/java/org/apache/oozie/servlet/TestV2JobServlet.java index fb203a6..bacfe89 100644 --- a/core/src/test/java/org/apache/oozie/servlet/TestV2JobServlet.java +++ b/core/src/test/java/org/apache/oozie/servlet/TestV2JobServlet.java @@ -18,9 +18,12 @@ package org.apache.oozie.servlet; +import org.apache.oozie.client.CoordinatorWfAction; import org.apache.oozie.client.OozieClient; import org.apache.oozie.client.rest.RestConstants; import org.apache.oozie.client.rest.JsonTags; +import org.apache.oozie.service.ConfigurationService; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; @@ -256,4 +259,190 @@ public class TestV2JobServlet extends DagServletTestCase { } }); } + + //test normal request + public void testGetWfActionByJobIdAndNameNormal() throws Exception { + runTest("/v2/job/*", V2JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "2"); + params.put(RestConstants.LEN_PARAM, "2"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); + assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE)); + JSONObject obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); + assertEquals(MockCoordinatorEngineService.JOB_ID+1, obj.get(JsonTags.COORDINATOR_JOB_ID)); + assertEquals(RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD, MockCoordinatorEngineService.did); + assertEquals(MockCoordinatorEngineService.offset.intValue(), 2); + assertEquals(MockCoordinatorEngineService.length.intValue(), 2); + JSONArray coordWfActions = (JSONArray) obj.get(JsonTags.COORDINATOR_WF_ACTIONS); + assertEquals(coordWfActions.size(), 3); + for(int i = 0; i < coordWfActions.size(); i++) { + JSONObject coordWfAction = (JSONObject) coordWfActions.get(i); + JSONObject wfAction = (JSONObject) coordWfAction.get(JsonTags.COORDINATOR_WF_ACTION); + if (i == (coordWfActions.size() - 1)) { + assertEquals(null, wfAction); + String nullReason = CoordinatorWfAction.NullReason.ACTION_NULL.getNullReason("actionTest2", "wf1"); + assertEquals(nullReason, coordWfAction.get(JsonTags.COORDINATOR_WF_ACTION_NULL_REASON)); + } + else { + assertEquals("actionTest", wfAction.get(JsonTags.WORKFLOW_ACTION_NAME)); + } + } + + return null; + } + }); + } + + //test missing parameter action-name + public void testGetWfActionByJobIdAndNameActionNameMissing() throws Exception { + runTest("/v2/job/*", V2JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); + + return null; + } + }); + } + + //test unparseable offset + public void testGetWfActionByJobIdAndNameUnparseableOffset() throws Exception { + runTest("/v2/job/*", V2JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "2abc"); + params.put(RestConstants.LEN_PARAM, "2"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); + + return null; + } + }); + } + + //test unparseable len + public void testGetWfActionByJobIdAndNameUnparseableLen() throws Exception { + runTest("/v2/job/*", V2JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "2"); + params.put(RestConstants.LEN_PARAM, "2abc"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); + + return null; + } + }); + } + + public void testGetWfActionByJobIdAndNameOffsetOutOfRange() throws Exception { + runTest("/v2/job/*", V2JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "-1"); + params.put(RestConstants.LEN_PARAM, "2"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); + assertEquals(MockCoordinatorEngineService.offset.intValue(), 1); + + return null; + } + }); + } + + public void testGetWfActionByJobIdAndNameLenOutOfRange() throws Exception { + runTest("/v2/job/*", V2JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "1"); + params.put(RestConstants.LEN_PARAM, "-1"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); + assertEquals(MockCoordinatorEngineService.length.intValue(), + ConfigurationService.getInt("oozie.coord.actions.default.length")); + + return null; + } + }); + } + + public void testGetWfActionFromV0JobServlet() throws Exception { + runTest("/v0/job/*", V0JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "2"); + params.put(RestConstants.LEN_PARAM, "2"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); + + return null; + } + }); + } + + public void testGetWfActionFromV1JobServlet() throws Exception { + runTest("/v1/job/*", V1JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { + @Override + public Void call() throws Exception { + MockCoordinatorEngineService.reset(); + Map<String, String> params = new HashMap<String, String>(); + params = new HashMap<String, String>(); + params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD); + params.put(RestConstants.OFFSET_PARAM, "2"); + params.put(RestConstants.LEN_PARAM, "2"); + params.put(RestConstants.ACTION_NAME_PARAM, "actionTest"); + URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); + return null; + } + }); + } } http://git-wip-us.apache.org/repos/asf/oozie/blob/40618313/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 69c82ff..71af781 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 4.4.0 release (trunk - unreleased) +OOZIE-2827 More directly view of the coordinatorâs history from perspective of workflow action. (Alonzo Zhou via pbacsko) OOZIE-2864 Maven artifacts for package com.codahale.metrics have inconsistent groupId (andras.piros via pbacsko) OOZIE-2862 Coord change command doesn't change job to running if job was killed without creating any actions (puru) OOZIE-2815 Oozie not always display job log (puru)