Repository: sqoop Updated Branches: refs/heads/sqoop2 a79ec0527 -> 24e9b4c5b
http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java b/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java index 0369b4d..b9d4d60 100644 --- a/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java +++ b/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java @@ -19,6 +19,7 @@ package org.apache.sqoop.connector; import java.net.URL; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -33,10 +34,10 @@ import org.apache.sqoop.core.ConfigurationConstants; import org.apache.sqoop.core.Reconfigurable; import org.apache.sqoop.core.SqoopConfiguration; import org.apache.sqoop.core.SqoopConfiguration.CoreConfigurationListener; +import org.apache.sqoop.model.MConnector; import org.apache.sqoop.repository.Repository; import org.apache.sqoop.repository.RepositoryManager; import org.apache.sqoop.repository.RepositoryTransaction; -import org.apache.sqoop.model.MConnector; public class ConnectorManager implements Reconfigurable { @@ -86,27 +87,31 @@ public class ConnectorManager implements Reconfigurable { } // key: connector id, value: connector name - private Map<Long, String> nameMap = new HashMap<Long, String>(); + private Map<Long, String> idToNameMap = new HashMap<Long, String>(); + private Set<String> connectorNames = new HashSet<String>(); // key: connector name, value: connector handler - private Map<String, ConnectorHandler> handlerMap = - new HashMap<String, ConnectorHandler>(); + private Map<String, ConnectorHandler> handlerMap = new HashMap<String, ConnectorHandler>(); public List<MConnector> getConnectorConfigurables() { List<MConnector> connectors = new LinkedList<MConnector>(); - for(ConnectorHandler handler : handlerMap.values()) { + for (ConnectorHandler handler : handlerMap.values()) { connectors.add(handler.getConnectorConfigurable()); } return connectors; } public Set<Long> getConnectorIds() { - return nameMap.keySet(); + return idToNameMap.keySet(); + } + + public Set<String> getConnectorNames() { + return connectorNames; } public Map<Long, ResourceBundle> getResourceBundles(Locale locale) { Map<Long, ResourceBundle> bundles = new HashMap<Long, ResourceBundle>(); - for(ConnectorHandler handler : handlerMap.values()) { + for (ConnectorHandler handler : handlerMap.values()) { long id = handler.getConnectorConfigurable().getPersistenceId(); ResourceBundle bundle = handler.getSqoopConnector().getBundle(locale); bundles.put(id, bundle); @@ -115,20 +120,28 @@ public class ConnectorManager implements Reconfigurable { } public ResourceBundle getResourceBundle(long connectorId, Locale locale) { - ConnectorHandler handler = handlerMap.get(nameMap.get(connectorId)); + ConnectorHandler handler = handlerMap.get(idToNameMap.get(connectorId)); return handler.getSqoopConnector().getBundle(locale); } public MConnector getConnectorConfigurable(long connectorId) { - ConnectorHandler handler = handlerMap.get(nameMap.get(connectorId)); - if(handler == null) { + ConnectorHandler handler = handlerMap.get(idToNameMap.get(connectorId)); + if (handler == null) { + return null; + } + return handler.getConnectorConfigurable(); + } + + public MConnector getConnectorConfigurable(String connectorName) { + ConnectorHandler handler = handlerMap.get(connectorName); + if (handler == null) { return null; } return handler.getConnectorConfigurable(); } public SqoopConnector getSqoopConnector(long connectorId) { - ConnectorHandler handler = handlerMap.get(nameMap.get(connectorId)); + ConnectorHandler handler = handlerMap.get(idToNameMap.get(connectorId)); return handler.getSqoopConnector(); } @@ -165,13 +178,20 @@ public class ConnectorManager implements Reconfigurable { registerConnectors(autoUpgrade); - SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this)); + SqoopConfiguration.getInstance().getProvider() + .registerListener(new CoreConfigurationListener(this)); if (LOG.isInfoEnabled()) { LOG.info("Connectors loaded: " + handlerMap); } } + public synchronized Long getConnectorId(String connectorName) { + Repository repository = RepositoryManager.getInstance().getRepository(); + return repository.findConnector(connectorName) != null ? repository + .findConnector(connectorName).getPersistenceId() : null; + } + private synchronized void registerConnectors(boolean autoUpgrade) { Repository repository = RepositoryManager.getInstance().getRepository(); @@ -181,20 +201,17 @@ public class ConnectorManager implements Reconfigurable { rtx.begin(); for (String name : handlerMap.keySet()) { ConnectorHandler handler = handlerMap.get(name); - MConnector connectorMetadata = handler.getConnectorConfigurable(); - MConnector registeredMetadata = - repository.registerConnector(connectorMetadata, autoUpgrade); - - // Set registered metadata instead of connector metadata as they will - // have filled persistent ids. We should be confident at this point that - // there are no differences between those two structures. - handler.setConnectorConfigurable(registeredMetadata); + MConnector newConnector = handler.getConnectorConfigurable(); + MConnector registeredConnector = repository.registerConnector(newConnector, autoUpgrade); + // Set the registered connector in the database to the connector configurable instance + handler.setConnectorConfigurable(registeredConnector); String connectorName = handler.getUniqueName(); if (!handler.getConnectorConfigurable().hasPersistenceId()) { throw new SqoopException(ConnectorError.CONN_0010, connectorName); } - nameMap.put(handler.getConnectorConfigurable().getPersistenceId(), connectorName); + idToNameMap.put(handler.getConnectorConfigurable().getPersistenceId(), connectorName); + connectorNames.add(connectorName); LOG.debug("Registered connector: " + handler.getConnectorConfigurable()); } rtx.commit(); @@ -212,7 +229,7 @@ public class ConnectorManager implements Reconfigurable { public synchronized void destroy() { handlerMap = null; - nameMap = null; + idToNameMap = null; } @Override http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/core/src/main/java/org/apache/sqoop/driver/Driver.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/sqoop/driver/Driver.java b/core/src/main/java/org/apache/sqoop/driver/Driver.java index 6942891..ce0b471 100644 --- a/core/src/main/java/org/apache/sqoop/driver/Driver.java +++ b/core/src/main/java/org/apache/sqoop/driver/Driver.java @@ -132,18 +132,18 @@ public class Driver implements Reconfigurable { } public synchronized void initialize(boolean autoUpgrade) { - LOG.trace("Begin Driver Config initialization"); + LOG.trace("Begin Driver initialization"); - // Register driver config in repository + // Register driver in repository mDriver = RepositoryManager.getInstance().getRepository().registerDriver(mDriver, autoUpgrade); SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this)); - LOG.info("Driver Config initialized: OK"); + LOG.info("Driver initialized: OK"); } public synchronized void destroy() { - LOG.trace("Begin Driver Config destroy"); + LOG.trace("Begin Driver destroy"); } public Validator getValidator() { http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/core/src/main/java/org/apache/sqoop/driver/DriverConfigValidator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/sqoop/driver/DriverConfigValidator.java b/core/src/main/java/org/apache/sqoop/driver/DriverConfigValidator.java index 0d9a9b8..d9eb182 100644 --- a/core/src/main/java/org/apache/sqoop/driver/DriverConfigValidator.java +++ b/core/src/main/java/org/apache/sqoop/driver/DriverConfigValidator.java @@ -29,9 +29,8 @@ public class DriverConfigValidator extends Validator { ConfigValidator validation = new ConfigValidator(JobConfiguration.class); JobConfiguration conf = (JobConfiguration)jobConfiguration; validateThrottlingConfig(validation,conf.throttlingConfig); - return validation; - }; + } private void validateThrottlingConfig(ConfigValidator validation, ThrottlingConfig throttlingConfig) { if(throttlingConfig.numExtractors != null && throttlingConfig.numExtractors < 1) { http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/core/src/main/java/org/apache/sqoop/driver/DriverError.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/sqoop/driver/DriverError.java b/core/src/main/java/org/apache/sqoop/driver/DriverError.java index 56ef9bb..ddee282 100644 --- a/core/src/main/java/org/apache/sqoop/driver/DriverError.java +++ b/core/src/main/java/org/apache/sqoop/driver/DriverError.java @@ -24,8 +24,6 @@ import org.apache.sqoop.common.ErrorCode; */ public enum DriverError implements ErrorCode { - DRIVER_0000("Metadata are not registered in repository"), - DRIVER_0001("Invalid submission engine"), DRIVER_0002("Given job is already running"), @@ -44,9 +42,9 @@ public enum DriverError implements ErrorCode { DRIVER_0009("Job has been disabled. Cannot submit this job."), - DRIVER_0010("Connection for this job has been disabled. Cannot submit this job."), + DRIVER_0010("Link for this job has been disabled. Cannot submit this job."), - DRIVER_0011("Connector does not support direction. Cannot submit this job."), + DRIVER_0011("Connector does not support specified direction. Cannot submit this job."), ; http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/core/src/main/java/org/apache/sqoop/repository/JdbcRepository.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/sqoop/repository/JdbcRepository.java b/core/src/main/java/org/apache/sqoop/repository/JdbcRepository.java index d7b526a..254ba9e 100644 --- a/core/src/main/java/org/apache/sqoop/repository/JdbcRepository.java +++ b/core/src/main/java/org/apache/sqoop/repository/JdbcRepository.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.driver.Driver; import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MDriver; import org.apache.sqoop.model.MJob; http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/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 c50e029..5b03a8f 100644 --- a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java +++ b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java @@ -17,84 +17,75 @@ */ package org.apache.sqoop.handler; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; + import org.apache.log4j.Logger; +import org.apache.sqoop.audit.AuditLoggerManager; import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.connector.ConnectorManager; -import org.apache.sqoop.audit.AuditLoggerManager; -import org.apache.sqoop.json.JsonBean; 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.server.RequestContext; import org.apache.sqoop.server.RequestHandler; import org.apache.sqoop.server.common.ServerError; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -/** - * Connector request handler is supporting following resources: - * - * GET /v1/connector/:cid - * Return details about one particular connector with id :cid or about all of - * them if :cid equals to "all". - * - * Planned resources: - * - * GET /v1/connector - * Get brief list of all connectors present in the system. This resource is not - * yet implemented. - * - */ public class ConnectorRequestHandler implements RequestHandler { - private static final Logger LOG = - Logger.getLogger(ConnectorRequestHandler.class); + private static final Logger LOG = Logger.getLogger(ConnectorRequestHandler.class); + + private static final String CONNECTORS_PATH = "connectors"; public ConnectorRequestHandler() { LOG.info("ConnectorRequestHandler initialized"); } - @Override public JsonBean handleEvent(RequestContext ctx) { List<MConnector> connectors; - Map<Long, ResourceBundle> bundles; + Map<Long, ResourceBundle> configParamBundles; Locale locale = ctx.getAcceptLanguageHeader(); + String cIdentifier = ctx.getLastURLElement(); - String cid = ctx.getLastURLElement(); + LOG.info("ConnectorRequestHandler handles cid: " + cIdentifier); - LOG.info("ConnectorRequestHandler handles cid: " + cid); - if (cid.equals("all")) { - // display all connectors + if (ctx.getPath().contains(CONNECTORS_PATH) || cIdentifier.equals("all")) { connectors = ConnectorManager.getInstance().getConnectorConfigurables(); - bundles = ConnectorManager.getInstance().getResourceBundles(locale); + configParamBundles = ConnectorManager.getInstance().getResourceBundles(locale); + AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), + ctx.getRequest().getRemoteAddr(), "get", "connector", "all"); + return new ConnectorsBean(connectors, configParamBundles); - AuditLoggerManager.getInstance() - .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(), - "get", "connector", "all"); } else { - Long id = Long.parseLong(cid); - - // Check that user is not asking for non existing connector id - if(!ConnectorManager.getInstance().getConnectorIds().contains(id)) { - throw new SqoopException(ServerError.SERVER_0004, "Invalid id " + id); + // NOTE: we now support using unique name as well as the connector id + boolean cIdNameIdentfierUsed = true; + Long cId = ConnectorManager.getInstance().getConnectorId(cIdentifier); + if (cId == null) { + // support for cId in the query + cIdNameIdentfierUsed = false; + cId = Long.parseLong(cIdentifier); + } + // Check that user is not asking for non existing connector id or non + // existing unique connector name + if (!cIdNameIdentfierUsed && !ConnectorManager.getInstance().getConnectorIds().contains(cId)) { + throw new SqoopException(ServerError.SERVER_0004, "Invalid connector id " + cId); } connectors = new LinkedList<MConnector>(); - bundles = new HashMap<Long, ResourceBundle>(); + configParamBundles = new HashMap<Long, ResourceBundle>(); - connectors.add(ConnectorManager.getInstance().getConnectorConfigurable(id)); - bundles.put(id, ConnectorManager.getInstance().getResourceBundle(id, locale)); + connectors.add(ConnectorManager.getInstance().getConnectorConfigurable(cId)); + configParamBundles.put(cId, ConnectorManager.getInstance().getResourceBundle(cId, locale)); - AuditLoggerManager.getInstance() - .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(), - "get", "connector", String.valueOf(id)); + AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), + ctx.getRequest().getRemoteAddr(), "get", "connector", String.valueOf(cIdentifier)); + return new ConnectorBean(connectors, configParamBundles); } - - return new ConnectorBean(connectors, bundles); } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/handler/DriverConfigRequestHandler.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/handler/DriverConfigRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/DriverConfigRequestHandler.java deleted file mode 100644 index aa773a9..0000000 --- a/server/src/main/java/org/apache/sqoop/handler/DriverConfigRequestHandler.java +++ /dev/null @@ -1,49 +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.handler; - -import org.apache.log4j.Logger; -import org.apache.sqoop.audit.AuditLoggerManager; -import org.apache.sqoop.driver.Driver; -import org.apache.sqoop.json.DriverBean; -import org.apache.sqoop.json.JsonBean; -import org.apache.sqoop.server.RequestContext; -import org.apache.sqoop.server.RequestHandler; - -/** - * Driver Config request handler is supporting following resources: - * - */ -public class DriverConfigRequestHandler implements RequestHandler { - - private static final Logger LOG = - Logger.getLogger(DriverConfigRequestHandler.class); - - public DriverConfigRequestHandler() { - LOG.info("DriverConfigRequestHandler initialized"); - } - - @Override - public JsonBean handleEvent(RequestContext ctx) { - AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), - ctx.getRequest().getRemoteAddr(), "get", "driverConfig", ""); - - return new DriverBean(Driver.getInstance().getDriver(), Driver.getInstance() - .getBundle(ctx.getAcceptLanguageHeader())); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java new file mode 100644 index 0000000..be9685b --- /dev/null +++ b/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java @@ -0,0 +1,45 @@ +/** + * 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.handler; + +import org.apache.log4j.Logger; +import org.apache.sqoop.audit.AuditLoggerManager; +import org.apache.sqoop.driver.Driver; +import org.apache.sqoop.json.DriverBean; +import org.apache.sqoop.json.JsonBean; +import org.apache.sqoop.server.RequestContext; +import org.apache.sqoop.server.RequestHandler; + +public class DriverRequestHandler implements RequestHandler { + + private static final Logger LOG = + Logger.getLogger(DriverRequestHandler.class); + + public DriverRequestHandler() { + LOG.info("DriverRequestHandler initialized"); + } + + @Override + public JsonBean handleEvent(RequestContext ctx) { + AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), + ctx.getRequest().getRemoteAddr(), "get", "driver", ""); + + return new DriverBean(Driver.getInstance().getDriver(), Driver.getInstance() + .getBundle(ctx.getAcceptLanguageHeader())); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java index 0cd5acb..21ff376 100644 --- a/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java +++ b/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java @@ -31,7 +31,6 @@ import org.apache.sqoop.driver.Driver; import org.apache.sqoop.json.JobBean; import org.apache.sqoop.json.JsonBean; import org.apache.sqoop.json.ValidationResultBean; -import org.apache.sqoop.json.util.ConfigSerialization; import org.apache.sqoop.model.ConfigUtils; import org.apache.sqoop.model.MDriverConfig; import org.apache.sqoop.model.MFromConfig; @@ -250,7 +249,7 @@ public class JobRequestHandler implements RequestHandler { Locale locale = ctx.getAcceptLanguageHeader(); Repository repository = RepositoryManager.getInstance().getRepository(); - if (sjid.equals(ConfigSerialization.ALL)) { + if (sjid.equals(JsonBean.ALL)) { List<MJob> jobs = repository.findJobs(); bean = new JobBean(jobs); @@ -275,9 +274,8 @@ public class JobRequestHandler implements RequestHandler { ConnectorManager.getInstance().getResourceBundle(connectorId, locale)); } - // Sent framework resource bundle in all cases + // set driver config bundle bean.setDriverConfigBundle(Driver.getInstance().getBundle(locale)); - return bean; } @@ -288,7 +286,6 @@ public class JobRequestHandler implements RequestHandler { Repository repository = RepositoryManager.getInstance().getRepository(); repository.enableJob(xid, enabled); - return JsonBean.EMPTY_BEAN; } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/server/v1/ConfigurableServlet.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/server/v1/ConfigurableServlet.java b/server/src/main/java/org/apache/sqoop/server/v1/ConfigurableServlet.java new file mode 100644 index 0000000..c2aaeda --- /dev/null +++ b/server/src/main/java/org/apache/sqoop/server/v1/ConfigurableServlet.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.server.v1; + +import org.apache.sqoop.handler.ConnectorRequestHandler; +import org.apache.sqoop.handler.DriverRequestHandler; +import org.apache.sqoop.json.JsonBean; +import org.apache.sqoop.server.RequestContext; +import org.apache.sqoop.server.RequestHandler; +import org.apache.sqoop.server.SqoopProtocolServlet; + +/** + * Displays a given configurable registered in sqoop + * GET v1/configurable/connector/{cname} + * Return a registered connector with given name + * GET v1/configurable/connector/{cid} + * Return a registered connector with given id + * GET v1/configurable/driver + * Return the only driver registered in sqoop + */ +@SuppressWarnings("serial") +public class ConfigurableServlet extends SqoopProtocolServlet { + + private RequestHandler configurableRequestHandler; + private static String CONNECTOR_CONFIGURABLE = "connector"; + private static String DRIVER_CONFIGURABLE = "connector"; + + public ConfigurableServlet() { + // be default + configurableRequestHandler = new DriverRequestHandler(); + } + + @Override + protected JsonBean handleGetRequest(RequestContext ctx) throws Exception { + if (ctx.getPath().contains(CONNECTOR_CONFIGURABLE)) { + configurableRequestHandler = new ConnectorRequestHandler(); + } else if (ctx.getPath().contains(DRIVER_CONFIGURABLE)) { + configurableRequestHandler = new DriverRequestHandler(); + } + return configurableRequestHandler.handleEvent(ctx); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/server/v1/ConnectorServlet.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/server/v1/ConnectorServlet.java b/server/src/main/java/org/apache/sqoop/server/v1/ConnectorServlet.java index d24ac10..781abc3 100644 --- a/server/src/main/java/org/apache/sqoop/server/v1/ConnectorServlet.java +++ b/server/src/main/java/org/apache/sqoop/server/v1/ConnectorServlet.java @@ -23,9 +23,17 @@ import org.apache.sqoop.server.RequestContext; import org.apache.sqoop.server.RequestHandler; import org.apache.sqoop.server.SqoopProtocolServlet; + /** - * Displays the list of connectors that are available in the system via - * a GET request. + * Connector request handler is supporting following resources: + * + * GET v1/connector/all (remains for backward compatibility) + * Return all connectors registered in the sqoop system with their corresponding config params + * GET /v1/connector/{cname} + * Return details about one particular connector with name {cname} with its config params + * GET /v1/connector/{cid} + * Return details about one particular connector with id {cid} with its config params + * */ @SuppressWarnings("serial") public class ConnectorServlet extends SqoopProtocolServlet { http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/server/v1/ConnectorsServlet.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/server/v1/ConnectorsServlet.java b/server/src/main/java/org/apache/sqoop/server/v1/ConnectorsServlet.java new file mode 100644 index 0000000..f58275e --- /dev/null +++ b/server/src/main/java/org/apache/sqoop/server/v1/ConnectorsServlet.java @@ -0,0 +1,43 @@ +/** + * 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.server.v1; + +import org.apache.sqoop.handler.ConnectorRequestHandler; +import org.apache.sqoop.json.JsonBean; +import org.apache.sqoop.server.RequestContext; +import org.apache.sqoop.server.RequestHandler; +import org.apache.sqoop.server.SqoopProtocolServlet; + +/** + * Displays all connectors registered in sqoop + * GET v1/connectors + */ +@SuppressWarnings("serial") +public class ConnectorsServlet extends SqoopProtocolServlet { + + private RequestHandler connectorRequestHandler; + + public ConnectorsServlet() { + connectorRequestHandler = new ConnectorRequestHandler(); + } + + @Override + protected JsonBean handleGetRequest(RequestContext ctx) throws Exception { + return connectorRequestHandler.handleEvent(ctx); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/server/v1/DriverConfigServlet.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/server/v1/DriverConfigServlet.java b/server/src/main/java/org/apache/sqoop/server/v1/DriverConfigServlet.java deleted file mode 100644 index c2b1f9f..0000000 --- a/server/src/main/java/org/apache/sqoop/server/v1/DriverConfigServlet.java +++ /dev/null @@ -1,41 +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.server.v1; - -import org.apache.sqoop.handler.DriverConfigRequestHandler; -import org.apache.sqoop.json.JsonBean; -import org.apache.sqoop.server.RequestContext; -import org.apache.sqoop.server.RequestHandler; -import org.apache.sqoop.server.SqoopProtocolServlet; - -/** - * Get driver config - */ -@SuppressWarnings("serial") -public class DriverConfigServlet extends SqoopProtocolServlet { - private RequestHandler driverConfigRequestHandler; - - public DriverConfigServlet() { - driverConfigRequestHandler = new DriverConfigRequestHandler(); - } - - @Override - protected JsonBean handleGetRequest(RequestContext ctx) throws Exception { - return driverConfigRequestHandler.handleEvent(ctx); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/java/org/apache/sqoop/server/v1/DriverServlet.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/sqoop/server/v1/DriverServlet.java b/server/src/main/java/org/apache/sqoop/server/v1/DriverServlet.java new file mode 100644 index 0000000..43454fd --- /dev/null +++ b/server/src/main/java/org/apache/sqoop/server/v1/DriverServlet.java @@ -0,0 +1,44 @@ +/** + * 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.server.v1; + +import org.apache.sqoop.handler.DriverRequestHandler; +import org.apache.sqoop.json.JsonBean; +import org.apache.sqoop.server.RequestContext; +import org.apache.sqoop.server.RequestHandler; +import org.apache.sqoop.server.SqoopProtocolServlet; + +/** + * Driver request handler is supporting following resources: + * + * GET /v1/driver/ + * Return details about the registered driver and its configs + */ +@SuppressWarnings("serial") +public class DriverServlet extends SqoopProtocolServlet { + private RequestHandler driverRequestHandler; + + public DriverServlet() { + driverRequestHandler = new DriverRequestHandler(); + } + + @Override + protected JsonBean handleGetRequest(RequestContext ctx) throws Exception { + return driverRequestHandler.handleEvent(ctx); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/server/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/server/src/main/webapp/WEB-INF/web.xml b/server/src/main/webapp/WEB-INF/web.xml index d31120a..a6f7b0d 100644 --- a/server/src/main/webapp/WEB-INF/web.xml +++ b/server/src/main/webapp/WEB-INF/web.xml @@ -39,30 +39,53 @@ limitations under the License. <url-pattern>/version</url-pattern> </servlet-mapping> + <!-- Generic Configurable servlet --> + <servlet> + <servlet-name>v1.ConfigurableServlet</servlet-name> + <servlet-class>org.apache.sqoop.server.v1.ConfigurableServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + + <servlet-mapping> + <servlet-name>v1.ConfigurableServlet</servlet-name> + <url-pattern>/v1/configurable/*</url-pattern> + </servlet-mapping> + <!-- Connector servlet --> <servlet> <servlet-name>v1.ConnectorServlet</servlet-name> <servlet-class>org.apache.sqoop.server.v1.ConnectorServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> - + <servlet-mapping> <servlet-name>v1.ConnectorServlet</servlet-name> <url-pattern>/v1/connector/*</url-pattern> </servlet-mapping> - <!-- Driver Config servlet --> + <!-- Connectors servlet --> <servlet> - <servlet-name>v1.DriverConfigServlet</servlet-name> - <servlet-class>org.apache.sqoop.server.v1.DriverConfigServlet</servlet-class> + <servlet-name>v1.ConnectorsServlet</servlet-name> + <servlet-class>org.apache.sqoop.server.v1.ConnectorServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> - <servlet-name>v1.DriverConfigServlet</servlet-name> - <url-pattern>/v1/config/driver/*</url-pattern> + <servlet-name>v1.ConnectorsServlet</servlet-name> + <url-pattern>/v1/connectors/*</url-pattern> </servlet-mapping> + <!-- Driver servlet --> + <servlet> + <servlet-name>v1.DriverServlet</servlet-name> + <servlet-class>org.apache.sqoop.server.v1.DriverServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + + <servlet-mapping> + <servlet-name>v1.DriverServlet</servlet-name> + <url-pattern>/v1/driver/*</url-pattern> + </servlet-mapping> <!-- Link servlet --> <servlet> http://git-wip-us.apache.org/repos/asf/sqoop/blob/24e9b4c5/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java ---------------------------------------------------------------------- diff --git a/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java b/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java index 819cf6a..534877f 100644 --- a/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java +++ b/tools/src/main/java/org/apache/sqoop/tools/tool/RepositoryDumpTool.java @@ -17,30 +17,30 @@ */ package org.apache.sqoop.tools.tool; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.OptionBuilder; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; + +import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.log4j.Logger; +import org.apache.sqoop.common.VersionInfo; import org.apache.sqoop.connector.ConnectorManager; import org.apache.sqoop.json.JobBean; +import org.apache.sqoop.json.JsonBean; import org.apache.sqoop.json.LinkBean; import org.apache.sqoop.json.SubmissionBean; import org.apache.sqoop.repository.Repository; import org.apache.sqoop.repository.RepositoryManager; import org.apache.sqoop.tools.ConfiguredTool; -import org.apache.sqoop.common.VersionInfo; -import static org.apache.sqoop.json.util.ConfigSerialization.ALL; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; - /** * Write user-created content of Sqoop repository to JSON formatted file */ @@ -132,7 +132,7 @@ public class RepositoryDumpTool extends ConfiguredTool { private JSONObject addConnectorName(JSONObject json) { ConnectorManager connectorManager = ConnectorManager.getInstance(); - JSONArray results = (JSONArray) json.get(ALL); + JSONArray results = (JSONArray) json.get(JsonBean.ALL); Iterator<JSONObject> iterator = results.iterator();
