Repository: sqoop Updated Branches: refs/heads/sqoop2 7b158d51e -> 2df3db3e7
SQOOP-2770: Sqoop2: Remove the notion of ConnectorsBeans (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/2df3db3e Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/2df3db3e Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/2df3db3e Branch: refs/heads/sqoop2 Commit: 2df3db3e785484d27f479711412fe19f6f9b2dbb Parents: 7b158d5 Author: Colin Ma <[email protected]> Authored: Thu Jan 14 14:31:21 2016 +0800 Committer: Colin Ma <[email protected]> Committed: Thu Jan 14 14:31:21 2016 +0800 ---------------------------------------------------------------------- .../request/ConnectorResourceRequest.java | 3 +- .../org/apache/sqoop/json/ConnectorBean.java | 27 ++-- .../org/apache/sqoop/json/ConnectorsBean.java | 64 --------- .../apache/sqoop/json/TestConnectorBean.java | 94 ++++++++++++++ .../apache/sqoop/json/TestConnectorsBean.java | 129 ------------------- .../sqoop/handler/ConnectorRequestHandler.java | 3 +- 6 files changed, 109 insertions(+), 211 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/2df3db3e/client/src/main/java/org/apache/sqoop/client/request/ConnectorResourceRequest.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/sqoop/client/request/ConnectorResourceRequest.java b/client/src/main/java/org/apache/sqoop/client/request/ConnectorResourceRequest.java index 953b23f..1556e34 100644 --- a/client/src/main/java/org/apache/sqoop/client/request/ConnectorResourceRequest.java +++ b/client/src/main/java/org/apache/sqoop/client/request/ConnectorResourceRequest.java @@ -19,7 +19,6 @@ package org.apache.sqoop.client.request; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL; import org.apache.sqoop.json.ConnectorBean; -import org.apache.sqoop.json.ConnectorsBean; import org.apache.sqoop.json.JSONUtils; import org.json.simple.JSONObject; @@ -48,7 +47,7 @@ public class ConnectorResourceRequest extends ResourceRequest { } JSONObject jsonObject = JSONUtils.parse(response); // defaults to all - ConnectorBean bean = new ConnectorsBean(); + ConnectorBean bean = new ConnectorBean(); if (connectorName != null) { bean = new ConnectorBean(); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/2df3db3e/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java b/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java index b50fa69..02222f5 100644 --- a/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java +++ b/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java @@ -54,7 +54,7 @@ public class ConnectorBean extends ConfigurableBean { // to represent the config and inputs with values public static final String CONNECTOR_LINK_CONFIG = "link-config"; public static final String CONNECTOR_JOB_CONFIG = "job-config"; - private static final String CONNECTOR = "connector"; + private static final String CONNECTORS = "connectors"; private List<MConnector> connectors; private Map<String, ResourceBundle> connectorConfigBundles; @@ -80,9 +80,16 @@ public class ConnectorBean extends ConfigurableBean { @SuppressWarnings("unchecked") @Override public JSONObject extract(boolean skipSensitive) { - JSONObject connector = new JSONObject(); - connector.put(CONNECTOR, extractConnector(skipSensitive, connectors.get(0))); - return connector; + JSONArray connectorArray = extractConnectors(skipSensitive); + JSONObject connectors = new JSONObject(); + connectors.put(CONNECTORS, connectorArray); + return connectors; + } + + @Override + public void restore(JSONObject jsonObject) { + JSONArray array = JSONUtils.getJSONArray(jsonObject, CONNECTORS); + restoreConnectors(array); } @SuppressWarnings("unchecked") @@ -126,17 +133,9 @@ public class ConnectorBean extends ConfigurableBean { return connectorJsonObject; } - @Override - public void restore(JSONObject jsonObject) { - connectors = new ArrayList<MConnector>(); - connectorConfigBundles = new HashMap<String, ResourceBundle>(); - JSONObject obj = JSONUtils.getJSONObject(jsonObject, CONNECTOR); - connectors.add(restoreConnector(obj)); - } - protected void restoreConnectors(JSONArray array) { - connectors = new ArrayList<MConnector>(); - connectorConfigBundles = new HashMap<String, ResourceBundle>(); + connectors = new ArrayList<>(); + connectorConfigBundles = new HashMap<>(); for (Object obj : array) { connectors.add(restoreConnector(obj)); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/2df3db3e/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java b/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java deleted file mode 100644 index c31e52b..0000000 --- a/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java +++ /dev/null @@ -1,64 +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 java.util.List; -import java.util.Map; -import java.util.ResourceBundle; - -import org.apache.sqoop.classification.InterfaceAudience; -import org.apache.sqoop.classification.InterfaceStability; -import org.apache.sqoop.model.MConnector; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -/** - * Json representation of the connectors object - * - */ [email protected] [email protected] -public class ConnectorsBean extends ConnectorBean { - - // to represent the config and inputs with values - private static final String CONNECTORS = "connectors"; - - // for "extract" - public ConnectorsBean(List<MConnector> connectors, Map<String, ResourceBundle> bundles) { - super(connectors, bundles); - } - - // for "restore" - public ConnectorsBean() { - } - - @SuppressWarnings("unchecked") - @Override - public JSONObject extract(boolean skipSensitive) { - JSONArray connectorArray = extractConnectors(skipSensitive); - JSONObject connectors = new JSONObject(); - connectors.put(CONNECTORS, connectorArray); - return connectors; - } - - @Override - public void restore(JSONObject jsonObject) { - JSONArray array = JSONUtils.getJSONArray(jsonObject, CONNECTORS); - super.restoreConnectors(array); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/2df3db3e/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java b/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java index f487bba..e5a2ab3 100644 --- a/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java +++ b/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java @@ -67,4 +67,98 @@ public class TestConnectorBean { assertEquals("a", retrievedBundle.getString("a")); assertEquals("b", retrievedBundle.getString("b")); } + + + @Test + public void testConnectorsSerialization() { + // Create testing connector + List<MConnector> connectors = new LinkedList<>(); + connectors.add(BeanTestUtil.getConnector(1L, "jdbc")); + connectors.add(BeanTestUtil.getConnector(2L, "mysql")); + + // Create testing bundles + Map<String, ResourceBundle> configBundles = new HashMap<>(); + configBundles.put("jdbc", ConfigTestUtil.getResourceBundle()); + configBundles.put("mysql", ConfigTestUtil.getResourceBundle()); + + // Serialize it to JSON object + ConnectorBean connectorsBean = new ConnectorBean(connectors, configBundles); + JSONObject connectorsJSON = connectorsBean.extract(false); + + // "Move" it across network in text form + String connectorsJSONString = connectorsJSON.toJSONString(); + + // Retrieved transferred object + JSONObject parsedConnectors = JSONUtils.parse(connectorsJSONString); + ConnectorBean parsedConnectorsBean = new ConnectorBean(); + parsedConnectorsBean.restore(parsedConnectors); + + assertEquals(connectors.size(), parsedConnectorsBean.getConnectors().size()); + assertEquals(connectors.get(0), parsedConnectorsBean.getConnectors().get(0)); + assertEquals(connectors.get(1), parsedConnectorsBean.getConnectors().get(1)); + + ResourceBundle retrievedBundle = parsedConnectorsBean.getResourceBundles().get("jdbc"); + assertNotNull(retrievedBundle); + assertEquals("a", retrievedBundle.getString("a")); + assertEquals("b", retrievedBundle.getString("b")); + } + + @Test + public void testSingleDirection() { + // Create testing connector + List<MConnector> connectors = new LinkedList<>(); + connectors.add(BeanTestUtil.getConnector(1L, "jdbc", true, false)); + connectors.add(BeanTestUtil.getConnector(2L, "mysql", false, true)); + + // Create testing bundles + Map<String, ResourceBundle> bundles = new HashMap<>(); + bundles.put("jdbc", ConfigTestUtil.getResourceBundle()); + bundles.put("mysql", ConfigTestUtil.getResourceBundle()); + + // Serialize it to JSON object + ConnectorBean bean = new ConnectorBean(connectors, bundles); + JSONObject json = bean.extract(false); + + // "Move" it across network in text form + String string = json.toJSONString(); + + // Retrieved transferred object + JSONObject retrievedJson = JSONUtils.parse(string); + ConnectorBean retrievedBean = new ConnectorBean(); + retrievedBean.restore(retrievedJson); + + assertEquals(connectors.size(), retrievedBean.getConnectors().size()); + assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0)); + assertEquals(connectors.get(1), retrievedBean.getConnectors().get(1)); + } + + @Test + public void testNoDirection() { + // Create testing connector + List<MConnector> connectors = new LinkedList<>(); + connectors.add(BeanTestUtil.getConnector(1L, "jdbc", false, false)); + connectors.add(BeanTestUtil.getConnector(2L, "mysql", false, false)); + + // Create testing bundles + Map<String, ResourceBundle> bundles = new HashMap<>(); + bundles.put("jdbc", ConfigTestUtil.getResourceBundle()); + bundles.put("mysql", ConfigTestUtil.getResourceBundle()); + + // Serialize it to JSON object + ConnectorBean bean = new ConnectorBean(connectors, bundles); + JSONObject json = bean.extract(false); + + // "Move" it across network in text form + String string = json.toJSONString(); + + // Retrieved transferred object + JSONObject retrievedJson = JSONUtils.parse(string); + ConnectorBean retrievedBean = new ConnectorBean(); + retrievedBean.restore(retrievedJson); + + assertEquals(connectors.size(), retrievedBean.getConnectors().size()); + assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0)); + assertEquals(connectors.get(1), retrievedBean.getConnectors().get(1)); + } + } http://git-wip-us.apache.org/repos/asf/sqoop/blob/2df3db3e/common/src/test/java/org/apache/sqoop/json/TestConnectorsBean.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/json/TestConnectorsBean.java b/common/src/test/java/org/apache/sqoop/json/TestConnectorsBean.java deleted file mode 100644 index ed036fb..0000000 --- a/common/src/test/java/org/apache/sqoop/json/TestConnectorsBean.java +++ /dev/null @@ -1,129 +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 static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.ResourceBundle; - -import org.apache.sqoop.json.util.BeanTestUtil; -import org.apache.sqoop.json.util.ConfigTestUtil; -import org.apache.sqoop.model.MConnector; -import org.json.simple.JSONObject; -import org.testng.annotations.Test; - -public class TestConnectorsBean { - - @Test - public void testConnectorsSerialization() { - // Create testing connector - List<MConnector> connectors = new LinkedList<MConnector>(); - connectors.add(BeanTestUtil.getConnector(1L, "jdbc")); - connectors.add(BeanTestUtil.getConnector(2L, "mysql")); - - // Create testing bundles - Map<String, ResourceBundle> configBundles = new HashMap<String, ResourceBundle>(); - configBundles.put("jdbc", ConfigTestUtil.getResourceBundle()); - configBundles.put("mysql", ConfigTestUtil.getResourceBundle()); - - // Serialize it to JSON object - ConnectorsBean connectorsBean = new ConnectorsBean(connectors, configBundles); - JSONObject connectorsJSON = connectorsBean.extract(false); - - // "Move" it across network in text form - String connectorsJSONString = connectorsJSON.toJSONString(); - - // Retrieved transferred object - JSONObject parsedConnectors = JSONUtils.parse(connectorsJSONString); - ConnectorsBean parsedConnectorsBean = new ConnectorsBean(); - parsedConnectorsBean.restore(parsedConnectors); - - assertEquals(connectors.size(), parsedConnectorsBean.getConnectors().size()); - assertEquals(connectors.get(0), parsedConnectorsBean.getConnectors().get(0)); - assertEquals(connectors.get(1), parsedConnectorsBean.getConnectors().get(1)); - - ResourceBundle retrievedBundle = parsedConnectorsBean.getResourceBundles().get("jdbc"); - assertNotNull(retrievedBundle); - assertEquals("a", retrievedBundle.getString("a")); - assertEquals("b", retrievedBundle.getString("b")); - } - - @Test - public void testSingleDirection() { - // Create testing connector - List<MConnector> connectors = new LinkedList<MConnector>(); - connectors.add(BeanTestUtil.getConnector(1L, "jdbc", true, false)); - connectors.add(BeanTestUtil.getConnector(2L, "mysql", false, true)); - - // Create testing bundles - Map<String, ResourceBundle> bundles = new HashMap<String, ResourceBundle>(); - bundles.put("jdbc", ConfigTestUtil.getResourceBundle()); - bundles.put("mysql", ConfigTestUtil.getResourceBundle()); - - // Serialize it to JSON object - ConnectorsBean bean = new ConnectorsBean(connectors, bundles); - JSONObject json = bean.extract(false); - - // "Move" it across network in text form - String string = json.toJSONString(); - - // Retrieved transferred object - JSONObject retrievedJson = JSONUtils.parse(string); - ConnectorsBean retrievedBean = new ConnectorsBean(); - retrievedBean.restore(retrievedJson); - - assertEquals(connectors.size(), retrievedBean.getConnectors().size()); - assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0)); - assertEquals(connectors.get(1), retrievedBean.getConnectors().get(1)); - } - - @Test - public void testNoDirection() { - // Create testing connector - List<MConnector> connectors = new LinkedList<MConnector>(); - connectors.add(BeanTestUtil.getConnector(1L, "jdbc", false, false)); - connectors.add(BeanTestUtil.getConnector(2L, "mysql", false, false)); - - // Create testing bundles - Map<String, ResourceBundle> bundles = new HashMap<String, ResourceBundle>(); - bundles.put("jdbc", ConfigTestUtil.getResourceBundle()); - bundles.put("mysql", ConfigTestUtil.getResourceBundle()); - - // Serialize it to JSON object - ConnectorsBean bean = new ConnectorsBean(connectors, bundles); - JSONObject json = bean.extract(false); - - // "Move" it across network in text form - String string = json.toJSONString(); - - // Retrieved transferred object - JSONObject retrievedJson = JSONUtils.parse(string); - ConnectorsBean retrievedBean = new ConnectorsBean(); - retrievedBean.restore(retrievedJson); - - assertEquals(connectors.size(), retrievedBean.getConnectors().size()); - assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0)); - assertEquals(connectors.get(1), retrievedBean.getConnectors().get(1)); - } - -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/2df3db3e/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java index 2d0c377..c760689 100644 --- a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java +++ b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java @@ -28,7 +28,6 @@ import org.apache.log4j.Logger; import org.apache.sqoop.audit.AuditLoggerManager; import org.apache.sqoop.connector.ConnectorManager; import org.apache.sqoop.json.ConnectorBean; -import org.apache.sqoop.json.ConnectorsBean; import org.apache.sqoop.json.JsonBean; import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MResource; @@ -63,7 +62,7 @@ public class ConnectorRequestHandler implements RequestHandler { // Authorization check connectors = AuthorizationEngine.filterResource(ctx.getUserName(), MResource.TYPE.CONNECTOR, connectors); - return new ConnectorsBean(connectors, configParamBundles); + return new ConnectorBean(connectors, configParamBundles); } else { // support using unique name
