sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject sqoop git commit: SQOOP-2774: Sqoop2: Remove the notion of RolesBean (Jarek Jarcec Cecho via Colin Ma)
Date Fri, 15 Jan 2016 02:35:19 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 67214a48c -> 63002273d


SQOOP-2774: Sqoop2: Remove the notion of RolesBean
 (Jarek Jarcec Cecho via Colin Ma)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/63002273
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/63002273
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/63002273

Branch: refs/heads/sqoop2
Commit: 63002273d07dcb7e599d699d341e9a28dd5f10a5
Parents: 67214a4
Author: Colin Ma <colin@apache.org>
Authored: Fri Jan 15 11:25:41 2016 +0800
Committer: Colin Ma <colin@apache.org>
Committed: Fri Jan 15 11:25:41 2016 +0800

----------------------------------------------------------------------
 .../request/AuthorizationResourceRequest.java   | 10 ++--
 .../client/request/SqoopResourceRequests.java   |  4 +-
 .../java/org/apache/sqoop/json/RoleBean.java    | 26 ++++----
 .../java/org/apache/sqoop/json/RolesBean.java   | 63 --------------------
 .../org/apache/sqoop/json/TestRoleBean.java     | 57 ++++++++++++++++++
 .../handler/AuthorizationRequestHandler.java    |  6 +-
 6 files changed, 80 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/63002273/client/src/main/java/org/apache/sqoop/client/request/AuthorizationResourceRequest.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/AuthorizationResourceRequest.java
b/client/src/main/java/org/apache/sqoop/client/request/AuthorizationResourceRequest.java
index e99e913..f696724 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/AuthorizationResourceRequest.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/AuthorizationResourceRequest.java
@@ -52,10 +52,10 @@ public class AuthorizationResourceRequest extends ResourceRequest {
     super(token);
   }
 
