Repository: oozie Updated Branches: refs/heads/master a175747df -> f2446d5c0
OOZIE-2181 JsonToBean has some missing and incorrect mappings (rkanter) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/f2446d5c Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/f2446d5c Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/f2446d5c Branch: refs/heads/master Commit: f2446d5c04ee1306716d1a6fdab8449f6dd7d9f8 Parents: a175747 Author: Robert Kanter <[email protected]> Authored: Mon Mar 30 22:19:23 2015 -0700 Committer: Robert Kanter <[email protected]> Committed: Mon Mar 30 22:19:23 2015 -0700 ---------------------------------------------------------------------- .../org/apache/oozie/client/rest/JsonTags.java | 5 +- .../apache/oozie/client/rest/JsonToBean.java | 34 ++++++--- .../oozie/client/rest/TestJsonToBean.java | 78 ++++++++++++++++++++ .../org/apache/oozie/WorkflowActionBean.java | 4 + release-log.txt | 1 + 5 files changed, 111 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/f2446d5c/client/src/main/java/org/apache/oozie/client/rest/JsonTags.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/client/rest/JsonTags.java b/client/src/main/java/org/apache/oozie/client/rest/JsonTags.java index 3c2409f..47da15e 100644 --- a/client/src/main/java/org/apache/oozie/client/rest/JsonTags.java +++ b/client/src/main/java/org/apache/oozie/client/rest/JsonTags.java @@ -85,7 +85,10 @@ public interface JsonTags { public static final String WORKFLOW_ACTION_CONSOLE_URL = "consoleUrl"; public static final String WORKFLOW_ACTION_ERROR_CODE = "errorCode"; public static final String WORKFLOW_ACTION_ERROR_MESSAGE = "errorMessage"; - + public static final String WORKFLOW_ACTION_USER_RETRY_INTERVAL = "userRetryInterval"; + public static final String WORKFLOW_ACTION_USER_RETRY_COUNT = "userRetryCount"; + public static final String WORKFLOW_ACTION_USER_RETRY_MAX = "userRetryMax"; + public static final String WORKFLOW_ACTION_CRED = "cred"; public static final String COORDINATOR_JOB_ID = "coordJobId"; public static final String COORDINATOR_JOB_NAME = "coordJobName"; http://git-wip-us.apache.org/repos/asf/oozie/blob/f2446d5c/client/src/main/java/org/apache/oozie/client/rest/JsonToBean.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/oozie/client/rest/JsonToBean.java b/client/src/main/java/org/apache/oozie/client/rest/JsonToBean.java index 4e01a3e..d6aa43e 100644 --- a/client/src/main/java/org/apache/oozie/client/rest/JsonToBean.java +++ b/client/src/main/java/org/apache/oozie/client/rest/JsonToBean.java @@ -18,6 +18,7 @@ package org.apache.oozie.client.rest; +import com.google.common.annotations.VisibleForTesting; import org.apache.oozie.client.BulkResponse; import org.apache.oozie.client.BundleJob; import org.apache.oozie.client.CoordinatorAction; @@ -51,7 +52,8 @@ import java.util.Set; @SuppressWarnings("rawtypes") public class JsonToBean { - private static class Property { + @VisibleForTesting + static class Property { String label; Class type; boolean isList; @@ -67,13 +69,20 @@ public class JsonToBean { } } - private static final Map<String, Property> WF_JOB = new HashMap<String, Property>(); - private static final Map<String, Property> WF_ACTION = new HashMap<String, Property>(); - private static final Map<String, Property> COORD_JOB = new HashMap<String, Property>(); - private static final Map<String, Property> COORD_ACTION = new HashMap<String, Property>(); - private static final Map<String, Property> BUNDLE_JOB = new HashMap<String, Property>(); - private static final Map<String, Property> BULK_RESPONSE = new HashMap<String, Property>(); - private static final Map<String, Property> JMS_CONNECTION_INFO = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> WF_JOB = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> WF_ACTION = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> COORD_JOB = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> COORD_ACTION = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> BUNDLE_JOB = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> BULK_RESPONSE = new HashMap<String, Property>(); + @VisibleForTesting + static final Map<String, Property> JMS_CONNECTION_INFO = new HashMap<String, Property>(); static { WF_ACTION.put("getId", new Property(JsonTags.WORKFLOW_ACTION_ID, String.class)); @@ -95,6 +104,10 @@ public class JsonToBean { WF_ACTION.put("getErrorCode", new Property(JsonTags.WORKFLOW_ACTION_ERROR_CODE, String.class)); WF_ACTION.put("getErrorMessage", new Property(JsonTags.WORKFLOW_ACTION_ERROR_MESSAGE, String.class)); WF_ACTION.put("toString", new Property(JsonTags.TO_STRING, String.class)); + WF_ACTION.put("getUserRetryInterval", new Property(JsonTags.WORKFLOW_ACTION_USER_RETRY_INTERVAL, Integer.TYPE)); + WF_ACTION.put("getUserRetryCount", new Property(JsonTags.WORKFLOW_ACTION_USER_RETRY_COUNT, Integer.TYPE)); + WF_ACTION.put("getUserRetryMax", new Property(JsonTags.WORKFLOW_ACTION_USER_RETRY_MAX, Integer.TYPE)); + WF_ACTION.put("getCred", new Property(JsonTags.WORKFLOW_ACTION_CRED, String.class)); WF_JOB.put("getExternalId", new Property(JsonTags.WORKFLOW_EXTERNAL_ID, String.class)); WF_JOB.put("getAppPath", new Property(JsonTags.WORKFLOW_APP_PATH, String.class)); @@ -161,8 +174,8 @@ public class JsonToBean { COORD_JOB.put("getConsoleUrl", new Property(JsonTags.COORDINATOR_JOB_CONSOLE_URL, String.class)); COORD_JOB.put("getActions", new Property(JsonTags.COORDINATOR_ACTIONS, CoordinatorAction.class, true)); COORD_JOB.put("toString", new Property(JsonTags.TO_STRING, String.class)); - - BUNDLE_JOB.put("getActions", new Property(JsonTags.COORDINATOR_ACTIONS, CoordinatorAction.class, true)); + COORD_JOB.put("getBundleId", new Property(JsonTags.COORDINATOR_JOB_BUNDLE_ID, String.class)); + COORD_JOB.put("getExternalId", new Property(JsonTags.COORDINATOR_JOB_EXTERNAL_ID, String.class)); BUNDLE_JOB.put("getAppPath",new Property(JsonTags.BUNDLE_JOB_PATH, String.class)); BUNDLE_JOB.put("getAppName",new Property(JsonTags.BUNDLE_JOB_NAME, String.class)); @@ -182,6 +195,7 @@ public class JsonToBean { BUNDLE_JOB.put("getConsoleUrl",new Property(JsonTags.BUNDLE_JOB_CONSOLE_URL, String.class)); BUNDLE_JOB.put("getCoordinators",new Property(JsonTags.BUNDLE_COORDINATOR_JOBS, CoordinatorJob.class, true)); BUNDLE_JOB.put("toString", new Property(JsonTags.TO_STRING, String.class)); + BUNDLE_JOB.put("getAcl", new Property(JsonTags.BUNDLE_JOB_ACL, String.class)); BULK_RESPONSE.put("getBundle", new Property(JsonTags.BULK_RESPONSE_BUNDLE, BundleJob.class, false)); BULK_RESPONSE.put("getCoordinator", new Property(JsonTags.BULK_RESPONSE_COORDINATOR, CoordinatorJob.class, false)); http://git-wip-us.apache.org/repos/asf/oozie/blob/f2446d5c/client/src/test/java/org/apache/oozie/client/rest/TestJsonToBean.java ---------------------------------------------------------------------- diff --git a/client/src/test/java/org/apache/oozie/client/rest/TestJsonToBean.java b/client/src/test/java/org/apache/oozie/client/rest/TestJsonToBean.java index ed02036..a102699 100644 --- a/client/src/test/java/org/apache/oozie/client/rest/TestJsonToBean.java +++ b/client/src/test/java/org/apache/oozie/client/rest/TestJsonToBean.java @@ -18,7 +18,12 @@ package org.apache.oozie.client.rest; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import junit.framework.TestCase; @@ -29,6 +34,7 @@ import org.apache.oozie.client.BundleJob; import org.apache.oozie.client.CoordinatorAction; import org.apache.oozie.client.CoordinatorJob; import org.apache.oozie.client.JMSConnectionInfo; +import org.apache.oozie.client.JMSConnectionInfoWrapper; import org.apache.oozie.client.WorkflowAction; import org.apache.oozie.client.WorkflowJob; import org.json.simple.JSONArray; @@ -438,4 +444,76 @@ public class TestJsonToBean extends TestCase { assertEquals("cj2", list.get(1).getCoordinator().getId()); } + public void testWorkflowActionMappings() throws Exception { + _testMappings(JsonToBean.WF_ACTION, WorkflowAction.class, true); + } + + public void testWorkflowJobMappings() throws Exception { + _testMappings(JsonToBean.WF_JOB, WorkflowJob.class, true); + } + + public void testCoordActionMappings() throws Exception { + _testMappings(JsonToBean.COORD_ACTION, CoordinatorAction.class, true); + } + + public void testCoordJobMappings() throws Exception { + _testMappings(JsonToBean.COORD_JOB, CoordinatorJob.class, true); + } + + public void testBundleJobMappings() throws Exception { + _testMappings(JsonToBean.BUNDLE_JOB, BundleJob.class, true); + } + + public void testBulkResponseMappings() throws Exception { + _testMappings(JsonToBean.BULK_RESPONSE, BulkResponse.class, false); + } + + public void testJMSConnectionInfoMappings() throws Exception { + _testMappings(JsonToBean.JMS_CONNECTION_INFO, JMSConnectionInfoWrapper.class, false); + } + + private void _testMappings(Map<String, JsonToBean.Property> mappings, Class klass, boolean toString) throws Exception { + Map<String, Type> methods = getGetMethods(klass); + if (toString) { + methods.put("toString", String.class); + } + for (Map.Entry<String, Type> method : methods.entrySet()) { + JsonToBean.Property prop = mappings.get(method.getKey()); + assertNotNull("JsonToBean is missing a mapping for " + method.getKey(), prop); + if (method.getValue() instanceof ParameterizedType) { + assertTrue("Return type for " + method.getKey() + " is not a List in JsonToBean", prop.isList); + ParameterizedType parType = (ParameterizedType) method.getValue(); + assertEquals("Return type for " + method.getKey() + " is not a List in klass.getName()", + List.class, parType.getRawType()); + assertEquals("Return types do not match for " + method.getKey(), parType.getActualTypeArguments()[0], prop.type); + } else { + assertEquals("Return types do not match for " + method.getKey(), method.getValue(), prop.type); + } + } + for (Map.Entry<String, JsonToBean.Property> mapping : mappings.entrySet()) { + Type type = methods.get(mapping.getKey()); + assertNotNull(klass.getName() + " is missing a method for " + mapping.getKey(), type); + if (mapping.getValue().isList) { + assertTrue("Return type for " + mapping.getKey() + " is not a List in " + klass.getName(), + type instanceof ParameterizedType); + ParameterizedType parType = (ParameterizedType) type; + assertEquals("Return type for " + mapping.getKey() + " is not a List in " + klass.getName(), + List.class, parType.getRawType()); + assertEquals("Return types do not match for " + mapping.getKey(), + mapping.getValue().type, parType.getActualTypeArguments()[0]); + } else { + assertEquals("Return types do not match for " + mapping.getKey(), mapping.getValue().type, type); + } + } + } + + private Map<String, Type> getGetMethods(Class klass) { + Map<String, Type> methods = new HashMap<String, Type>(); + for (Method method : klass.getMethods()) { + if (method.getName().startsWith("get")) { + methods.put(method.getName(), method.getGenericReturnType()); + } + } + return methods; + } } http://git-wip-us.apache.org/repos/asf/oozie/blob/f2446d5c/core/src/main/java/org/apache/oozie/WorkflowActionBean.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/WorkflowActionBean.java b/core/src/main/java/org/apache/oozie/WorkflowActionBean.java index a6cf74a..6289158 100644 --- a/core/src/main/java/org/apache/oozie/WorkflowActionBean.java +++ b/core/src/main/java/org/apache/oozie/WorkflowActionBean.java @@ -861,6 +861,10 @@ public class WorkflowActionBean implements Writable, WorkflowAction, JsonBean { json.put(JsonTags.WORKFLOW_ACTION_ERROR_CODE, errorCode); json.put(JsonTags.WORKFLOW_ACTION_ERROR_MESSAGE, errorMessage); json.put(JsonTags.TO_STRING, toString()); + json.put(JsonTags.WORKFLOW_ACTION_USER_RETRY_INTERVAL, userRetryInterval); + json.put(JsonTags.WORKFLOW_ACTION_USER_RETRY_COUNT, userRetryCount); + json.put(JsonTags.WORKFLOW_ACTION_USER_RETRY_MAX, userRetryMax); + json.put(JsonTags.WORKFLOW_ACTION_CRED, cred); return json; } http://git-wip-us.apache.org/repos/asf/oozie/blob/f2446d5c/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 23997bb..c612407 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 4.2.0 release (trunk - unreleased) +OOZIE-2181 JsonToBean has some missing and incorrect mappings (rkanter) OOZIE-2184 Change default value of action tmp dir removal to true (Viji via harsh) OOZIE-2006 Hive 2 action should support tez delegation tokens (bzhang) OOZIE-2180 Oozie hive2 should explicitly depend on commons-io rather than transitive dependency of hive-exec (bzhang)