-  public RolesBean readRoles(String serverUrl) {
+  public RoleBean readRoles(String serverUrl) {
     String response = super.get(serverUrl + RESOURCE + ROLES);
     JSONObject jsonObject = JSONUtils.parse(response);
-    RolesBean bean = new RolesBean();
+    RoleBean bean = new RoleBean();
     bean.restore(jsonObject);
     return bean;
   }
@@ -72,7 +72,7 @@ public class AuthorizationResourceRequest extends ResourceRequest {
   }
 
   public void grantRevokeRole(String serverUrl, List<MRole> roles, List<MPrincipal>
principals, boolean isGrant) {
-    RolesBean rolesBean = new RolesBean(roles);
+    RoleBean rolesBean = new RoleBean(roles);
     PrincipalBean principalsBean = new PrincipalBean(principals);
     // Extract all config inputs including sensitive inputs
     JSONObject jsonObject = new JSONObject();
@@ -85,12 +85,12 @@ public class AuthorizationResourceRequest extends ResourceRequest {
     }
   }
 
-  public RolesBean readRolesByPrincipal(String serverUrl, MPrincipal principal) {
+  public RoleBean readRolesByPrincipal(String serverUrl, MPrincipal principal) {
     String response = super.get(serverUrl + RESOURCE + ROLES
             + "?principal_name=" + UrlSafeUtils.urlEncode(principal.getName())
             + "&principal_type=" + UrlSafeUtils.urlEncode(principal.getType()));
     JSONObject jsonObject = JSONUtils.parse(response);
-    RolesBean bean = new RolesBean();
+    RoleBean bean = new RoleBean();
     bean.restore(jsonObject);
     return bean;
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/63002273/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
b/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
index c962842..bb5242f 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/SqoopResourceRequests.java
@@ -178,7 +178,7 @@ public class SqoopResourceRequests {
     return getSubmissionResourceRequest().read(serverUrl, jArg);
   }
 
-  public RolesBean readRoles() {
+  public RoleBean readRoles() {
     return getAuthorizationRequest().readRoles(serverUrl);
   }
 
@@ -198,7 +198,7 @@ public class SqoopResourceRequests {
     getAuthorizationRequest().grantRevokeRole(serverUrl, roles, principals, false);
   }
 
-  public RolesBean readRolesByPrincipal(MPrincipal principal) {
+  public RoleBean readRolesByPrincipal(MPrincipal principal) {
     return getAuthorizationRequest().readRolesByPrincipal(serverUrl, principal);
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/63002273/common/src/main/java/org/apache/sqoop/json/RoleBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/RoleBean.java b/common/src/main/java/org/apache/sqoop/json/RoleBean.java
index ffafddb..3a034c7 100644
--- a/common/src/main/java/org/apache/sqoop/json/RoleBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/RoleBean.java
@@ -33,7 +33,7 @@ import java.util.List;
 @InterfaceStability.Unstable
 public class RoleBean implements JsonBean {
 
-  public static final String ROLE = "role";
+  private static final String ROLES = "roles";
   private static final String NAME = "name";
 
   private List<MRole> roles;
@@ -45,7 +45,7 @@ public class RoleBean implements JsonBean {
   // For "extract"
   public RoleBean(MRole role) {
     this();
-    this.roles = new ArrayList<MRole>();
+    this.roles = new ArrayList<>();
     this.roles.add(role);
   }
 
@@ -61,9 +61,16 @@ public class RoleBean implements JsonBean {
   @Override
   @SuppressWarnings("unchecked")
   public JSONObject extract(boolean skipSensitive) {
-    JSONObject role = new JSONObject();
-    role.put(ROLE, extractRole(roles.get(0)));
-    return role;
+    JSONArray rolesArray = extractRoles();
+    JSONObject roles = new JSONObject();
+    roles.put(ROLES, rolesArray);
+    return roles;
+  }
+
+  @Override
+  public void restore(JSONObject json) {
+    JSONArray rolesArray = JSONUtils.getJSONArray(json, ROLES);
+    restoreRoles(rolesArray);
   }
 
   @SuppressWarnings("unchecked")
@@ -84,15 +91,8 @@ public class RoleBean implements JsonBean {
     return object;
   }
 
-  @Override
-  public void restore(JSONObject json) {
-    roles = new ArrayList<MRole>();
-    JSONObject obj = JSONUtils.getJSONObject(json, ROLE);
-    roles.add(restoreRole(obj));
-  }
-
   protected void restoreRoles(JSONArray array) {
-    roles = new ArrayList<MRole>();
+    roles = new ArrayList<>();
     for (Object obj : array) {
       roles.add(restoreRole(obj));
     }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/63002273/common/src/main/java/org/apache/sqoop/json/RolesBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/RolesBean.java b/common/src/main/java/org/apache/sqoop/json/RolesBean.java
deleted file mode 100644
index c09ba95..0000000
--- a/common/src/main/java/org/apache/sqoop/json/RolesBean.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.json;
-
-import org.apache.sqoop.classification.InterfaceAudience;
-import org.apache.sqoop.classification.InterfaceStability;
-import org.apache.sqoop.model.MRole;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-
-import java.util.List;
-
-@InterfaceAudience.Private
-@InterfaceStability.Unstable
-public class RolesBean extends RoleBean {
-
-  private static final String ROLES = "roles";
-
-  // For "extract"
-  public RolesBean(MRole role) {
-    super(role);
-  }
-
-  public RolesBean(List<MRole> roles) {
-    super(roles);
-
-  }
-
-  // For "restore"
-  public RolesBean() {
-  }
-
-  @Override
-  @SuppressWarnings("unchecked")
-  public JSONObject extract(boolean skipSensitive) {
-    JSONArray rolesArray = super.extractRoles();
-    JSONObject roles = new JSONObject();
-    roles.put(ROLES, rolesArray);
-    return roles;
-  }
-
-  @Override
-  public void restore(JSONObject json) {
-    JSONArray rolesArray = JSONUtils.getJSONArray(json, ROLES);
-    restoreRoles(rolesArray);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/63002273/common/src/test/java/org/apache/sqoop/json/TestRoleBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestRoleBean.java b/common/src/test/java/org/apache/sqoop/json/TestRoleBean.java
new file mode 100644
index 0000000..1974113
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/json/TestRoleBean.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.json;
+
+import org.apache.sqoop.model.MRole;
+import org.json.simple.JSONObject;
+import org.testng.annotations.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+public class TestRoleBean {
+
+  @Test
+  public void testLinkSerialization() {
+    MRole godRole = new MRole("god");
+    MRole janitorRole = new MRole("janitor");
+    List<MRole> roles = new LinkedList<>();
+    roles.add(godRole);
+    roles.add(janitorRole);
+
+    // Serialize it to JSON object
+    RoleBean outputBean = new RoleBean(roles);
+    JSONObject json = outputBean.extract(false);
+
+    // "Move" it across network in text form
+    String jsonString = json.toJSONString();
+
+    // Retrieved transferred object
+    JSONObject parsedJson = JSONUtils.parse(jsonString);
+    RoleBean inputBean = new RoleBean(roles);
+    inputBean.restore(parsedJson);
+
+    assertEquals(inputBean.getRoles().size(), 2);
+    assertEquals(inputBean.getRoles().get(0).getName(), "god");
+    assertEquals(inputBean.getRoles().get(1).getName(), "janitor");
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/63002273/server/src/main/java/org/apache/sqoop/handler/AuthorizationRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/AuthorizationRequestHandler.java
b/server/src/main/java/org/apache/sqoop/handler/AuthorizationRequestHandler.java
index 45bf4d0..6cd77e9 100644
--- a/server/src/main/java/org/apache/sqoop/handler/AuthorizationRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/AuthorizationRequestHandler.java
@@ -145,12 +145,12 @@ public class AuthorizationRequestHandler implements RequestHandler {
       MPrincipal principal = new MPrincipal(principal_name, principal_type);
       manager.logAuditEvent(ctx.getUserName(),
               ctx.getRequest().getRemoteAddr(), "get", "roles by principal", principal.toString());
-      return new RolesBean(handler.getRolesByPrincipal(principal));
+      return new RoleBean(handler.getRolesByPrincipal(principal));
     } else {
       // get all roles in the system
       manager.logAuditEvent(ctx.getUserName(),
               ctx.getRequest().getRemoteAddr(), "get", "roles", "all");
-      return new RolesBean(handler.getAllRoles());
+      return new RoleBean(handler.getAllRoles());
     }
   }
 
@@ -258,7 +258,7 @@ public class AuthorizationRequestHandler implements RequestHandler {
     AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
     AuditLoggerManager manager = AuditLoggerManager.getInstance();
 
-    RolesBean rolesBean = new RolesBean();
+    RoleBean rolesBean = new RoleBean();
     PrincipalBean principalsBean = new PrincipalBean();
 
     try {


Mime
View raw message