5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-16 17:00:53 +08:00

SQOOP-1498: Sqoop2: Repository Object refactoring (objects prefixed with M)

(Veena Basavaraj via Abraham Elmahrek)
This commit is contained in:
Abraham Elmahrek 2014-10-02 23:29:50 -07:00
parent e540668b55
commit 8362c73cc0
177 changed files with 4807 additions and 5247 deletions

View File

@ -17,27 +17,28 @@
*/ */
package org.apache.sqoop.client; package org.apache.sqoop.client;
import org.apache.sqoop.client.request.SqoopResourceRequests;
import org.apache.sqoop.common.Direction;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.ConnectorBean;
import org.apache.sqoop.json.DriverConfigBean;
import org.apache.sqoop.json.ValidationResultBean;
import org.apache.sqoop.model.FormUtils;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MSubmission;
import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.ValidationResult;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.apache.sqoop.client.request.SqoopResourceRequests;
import org.apache.sqoop.common.Direction;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.ConnectorBean;
import org.apache.sqoop.json.DriverBean;
import org.apache.sqoop.json.ValidationResultBean;
import org.apache.sqoop.model.ConfigUtils;
import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.model.MDriver;
import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MSubmission;
import org.apache.sqoop.validation.ConfigValidationResult;
import org.apache.sqoop.validation.Status;
/** /**
* Sqoop client API. * Sqoop client API.
* *
@ -69,9 +70,9 @@ public class SqoopClient {
private Map<Long, ResourceBundle> connectorConfigBundles; private Map<Long, ResourceBundle> connectorConfigBundles;
/** /**
* Cached driverConfig. * Cached driver.
*/ */
private MDriverConfig driverConfig; private MDriver mDriver;
/** /**
* Cached driverConfig bundle. * Cached driverConfig bundle.
*/ */
@ -120,7 +121,7 @@ public void clearCache() {
connectorConfigBundles = new HashMap<Long, ResourceBundle>(); connectorConfigBundles = new HashMap<Long, ResourceBundle>();
driverConfigBundle = null; driverConfigBundle = null;
connectors = new HashMap<Long, MConnector>(); connectors = new HashMap<Long, MConnector>();
driverConfig = null; mDriver = null;
isAllConnectors = false; isAllConnectors = false;
} }
@ -214,11 +215,10 @@ public Collection<MConnector> getConnectors() {
* @param connectorId Connector id. * @param connectorId Connector id.
* @return * @return
*/ */
public ResourceBundle getConnectorConfigResourceBundle(long connectorId) { public ResourceBundle getConnectorConfigBundle(long connectorId) {
if(connectorConfigBundles.containsKey(connectorId)) { if(connectorConfigBundles.containsKey(connectorId)) {
return connectorConfigBundles.get(connectorId); return connectorConfigBundles.get(connectorId);
} }
retrieveConnector(connectorId); retrieveConnector(connectorId);
return connectorConfigBundles.get(connectorId); return connectorConfigBundles.get(connectorId);
} }
@ -229,33 +229,46 @@ public ResourceBundle getConnectorConfigResourceBundle(long connectorId) {
* @return * @return
*/ */
public MDriverConfig getDriverConfig() { public MDriverConfig getDriverConfig() {
if(driverConfig != null) { if (mDriver != null) {
return driverConfig.clone(false); return mDriver.clone(false).getDriverConfig();
} }
retrieveAndCacheDriverConfig(); retrieveAndCacheDriver();
return driverConfig.clone(false); return mDriver.clone(false).getDriverConfig();
}
/**
* Return driver.
*
* @return
*/
public MDriver getDriver() {
if (mDriver != null) {
return mDriver.clone(false);
}
retrieveAndCacheDriver();
return mDriver.clone(false);
} }
/** /**
* Retrieve driverConfig and cache it. * Retrieve driverConfig and cache it.
*/ */
private void retrieveAndCacheDriverConfig() { private void retrieveAndCacheDriver() {
DriverConfigBean driverConfigBean = resourceRequests.readDriverConfig(); DriverBean driverBean = resourceRequests.readDriver();
driverConfig = driverConfigBean.getDriverConfig(); mDriver = driverBean.getDriver();
driverConfigBundle = driverConfigBean.getResourceBundle(); driverConfigBundle = driverBean.getDriverConfigResourceBundle();
} }
/** /**
* Return driverConfig bundle. * Return driverConfig bundle.
* *xx
* @return * @return
*/ */
public ResourceBundle getDriverConfigBundle() { public ResourceBundle getDriverConfigBundle() {
if(driverConfigBundle != null) { if(driverConfigBundle != null) {
return driverConfigBundle; return driverConfigBundle;
} }
retrieveAndCacheDriverConfig(); retrieveAndCacheDriver();
return driverConfigBundle; return driverConfigBundle;
} }
@ -266,11 +279,7 @@ public ResourceBundle getDriverConfigBundle() {
* @return * @return
*/ */
public MLink createLink(long connectorId) { public MLink createLink(long connectorId) {
return new MLink( return new MLink(connectorId, getConnector(connectorId).getLinkConfig());
connectorId,
getConnector(connectorId).getConnectionForms(),
getDriverConfig().getConnectionForms()
);
} }
/** /**
@ -281,10 +290,9 @@ public MLink createLink(long connectorId) {
*/ */
public MLink createLink(String connectorName) { public MLink createLink(String connectorName) {
MConnector connector = getConnector(connectorName); MConnector connector = getConnector(connectorName);
if(connector == null) { if (connector == null) {
throw new SqoopException(ClientError.CLIENT_0003, connectorName); throw new SqoopException(ClientError.CLIENT_0003, connectorName);
} }
return createLink(connector.getPersistenceId()); return createLink(connector.getPersistenceId());
} }
@ -362,9 +370,9 @@ public MJob createJob(long fromLinkId, long toLinkId) {
toLink.getConnectorId(), toLink.getConnectorId(),
fromLink.getPersistenceId(), fromLink.getPersistenceId(),
toLink.getPersistenceId(), toLink.getPersistenceId(),
getConnector(fromLink.getConnectorId()).getJobForms(Direction.FROM), getConnector(fromLink.getConnectorId()).getFromConfig(),
getConnector(toLink.getConnectorId()).getJobForms(Direction.TO), getConnector(toLink.getConnectorId()).getToConfig(),
getDriverConfig().getJobForms() getDriverConfig()
); );
} }
@ -530,41 +538,36 @@ public List<MSubmission> getSubmissionsForJob(long jobId) {
} }
private Status applyLinkValidations(ValidationResultBean bean, MLink link) { private Status applyLinkValidations(ValidationResultBean bean, MLink link) {
ValidationResult connector = bean.getValidationResults()[0]; ConfigValidationResult linkConfig = bean.getValidationResults()[0];
ValidationResult driverConfig = bean.getValidationResults()[1];
// Apply validation results // Apply validation results
FormUtils.applyValidation(link.getConnectorPart().getForms(), connector); ConfigUtils.applyValidation(link.getConnectorLinkConfig().getConfigs(), linkConfig);
FormUtils.applyValidation(link.getFrameworkPart().getForms(), driverConfig);
Long id = bean.getId(); Long id = bean.getId();
if(id != null) { if(id != null) {
link.setPersistenceId(id); link.setPersistenceId(id);
} }
return Status.getWorstStatus(linkConfig.getStatus());
return Status.getWorstStatus(connector.getStatus(), driverConfig.getStatus());
} }
private Status applyJobValidations(ValidationResultBean bean, MJob job) { private Status applyJobValidations(ValidationResultBean bean, MJob job) {
ValidationResult fromConnector = bean.getValidationResults()[0]; ConfigValidationResult fromConfig = bean.getValidationResults()[0];
ValidationResult toConnector = bean.getValidationResults()[1]; ConfigValidationResult toConfig = bean.getValidationResults()[1];
ValidationResult driverConfig = bean.getValidationResults()[2]; // TODO(VB): fix this as part of SQOOP 1509
//ConfigValidationResult driverConfig = bean.getValidationResults()[2];
// Apply validation results ConfigUtils.applyValidation(
// @TODO(Abe): From/To validation. job.getJobConfig(Direction.FROM).getConfigs(),
FormUtils.applyValidation( fromConfig);
job.getConnectorPart(Direction.FROM).getForms(), ConfigUtils.applyValidation(
fromConnector); job.getJobConfig(Direction.TO).getConfigs(),
FormUtils.applyValidation(job.getFrameworkPart().getForms(), driverConfig); toConfig);
FormUtils.applyValidation( //ConfigUtils.applyValidation(job.getDriverConfig().getSelf().getConfigs(), driverConfig);
job.getConnectorPart(Direction.TO).getForms(),
toConnector);
Long id = bean.getId(); Long id = bean.getId();
if(id != null) { if(id != null) {
job.setPersistenceId(id); job.setPersistenceId(id);
} }
return Status.getWorstStatus(fromConnector.getStatus(), driverConfig.getStatus(), toConnector.getStatus()); return Status.getWorstStatus(fromConfig.getStatus(), toConfig.getStatus());
// driverConfig.getStatus());
} }
} }

View File

@ -22,7 +22,7 @@
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
/** /**
* Provide cRud semantics over RESTfull HTTP API for connectors. Only read * Provide Read semantics over RESTfull HTTP API for connectors. Only read
* is supported as creation, update and delete might be done only directly on * is supported as creation, update and delete might be done only directly on
* server side. * server side.
*/ */
@ -38,10 +38,8 @@ public ConnectorBean read(String serverUrl, Long cid) {
response = super.get(serverUrl + RESOURCE + cid); response = super.get(serverUrl + RESOURCE + cid);
} }
JSONObject jsonObject = (JSONObject)JSONValue.parse(response); JSONObject jsonObject = (JSONObject)JSONValue.parse(response);
ConnectorBean connectorBean = new ConnectorBean(); ConnectorBean connectorBean = new ConnectorBean();
connectorBean.restore(jsonObject); connectorBean.restore(jsonObject);
return connectorBean; return connectorBean;
} }
} }

View File

@ -17,26 +17,23 @@
*/ */
package org.apache.sqoop.client.request; package org.apache.sqoop.client.request;
import org.apache.sqoop.json.DriverConfigBean; import org.apache.sqoop.json.DriverBean;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
/** /**
* Provide cRud semantics over RESTfull HTTP API for driverConfig. Only read * Provide CRUD semantics over RESTfull HTTP API for driverConfig
* is supported as creation, update and delete is not allowed.
*/ */
public class DriverConfigResourceRequest extends ResourceRequest { public class DriverConfigResourceRequest extends ResourceRequest {
public static final String RESOURCE = "v1/config/driver"; public static final String RESOURCE = "v1/config/driver";
public DriverConfigBean read(String serverUrl) { public DriverBean read(String serverUrl) {
String response = null; String response = null;
response = super.get(serverUrl + RESOURCE); response = super.get(serverUrl + RESOURCE);
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
DriverBean driverBean = new DriverBean();
DriverConfigBean driverConfigBean = new DriverConfigBean(); driverBean.restore(jsonObject);
driverConfigBean.restore(jsonObject); return driverBean;
return driverConfigBean;
} }
} }

View File

@ -34,46 +34,36 @@ public class JobResourceRequest extends ResourceRequest {
private static final String ENABLE = "/enable"; private static final String ENABLE = "/enable";
private static final String DISABLE = "/disable"; private static final String DISABLE = "/disable";
public JobBean read(String serverUrl, Long xid) { public JobBean read(String serverUrl, Long linkId) {
String response; String response;
if (xid == null) { if (linkId == null) {
response = super.get(serverUrl + RESOURCE + "all"); response = super.get(serverUrl + RESOURCE + "all");
} else { } else {
response = super.get(serverUrl + RESOURCE + xid); response = super.get(serverUrl + RESOURCE + linkId);
} }
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
JobBean jobBean = new JobBean(); JobBean jobBean = new JobBean();
jobBean.restore(jsonObject); jobBean.restore(jsonObject);
return jobBean; return jobBean;
} }
public ValidationResultBean create(String serverUrl, MJob job) { public ValidationResultBean create(String serverUrl, MJob job) {
JobBean jobBean = new JobBean(job); JobBean jobBean = new JobBean(job);
// Extract all config inputs including sensitive inputs
// Extract all form inputs including sensitive inputs
JSONObject jobJson = jobBean.extract(false); JSONObject jobJson = jobBean.extract(false);
String response = super.post(serverUrl + RESOURCE, jobJson.toJSONString()); String response = super.post(serverUrl + RESOURCE, jobJson.toJSONString());
ValidationResultBean validationResultBean = new ValidationResultBean();
ValidationResultBean validationBean = new ValidationResultBean(); validationResultBean.restore((JSONObject) JSONValue.parse(response));
validationBean.restore((JSONObject) JSONValue.parse(response)); return validationResultBean;
return validationBean;
} }
public ValidationResultBean update(String serverUrl, MJob job) { public ValidationResultBean update(String serverUrl, MJob job) {
JobBean jobBean = new JobBean(job); JobBean jobBean = new JobBean(job);
// Extract all config inputs including sensitive inputs
// Extract all form inputs including sensitive inputs
JSONObject jobJson = jobBean.extract(false); JSONObject jobJson = jobBean.extract(false);
String response = super.put(serverUrl + RESOURCE + job.getPersistenceId(), jobJson.toJSONString()); String response = super.put(serverUrl + RESOURCE + job.getPersistenceId(), jobJson.toJSONString());
ValidationResultBean validationBean = new ValidationResultBean(); ValidationResultBean validationBean = new ValidationResultBean();
validationBean.restore((JSONObject) JSONValue.parse(response)); validationBean.restore((JSONObject) JSONValue.parse(response));
return validationBean; return validationBean;
} }

View File

@ -50,28 +50,22 @@ public LinkBean read(String serverUrl, Long xid) {
public ValidationResultBean create(String serverUrl, MLink link) { public ValidationResultBean create(String serverUrl, MLink link) {
LinkBean linkBean = new LinkBean(link); LinkBean linkBean = new LinkBean(link);
// Extract all form inputs including sensitive inputs // Extract all config inputs including sensitive inputs
JSONObject linkJson = linkBean.extract(false); JSONObject linkJson = linkBean.extract(false);
String response = super.post(serverUrl + RESOURCE, linkJson.toJSONString()); String response = super.post(serverUrl + RESOURCE, linkJson.toJSONString());
ValidationResultBean validationBean = new ValidationResultBean(); ValidationResultBean validationBean = new ValidationResultBean();
validationBean.restore((JSONObject) JSONValue.parse(response)); validationBean.restore((JSONObject) JSONValue.parse(response));
return validationBean; return validationBean;
} }
public ValidationResultBean update(String serverUrl, MLink link) { public ValidationResultBean update(String serverUrl, MLink link) {
LinkBean linkBean = new LinkBean(link); LinkBean linkBean = new LinkBean(link);
// Extract all form inputs including sensitive inputs // Extract all config inputs including sensitive inputs
JSONObject linkJson = linkBean.extract(false); JSONObject linkJson = linkBean.extract(false);
String response = super.put(serverUrl + RESOURCE + link.getPersistenceId(), linkJson.toJSONString()); String response = super.put(serverUrl + RESOURCE + link.getPersistenceId(), linkJson.toJSONString());
ValidationResultBean validationBean = new ValidationResultBean(); ValidationResultBean validationBean = new ValidationResultBean();
validationBean.restore((JSONObject) JSONValue.parse(response)); validationBean.restore((JSONObject) JSONValue.parse(response));
return validationBean; return validationBean;
} }

View File

@ -19,7 +19,7 @@
import org.apache.sqoop.json.LinkBean; import org.apache.sqoop.json.LinkBean;
import org.apache.sqoop.json.ConnectorBean; import org.apache.sqoop.json.ConnectorBean;
import org.apache.sqoop.json.DriverConfigBean; import org.apache.sqoop.json.DriverBean;
import org.apache.sqoop.json.JobBean; import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.json.SubmissionBean; import org.apache.sqoop.json.SubmissionBean;
import org.apache.sqoop.json.ValidationResultBean; import org.apache.sqoop.json.ValidationResultBean;
@ -83,7 +83,7 @@ public SubmissionResourceRequest getSubmissionResourceRequest() {
return submissionRequest; return submissionRequest;
} }
public DriverConfigBean readDriverConfig() { public DriverBean readDriver() {
return getDriverConfigResourceRequest().read(serverUrl); return getDriverConfigResourceRequest().read(serverUrl);
} }

View File

@ -17,28 +17,36 @@
*/ */
package org.apache.sqoop.client; package org.apache.sqoop.client;
import org.apache.sqoop.client.request.SqoopResourceRequests; import static org.junit.Assert.assertEquals;
import org.apache.sqoop.common.SqoopException; import static org.junit.Assert.assertNull;
import org.apache.sqoop.json.ConnectorBean; import static org.mockito.Mockito.mock;
import org.apache.sqoop.json.DriverConfigBean; import static org.mockito.Mockito.times;
import org.apache.sqoop.model.MConnectionForms; import static org.mockito.Mockito.verify;
import org.apache.sqoop.model.MConnector; import static org.mockito.Mockito.verifyNoMoreInteractions;
import org.apache.sqoop.model.MDriverConfig; import static org.mockito.Mockito.when;
import org.apache.sqoop.model.MJobForms;
import org.apache.sqoop.utils.MapResourceBundle;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import static org.junit.Assert.assertEquals; import org.apache.sqoop.client.request.SqoopResourceRequests;
import static org.junit.Assert.assertNull; import org.apache.sqoop.common.SqoopException;
import static org.mockito.Mockito.*; import org.apache.sqoop.json.ConnectorBean;
import org.apache.sqoop.json.DriverBean;
import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.model.MDriver;
import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MFromConfig;
import org.apache.sqoop.model.MLinkConfig;
import org.apache.sqoop.model.MToConfig;
import org.apache.sqoop.utils.MapResourceBundle;
import org.junit.Before;
import org.junit.Test;
public class TestSqoopClient { public class TestSqoopClient {
@ -62,7 +70,7 @@ public void testGetConnector() {
MConnector connector = client.getConnector(1); MConnector connector = client.getConnector(1);
assertEquals(1, connector.getPersistenceId()); assertEquals(1, connector.getPersistenceId());
client.getConnectorConfigResourceBundle(1L); client.getConnectorConfigBundle(1L);
verify(resourceRequests, times(1)).readConnector(1L); verify(resourceRequests, times(1)).readConnector(1L);
} }
@ -74,7 +82,7 @@ public void testGetConnectorByString() {
assertEquals(1, connector.getPersistenceId()); assertEquals(1, connector.getPersistenceId());
assertEquals("A1", connector.getUniqueName()); assertEquals("A1", connector.getUniqueName());
client.getConnectorConfigResourceBundle(1L); client.getConnectorConfigBundle(1L);
verify(resourceRequests, times(0)).readConnector(1L); verify(resourceRequests, times(0)).readConnector(1L);
verify(resourceRequests, times(1)).readConnector(null); verify(resourceRequests, times(1)).readConnector(null);
@ -87,7 +95,7 @@ public void testGetConnectorByString() {
@Test @Test
public void testGetConnectorBundle() { public void testGetConnectorBundle() {
when(resourceRequests.readConnector(1L)).thenReturn(connectorBean(connector(1))); when(resourceRequests.readConnector(1L)).thenReturn(connectorBean(connector(1)));
client.getConnectorConfigResourceBundle(1L); client.getConnectorConfigBundle(1L);
MConnector connector = client.getConnector(1); MConnector connector = client.getConnector(1);
assertEquals(1, connector.getPersistenceId()); assertEquals(1, connector.getPersistenceId());
@ -101,12 +109,12 @@ public void testGetConnectorBundle() {
*/ */
@Test @Test
public void testGetDriverConfig() { public void testGetDriverConfig() {
when(resourceRequests.readDriverConfig()).thenReturn(driverConfigBean(driverConfig())); when(resourceRequests.readDriver()).thenReturn(driverBean(driver()));
client.getDriverConfig(); client.getDriverConfig();
client.getDriverConfigBundle(); client.getDriverConfigBundle();
verify(resourceRequests, times(1)).readDriverConfig(); verify(resourceRequests, times(1)).readDriver();
} }
/** /**
@ -115,12 +123,12 @@ public void testGetDriverConfig() {
*/ */
@Test @Test
public void testGetDriverConfigBundle() { public void testGetDriverConfigBundle() {
when(resourceRequests.readDriverConfig()).thenReturn(driverConfigBean(driverConfig())); when(resourceRequests.readDriver()).thenReturn(driverBean(driver()));
client.getDriverConfigBundle(); client.getDriverConfigBundle();
client.getDriverConfig(); client.getDriverConfig();
verify(resourceRequests, times(1)).readDriverConfig(); verify(resourceRequests, times(1)).readDriver();
} }
/** /**
@ -135,12 +143,12 @@ public void testGetConnectors() {
Collection<MConnector> connectors = client.getConnectors(); Collection<MConnector> connectors = client.getConnectors();
assertEquals(2, connectors.size()); assertEquals(2, connectors.size());
client.getConnectorConfigResourceBundle(1); client.getConnectorConfigBundle(1);
connector = client.getConnector(1); connector = client.getConnector(1);
assertEquals(1, connector.getPersistenceId()); assertEquals(1, connector.getPersistenceId());
connector = client.getConnector(2); connector = client.getConnector(2);
client.getConnectorConfigResourceBundle(2); client.getConnectorConfigBundle(2);
assertEquals(2, connector.getPersistenceId()); assertEquals(2, connector.getPersistenceId());
connectors = client.getConnectors(); connectors = client.getConnectors();
@ -173,11 +181,11 @@ public void testGetConnectorOneByOne() {
when(resourceRequests.readConnector(1L)).thenReturn(bean); when(resourceRequests.readConnector(1L)).thenReturn(bean);
when(resourceRequests.readConnector(2L)).thenReturn(bean); when(resourceRequests.readConnector(2L)).thenReturn(bean);
client.getConnectorConfigResourceBundle(1); client.getConnectorConfigBundle(1);
client.getConnector(1); client.getConnector(1);
client.getConnector(2); client.getConnector(2);
client.getConnectorConfigResourceBundle(2); client.getConnectorConfigBundle(2);
Collection<MConnector> connectors = client.getConnectors(); Collection<MConnector> connectors = client.getConnectors();
assertEquals(2, connectors.size()); assertEquals(2, connectors.size());
@ -207,21 +215,20 @@ private ConnectorBean connectorBean(MConnector...connectors) {
} }
return new ConnectorBean(connectorList, bundles); return new ConnectorBean(connectorList, bundles);
} }
private DriverConfigBean driverConfigBean(MDriverConfig driverConfig) { private DriverBean driverBean(MDriver driver) {
return new DriverConfigBean(driverConfig, new MapResourceBundle(null)); return new DriverBean(driver, new MapResourceBundle(null));
} }
private MConnector connector(long id) { private MConnector connector(long id) {
MConnector connector = new MConnector("A" + id, "A" + id, "1.0" + id, MConnector connector = new MConnector("A" + id, "A" + id, "1.0" + id,
new MConnectionForms(null), new MJobForms(null), new MJobForms(null)); new MLinkConfig(null), new MFromConfig(null), new MToConfig(null));
connector.setPersistenceId(id); connector.setPersistenceId(id);
return connector; return connector;
} }
private MDriverConfig driverConfig() { private MDriver driver() {
MDriverConfig driverConfig = new MDriverConfig(new MConnectionForms(null), MDriver driver = new MDriver(new MDriverConfig(new LinkedList<MConfig>()), "1");
new MJobForms(null), "1"); driver.setPersistenceId(1);
driverConfig.setPersistenceId(1); return driver;
return driverConfig;
} }
} }

View File

@ -17,15 +17,15 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import static org.apache.sqoop.json.util.FormSerialization.ALL; import static org.apache.sqoop.json.util.ConfigSerialization.ALL;
import static org.apache.sqoop.json.util.FormSerialization.CLASS; import static org.apache.sqoop.json.util.ConfigSerialization.CLASS;
import static org.apache.sqoop.json.util.FormSerialization.CON_FORMS; import static org.apache.sqoop.json.util.ConfigSerialization.ID;
import static org.apache.sqoop.json.util.FormSerialization.ID; import static org.apache.sqoop.json.util.ConfigSerialization.CONNECTOR_JOB_CONFIG;
import static org.apache.sqoop.json.util.FormSerialization.JOB_FORMS; import static org.apache.sqoop.json.util.ConfigSerialization.CONNECTOR_LINK_CONFIG;
import static org.apache.sqoop.json.util.FormSerialization.NAME; import static org.apache.sqoop.json.util.ConfigSerialization.NAME;
import static org.apache.sqoop.json.util.FormSerialization.VERSION; import static org.apache.sqoop.json.util.ConfigSerialization.VERSION;
import static org.apache.sqoop.json.util.FormSerialization.extractForms; import static org.apache.sqoop.json.util.ConfigSerialization.extractConfigList;
import static org.apache.sqoop.json.util.FormSerialization.restoreForms; import static org.apache.sqoop.json.util.ConfigSerialization.restoreConfigList;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.CONNECTOR_CONFIGS; import static org.apache.sqoop.json.util.ResourceBundleSerialization.CONNECTOR_CONFIGS;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.extractResourceBundle; import static org.apache.sqoop.json.util.ResourceBundleSerialization.extractResourceBundle;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.restoreResourceBundle; import static org.apache.sqoop.json.util.ResourceBundleSerialization.restoreResourceBundle;
@ -38,24 +38,28 @@
import java.util.Set; import java.util.Set;
import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.Direction;
import org.apache.sqoop.model.MConnectionForms; import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MFromConfig;
import org.apache.sqoop.model.MJobForms; import org.apache.sqoop.model.MLinkConfig;
import org.apache.sqoop.model.MToConfig;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
/**
* Json representation of the connector object
*
*/
public class ConnectorBean implements JsonBean { public class ConnectorBean implements JsonBean {
private List<MConnector> connectors; private List<MConnector> connectors;
private Map<Long, ResourceBundle> bundles; private Map<Long, ResourceBundle> connectorConfigBundles;
// for "extract" // for "extract"
public ConnectorBean(List<MConnector> connectors, public ConnectorBean(List<MConnector> connectors, Map<Long, ResourceBundle> bundles) {
Map<Long, ResourceBundle> bundles) {
this.connectors = connectors; this.connectors = connectors;
this.bundles = bundles; this.connectorConfigBundles = bundles;
} }
// for "restore" // for "restore"
@ -67,46 +71,46 @@ public List<MConnector> getConnectors() {
} }
public Map<Long, ResourceBundle> getResourceBundles() { public Map<Long, ResourceBundle> getResourceBundles() {
return bundles; return connectorConfigBundles;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public JSONObject extract(boolean skipSensitive) { public JSONObject extract(boolean skipSensitive) {
JSONArray array = new JSONArray(); JSONArray connectorArray = new JSONArray();
for (MConnector connector : connectors) { for (MConnector connector : connectors) {
JSONObject object = new JSONObject(); JSONObject connectorJsonObject = new JSONObject();
object.put(ID, connector.getPersistenceId()); connectorJsonObject.put(ID, connector.getPersistenceId());
object.put(NAME, connector.getUniqueName()); connectorJsonObject.put(NAME, connector.getUniqueName());
object.put(CLASS, connector.getClassName()); connectorJsonObject.put(CLASS, connector.getClassName());
object.put(VERSION, connector.getVersion()); connectorJsonObject.put(VERSION, connector.getVersion());
connectorJsonObject.put(CONNECTOR_LINK_CONFIG,
extractConfigList(connector.getLinkConfig().getConfigs(), skipSensitive));
object.put(CON_FORMS, extractForms(connector.getConnectionForms().getForms(), skipSensitive)); connectorJsonObject.put(CONNECTOR_JOB_CONFIG, new JSONObject());
object.put(JOB_FORMS, new JSONObject()); // add sub fields to the job config for from and to
if (connector.getJobForms(Direction.FROM) != null) { if (connector.getFromConfig() != null) {
((JSONObject)object.get(JOB_FORMS)).put( ((JSONObject) connectorJsonObject.get(CONNECTOR_JOB_CONFIG)).put(Direction.FROM,
Direction.FROM, extractForms(connector.getJobForms(Direction.FROM).getForms(), skipSensitive)); extractConfigList(connector.getFromConfig().getConfigs(), skipSensitive));
} }
if (connector.getToConfig() != null) {
if (connector.getJobForms(Direction.TO) != null) { ((JSONObject) connectorJsonObject.get(CONNECTOR_JOB_CONFIG)).put(Direction.TO,
((JSONObject)object.get(JOB_FORMS)).put( extractConfigList(connector.getToConfig().getConfigs(), skipSensitive));
Direction.TO, extractForms(connector.getJobForms(Direction.TO).getForms(), skipSensitive));
} }
array.add(object); connectorArray.add(connectorJsonObject);
} }
JSONObject all = new JSONObject(); JSONObject all = new JSONObject();
all.put(ALL, array); all.put(ALL, connectorArray);
if(bundles != null && !bundles.isEmpty()) { if (connectorConfigBundles != null && !connectorConfigBundles.isEmpty()) {
JSONObject jsonBundles = new JSONObject(); JSONObject jsonBundles = new JSONObject();
for(Map.Entry<Long, ResourceBundle> entry : bundles.entrySet()) { for (Map.Entry<Long, ResourceBundle> entry : connectorConfigBundles.entrySet()) {
jsonBundles.put(entry.getKey().toString(), jsonBundles.put(entry.getKey().toString(), extractResourceBundle(entry.getValue()));
extractResourceBundle(entry.getValue()));
} }
all.put(CONNECTOR_CONFIGS, jsonBundles); all.put(CONNECTOR_CONFIGS, jsonBundles);
} }
@ -129,35 +133,42 @@ public void restore(JSONObject jsonObject) {
String className = (String) object.get(CLASS); String className = (String) object.get(CLASS);
String version = (String) object.get(VERSION); String version = (String) object.get(VERSION);
MJobForms fromJob = null; List<MConfig> linkConfigs = restoreConfigList((JSONArray) object.get(CONNECTOR_LINK_CONFIG));
MJobForms toJob = null;
List<MForm> connForms = restoreForms((JSONArray) object.get(CON_FORMS)); // parent that encapsualtes both the from/to configs
JSONObject jobJson = (JSONObject) object.get(JOB_FORMS); JSONObject jobConfigJson = (JSONObject) object.get(CONNECTOR_JOB_CONFIG);
JSONArray fromJobJson = (JSONArray)jobJson.get(Direction.FROM.name()); JSONArray fromJobConfigJson = (JSONArray) jobConfigJson.get(Direction.FROM.name());
JSONArray toJobJson = (JSONArray)jobJson.get(Direction.TO.name()); JSONArray toJobConfigJson = (JSONArray) jobConfigJson.get(Direction.TO.name());
if (fromJobJson != null) {
List<MForm> fromJobForms = restoreForms(fromJobJson); MFromConfig fromConfig = null;
fromJob = new MJobForms(fromJobForms); MToConfig toConfig = null;
if (fromJobConfigJson != null) {
List<MConfig> fromJobConfig = restoreConfigList(fromJobConfigJson);
fromConfig = new MFromConfig(fromJobConfig);
} }
if (toJobJson != null) { if (toJobConfigJson != null) {
List<MForm> toJobForms = restoreForms(toJobJson); List<MConfig> toJobConfig = restoreConfigList(toJobConfigJson);
toJob = new MJobForms(toJobForms); toConfig = new MToConfig(toJobConfig);
} }
MConnectionForms connection = new MConnectionForms(connForms);
MConnector connector = new MConnector(uniqueName, className, version, MLinkConfig linkConfig = new MLinkConfig(linkConfigs);
connection, fromJob, toJob); MConnector connector = new MConnector(uniqueName, className, version, linkConfig, fromConfig,
toConfig);
connector.setPersistenceId(connectorId); connector.setPersistenceId(connectorId);
connectors.add(connector); connectors.add(connector);
} }
if(jsonObject.containsKey(CONNECTOR_CONFIGS)) { if (jsonObject.containsKey(CONNECTOR_CONFIGS)) {
bundles = new HashMap<Long, ResourceBundle>(); connectorConfigBundles = new HashMap<Long, ResourceBundle>();
JSONObject jsonBundles = (JSONObject) jsonObject.get(CONNECTOR_CONFIGS); JSONObject jsonBundles = (JSONObject) jsonObject.get(CONNECTOR_CONFIGS);
Set<Map.Entry<String, JSONObject>> entrySet = jsonBundles.entrySet(); Set<Map.Entry<String, JSONObject>> entrySet = jsonBundles.entrySet();
for (Map.Entry<String, JSONObject> entry : entrySet) { for (Map.Entry<String, JSONObject> entry : entrySet) {
bundles.put(Long.parseLong(entry.getKey()), connectorConfigBundles.put(Long.parseLong(entry.getKey()),
restoreResourceBundle(entry.getValue())); restoreResourceBundle(entry.getValue()));
} }
} }
} }

View File

@ -17,56 +17,63 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.model.MConnectionForms; import static org.apache.sqoop.json.util.ConfigSerialization.DRIVER_CONFIG;
import org.apache.sqoop.model.MForm; import static org.apache.sqoop.json.util.ConfigSerialization.DRIVER_VERSION;
import org.apache.sqoop.model.MDriverConfig; import static org.apache.sqoop.json.util.ConfigSerialization.ID;
import org.apache.sqoop.model.MJobForms; import static org.apache.sqoop.json.util.ConfigSerialization.extractConfigList;
import org.json.simple.JSONArray; import static org.apache.sqoop.json.util.ConfigSerialization.restoreConfigList;
import org.json.simple.JSONObject; import static org.apache.sqoop.json.util.ResourceBundleSerialization.CONFIGS;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.extractResourceBundle;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.restoreResourceBundle;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import static org.apache.sqoop.json.util.FormSerialization.*; import org.apache.sqoop.model.MConfig;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.*; import org.apache.sqoop.model.MDriver;
import org.apache.sqoop.model.MDriverConfig;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
/**
* Json representation of the driver
*
*/
public class DriverBean implements JsonBean {
public class DriverConfigBean implements JsonBean { public static final String CURRENT_DRIVER_VERSION = "1";
private MDriverConfig driverConfig; private MDriver driver;
private ResourceBundle bundle; private ResourceBundle bundle;
// for "extract" // for "extract"
public DriverConfigBean(MDriverConfig driverConfig, ResourceBundle bundle) { public DriverBean(MDriver driver, ResourceBundle bundle) {
this.driverConfig = driverConfig; this.driver = driver;
this.bundle = bundle; this.bundle = bundle;
} }
// for "restore" // for "restore"
public DriverConfigBean() { public DriverBean() {
} }
public MDriverConfig getDriverConfig() { public MDriver getDriver() {
return driverConfig; return driver;
} }
public ResourceBundle getResourceBundle() { public ResourceBundle getDriverConfigResourceBundle() {
return bundle; return bundle;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public JSONObject extract(boolean skipSensitive) { public JSONObject extract(boolean skipSensitive) {
// TODO(Abe): Add From/To connection forms. JSONArray configs =
JSONArray conForms = extractConfigList(driver.getDriverConfig().getConfigs(), skipSensitive);
extractForms(driverConfig.getConnectionForms().getForms(), skipSensitive);
JSONArray jobForms = extractForms(driverConfig.getJobForms().getForms(), skipSensitive);
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put(ID, driverConfig.getPersistenceId()); result.put(ID, driver.getPersistenceId());
result.put(DRIVER_VERSION, driverConfig.getVersion()); result.put(DRIVER_VERSION, driver.getVersion());
result.put(CON_FORMS, conForms); result.put(DRIVER_CONFIG, configs);
result.put(JOB_FORMS, jobForms);
result.put(CONFIGS, extractResourceBundle(bundle)); result.put(CONFIGS, extractResourceBundle(bundle));
return result; return result;
} }
@ -75,18 +82,9 @@ public JSONObject extract(boolean skipSensitive) {
public void restore(JSONObject jsonObject) { public void restore(JSONObject jsonObject) {
long id = (Long) jsonObject.get(ID); long id = (Long) jsonObject.get(ID);
String driverVersion = (String) jsonObject.get(DRIVER_VERSION); String driverVersion = (String) jsonObject.get(DRIVER_VERSION);
List<MConfig> driverConfig = restoreConfigList((JSONArray) jsonObject.get(DRIVER_CONFIG));
List<MForm> connForms = restoreForms((JSONArray) jsonObject.get(CON_FORMS)); driver = new MDriver(new MDriverConfig(driverConfig), driverVersion);
List<MForm> jobForms = restoreForms((JSONArray) jsonObject.get(JOB_FORMS)); driver.setPersistenceId(id);
// TODO(Abe): Get From/To connection forms.
driverConfig = new MDriverConfig(
new MConnectionForms(connForms),
new MJobForms(jobForms),
driverVersion);
driverConfig.setPersistenceId(id);
bundle = restoreResourceBundle((JSONObject) jsonObject.get(CONFIGS)); bundle = restoreResourceBundle((JSONObject) jsonObject.get(CONFIGS));
} }
} }

View File

@ -17,12 +17,17 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.common.Direction; import static org.apache.sqoop.json.util.ConfigSerialization.CREATION_DATE;
import org.apache.sqoop.model.MForm; import static org.apache.sqoop.json.util.ConfigSerialization.CREATION_USER;
import org.apache.sqoop.model.MJob; import static org.apache.sqoop.json.util.ConfigSerialization.ENABLED;
import org.apache.sqoop.model.MJobForms; import static org.apache.sqoop.json.util.ConfigSerialization.UPDATE_DATE;
import org.json.simple.JSONArray; import static org.apache.sqoop.json.util.ConfigSerialization.UPDATE_USER;
import org.json.simple.JSONObject; import static org.apache.sqoop.json.util.ConfigSerialization.extractConfigList;
import static org.apache.sqoop.json.util.ConfigSerialization.restoreConfigList;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.CONNECTOR_CONFIGS;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.DRIVER_CONFIGS;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.extractResourceBundle;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.restoreResourceBundle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -32,11 +37,18 @@
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import static org.apache.sqoop.json.util.FormSerialization.*; import org.apache.sqoop.common.Direction;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.*; import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MDriver;
import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MFromConfig;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MToConfig;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
/** /**
* * Json representation of the job config
*/ */
public class JobBean implements JsonBean { public class JobBean implements JsonBean {
@ -47,9 +59,9 @@ public class JobBean implements JsonBean {
private static final String TO_LINK_ID = "to-link-id"; private static final String TO_LINK_ID = "to-link-id";
private static final String FROM_CONNECTOR_ID = "from-connector-id"; private static final String FROM_CONNECTOR_ID = "from-connector-id";
private static final String TO_CONNECTOR_ID = "to-connector-id"; private static final String TO_CONNECTOR_ID = "to-connector-id";
private static final String FROM_CONNECTOR_PART = "from-connector"; private static final String FROM_CONFIG = "from-config";
private static final String TO_CONNECTOR_PART = "to-connector"; private static final String TO_CONFIG = "to-config";
private static final String FRAMEWORK_PART = "framework"; private static final String DRIVER_CONFIG = "driver-config";
// Required // Required
private List<MJob> jobs; private List<MJob> jobs;
@ -114,18 +126,21 @@ public JSONObject extract(boolean skipSensitive) {
object.put(CREATION_DATE, job.getCreationDate().getTime()); object.put(CREATION_DATE, job.getCreationDate().getTime());
object.put(UPDATE_USER, job.getLastUpdateUser()); object.put(UPDATE_USER, job.getLastUpdateUser());
object.put(UPDATE_DATE, job.getLastUpdateDate().getTime()); object.put(UPDATE_DATE, job.getLastUpdateDate().getTime());
object.put(FROM_LINK_ID, job.getLinkId(Direction.FROM)); // job link associated connectors
object.put(TO_LINK_ID, job.getLinkId(Direction.TO));
object.put(FROM_CONNECTOR_ID, job.getConnectorId(Direction.FROM)); object.put(FROM_CONNECTOR_ID, job.getConnectorId(Direction.FROM));
object.put(TO_CONNECTOR_ID, job.getConnectorId(Direction.TO)); object.put(TO_CONNECTOR_ID, job.getConnectorId(Direction.TO));
object.put(FROM_CONNECTOR_PART, // job associated links
extractForms(job.getConnectorPart(Direction.FROM).getForms(),skipSensitive)); object.put(FROM_LINK_ID, job.getLinkId(Direction.FROM));
object.put(TO_CONNECTOR_PART, object.put(TO_LINK_ID, job.getLinkId(Direction.TO));
extractForms(job.getConnectorPart(Direction.TO).getForms(), skipSensitive)); // job configs
object.put(FRAMEWORK_PART, object.put(FROM_CONFIG, extractConfigList(job
extractForms(job.getFrameworkPart().getForms(), skipSensitive)); .getJobConfig(Direction.FROM).getConfigs(), skipSensitive));
object.put(TO_CONFIG,
extractConfigList(job.getJobConfig(Direction.TO).getConfigs(), skipSensitive));
object.put(DRIVER_CONFIG,
extractConfigList(job.getDriverConfig().getConfigs(), skipSensitive));
array.add(object); array.add(object);
} }
JSONObject all = new JSONObject(); JSONObject all = new JSONObject();
@ -160,22 +175,22 @@ public void restore(JSONObject jsonObject) {
long toConnectorId = (Long) object.get(TO_CONNECTOR_ID); long toConnectorId = (Long) object.get(TO_CONNECTOR_ID);
long fromConnectionId = (Long) object.get(FROM_LINK_ID); long fromConnectionId = (Long) object.get(FROM_LINK_ID);
long toConnectionId = (Long) object.get(TO_LINK_ID); long toConnectionId = (Long) object.get(TO_LINK_ID);
JSONArray fromConnectorPart = (JSONArray) object.get(FROM_CONNECTOR_PART); JSONArray fromConfigJson = (JSONArray) object.get(FROM_CONFIG);
JSONArray toConnectorPart = (JSONArray) object.get(TO_CONNECTOR_PART); JSONArray toConfigJson = (JSONArray) object.get(TO_CONFIG);
JSONArray frameworkPart = (JSONArray) object.get(FRAMEWORK_PART); JSONArray driverConfigJson = (JSONArray) object.get(DRIVER_CONFIG);
List<MForm> fromConnectorParts = restoreForms(fromConnectorPart); List<MConfig> fromConfig = restoreConfigList(fromConfigJson);
List<MForm> toConnectorParts = restoreForms(toConnectorPart); List<MConfig> toConfig = restoreConfigList(toConfigJson);
List<MForm> frameworkForms = restoreForms(frameworkPart); List<MConfig> driverConfig = restoreConfigList(driverConfigJson);
MJob job = new MJob( MJob job = new MJob(
fromConnectorId, fromConnectorId,
toConnectorId, toConnectorId,
fromConnectionId, fromConnectionId,
toConnectionId, toConnectionId,
new MJobForms(fromConnectorParts), new MFromConfig(fromConfig),
new MJobForms(toConnectorParts), new MToConfig(toConfig),
new MJobForms(frameworkForms) new MDriverConfig(driverConfig)
); );
job.setPersistenceId((Long) object.get(ID)); job.setPersistenceId((Long) object.get(ID));

View File

@ -21,41 +21,41 @@
import org.apache.sqoop.common.DirectionError; import org.apache.sqoop.common.DirectionError;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.Validation; import org.apache.sqoop.validation.ConfigValidator;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Bean for sending validations across network. This bean will move two * Bean for sending validations across network. This bean will send job validation results
* validation objects at one time - one for connector and second for framework * Optionally validation bean can also transfer
* part of validated entity. Optionally validation bean can also transfer
* created persistent id in case that new entity was created. * created persistent id in case that new entity was created.
*/ */
public class JobValidationBean implements JsonBean { public class JobValidationBean implements JsonBean {
private static final String ID = "id"; private static final String ID = "id";
private static final String FRAMEWORK = "framework"; private static final String JOB = "job";
private static final String CONNECTOR = "connector";
private static final String FROM = "from"; private static final String FROM = "from";
private static final String TO = "to"; private static final String TO = "to";
private static final String DRIVER = "driver";
private static final String STATUS = "status"; private static final String STATUS = "status";
private static final String MESSAGE = "message"; private static final String MESSAGE = "message";
private static final String MESSAGES = "messages"; private static final String MESSAGES = "messages";
private Long id; private Long id;
private Validation fromConnectorValidation; private ConfigValidator fromConfigValidation;
private Validation toConnectorValidation; private ConfigValidator toConfigValidation;
private Validation frameworkValidation; private ConfigValidator driverConfigValidation;
// For "extract" // For "extract"
public JobValidationBean(Validation fromConnector, Validation framework, Validation toConnector) { public JobValidationBean(ConfigValidator fromConnector, ConfigValidator framework, ConfigValidator toConnector) {
this(); this();
this.fromConnectorValidation = fromConnector; this.fromConfigValidation = fromConnector;
this.toConnectorValidation = toConnector; this.toConfigValidation = toConnector;
this.frameworkValidation = framework; this.driverConfigValidation = framework;
} }
// For "restore" // For "restore"
@ -63,21 +63,21 @@ public JobValidationBean() {
id = null; id = null;
} }
public Validation getConnectorValidation(Direction type) { public ConfigValidator getConnectorValidation(Direction type) {
switch(type) { switch(type) {
case FROM: case FROM:
return fromConnectorValidation; return fromConfigValidation;
case TO: case TO:
return toConnectorValidation; return toConfigValidation;
default: default:
throw new SqoopException(DirectionError.DIRECTION_0000, "Direction: " + type); throw new SqoopException(DirectionError.DIRECTION_0000, "Direction: " + type);
} }
} }
public Validation getFrameworkValidation() { public ConfigValidator getFrameworkValidation() {
return frameworkValidation; return driverConfigValidation;
} }
public void setId(Long id) { public void setId(Long id) {
@ -91,32 +91,30 @@ public Long getId() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JSONObject extract(boolean skipSensitive) { public JSONObject extract(boolean skipSensitive) {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
JSONObject connectorObject = new JSONObject(); JSONObject jobObject = new JSONObject();
// Optionally transfer id // Optionally transfer id
if(id != null) { if(id != null) {
object.put(ID, id); object.put(ID, id);
} }
connectorObject.put(FROM, extractValidation(getConnectorValidation(Direction.FROM))); jobObject.put(FROM, extractValidation(getConnectorValidation(Direction.FROM)));
connectorObject.put(TO, extractValidation(getConnectorValidation(Direction.TO))); jobObject.put(TO, extractValidation(getConnectorValidation(Direction.TO)));
jobObject.put(DRIVER, extractValidation(driverConfigValidation));
object.put(FRAMEWORK, extractValidation(frameworkValidation)); object.put(JOB, jobObject);
object.put(CONNECTOR, connectorObject);
return object; return object;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private JSONObject extractValidation(Validation validation) { private JSONObject extractValidation(ConfigValidator validation) {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put(STATUS, validation.getStatus().name()); object.put(STATUS, validation.getStatus().name());
JSONObject jsonMessages = new JSONObject(); JSONObject jsonMessages = new JSONObject();
Map<Validation.FormInput, Validation.Message> messages = validation.getMessages(); Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages = validation.getMessages();
for(Map.Entry<Validation.FormInput, Validation.Message> entry : messages.entrySet()) { for(Map.Entry<ConfigValidator.ConfigInput, ConfigValidator.Message> entry : messages.entrySet()) {
JSONObject jsonEntry = new JSONObject(); JSONObject jsonEntry = new JSONObject();
jsonEntry.put(STATUS, entry.getValue().getStatus().name()); jsonEntry.put(STATUS, entry.getValue().getStatus().name());
jsonEntry.put(MESSAGE, entry.getValue().getMessage()); jsonEntry.put(MESSAGE, entry.getValue().getMessage());
@ -133,20 +131,21 @@ public void restore(JSONObject jsonObject) {
// Optional and accepting NULLs // Optional and accepting NULLs
id = (Long) jsonObject.get(ID); id = (Long) jsonObject.get(ID);
JSONObject jsonConnectorObject = (JSONObject)jsonObject.get(CONNECTOR); JSONObject jobJsonObject = (JSONObject)jsonObject.get(JOB);
fromConnectorValidation = restoreValidation( fromConfigValidation = restoreValidation(
(JSONObject)jsonConnectorObject.get(FROM)); (JSONObject)jobJsonObject.get(FROM));
toConnectorValidation = restoreValidation( toConfigValidation = restoreValidation(
(JSONObject)jsonConnectorObject.get(TO)); (JSONObject)jobJsonObject.get(TO));
frameworkValidation = restoreValidation( driverConfigValidation = restoreValidation(
(JSONObject)jsonObject.get(FRAMEWORK)); (JSONObject)jobJsonObject.get(DRIVER));
} }
public Validation restoreValidation(JSONObject jsonObject) { public ConfigValidator restoreValidation(JSONObject jsonObject) {
JSONObject jsonMessages = (JSONObject) jsonObject.get(MESSAGES); JSONObject jsonMessages = (JSONObject) jsonObject.get(MESSAGES);
Map<Validation.FormInput, Validation.Message> messages Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages
= new HashMap<Validation.FormInput, Validation.Message>(); = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
for(Object key : jsonMessages.keySet()) { for(Object key : jsonMessages.keySet()) {
JSONObject jsonMessage = (JSONObject) jsonMessages.get(key); JSONObject jsonMessage = (JSONObject) jsonMessages.get(key);
@ -154,14 +153,14 @@ public Validation restoreValidation(JSONObject jsonObject) {
Status status = Status.valueOf((String) jsonMessage.get(STATUS)); Status status = Status.valueOf((String) jsonMessage.get(STATUS));
String stringMessage = (String) jsonMessage.get(MESSAGE); String stringMessage = (String) jsonMessage.get(MESSAGE);
Validation.Message message ConfigValidator.Message message
= new Validation.Message(status, stringMessage); = new ConfigValidator.Message(status, stringMessage);
messages.put(new Validation.FormInput((String)key), message); messages.put(new ConfigValidator.ConfigInput((String)key), message);
} }
Status status = Status.valueOf((String) jsonObject.get(STATUS)); Status status = Status.valueOf((String) jsonObject.get(STATUS));
return new Validation(status, messages); return new ConfigValidator(status, messages);
} }
} }

View File

@ -18,8 +18,8 @@
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.model.MLink; import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MConnectionForms; import org.apache.sqoop.model.MLinkConfig;
import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MConfig;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -31,7 +31,7 @@
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import static org.apache.sqoop.json.util.FormSerialization.*; import static org.apache.sqoop.json.util.ConfigSerialization.*;
import static org.apache.sqoop.json.util.ResourceBundleSerialization.*; import static org.apache.sqoop.json.util.ResourceBundleSerialization.*;
/** /**
@ -42,16 +42,14 @@
*/ */
public class LinkBean implements JsonBean { public class LinkBean implements JsonBean {
private static final String CONNECTOR_ID = "connector-id"; static final String CONNECTOR_ID = "connector-id";
private static final String CONNECTOR_PART = "connector"; static final String LINK_CONFIG = "link-config";
private static final String FRAMEWORK_PART = "framework";
// Required // Required
private List<MLink> links; private List<MLink> links;
// Optional // Optional
private Map<Long, ResourceBundle> connectorConfigBundles; private Map<Long, ResourceBundle> linkConfigBundles;
private ResourceBundle driverConfigBundle;
// For "extract" // For "extract"
public LinkBean(MLink link) { public LinkBean(MLink link) {
@ -67,72 +65,56 @@ public LinkBean(List<MLink> links) {
// For "restore" // For "restore"
public LinkBean() { public LinkBean() {
connectorConfigBundles = new HashMap<Long, ResourceBundle>(); linkConfigBundles = new HashMap<Long, ResourceBundle>();
}
public void setDriverConfigBundle(ResourceBundle driverConfigBundle) {
this.driverConfigBundle = driverConfigBundle;
} }
public void addConnectorConfigBundle(Long id, ResourceBundle connectorConfigBundle) { public void addConnectorConfigBundle(Long id, ResourceBundle connectorConfigBundle) {
connectorConfigBundles.put(id, connectorConfigBundle); linkConfigBundles.put(id, connectorConfigBundle);
} }
public boolean hasConnectorBundle(Long id) { public boolean hasConnectorConfigBundle(Long id) {
return connectorConfigBundles.containsKey(id); return linkConfigBundles.containsKey(id);
} }
public List<MLink> getLinks() { public List<MLink> getLinks() {
return links; return links;
} }
public ResourceBundle getConnectorBundle(Long id) { public ResourceBundle getConnectorConfigBundle(Long id) {
return connectorConfigBundles.get(id); return linkConfigBundles.get(id);
}
public ResourceBundle getFrameworkBundle() {
return driverConfigBundle;
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JSONObject extract(boolean skipSensitive) { public JSONObject extract(boolean skipSensitive) {
JSONArray array = new JSONArray(); JSONArray linkArray = new JSONArray();
for(MLink link : links) { for(MLink link : links) {
JSONObject object = new JSONObject(); JSONObject linkJsonObject = new JSONObject();
object.put(ID, link.getPersistenceId()); linkJsonObject.put(ID, link.getPersistenceId());
object.put(NAME, link.getName()); linkJsonObject.put(NAME, link.getName());
object.put(ENABLED, link.getEnabled()); linkJsonObject.put(ENABLED, link.getEnabled());
object.put(CREATION_USER, link.getCreationUser()); linkJsonObject.put(CREATION_USER, link.getCreationUser());
object.put(CREATION_DATE, link.getCreationDate().getTime()); linkJsonObject.put(CREATION_DATE, link.getCreationDate().getTime());
object.put(UPDATE_USER, link.getLastUpdateUser()); linkJsonObject.put(UPDATE_USER, link.getLastUpdateUser());
object.put(UPDATE_DATE, link.getLastUpdateDate().getTime()); linkJsonObject.put(UPDATE_DATE, link.getLastUpdateDate().getTime());
object.put(CONNECTOR_ID, link.getConnectorId()); linkJsonObject.put(CONNECTOR_ID, link.getConnectorId());
object.put(CONNECTOR_PART, linkJsonObject.put(LINK_CONFIG,
extractForms(link.getConnectorPart().getForms(), skipSensitive)); extractConfigList(link.getConnectorLinkConfig().getConfigs(), skipSensitive));
object.put(FRAMEWORK_PART,
extractForms(link.getFrameworkPart().getForms(), skipSensitive));
array.add(object); linkArray.add(linkJsonObject);
} }
JSONObject all = new JSONObject(); JSONObject all = new JSONObject();
all.put(ALL, array); all.put(ALL, linkArray);
if (!linkConfigBundles.isEmpty()) {
if(!connectorConfigBundles.isEmpty()) {
JSONObject bundles = new JSONObject(); JSONObject bundles = new JSONObject();
for (Map.Entry<Long, ResourceBundle> entry : linkConfigBundles.entrySet()) {
for(Map.Entry<Long, ResourceBundle> entry : connectorConfigBundles.entrySet()) { bundles.put(entry.getKey().toString(), extractResourceBundle(entry.getValue()));
bundles.put(entry.getKey().toString(),
extractResourceBundle(entry.getValue()));
} }
all.put(CONNECTOR_CONFIGS, bundles); all.put(CONNECTOR_CONFIGS, bundles);
} }
if(driverConfigBundle != null) {
all.put(DRIVER_CONFIGS,extractResourceBundle(driverConfigBundle));
}
return all; return all;
} }
@ -147,15 +129,11 @@ public void restore(JSONObject jsonObject) {
JSONObject object = (JSONObject) obj; JSONObject object = (JSONObject) obj;
long connectorId = (Long) object.get(CONNECTOR_ID); long connectorId = (Long) object.get(CONNECTOR_ID);
JSONArray connectorPart = (JSONArray) object.get(CONNECTOR_PART); JSONArray connectorLinkConfig = (JSONArray) object.get(LINK_CONFIG);
JSONArray frameworkPart = (JSONArray) object.get(FRAMEWORK_PART);
List<MForm> connectorForms = restoreForms(connectorPart); List<MConfig> linkConfig = restoreConfigList(connectorLinkConfig);
List<MForm> frameworkForms = restoreForms(frameworkPart);
MLink link = new MLink(connectorId, MLink link = new MLink(connectorId, new MLinkConfig(linkConfig));
new MConnectionForms(connectorForms),
new MConnectionForms(frameworkForms));
link.setPersistenceId((Long) object.get(ID)); link.setPersistenceId((Long) object.get(ID));
link.setName((String) object.get(NAME)); link.setName((String) object.get(NAME));
@ -172,13 +150,9 @@ public void restore(JSONObject jsonObject) {
JSONObject bundles = (JSONObject) jsonObject.get(CONNECTOR_CONFIGS); JSONObject bundles = (JSONObject) jsonObject.get(CONNECTOR_CONFIGS);
Set<Map.Entry<String, JSONObject>> entrySet = bundles.entrySet(); Set<Map.Entry<String, JSONObject>> entrySet = bundles.entrySet();
for (Map.Entry<String, JSONObject> entry : entrySet) { for (Map.Entry<String, JSONObject> entry : entrySet) {
connectorConfigBundles.put(Long.parseLong(entry.getKey()), linkConfigBundles.put(Long.parseLong(entry.getKey()),
restoreResourceBundle(entry.getValue())); restoreResourceBundle(entry.getValue()));
} }
} }
if(jsonObject.containsKey(DRIVER_CONFIGS)) {
driverConfigBundle = restoreResourceBundle(
(JSONObject) jsonObject.get(DRIVER_CONFIGS));
}
} }
} }

View File

@ -18,37 +18,32 @@
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.Validation; import org.apache.sqoop.validation.ConfigValidator;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Bean for sending validations across network. This bean will move two * Bean for sending validations across network.This bean will transfer link config
* validation objects at one time - one for connector and second for framework * validation results. Optionally validation bean can also transfer
* part of validated entity. Optionally validation bean can also transfer
* created persistent id in case that new entity was created. * created persistent id in case that new entity was created.
*/ */
public class LinkValidationBean implements JsonBean { public class LinkValidationBean implements JsonBean {
private static final String ID = "id"; private static final String ID = "id";
private static final String FRAMEWORK = "framework";
private static final String CONNECTOR = "connector";
private static final String STATUS = "status"; private static final String STATUS = "status";
private static final String MESSAGE = "message"; private static final String MESSAGE = "message";
private static final String MESSAGES = "messages"; private static final String MESSAGES = "messages";
private Long id; private Long id;
private Validation connectorValidation; private ConfigValidator linkConfigValidation;
private Validation frameworkValidation;
// For "extract" // For "extract"
public LinkValidationBean(Validation connector, Validation framework) { public LinkValidationBean(ConfigValidator linkConfigValidator) {
this(); this();
this.connectorValidation = connector; this.linkConfigValidation = linkConfigValidator;
this.frameworkValidation = framework;
} }
// For "restore" // For "restore"
@ -56,12 +51,8 @@ public LinkValidationBean() {
id = null; id = null;
} }
public Validation getConnectorValidation() { public ConfigValidator getLinkConfigValidator() {
return connectorValidation; return linkConfigValidation;
}
public Validation getFrameworkValidation() {
return frameworkValidation;
} }
public void setId(Long id) { public void setId(Long id) {
@ -80,23 +71,20 @@ public JSONObject extract(boolean skipSensitive) {
if(id != null) { if(id != null) {
object.put(ID, id); object.put(ID, id);
} }
object.put(LinkBean.LINK_CONFIG, extractValidation(linkConfigValidation));
object.put(CONNECTOR, extractValidation(connectorValidation));
object.put(FRAMEWORK, extractValidation(frameworkValidation));
return object; return object;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private JSONObject extractValidation(Validation validation) { private JSONObject extractValidation(ConfigValidator validation) {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put(STATUS, validation.getStatus().name()); object.put(STATUS, validation.getStatus().name());
JSONObject jsonMessages = new JSONObject(); JSONObject jsonMessages = new JSONObject();
Map<Validation.FormInput, Validation.Message> messages = validation.getMessages(); Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages = validation.getMessages();
for(Map.Entry<Validation.FormInput, Validation.Message> entry : messages.entrySet()) { for(Map.Entry<ConfigValidator.ConfigInput, ConfigValidator.Message> entry : messages.entrySet()) {
JSONObject jsonEntry = new JSONObject(); JSONObject jsonEntry = new JSONObject();
jsonEntry.put(STATUS, entry.getValue().getStatus().name()); jsonEntry.put(STATUS, entry.getValue().getStatus().name());
jsonEntry.put(MESSAGE, entry.getValue().getMessage()); jsonEntry.put(MESSAGE, entry.getValue().getMessage());
@ -113,16 +101,14 @@ public void restore(JSONObject jsonObject) {
// Optional and accepting NULLs // Optional and accepting NULLs
id = (Long) jsonObject.get(ID); id = (Long) jsonObject.get(ID);
connectorValidation = restoreValidation( linkConfigValidation = restoreValidation(
(JSONObject)jsonObject.get(CONNECTOR)); (JSONObject)jsonObject.get(LinkBean.LINK_CONFIG));
frameworkValidation = restoreValidation(
(JSONObject)jsonObject.get(FRAMEWORK));
} }
public Validation restoreValidation(JSONObject jsonObject) { public ConfigValidator restoreValidation(JSONObject jsonObject) {
JSONObject jsonMessages = (JSONObject) jsonObject.get(MESSAGES); JSONObject jsonMessages = (JSONObject) jsonObject.get(MESSAGES);
Map<Validation.FormInput, Validation.Message> messages Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages
= new HashMap<Validation.FormInput, Validation.Message>(); = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
for(Object key : jsonMessages.keySet()) { for(Object key : jsonMessages.keySet()) {
JSONObject jsonMessage = (JSONObject) jsonMessages.get(key); JSONObject jsonMessage = (JSONObject) jsonMessages.get(key);
@ -130,14 +116,14 @@ public Validation restoreValidation(JSONObject jsonObject) {
Status status = Status.valueOf((String) jsonMessage.get(STATUS)); Status status = Status.valueOf((String) jsonMessage.get(STATUS));
String stringMessage = (String) jsonMessage.get(MESSAGE); String stringMessage = (String) jsonMessage.get(MESSAGE);
Validation.Message message ConfigValidator.Message message
= new Validation.Message(status, stringMessage); = new ConfigValidator.Message(status, stringMessage);
messages.put(new Validation.FormInput((String)key), message); messages.put(new ConfigValidator.ConfigInput((String)key), message);
} }
Status status = Status.valueOf((String) jsonObject.get(STATUS)); Status status = Status.valueOf((String) jsonObject.get(STATUS));
return new Validation(status, messages); return new ConfigValidator(status, messages);
} }
} }

View File

@ -26,7 +26,7 @@
import java.util.List; import java.util.List;
/** /**
* Transfer throwable instance. * Transfer throwable instance as a throwable bean.
*/ */
public class ThrowableBean implements JsonBean { public class ThrowableBean implements JsonBean {

View File

@ -19,7 +19,7 @@
import org.apache.sqoop.validation.Message; import org.apache.sqoop.validation.Message;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.ValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -38,18 +38,18 @@ public class ValidationResultBean implements JsonBean {
private static final String STATUS = "STATUS"; private static final String STATUS = "STATUS";
private static final String TEXT = "TEXT"; private static final String TEXT = "TEXT";
private ValidationResult[] results; private ConfigValidationResult[] results;
private Long id; private Long id;
public ValidationResultBean() { public ValidationResultBean() {
// Empty, for restore // Empty, for restore
} }
public ValidationResultBean(ValidationResult ... results) { public ValidationResultBean(ConfigValidationResult ... results) {
this.results = results; this.results = results;
} }
public ValidationResult[] getValidationResults() { public ConfigValidationResult[] getValidationResults() {
return results; return results;
} }
@ -65,7 +65,7 @@ public Long getId() {
public JSONObject extract(boolean skipSensitive) { public JSONObject extract(boolean skipSensitive) {
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
for(ValidationResult result : results) { for(ConfigValidationResult result : results) {
JSONObject output = extractValidationResult(result); JSONObject output = extractValidationResult(result);
array.add(output); array.add(output);
} }
@ -78,7 +78,7 @@ public JSONObject extract(boolean skipSensitive) {
return object; return object;
} }
private JSONObject extractValidationResult(ValidationResult result) { private JSONObject extractValidationResult(ConfigValidationResult result) {
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
for(Map.Entry<String, List<Message>> entry : result.getMessages().entrySet()) { for(Map.Entry<String, List<Message>> entry : result.getMessages().entrySet()) {
@ -110,7 +110,7 @@ private Object extractMessage(Message message) {
@Override @Override
public void restore(JSONObject jsonObject) { public void restore(JSONObject jsonObject) {
JSONArray array = (JSONArray) jsonObject.get(ROOT); JSONArray array = (JSONArray) jsonObject.get(ROOT);
results = new ValidationResult[array.size()]; results = new ConfigValidationResult[array.size()];
int i = 0; int i = 0;
for(Object item : array) { for(Object item : array) {
@ -122,8 +122,8 @@ public void restore(JSONObject jsonObject) {
} }
} }
private ValidationResult restoreValidationResult(JSONObject item) { private ConfigValidationResult restoreValidationResult(JSONObject item) {
ValidationResult result = new ValidationResult(); ConfigValidationResult result = new ConfigValidationResult();
Set<Map.Entry<String, JSONArray>> entrySet = item.entrySet(); Set<Map.Entry<String, JSONArray>> entrySet = item.entrySet();
for(Map.Entry<String, JSONArray> entry : entrySet) { for(Map.Entry<String, JSONArray> entry : entrySet) {

View File

@ -21,8 +21,8 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.model.MBooleanInput; import org.apache.sqoop.model.MBooleanInput;
import org.apache.sqoop.model.MEnumInput; import org.apache.sqoop.model.MEnumInput;
import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MFormType; import org.apache.sqoop.model.MConfigType;
import org.apache.sqoop.model.MInput; import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MInputType; import org.apache.sqoop.model.MInputType;
import org.apache.sqoop.model.MIntegerInput; import org.apache.sqoop.model.MIntegerInput;
@ -36,83 +36,86 @@
import java.util.Map; import java.util.Map;
/** /**
* Convenient static methods for serializing forms. * Convenient static methods for serializing config objects.
*/ */
public final class FormSerialization { public final class ConfigSerialization {
public static final String ALL = "all"; public static final String ALL = "all";
public static final String ID = "id"; public static final String ID = "id";
public static final String NAME = "name"; public static final String NAME = "name";
public static final String VERSION = "version"; public static final String VERSION = "version";
public static final String DRIVER_VERSION = "driver-version";
public static final String CLASS = "class"; public static final String CLASS = "class";
public static final String ENABLED = "enabled"; public static final String ENABLED = "enabled";
public static final String CREATION_USER = "creation-user"; public static final String CREATION_USER = "creation-user";
public static final String CREATION_DATE = "creation-date"; public static final String CREATION_DATE = "creation-date";
public static final String UPDATE_USER = "update-user"; public static final String UPDATE_USER = "update-user";
public static final String UPDATE_DATE = "update-date"; public static final String UPDATE_DATE = "update-date";
public static final String CON_FORMS = "con-forms"; // TODO(VB): Move these constants to connector bean
public static final String JOB_FORMS = "job-forms"; public static final String CONNECTOR_LINK_CONFIG = "link-config";
public static final String CONNECTOR_JOB_CONFIG = "job-config";
// TODO:move these configs to driver bean
public static final String DRIVER_VERSION = "driver-version";
public static final String DRIVER_CONFIG = "driver-config";
public static final String FORM_NAME = "name"; public static final String CONFIG_NAME = "name";
public static final String FORM_TYPE = "type"; public static final String CONFIG_TYPE = "type";
public static final String FORM_INPUTS = "inputs"; public static final String CONFIG_INPUTS = "inputs";
public static final String FORM_INPUT_NAME = "name"; public static final String CONFIG_INPUT_NAME = "name";
public static final String FORM_INPUT_TYPE = "type"; public static final String CONFIG_INPUT_TYPE = "type";
public static final String FORM_INPUT_SENSITIVE = "sensitive"; public static final String CONFIG_INPUT_SENSITIVE = "sensitive";
public static final String FORM_INPUT_SIZE = "size"; public static final String CONFIG_INPUT_SIZE = "size";
public static final String FORM_INPUT_VALUE = "value"; public static final String CONFIG_INPUT_VALUE = "value";
public static final String FORM_INPUT_VALUES = "values"; public static final String CONFIG_INPUT_VALUES = "values";
/** /**
* Transform given list of forms to JSON Array object. * Transform given list of configs to JSON Array object.
* *
* @param mForms List of forms. * @param mConfigs List of configs.
* @return JSON object with serialized form of the list. * @return JSON object with serialized config of the list.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static JSONArray extractForms(List<MForm> mForms, boolean skipSensitive) { public static JSONArray extractConfigList(List<MConfig> mConfigs, boolean skipSensitive) {
JSONArray forms = new JSONArray(); JSONArray configs = new JSONArray();
for (MForm mForm : mForms) { for (MConfig mConfig : mConfigs) {
forms.add(extractForm(mForm, skipSensitive)); configs.add(extractConfig(mConfig, skipSensitive));
} }
return forms; return configs;
} }
/** /**
* Transform given form to JSON Object. * Transform given config to JSON Object.
* *
* @param mForm Given MForm instance * @param mConfig Given MConfig instance
* @param skipSensitive conditionally add sensitive input values * @param skipSensitive conditionally add sensitive input values
* @return Serialized JSON object. * @return Serialized JSON object.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static JSONObject extractForm(MForm mForm, boolean skipSensitive) { static JSONObject extractConfig(MConfig mConfig, boolean skipSensitive) {
JSONObject form = new JSONObject(); JSONObject config = new JSONObject();
form.put(ID, mForm.getPersistenceId()); config.put(ID, mConfig.getPersistenceId());
form.put(FORM_NAME, mForm.getName()); config.put(CONFIG_NAME, mConfig.getName());
form.put(FORM_TYPE, MFormType.CONNECTION.toString()); config.put(CONFIG_TYPE, MConfigType.LINK.toString());
JSONArray mInputs = new JSONArray(); JSONArray mInputs = new JSONArray();
form.put(FORM_INPUTS, mInputs); config.put(CONFIG_INPUTS, mInputs);
for (MInput<?> mInput : mForm.getInputs()) { for (MInput<?> mInput : mConfig.getInputs()) {
JSONObject input = new JSONObject(); JSONObject input = new JSONObject();
input.put(ID, mInput.getPersistenceId()); input.put(ID, mInput.getPersistenceId());
input.put(FORM_INPUT_NAME, mInput.getName()); input.put(CONFIG_INPUT_NAME, mInput.getName());
input.put(FORM_INPUT_TYPE, mInput.getType().toString()); input.put(CONFIG_INPUT_TYPE, mInput.getType().toString());
input.put(FORM_INPUT_SENSITIVE, mInput.isSensitive()); input.put(CONFIG_INPUT_SENSITIVE, mInput.isSensitive());
// String specific serialization // String specific serialization
if (mInput.getType() == MInputType.STRING) { if (mInput.getType() == MInputType.STRING) {
input.put(FORM_INPUT_SIZE, input.put(CONFIG_INPUT_SIZE,
((MStringInput)mInput).getMaxLength()); ((MStringInput)mInput).getMaxLength());
} }
// Enum specific serialization // Enum specific serialization
if(mInput.getType() == MInputType.ENUM) { if(mInput.getType() == MInputType.ENUM) {
input.put(FORM_INPUT_VALUES, input.put(CONFIG_INPUT_VALUES,
StringUtils.join(((MEnumInput)mInput).getValues(), ",")); StringUtils.join(((MEnumInput)mInput).getValues(), ","));
} }
@ -120,54 +123,54 @@ public static JSONObject extractForm(MForm mForm, boolean skipSensitive) {
// Skip if sensitive // Skip if sensitive
if (!mInput.isEmpty() && !(skipSensitive && mInput.isSensitive())) { if (!mInput.isEmpty() && !(skipSensitive && mInput.isSensitive())) {
if (mInput.getType() == MInputType.MAP) { if (mInput.getType() == MInputType.MAP) {
input.put(FORM_INPUT_VALUE, mInput.getValue()); input.put(CONFIG_INPUT_VALUE, mInput.getValue());
} else { } else {
input.put(FORM_INPUT_VALUE, mInput.getUrlSafeValueString()); input.put(CONFIG_INPUT_VALUE, mInput.getUrlSafeValueString());
} }
} }
mInputs.add(input); mInputs.add(input);
} }
return form; return config;
} }
/** /**
* Restore List of MForms from JSON Array. * Restore List of MConfigs from JSON Array.
* *
* @param forms JSON array representing list of MForms * @param configs JSON array representing list of MConfigs
* @return Restored list of MForms * @return Restored list of MConfigs
*/ */
public static List<MForm> restoreForms(JSONArray forms) { public static List<MConfig> restoreConfigList(JSONArray configs) {
List<MForm> mForms = new ArrayList<MForm>(); List<MConfig> mConfigs = new ArrayList<MConfig>();
for (int i = 0; i < forms.size(); i++) { for (int i = 0; i < configs.size(); i++) {
mForms.add(restoreForm((JSONObject) forms.get(i))); mConfigs.add(restoreConfig((JSONObject) configs.get(i)));
} }
return mForms; return mConfigs;
} }
/** /**
* Restore one MForm from JSON Object. * Restore one MConfig from JSON Object.
* *
* @param form JSON representation of the MForm. * @param config JSON representation of the MConfig.
* @return Restored MForm. * @return Restored MConfig.
*/ */
public static MForm restoreForm(JSONObject form) { static MConfig restoreConfig(JSONObject config) {
JSONArray inputs = (JSONArray) form.get(FORM_INPUTS); JSONArray inputs = (JSONArray) config.get(CONFIG_INPUTS);
List<MInput<?>> mInputs = new ArrayList<MInput<?>>(); List<MInput<?>> mInputs = new ArrayList<MInput<?>>();
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
JSONObject input = (JSONObject) inputs.get(i); JSONObject input = (JSONObject) inputs.get(i);
MInputType type = MInputType type =
MInputType.valueOf((String) input.get(FORM_INPUT_TYPE)); MInputType.valueOf((String) input.get(CONFIG_INPUT_TYPE));
String name = (String) input.get(FORM_INPUT_NAME); String name = (String) input.get(CONFIG_INPUT_NAME);
Boolean sensitive = (Boolean) input.get(FORM_INPUT_SENSITIVE); Boolean sensitive = (Boolean) input.get(CONFIG_INPUT_SENSITIVE);
MInput mInput = null; MInput mInput = null;
switch (type) { switch (type) {
case STRING: { case STRING: {
long size = (Long) input.get(FORM_INPUT_SIZE); long size = (Long) input.get(CONFIG_INPUT_SIZE);
mInput = new MStringInput(name, sensitive.booleanValue(), (short) size); mInput = new MStringInput(name, sensitive.booleanValue(), (short) size);
break; break;
} }
@ -184,40 +187,40 @@ public static MForm restoreForm(JSONObject form) {
break; break;
} }
case ENUM: { case ENUM: {
String values = (String) input.get(FORM_INPUT_VALUES); String values = (String) input.get(CONFIG_INPUT_VALUES);
mInput = new MEnumInput(name, sensitive.booleanValue(), values.split(",")); mInput = new MEnumInput(name, sensitive.booleanValue(), values.split(","));
break; break;
} }
} }
// Propagate form ID // Propagate config ID
mInput.setPersistenceId((Long)input.get(ID)); mInput.setPersistenceId((Long)input.get(ID));
// Propagate form optional value // Propagate config optional value
if(input.containsKey(FORM_INPUT_VALUE)) { if(input.containsKey(CONFIG_INPUT_VALUE)) {
switch (type) { switch (type) {
case MAP: case MAP:
try { try {
mInput.setValue((Map<String, String>)input.get(FORM_INPUT_VALUE)); mInput.setValue((Map<String, String>)input.get(CONFIG_INPUT_VALUE));
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new SqoopException(SerializationError.SERIALIZATION_001, name + " requires a 'map' value."); throw new SqoopException(SerializationError.SERIALIZATION_001, name + " requires a 'map' value.");
} }
break; break;
default: default:
mInput.restoreFromUrlSafeValueString( mInput.restoreFromUrlSafeValueString(
(String) input.get(FORM_INPUT_VALUE)); (String) input.get(CONFIG_INPUT_VALUE));
break; break;
} }
} }
mInputs.add(mInput); mInputs.add(mInput);
} }
MForm mForm = new MForm((String) form.get(FORM_NAME), mInputs); MConfig mConfig = new MConfig((String) config.get(CONFIG_NAME), mInputs);
mForm.setPersistenceId((Long) form.get(ID)); mConfig.setPersistenceId((Long) config.get(ID));
return mForm; return mConfig;
} }
private FormSerialization() { private ConfigSerialization() {
// Do not instantiate // Do not instantiate
} }
} }

View File

@ -43,7 +43,6 @@ public static JSONArray extractResourceBundles(List<ResourceBundle> bundles) {
for (ResourceBundle bundle : bundles) { for (ResourceBundle bundle : bundles) {
array.add(extractResourceBundle(bundle)); array.add(extractResourceBundle(bundle));
} }
return array; return array;
} }
@ -58,7 +57,6 @@ public static JSONObject extractResourceBundle(ResourceBundle bundle) {
return json; return json;
} }
@SuppressWarnings("unchecked")
public static List<ResourceBundle> restoreResourceBundles(JSONArray array) { public static List<ResourceBundle> restoreResourceBundles(JSONArray array) {
List<ResourceBundle> bundles = new LinkedList<ResourceBundle>(); List<ResourceBundle> bundles = new LinkedList<ResourceBundle>();
for (Object item : array) { for (Object item : array) {

View File

@ -21,11 +21,10 @@
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
/** /**
* Denote form in Configuration class * Denote config in Configuration class
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Form { public @interface Config {
/** /**
* Optional name for the form object * Optional name for the form object
* *

View File

@ -27,17 +27,17 @@
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface FormClass { public @interface ConfigClass {
/** /**
* Default size for Inputs in this form. * Default size for Inputs in this config.
* *
* @return * @return
*/ */
short defaultSize() default -1; short defaultSize() default -1;
/** /**
* List of validators associated with this form. * List of validators associated with this config.
* *
* @return * @return
*/ */

View File

@ -22,8 +22,8 @@
import org.apache.sqoop.utils.ClassUtils; import org.apache.sqoop.utils.ClassUtils;
import org.apache.sqoop.validation.Message; import org.apache.sqoop.validation.Message;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.Validation; import org.apache.sqoop.validation.ConfigValidator;
import org.apache.sqoop.validation.ValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
@ -42,81 +42,80 @@
* *
* TODO: This class should see some overhaul into more reusable code, especially expose and re-use the methods at the end. * TODO: This class should see some overhaul into more reusable code, especially expose and re-use the methods at the end.
*/ */
public class FormUtils { public class ConfigUtils {
/** /**
* Transform correctly annotated configuration object to corresponding * Transform correctly annotated configuration object to corresponding
* list of forms. * list of configs.
* *
* Forms will be order according to the occurrence in the configuration * Configs will be order according to the occurrence in the configuration
* class. Inputs will be also ordered based on occurrence. * class. Inputs will be also ordered based on occurrence.
* *
* @param configuration Annotated arbitrary configuration object * @param configuration Annotated arbitrary configuration object
* @return Corresponding list of forms * @return Corresponding list of configs
*/ */
public static List<MForm> toForms(Object configuration) { public static List<MConfig> toConfigs(Object configuration) {
return toForms(configuration.getClass(), configuration); return toConfigs(configuration.getClass(), configuration);
} }
public static List<MForm> toForms(Class klass) { public static List<MConfig> toConfigs(Class klass) {
return toForms(klass, null); return toConfigs(klass, null);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<MForm> toForms(Class klass, Object configuration) { public static List<MConfig> toConfigs(Class klass, Object configuration) {
Set<String> formNames = new HashSet<String>(); Set<String> formNames = new HashSet<String>();
ConfigurationClass global = ConfigurationClass configurationClass =
(ConfigurationClass)klass.getAnnotation(ConfigurationClass.class); (ConfigurationClass)klass.getAnnotation(ConfigurationClass.class);
// Each configuration object must have this class annotation // Each configuration object must have this class annotation
if(global == null) { if(configurationClass == null) {
throw new SqoopException(ModelError.MODEL_003, throw new SqoopException(ModelError.MODEL_003,
"Missing annotation ConfigurationClass on class " + klass.getName()); "Missing annotation ConfigurationClass on class " + klass.getName());
} }
List<MForm> forms = new LinkedList<MForm>(); List<MConfig> configs = new LinkedList<MConfig>();
// Iterate over all declared fields // Iterate over all declared fields
for (Field formField : klass.getDeclaredFields()) { for (Field field : klass.getDeclaredFields()) {
formField.setAccessible(true); field.setAccessible(true);
// Each field that should be part of user input should have Input // Each field that should be part of user input should have Input
// annotation. // annotation.
Form formAnnotation = formField.getAnnotation(Form.class); Config formAnnotation = field.getAnnotation(Config.class);
if (formAnnotation != null) { if (formAnnotation != null) {
String formName = getFormName(formField, formAnnotation, formNames); String formName = getFormName(field, formAnnotation, formNames);
Class type = formField.getType(); Class type = field.getType();
Object value = null; Object value = null;
if(configuration != null) { if(configuration != null) {
try { try {
value = formField.get(configuration); value = field.get(configuration);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, throw new SqoopException(ModelError.MODEL_005,
"Can't retrieve value from " + formField.getName(), e); "Can't retrieve value from " + field.getName(), e);
} }
} }
forms.add(toForm(formName, type, value)); configs.add(toConfig(formName, type, value));
} }
} }
return forms; return configs;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static MForm toForm(String formName, Class<?> klass, Object object) { private static MConfig toConfig(String formName, Class klass, Object object) {
FormClass global = ConfigClass global =
(FormClass)klass.getAnnotation(FormClass.class); (ConfigClass)klass.getAnnotation(ConfigClass.class);
// Each configuration object must have this class annotation // Each configuration object must have this class annotation
if(global == null) { if(global == null) {
throw new SqoopException(ModelError.MODEL_003, throw new SqoopException(ModelError.MODEL_003,
"Missing annotation FormClass on class " + klass.getName()); "Missing annotation ConfigClass on class " + klass.getName());
} }
// Intermediate list of inputs // Intermediate list of inputs
@ -183,7 +182,7 @@ private static MForm toForm(String formName, Class<?> klass, Object object) {
} }
} }
return new MForm(formName, inputs); return new MConfig(formName, inputs);
} }
private static Field getFieldFromName(Class<?> klass, String name) { private static Field getFieldFromName(Class<?> klass, String name) {
@ -194,7 +193,7 @@ private static Field getFieldFromName(Class<?> klass, String name) {
// reverse lookup form field from custom form name // reverse lookup form field from custom form name
if (name != null) { if (name != null) {
for (Field field : klass.getDeclaredFields()) { for (Field field : klass.getDeclaredFields()) {
Form formAnnotation = field.getAnnotation(Form.class); Config formAnnotation = field.getAnnotation(Config.class);
if (formAnnotation == null) { if (formAnnotation == null) {
continue; continue;
} }
@ -210,29 +209,35 @@ private static Field getFieldFromName(Class<?> klass, String name) {
} }
/** /**
* Move form values from form list into corresponding configuration object. * Move config values from config list into corresponding configuration object.
* *
* @param forms * @param configs Input config list
* Input form list * @param configuration Output configuration object
* @param configuration
* Output configuration object
*/ */
public static void fromForms(List<MForm> forms, Object configuration) { public static void fromConfigs(List<MConfig> configs, Object configuration) {
Class<?> klass = configuration.getClass(); Class klass = configuration.getClass();
for (MForm form : forms) { for(MConfig config : configs) {
Field formField = getFieldFromName(klass, form.getName()); Field configField;
try {
configField = klass.getDeclaredField(config.getName());
} catch (NoSuchFieldException e) {
throw new SqoopException(ModelError.MODEL_006,
"Missing field " + config.getName() + " on config class " + klass.getCanonicalName(), e);
}
Field formField = getFieldFromName(klass, config.getName());
// We need to access this field even if it would be declared as private // We need to access this field even if it would be declared as private
formField.setAccessible(true); configField.setAccessible(true);
Class<?> formClass = formField.getType(); Class configClass = configField.getType();
Object newValue = ClassUtils.instantiate(formClass); Object newValue = ClassUtils.instantiate(configClass);
if (newValue == null) { if (newValue == null) {
throw new SqoopException(ModelError.MODEL_006, throw new SqoopException(ModelError.MODEL_006,
"Can't instantiate new form " + formClass); "Can't instantiate new config " + configClass);
} }
for (MInput input : form.getInputs()) { for(MInput input : config.getInputs()) {
String[] splitNames = input.getName().split("\\."); String[] splitNames = input.getName().split("\\.");
if (splitNames.length != 2) { if (splitNames.length != 2) {
throw new SqoopException(ModelError.MODEL_009, "Invalid name: " throw new SqoopException(ModelError.MODEL_009, "Invalid name: "
@ -243,7 +248,7 @@ public static void fromForms(List<MForm> forms, Object configuration) {
// TODO(jarcec): Names structures fix, handle error cases // TODO(jarcec): Names structures fix, handle error cases
Field inputField; Field inputField;
try { try {
inputField = formClass.getDeclaredField(inputName); inputField = configClass.getDeclaredField(inputName);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
throw new SqoopException(ModelError.MODEL_006, "Missing field " throw new SqoopException(ModelError.MODEL_006, "Missing field "
+ input.getName(), e); + input.getName(), e);
@ -271,30 +276,27 @@ public static void fromForms(List<MForm> forms, Object configuration) {
} }
try { try {
formField.set(configuration, newValue); configField.set(configuration, newValue);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, "Issue with field " throw new SqoopException(ModelError.MODEL_005,
+ formField.getName(), e); "Issue with field " + configField.getName(), e);
} }
} }
} }
/** /**
* Apply validations on the forms. * Apply validations on the configs.
* *
* @param forms * @param configs Configs that should be updated
* Forms that should be updated * @param validation Validation that we should apply
* @param validation
* Validation that we should apply
*/ */
public static void applyValidation(List<MForm> forms, Validation validation) { public static void applyValidation(List<MConfig> configs, ConfigValidator validation) {
Map<Validation.FormInput, Validation.Message> messages = validation Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages = validation.getMessages();
.getMessages();
for (MForm form : forms) { for(MConfig config : configs) {
applyValidation(form, messages); applyValidation(config, messages);
for (MInput input : form.getInputs()) { for(MInput input : config.getInputs()) {
applyValidation(input, messages); applyValidation(input, messages);
} }
} }
@ -308,12 +310,11 @@ public static void applyValidation(List<MForm> forms, Validation validation) {
* @param messages * @param messages
* Map of all validation messages * Map of all validation messages
*/ */
public static void applyValidation(MValidatedElement element, public static void applyValidation(MValidatedElement element, Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages) {
Map<Validation.FormInput, Validation.Message> messages) { ConfigValidator.ConfigInput name = new ConfigValidator.ConfigInput(element.getName());
Validation.FormInput name = new Validation.FormInput(element.getName());
if (messages.containsKey(name)) { if(messages.containsKey(name)) {
Validation.Message message = messages.get(name); ConfigValidator.Message message = messages.get(name);
element.addValidationMessage(new Message(message.getStatus(), message.getMessage())); element.addValidationMessage(new Message(message.getStatus(), message.getMessage()));
} else { } else {
element.addValidationMessage(new Message(Status.getDefault(), null)); element.addValidationMessage(new Message(Status.getDefault(), null));
@ -322,16 +323,16 @@ public static void applyValidation(MValidatedElement element,
/** /**
* Apply given validations on list of forms. * Apply given validations on list of configs.
* *
* @param forms * @param configs
* @param result * @param result
*/ */
public static void applyValidation(List<MForm> forms, ValidationResult result) { public static void applyValidation(List<MConfig> configs, ConfigValidationResult result) {
for(MForm form : forms) { for(MConfig config : configs) {
applyValidation(form, result); applyValidation(config, result);
for(MInput input : form.getInputs()) { for(MInput input : config.getInputs()) {
applyValidation(input, result); applyValidation(input, result);
} }
} }
@ -345,7 +346,7 @@ public static void applyValidation(List<MForm> forms, ValidationResult result) {
* @param element * @param element
* @param result * @param result
*/ */
public static void applyValidation(MValidatedElement element, ValidationResult result) { public static void applyValidation(MValidatedElement element, ConfigValidationResult result) {
List<Message> messages = result.getMessages().get(element.getName()); List<Message> messages = result.getMessages().get(element.getName());
if(messages != null) { if(messages != null) {
@ -366,13 +367,13 @@ public static void applyValidation(MValidatedElement element, ValidationResult r
public static String toJson(Object configuration) { public static String toJson(Object configuration) {
Class klass = configuration.getClass(); Class klass = configuration.getClass();
Set<String> formNames = new HashSet<String>(); Set<String> formNames = new HashSet<String>();
ConfigurationClass global = (ConfigurationClass) klass ConfigurationClass configurationClass =
.getAnnotation(ConfigurationClass.class); (ConfigurationClass)klass.getAnnotation(ConfigurationClass.class);
// Each configuration object must have this class annotation // Each configuration object must have this class annotation
if (global == null) { if(configurationClass == null) {
throw new SqoopException(ModelError.MODEL_003, throw new SqoopException(ModelError.MODEL_003,
"Missing annotation Configuration on class " + klass.getName()); "Missing annotation ConfigurationGroup on class " + klass.getName());
} }
JSONObject jsonOutput = new JSONObject(); JSONObject jsonOutput = new JSONObject();
@ -381,9 +382,9 @@ public static String toJson(Object configuration) {
for (Field formField : klass.getDeclaredFields()) { for (Field formField : klass.getDeclaredFields()) {
formField.setAccessible(true); formField.setAccessible(true);
// We're processing only form validations // We're processing only config validations
Form formAnnotation = formField.getAnnotation(Form.class); Config formAnnotation = formField.getAnnotation(Config.class);
if (formAnnotation == null) { if(formAnnotation == null) {
continue; continue;
} }
String formName = getFormName(formField, formAnnotation, formNames); String formName = getFormName(formField, formAnnotation, formNames);
@ -396,10 +397,10 @@ public static String toJson(Object configuration) {
+ formName, e); + formName, e);
} }
JSONObject jsonForm = new JSONObject(); JSONObject jsonConfig = new JSONObject();
// Now process each input on the form // Now process each input on the config
for (Field inputField : formField.getType().getDeclaredFields()) { for(Field inputField : formField.getType().getDeclaredFields()) {
inputField.setAccessible(true); inputField.setAccessible(true);
String inputName = inputField.getName(); String inputName = inputField.getName();
@ -424,27 +425,28 @@ public static String toJson(Object configuration) {
+ "." + inputName); + "." + inputName);
} }
if (type == String.class) { if(type == String.class) {
jsonForm.put(inputName, value); jsonConfig.put(inputName, value);
} else if (type.isAssignableFrom(Map.class)) { } else if (type.isAssignableFrom(Map.class)) {
JSONObject map = new JSONObject(); JSONObject map = new JSONObject();
for (Object key : ((Map) value).keySet()) { for (Object key : ((Map) value).keySet()) {
map.put(key, ((Map) value).get(key)); map.put(key, ((Map) value).get(key));
} }
jsonForm.put(inputName, map); jsonConfig.put(inputName, map);
} else if (type == Integer.class) { } else if(type == Integer.class) {
jsonForm.put(inputName, value); jsonConfig.put(inputName, value);
} else if (type.isEnum()) { } else if(type.isEnum()) {
jsonForm.put(inputName, value.toString()); jsonConfig.put(inputName, value.toString());
} else if (type == Boolean.class) { } else if(type == Boolean.class) {
jsonForm.put(inputName, value); jsonConfig.put(inputName, value);
} else { }else {
throw new SqoopException(ModelError.MODEL_004, "Unsupported type " throw new SqoopException(ModelError.MODEL_004,
+ type.getName() + " for input " + formName + "." + inputName); "Unsupported type " + type.getName() + " for input " + formName + "." + inputName);
} }
} }
} }
jsonOutput.put(formName, jsonForm);
jsonOutput.put(formName, jsonConfig);
} }
return jsonOutput.toJSONString(); return jsonOutput.toJSONString();
} }
@ -454,45 +456,46 @@ public static String toJson(Object configuration) {
* object. * object.
* *
* @param json JSON representation of the configuration object * @param json JSON representation of the configuration object
* @param configuration Configuration object to be filled * @param configuration ConfigurationGroup object to be filled
*/ */
public static void fillValues(String json, Object configuration) { public static void fillValues(String json, Object configuration) {
Class klass = configuration.getClass(); Class klass = configuration.getClass();
JSONObject jsonForms = (JSONObject) JSONValue.parse(json);
Set<String> formNames = new HashSet<String>(); Set<String> formNames = new HashSet<String>();
JSONObject jsonConfigs = (JSONObject) JSONValue.parse(json);
for(Field formField : klass.getDeclaredFields()) { for(Field configField : klass.getDeclaredFields()) {
formField.setAccessible(true); configField.setAccessible(true);
String configName = configField.getName();
// We're processing only form validations // We're processing only config validations
Form formAnnotation = formField.getAnnotation(Form.class); Config formAnnotation = configField.getAnnotation(Config.class);
if(formAnnotation == null) { if(formAnnotation == null) {
continue; continue;
} }
String formName = getFormName(formField, formAnnotation, formNames); String formName = getFormName(configField, formAnnotation, formNames);
try { try {
formField.set(configuration, formField.getType().newInstance()); configField.set(configuration, configField.getType().newInstance());
} catch (Exception e) { } catch (Exception e) {
throw new SqoopException(ModelError.MODEL_005, throw new SqoopException(ModelError.MODEL_005,
"Issue with field " + formName, e); "Issue with field " + configName, e);
} }
JSONObject jsonInputs = (JSONObject) jsonForms.get(formName); JSONObject jsonInputs = (JSONObject) jsonConfigs.get(configField.getName());
if(jsonInputs == null) { if(jsonInputs == null) {
continue; continue;
} }
Object formValue; Object configValue;
try { try {
formValue = formField.get(configuration); configValue = configField.get(configuration);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, throw new SqoopException(ModelError.MODEL_005,
"Issue with field " + formName, e); "Issue with field " + configName, e);
} }
for(Field inputField : formField.getType().getDeclaredFields()) { for(Field inputField : configField.getType().getDeclaredFields()) {
inputField.setAccessible(true); inputField.setAccessible(true);
String inputName = inputField.getName(); String inputName = inputField.getName();
@ -500,10 +503,10 @@ public static void fillValues(String json, Object configuration) {
if(inputAnnotation == null || jsonInputs.get(inputName) == null) { if(inputAnnotation == null || jsonInputs.get(inputName) == null) {
try { try {
inputField.set(formValue, null); inputField.set(configValue, null);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, throw new SqoopException(ModelError.MODEL_005,
"Issue with field " + formName + "." + inputName, e); "Issue with field " + configName + "." + inputName, e);
} }
continue; continue;
} }
@ -512,33 +515,33 @@ public static void fillValues(String json, Object configuration) {
try { try {
if(type == String.class) { if(type == String.class) {
inputField.set(formValue, jsonInputs.get(inputName)); inputField.set(configValue, jsonInputs.get(inputName));
} else if (type.isAssignableFrom(Map.class)) { } else if (type.isAssignableFrom(Map.class)) {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
JSONObject jsonObject = (JSONObject) jsonInputs.get(inputName); JSONObject jsonObject = (JSONObject) jsonInputs.get(inputName);
for(Object key : jsonObject.keySet()) { for(Object key : jsonObject.keySet()) {
map.put((String)key, (String)jsonObject.get(key)); map.put((String)key, (String)jsonObject.get(key));
} }
inputField.set(formValue, map); inputField.set(configValue, map);
} else if(type == Integer.class) { } else if(type == Integer.class) {
inputField.set(formValue, ((Long)jsonInputs.get(inputName)).intValue()); inputField.set(configValue, ((Long)jsonInputs.get(inputName)).intValue());
} else if(type.isEnum()) { } else if(type.isEnum()) {
inputField.set(formValue, Enum.valueOf((Class<? extends Enum>) inputField.getType(), (String) jsonInputs.get(inputName))); inputField.set(configValue, Enum.valueOf((Class<? extends Enum>) inputField.getType(), (String) jsonInputs.get(inputName)));
} else if(type == Boolean.class) { } else if(type == Boolean.class) {
inputField.set(formValue, (Boolean) jsonInputs.get(inputName)); inputField.set(configValue, (Boolean) jsonInputs.get(inputName));
}else { }else {
throw new SqoopException(ModelError.MODEL_004, throw new SqoopException(ModelError.MODEL_004,
"Unsupported type " + type.getName() + " for input " + formName + "." + inputName); "Unsupported type " + type.getName() + " for input " + configName + "." + inputName);
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new SqoopException(ModelError.MODEL_005, throw new SqoopException(ModelError.MODEL_005,
"Issue with field " + formName + "." + inputName, e); "Issue with field " + configName + "." + inputName, e);
} }
} }
} }
} }
private static String getFormName(Field member, Form annotation, Set<String> existingFormNames) { private static String getFormName(Field member, Config annotation, Set<String> existingFormNames) {
if (StringUtils.isEmpty(annotation.name())) { if (StringUtils.isEmpty(annotation.name())) {
return member.getName(); return member.getName();
} else { } else {
@ -578,35 +581,35 @@ public static String getName(Field input, Input annotation) {
return input.getName(); return input.getName();
} }
public static String getName(Field form, Form annotation) { public static String getName(Field config, Config annotation) {
return form.getName(); return config.getName();
} }
public static ConfigurationClass getConfigurationClassAnnotation(Object object, boolean strict) { public static ConfigurationClass getConfigurationClassAnnotation(Object object, boolean strict) {
ConfigurationClass annotation = object.getClass().getAnnotation(ConfigurationClass.class); ConfigurationClass annotation = object.getClass().getAnnotation(ConfigurationClass.class);
if(strict && annotation == null) { if(strict && annotation == null) {
throw new SqoopException(ModelError.MODEL_003, "Missing annotation ConfigurationClass on class " + object.getClass().getName()); throw new SqoopException(ModelError.MODEL_003, "Missing annotation ConfigurationGroupClass on class " + object.getClass().getName());
} }
return annotation; return annotation;
} }
public static FormClass getFormClassAnnotation(Object object, boolean strict) { public static ConfigClass getConfigClassAnnotation(Object object, boolean strict) {
FormClass annotation = object.getClass().getAnnotation(FormClass.class); ConfigClass annotation = object.getClass().getAnnotation(ConfigClass.class);
if(strict && annotation == null) { if(strict && annotation == null) {
throw new SqoopException(ModelError.MODEL_003, "Missing annotation ConfigurationClass on class " + object.getClass().getName()); throw new SqoopException(ModelError.MODEL_003, "Missing annotation ConfigurationGroupClass on class " + object.getClass().getName());
} }
return annotation; return annotation;
} }
public static Form getFormAnnotation(Field field, boolean strict) { public static Config getConfigAnnotation(Field field, boolean strict) {
Form annotation = field.getAnnotation(Form.class); Config annotation = field.getAnnotation(Config.class);
if(strict && annotation == null) { if(strict && annotation == null) {
throw new SqoopException(ModelError.MODEL_003, "Missing annotation Form on Field " + field.getName() + " on class " + field.getDeclaringClass().getName()); throw new SqoopException(ModelError.MODEL_003, "Missing annotation Config on Field " + field.getName() + " on class " + field.getDeclaringClass().getName());
} }
return annotation; return annotation;

View File

@ -23,15 +23,16 @@
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Class annotation. Each class that is used a configuration object where user * Class annotation to represent configuration for the connectors
* is expected to provide input need to have this annotation. * Each class that is used a configuration group object, the connector developer
* is expected to provide the inputs needed for this annotation
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface ConfigurationClass { public @interface ConfigurationClass {
/** /**
* List of validators associated with this Configuration class. * List of validators associated with this Configuration group class.
* *
* @return * @return
*/ */

View File

@ -27,11 +27,11 @@
* input gathering process to be broken down into multiple steps that can be * input gathering process to be broken down into multiple steps that can be
* then paged through by the user interface. * then paged through by the user interface.
*/ */
public final class MForm extends MValidatedElement implements MClonable { public final class MConfig extends MValidatedElement implements MClonable {
private final List<MInput<?>> inputs; private final List<MInput<?>> inputs;
public MForm(String name, List<MInput<?>> inputs) { public MConfig(String name, List<MInput<?>> inputs) {
super(name); super(name);
this.inputs = inputs; this.inputs = inputs;
@ -73,7 +73,7 @@ public MMapInput getMapInput(String inputName) {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("form-").append(getName()); StringBuilder sb = new StringBuilder("config-").append(getName());
sb.append(":").append(getPersistenceId()).append(":").append(inputs); sb.append(":").append(getPersistenceId()).append(":").append(inputs);
return sb.toString(); return sb.toString();
@ -85,11 +85,11 @@ public boolean equals(Object other) {
return true; return true;
} }
if (!(other instanceof MForm)) { if (!(other instanceof MConfig)) {
return false; return false;
} }
MForm mf = (MForm) other; MConfig mf = (MConfig) other;
return getName().equals(mf.getName()) return getName().equals(mf.getName())
&& inputs.equals(mf.inputs); && inputs.equals(mf.inputs);
} }
@ -106,12 +106,12 @@ public int hashCode() {
} }
@Override @Override
public MForm clone(boolean cloneWithValue) { public MConfig clone(boolean cloneWithValue) {
List<MInput<?>> copyInputs = new ArrayList<MInput<?>>(); List<MInput<?>> copyInputs = new ArrayList<MInput<?>>();
for(MInput<?> itr : this.getInputs()) { for(MInput<?> itr : this.getInputs()) {
copyInputs.add((MInput<?>)itr.clone(cloneWithValue)); copyInputs.add((MInput<?>)itr.clone(cloneWithValue));
} }
MForm copyForm = new MForm(this.getName(), copyInputs); MConfig copyConfig = new MConfig(this.getName(), copyInputs);
return copyForm; return copyConfig;
} }
} }

View File

@ -23,28 +23,28 @@
import java.util.List; import java.util.List;
/** /**
* Arbitrary list of forms. * Arbitrary list of config objects.
*/ */
public class MFormList implements MClonable { public class MConfigList implements MClonable {
private final List<MForm> forms; private final List<MConfig> configObjects;
public MFormList(List<MForm> forms) { public MConfigList(List<MConfig> configObjects) {
this.forms = forms; this.configObjects = configObjects;
} }
public List<MForm> getForms() { public List<MConfig> getConfigs() {
return forms; return configObjects;
} }
public MForm getForm(String formName) { public MConfig getConfig(String configName) {
for(MForm form: forms) { for(MConfig config: configObjects) {
if(formName.equals(form.getName())) { if(configName.equals(config.getName())) {
return form; return config;
} }
} }
throw new SqoopException(ModelError.MODEL_010, "Form name: " + formName); throw new SqoopException(ModelError.MODEL_010, "config name: " + configName);
} }
public MInput getInput(String name) { public MInput getInput(String name) {
@ -53,7 +53,7 @@ public MInput getInput(String name) {
throw new SqoopException(ModelError.MODEL_009, name); throw new SqoopException(ModelError.MODEL_009, name);
} }
return getForm(parts[0]).getInput(name); return getConfig(parts[0]).getInput(name);
} }
public MStringInput getStringInput(String name) { public MStringInput getStringInput(String name) {
@ -79,11 +79,11 @@ public MBooleanInput getBooleanInput(String name) {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof MFormList)) return false; if (!(o instanceof MConfigList)) return false;
MFormList mFormList = (MFormList) o; MConfigList mConfigList = (MConfigList) o;
if (!forms.equals(mFormList.forms)) return false; if (!configObjects.equals(mConfigList.configObjects)) return false;
return true; return true;
} }
@ -91,8 +91,8 @@ public boolean equals(Object o) {
@Override @Override
public int hashCode() { public int hashCode() {
int result = super.hashCode(); int result = super.hashCode();
for(MForm form : forms) { for(MConfig config : configObjects) {
result = 31 * result + form.hashCode(); result = 31 * result + config.hashCode();
} }
return result; return result;
@ -100,25 +100,25 @@ public int hashCode() {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("Forms: "); StringBuilder sb = new StringBuilder("Configs: ");
for(MForm form : forms) { for(MConfig config : configObjects) {
sb.append(form.toString()); sb.append(config.toString());
} }
return sb.toString(); return sb.toString();
} }
@Override @Override
public MFormList clone(boolean cloneWithValue) { public MConfigList clone(boolean cloneWithValue) {
List<MForm> copyForms = null; List<MConfig> copyConfigs = null;
if(this.getForms() != null) { if(this.getConfigs() != null) {
copyForms = new ArrayList<MForm>(); copyConfigs = new ArrayList<MConfig>();
for(MForm itr : this.getForms()) { for(MConfig itr : this.getConfigs()) {
MForm newForm = itr.clone(cloneWithValue); MConfig newConfig = itr.clone(cloneWithValue);
newForm.setPersistenceId(itr.getPersistenceId()); newConfig.setPersistenceId(itr.getPersistenceId());
copyForms.add(newForm); copyConfigs.add(newConfig);
} }
} }
MFormList copyFormList = new MFormList(copyForms); MConfigList copyConfigList = new MConfigList(copyConfigs);
return copyFormList; return copyConfigList;
} }
} }

View File

@ -18,17 +18,17 @@
package org.apache.sqoop.model; package org.apache.sqoop.model;
/** /**
* Represents the various form types supported by the system. * Represents the various config types supported by the system.
*/ */
public enum MFormType { public enum MConfigType {
/** Unknown form type */ /** Unknown config type */
OTHER, OTHER,
/** Connection form type */ /** link config type */
CONNECTION, LINK,
/** Job form type */ /** Job config type */
JOB; JOB;
} }

View File

@ -23,28 +23,27 @@
import org.apache.sqoop.common.SupportedDirections; import org.apache.sqoop.common.SupportedDirections;
/** /**
* Connector metadata. * Connector entity supports the FROM/TO {@link Transferable} Includes unique id
* * that identifies connector in the repository, unique human readable name,
* Includes unique id that identifies connector in metadata store, unique human * corresponding name and all configs to support the from and to data sources
* readable name, corresponding name and all forms for all supported job types.
*/ */
public final class MConnector extends MPersistableEntity implements MClonable { public final class MConnector extends MPersistableEntity implements MClonable {
private final String uniqueName; private final String uniqueName;
private final String className; private final String className;
private final MConnectionForms connectionForms; private final String version;
private final MJobForms fromJobForms; private final MLinkConfig linkConfig;
private final MJobForms toJobForms; private final MFromConfig fromConfig;
String version; private final MToConfig toConfig;
public MConnector(String uniqueName, String className, public MConnector(String uniqueName, String className, String version, MLinkConfig linkConfig,
String version, MConnectionForms connectionForms, MFromConfig fromConfig, MToConfig toConfig) {
MJobForms fromJobForms, MJobForms toJobForms) {
this.version = version; this.version = version;
this.connectionForms = connectionForms; this.linkConfig = linkConfig;
this.fromJobForms = fromJobForms; this.fromConfig = fromConfig;
this.toJobForms = toJobForms; this.toConfig = toConfig;
// Why are we abusing NPE?
if (uniqueName == null || className == null) { if (uniqueName == null || className == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
@ -63,17 +62,15 @@ public String getClassName() {
@Override @Override
public String toString() { public String toString() {
MJobForms fromJobForms = this.getJobForms(Direction.FROM);
MJobForms toJobForms = this.getJobForms(Direction.TO);
StringBuilder sb = new StringBuilder("connector-"); StringBuilder sb = new StringBuilder("connector-");
sb.append(uniqueName).append(":").append(getPersistenceId()).append(":"); sb.append(uniqueName).append(":").append(getPersistenceId()).append(":");
sb.append(className); sb.append(className);
sb.append(", ").append(getConnectionForms().toString()); sb.append(", ").append(getLinkConfig().toString());
if (fromJobForms != null) { if (getConfig(Direction.FROM) != null) {
sb.append(", ").append(fromJobForms.toString()); sb.append(", ").append(getConfig(Direction.FROM).toString());
} }
if (toJobForms != null) { if (getConfig(Direction.TO) != null) {
sb.append(", ").append(toJobForms.toString()); sb.append(", ").append(getConfig(Direction.TO).toString());
} }
return sb.toString(); return sb.toString();
} }
@ -94,41 +91,39 @@ public boolean equals(Object other) {
if (supportedDirections.isDirectionSupported(Direction.FROM) if (supportedDirections.isDirectionSupported(Direction.FROM)
&& mcSupportedDirections.isDirectionSupported(Direction.FROM) && mcSupportedDirections.isDirectionSupported(Direction.FROM)
&& !getJobForms(Direction.FROM).equals(mc.getJobForms(Direction.FROM))) { && !getFromConfig().equals(mc.getFromConfig())) {
return false; return false;
} }
if (supportedDirections.isDirectionSupported(Direction.FROM) if (supportedDirections.isDirectionSupported(Direction.FROM) != mcSupportedDirections
!= mcSupportedDirections.isDirectionSupported(Direction.FROM)) { .isDirectionSupported(Direction.FROM)) {
return false; return false;
} }
if (supportedDirections.isDirectionSupported(Direction.TO) if (supportedDirections.isDirectionSupported(Direction.TO)
&& mcSupportedDirections.isDirectionSupported(Direction.TO) && mcSupportedDirections.isDirectionSupported(Direction.TO)
&& !getJobForms(Direction.TO).equals(mc.getJobForms(Direction.TO))) { && !getToConfig().equals(mc.getToConfig())) {
return false; return false;
} }
if (supportedDirections.isDirectionSupported(Direction.TO) if (supportedDirections.isDirectionSupported(Direction.TO) != mcSupportedDirections
!= mcSupportedDirections.isDirectionSupported(Direction.TO)) { .isDirectionSupported(Direction.TO)) {
return false; return false;
} }
return uniqueName.equals(mc.uniqueName) return uniqueName.equals(mc.uniqueName) && className.equals(mc.className)
&& className.equals(mc.className) && version.equals(mc.version) && linkConfig.equals((mc.getLinkConfig()));
&& version.equals(mc.version)
&& connectionForms.equals(mc.getConnectionForms());
} }
@Override @Override
public int hashCode() { public int hashCode() {
SupportedDirections supportedDirections = getSupportedDirections(); SupportedDirections supportedDirections = getSupportedDirections();
int result = getConnectionForms().hashCode(); int result = getLinkConfig().hashCode();
if (supportedDirections.isDirectionSupported(Direction.FROM)) { if (supportedDirections.isDirectionSupported(Direction.FROM)) {
result = 31 * result + getJobForms(Direction.FROM).hashCode(); result = 31 * result + getFromConfig().hashCode();
} }
if (supportedDirections.isDirectionSupported(Direction.TO)) { if (supportedDirections.isDirectionSupported(Direction.TO)) {
result = 31 * result + getJobForms(Direction.TO).hashCode(); result = 31 * result + getToConfig().hashCode();
} }
result = 31 * result + version.hashCode(); result = 31 * result + version.hashCode();
result = 31 * result + uniqueName.hashCode(); result = 31 * result + uniqueName.hashCode();
@ -137,58 +132,57 @@ public int hashCode() {
} }
public MConnector clone(boolean cloneWithValue) { public MConnector clone(boolean cloneWithValue) {
//Connector never have any values filled // Connector never have any values filled
cloneWithValue = false; cloneWithValue = false;
MJobForms fromJobForms = this.getJobForms(Direction.FROM); MFromConfig fromConfig = this.getFromConfig();
MJobForms toJobForms = this.getJobForms(Direction.TO); MToConfig toConfig = this.getToConfig();
if (fromJobForms != null) { if (fromConfig != null) {
fromJobForms = fromJobForms.clone(cloneWithValue); fromConfig = fromConfig.clone(cloneWithValue);
} }
if (toJobForms != null) { if (toConfig != null) {
toJobForms = toJobForms.clone(cloneWithValue); toConfig = toConfig.clone(cloneWithValue);
} }
MConnector copy = new MConnector( MConnector copy = new MConnector(this.getUniqueName(), this.getClassName(), this.getVersion(),
this.getUniqueName(), this.getLinkConfig().clone(cloneWithValue), fromConfig, toConfig);
this.getClassName(),
this.getVersion(),
this.getConnectionForms().clone(cloneWithValue),
fromJobForms,
toJobForms);
copy.setPersistenceId(this.getPersistenceId()); copy.setPersistenceId(this.getPersistenceId());
return copy; return copy;
} }
public MConnectionForms getConnectionForms() { public MLinkConfig getLinkConfig() {
return connectionForms; return linkConfig;
} }
public MJobForms getJobForms(Direction type) { public MConfigList getConfig(Direction type) {
switch(type) { switch (type) {
case FROM: case FROM:
return fromJobForms; return fromConfig;
case TO: case TO:
return toJobForms; return toConfig;
default: default:
throw new SqoopException(DirectionError.DIRECTION_0000, "Direction: " + type); throw new SqoopException(DirectionError.DIRECTION_0000, "Direction: " + type);
} }
} }
public MFromConfig getFromConfig() {
return fromConfig;
}
public MToConfig getToConfig() {
return toConfig;
}
public String getVersion() { public String getVersion() {
return version; return version;
} }
public void setVersion(String version) {
this.version = version;
}
public SupportedDirections getSupportedDirections() { public SupportedDirections getSupportedDirections() {
return new SupportedDirections(this.getJobForms(Direction.FROM) != null, return new SupportedDirections(this.getConfig(Direction.FROM) != null,
this.getJobForms(Direction.TO) != null); this.getConfig(Direction.TO) != null);
} }
} }

View File

@ -0,0 +1,82 @@
/**
* 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.model;
import java.sql.Driver;
/**
* Describes the configs associated with the {@link Driver} for executing sqoop jobs.
*/
public class MDriver extends MPersistableEntity implements MClonable {
private final MDriverConfig driverConfig;
private final String version;
public MDriver(MDriverConfig driverConfig, String version) {
this.driverConfig = driverConfig;
this.version = version;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("driver-");
sb.append(getPersistenceId()).append(":");
sb.append("version = " + version);
sb.append(", ").append(driverConfig.toString());
return sb.toString();
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof MDriver)) {
return false;
}
MDriver driver = (MDriver) other;
return version.equals(driver.getVersion()) &&
driverConfig.equals(driver.driverConfig);
}
@Override
public int hashCode() {
int result = driverConfig.hashCode();
result = 31 * result + version.hashCode();
return result;
}
public MDriverConfig getDriverConfig() {
return driverConfig;
}
@Override
public MDriver clone(boolean cloneWithValue) {
cloneWithValue = false;
MDriver copy = new MDriver(this.driverConfig.clone(cloneWithValue), this.version);
copy.setPersistenceId(this.getPersistenceId());
return copy;
}
public String getVersion() {
return version;
}
}

View File

@ -17,29 +17,23 @@
*/ */
package org.apache.sqoop.model; package org.apache.sqoop.model;
import java.util.List;
/** /**
* Describes the configs associated with the {@link Driver} for executing sqoop jobs. * Config describing all required information for the driver
* NOTE: It extends a config list since {@link MToConfig} could consist of a related config groups
* In future this could be simplified to hold a single list of all configs for the driver
*/ */
public class MDriverConfig extends MPersistableEntity implements MClonable { public class MDriverConfig extends MConfigList {
public MDriverConfig(List<MConfig> configs) {
private final MConnectionForms connectionForms; super(configs);
private final MJobForms jobForms;
String version;
public MDriverConfig(MConnectionForms connectionForms, MJobForms jobForms, String version) {
this.connectionForms = connectionForms;
this.jobForms = jobForms;
this.version = version;
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("driver-"); StringBuilder sb = new StringBuilder("Driver:");
sb.append(getPersistenceId()).append(":"); sb.append(super.toString());
sb.append("version = " + version);
sb.append(", ").append(connectionForms.toString());
sb.append(jobForms.toString());
return sb.toString(); return sb.toString();
} }
@ -53,45 +47,18 @@ public boolean equals(Object other) {
return false; return false;
} }
MDriverConfig mo = (MDriverConfig) other; MDriverConfig mDriver = (MDriverConfig) other;
return version.equals(mo.getVersion()) && return super.equals(mDriver);
connectionForms.equals(mo.connectionForms) &&
jobForms.equals(mo.jobForms);
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = connectionForms.hashCode(); return super.hashCode();
result = 31 * result + jobForms.hashCode();
result = 31 * result + version.hashCode();
return result;
}
public MConnectionForms getConnectionForms() {
return connectionForms;
}
public MJobForms getJobForms() {
return jobForms;
} }
@Override @Override
public MDriverConfig clone(boolean cloneWithValue) { public MDriverConfig clone(boolean cloneWithValue) {
//Framework never have any values filled MDriverConfig copy = new MDriverConfig(super.clone(cloneWithValue).getConfigs());
cloneWithValue = false;
MDriverConfig copy = new MDriverConfig(this.getConnectionForms().clone(cloneWithValue),
this.getJobForms().clone(cloneWithValue), this.version);
copy.setPersistenceId(this.getPersistenceId());
return copy; return copy;
} }
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}

View File

@ -0,0 +1,64 @@
/**
* 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.model;
import java.util.List;
/**
* Config describing all required information to build the FROM part of the job
* NOTE: It extends a config list since {@link MFromConfig} could consist of a related config groups
* In future this could be simplified to hold a single list of all configs for the FROM object
*/
public class MFromConfig extends MConfigList {
public MFromConfig(List<MConfig> configs) {
super(configs);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("From: ");
sb.append(super.toString());
return sb.toString();
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof MFromConfig)) {
return false;
}
MFromConfig mj = (MFromConfig) other;
return super.equals(mj);
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public MFromConfig clone(boolean cloneWithValue) {
MFromConfig copy = new MFromConfig(super.clone(cloneWithValue).getConfigs());
return copy;
}
}

View File

@ -22,29 +22,23 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
/** /**
* Model describing entire job object including both connector and * Model describing entire job object including the from/to and driver config information
* framework part. * to execute the job
*/ */
public class MJob extends MAccountableEntity implements MClonable { public class MJob extends MAccountableEntity implements MClonable {
/** /**
* Connector reference. * NOTE : Job object do not immediately depend on connector as there is indirect
*
* Job object do not immediately depend on connector as there is indirect
* dependency through link object, but having this dependency explicitly * dependency through link object, but having this dependency explicitly
* carried along helps a lot. * carried along helps with not having to make the DB call everytime
*/ */
private final long fromConnectorId; private final long fromConnectorId;
private final long toConnectorId; private final long toConnectorId;
/**
* Corresponding link objects for connector.
*/
private final long fromLinkId; private final long fromLinkId;
private final long toLinkId; private final long toLinkId;
private final MJobForms fromConnectorPart; private final MFromConfig fromConfig;
private final MJobForms toConnectorPart; private final MToConfig toConfig;
private final MJobForms frameworkPart; private final MDriverConfig driverConfig;
/** /**
* Default constructor to build new MJob model. * Default constructor to build new MJob model.
@ -53,24 +47,24 @@ public class MJob extends MAccountableEntity implements MClonable {
* @param toConnectorId TO Connector id * @param toConnectorId TO Connector id
* @param fromLinkId FROM Link id * @param fromLinkId FROM Link id
* @param toLinkId TO Link id * @param toLinkId TO Link id
* @param fromPart FROM Connector forms * @param fromConfig FROM job config
* @param toPart TO Connector forms * @param toConfig TO job config
* @param frameworkPart Framework forms * @param driverConfig driver config
*/ */
public MJob(long fromConnectorId, public MJob(long fromConnectorId,
long toConnectorId, long toConnectorId,
long fromConnectionId, long fromLinkId,
long toConnectionId, long toLinkId,
MJobForms fromPart, MFromConfig fromConfig,
MJobForms toPart, MToConfig toConfig,
MJobForms frameworkPart) { MDriverConfig driverConfig) {
this.fromConnectorId = fromConnectorId; this.fromConnectorId = fromConnectorId;
this.toConnectorId = toConnectorId; this.toConnectorId = toConnectorId;
this.fromLinkId = fromConnectionId; this.fromLinkId = fromLinkId;
this.toLinkId = toConnectionId; this.toLinkId = toLinkId;
this.fromConnectorPart = fromPart; this.fromConfig = fromConfig;
this.toConnectorPart = toPart; this.toConfig = toConfig;
this.frameworkPart = frameworkPart; this.driverConfig = driverConfig;
} }
/** /**
@ -80,9 +74,9 @@ public MJob(long fromConnectorId,
*/ */
public MJob(MJob other) { public MJob(MJob other) {
this(other, this(other,
other.getConnectorPart(Direction.FROM).clone(true), other.getFromJobConfig().clone(true),
other.getConnectorPart(Direction.TO).clone(true), other.getToJobConfig().clone(true),
other.frameworkPart.clone(true)); other.driverConfig.clone(true));
} }
/** /**
@ -92,29 +86,29 @@ public MJob(MJob other) {
* used otherwise. * used otherwise.
* *
* @param other MJob model to copy * @param other MJob model to copy
* @param fromPart FROM Connector forms * @param fromConfig FROM Job config
* @param toPart TO Connector forms * @param toConfig TO Job config
* @param frameworkPart Framework forms * @param driverConfig driverConfig
*/ */
public MJob(MJob other, MJobForms fromPart, MJobForms toPart, MJobForms frameworkPart) { public MJob(MJob other, MFromConfig fromConfig, MToConfig toConfig, MDriverConfig driverConfig) {
super(other); super(other);
this.fromConnectorId = other.getConnectorId(Direction.FROM); this.fromConnectorId = other.getConnectorId(Direction.FROM);
this.toConnectorId = other.getConnectorId(Direction.TO); this.toConnectorId = other.getConnectorId(Direction.TO);
this.fromLinkId = other.getLinkId(Direction.FROM); this.fromLinkId = other.getLinkId(Direction.FROM);
this.toLinkId = other.getLinkId(Direction.TO); this.toLinkId = other.getLinkId(Direction.TO);
this.fromConnectorPart = fromPart; this.fromConfig = fromConfig;
this.toConnectorPart = toPart; this.toConfig = toConfig;
this.frameworkPart = frameworkPart; this.driverConfig = driverConfig;
this.setPersistenceId(other.getPersistenceId()); this.setPersistenceId(other.getPersistenceId());
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("job"); StringBuilder sb = new StringBuilder("job");
sb.append(" connector-from-part: ").append(getConnectorPart(Direction.FROM)); sb.append("From job config: ").append(getJobConfig(Direction.FROM));
sb.append(", connector-to-part: ").append(getConnectorPart(Direction.TO)); sb.append(", To job config: ").append(getJobConfig(Direction.TO));
sb.append(", framework-part: ").append(frameworkPart); sb.append(", Driver config: ").append(driverConfig);
return sb.toString(); return sb.toString();
} }
@ -145,21 +139,29 @@ public long getConnectorId(Direction type) {
} }
} }
public MJobForms getConnectorPart(Direction type) { public MConfigList getJobConfig(Direction type) {
switch(type) { switch(type) {
case FROM: case FROM:
return fromConnectorPart; return fromConfig;
case TO: case TO:
return toConnectorPart; return toConfig;
default: default:
throw new SqoopException(DirectionError.DIRECTION_0000, "Direction: " + type); throw new SqoopException(DirectionError.DIRECTION_0000, "Direction: " + type);
} }
} }
public MJobForms getFrameworkPart() { public MFromConfig getFromJobConfig() {
return frameworkPart; return fromConfig;
}
public MToConfig getToJobConfig() {
return toConfig;
}
public MDriverConfig getDriverConfig() {
return driverConfig;
} }
@Override @Override
@ -172,9 +174,9 @@ public MJob clone(boolean cloneWithValue) {
getConnectorId(Direction.TO), getConnectorId(Direction.TO),
getLinkId(Direction.FROM), getLinkId(Direction.FROM),
getLinkId(Direction.TO), getLinkId(Direction.TO),
getConnectorPart(Direction.FROM).clone(false), getFromJobConfig().clone(false),
getConnectorPart(Direction.TO).clone(false), getToJobConfig().clone(false),
frameworkPart.clone(false)); getDriverConfig().clone(false));
} }
} }
@ -194,8 +196,8 @@ public boolean equals(Object object) {
&& (job.getLinkId(Direction.FROM) == this.getLinkId(Direction.FROM)) && (job.getLinkId(Direction.FROM) == this.getLinkId(Direction.FROM))
&& (job.getLinkId(Direction.TO) == this.getLinkId(Direction.TO)) && (job.getLinkId(Direction.TO) == this.getLinkId(Direction.TO))
&& (job.getPersistenceId() == this.getPersistenceId()) && (job.getPersistenceId() == this.getPersistenceId())
&& (job.getConnectorPart(Direction.FROM).equals(this.getConnectorPart(Direction.FROM))) && (job.getFromJobConfig().equals(this.getJobConfig(Direction.FROM)))
&& (job.getConnectorPart(Direction.TO).equals(this.getConnectorPart(Direction.TO))) && (job.getToJobConfig().equals(this.getJobConfig(Direction.TO)))
&& (job.frameworkPart.equals(this.frameworkPart)); && (job.getDriverConfig().equals(this.driverConfig));
} }
} }

View File

@ -22,57 +22,49 @@
*/ */
public class MLink extends MAccountableEntity implements MClonable { public class MLink extends MAccountableEntity implements MClonable {
private long connectorId; private long connectorId;
// NOTE: we hold this in the model for easy access to the link config object, it might as well be retrieved on the fly using the connectorId
private final MConnectionForms connectorPart; private final MLinkConfig connectorLinkConfig;
private final MConnectionForms frameworkPart;
/** /**
* Default constructor to build new MConnection model. * Default constructor to build new MLink model.
* *
* @param connectorId Connector id * @param connectorId Connector id
* @param connectorPart Connector forms * @param linkConfig Connector forms
* @param frameworkPart Framework forms
*/ */
public MLink(long connectorId, public MLink(long connectorId, MLinkConfig linkConfig) {
MConnectionForms connectorPart,
MConnectionForms frameworkPart) {
this.connectorId = connectorId; this.connectorId = connectorId;
this.connectorPart = connectorPart; this.connectorLinkConfig = linkConfig;
this.frameworkPart = frameworkPart;
} }
/** /**
* Constructor to create deep copy of another MConnection model. * Constructor to create deep copy of another MLink model.
* *
* @param other MConnection model to copy * @param other MLink model to copy
*/ */
public MLink(MLink other) { public MLink(MLink other) {
this(other, other.connectorPart.clone(true), other.frameworkPart.clone(true)); this(other, other.connectorLinkConfig.clone(true));
} }
/** /**
* Construct new MConnection model as a copy of another with replaced forms. * Construct new MLink model as a copy of another with replaced forms.
* *
* This method is suitable only for metadata upgrade path and should not be * This method is suitable only for link upgrade path and should not be
* used otherwise. * used otherwise.
* *
* @param other MConnection model to copy * @param other MLink model to copy
* @param connectorPart Connector forms * @param linkConfig link config
* @param frameworkPart Framework forms
*/ */
public MLink(MLink other, MConnectionForms connectorPart, MConnectionForms frameworkPart) { public MLink(MLink other, MLinkConfig linkConfig) {
super(other); super(other);
this.connectorId = other.connectorId; this.connectorId = other.connectorId;
this.connectorPart = connectorPart; this.connectorLinkConfig = linkConfig;
this.frameworkPart = frameworkPart;
this.setPersistenceId(other.getPersistenceId()); this.setPersistenceId(other.getPersistenceId());
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("connection: ").append(getName()); StringBuilder sb = new StringBuilder("link: ").append(getName());
sb.append(" connector-part: ").append(connectorPart); sb.append(" link-config: ").append(connectorLinkConfig);
sb.append(", framework-part: ").append(frameworkPart);
return sb.toString(); return sb.toString();
} }
@ -85,20 +77,11 @@ public void setConnectorId(long connectorId) {
this.connectorId = connectorId; this.connectorId = connectorId;
} }
public MConnectionForms getConnectorPart() { public MLinkConfig getConnectorLinkConfig() {
return connectorPart; return connectorLinkConfig;
} }
public MConfig getConnectorLinkConfig(String formName) {
public MConnectionForms getFrameworkPart() { return connectorLinkConfig.getConfig(formName);
return frameworkPart;
}
public MForm getConnectorForm(String formName) {
return connectorPart.getForm(formName);
}
public MForm getFrameworkForm(String formName) {
return frameworkPart.getForm(formName);
} }
@Override @Override
@ -106,7 +89,7 @@ public MLink clone(boolean cloneWithValue) {
if(cloneWithValue) { if(cloneWithValue) {
return new MLink(this); return new MLink(this);
} else { } else {
return new MLink(connectorId, connectorPart.clone(false), frameworkPart.clone(false)); return new MLink(connectorId, connectorLinkConfig.clone(false));
} }
} }
@ -120,10 +103,9 @@ public boolean equals(Object object) {
return false; return false;
} }
MLink mc = (MLink)object; MLink mLink = (MLink)object;
return (mc.connectorId == this.connectorId) return (mLink.connectorId == this.connectorId)
&& (mc.getPersistenceId() == this.getPersistenceId()) && (mLink.getPersistenceId() == this.getPersistenceId())
&& (mc.connectorPart.equals(this.connectorPart)) && (mLink.connectorLinkConfig.equals(this.connectorLinkConfig));
&& (mc.frameworkPart.equals(this.frameworkPart)); }
}
} }

View File

@ -20,19 +20,19 @@
import java.util.List; import java.util.List;
/** /**
* Metadata describing all required information to build up an connection * Config describing all required information to build up an link object
* object for one part. Both connector and framework need to supply this object * NOTE: It extends a config list since {@link MLink} could consist of a related config groups
* to build up entire connection. * In future this could be simplified to hold a single list of all configs for the link object
*/ */
public class MConnectionForms extends MFormList { public class MLinkConfig extends MConfigList {
public MConnectionForms(List<MForm> forms) { public MLinkConfig(List<MConfig> configs) {
super(forms); super(configs);
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("Connection: "); StringBuilder sb = new StringBuilder("Link: ");
sb.append(super.toString()); sb.append(super.toString());
return sb.toString(); return sb.toString();
} }
@ -47,8 +47,8 @@ public boolean equals(Object other) {
} }
@Override @Override
public MConnectionForms clone(boolean cloneWithValue) { public MLinkConfig clone(boolean cloneWithValue) {
MConnectionForms copy = new MConnectionForms(super.clone(cloneWithValue).getForms()); MLinkConfig copy = new MLinkConfig(super.clone(cloneWithValue).getConfigs());
return copy; return copy;
} }
} }

View File

@ -20,12 +20,21 @@
import java.util.List; import java.util.List;
/** /**
* Metadata describing all required information to build a job * Config describing all required information to build the TO part of the job
* object with two connectors and a framework. * NOTE: It extends a config list since {@link MToConfig} could consist of a related config groups
* In future this could be simplified to hold a single list of all configs for the TO object
*/ */
public class MJobForms extends MFormList { public class MToConfig extends MConfigList {
public MJobForms(List<MForm> forms) { public MToConfig(List<MConfig> configs) {
super(forms); super(configs);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("To: ");
sb.append(super.toString());
return sb.toString();
} }
@Override @Override
@ -34,11 +43,11 @@ public boolean equals(Object other) {
return true; return true;
} }
if (!(other instanceof MJobForms)) { if (!(other instanceof MToConfig)) {
return false; return false;
} }
MJobForms mj = (MJobForms) other; MToConfig mj = (MToConfig) other;
return super.equals(mj); return super.equals(mj);
} }
@ -48,8 +57,8 @@ public int hashCode() {
} }
@Override @Override
public MJobForms clone(boolean cloneWithValue) { public MToConfig clone(boolean cloneWithValue) {
MJobForms copy = new MJobForms(super.clone(cloneWithValue).getForms()); MToConfig copy = new MToConfig(super.clone(cloneWithValue).getConfigs());
return copy; return copy;
} }
} }

View File

@ -24,7 +24,7 @@
*/ */
public enum ModelError implements ErrorCode { public enum ModelError implements ErrorCode {
MODEL_001("Attempt to pass two different set of MForms for single job type."), MODEL_001("Attempt to pass two different set of MConfigs for single job type."),
MODEL_002("Creating MJob of different job types"), MODEL_002("Creating MJob of different job types"),
@ -34,7 +34,7 @@ public enum ModelError implements ErrorCode {
MODEL_005("Can't get field value"), MODEL_005("Can't get field value"),
MODEL_006("Incompatible form list and configuration object"), MODEL_006("Incompatible config list and configuration object"),
MODEL_007("Primitive types in configuration objects are not allowed"), MODEL_007("Primitive types in configuration objects are not allowed"),
@ -42,7 +42,7 @@ public enum ModelError implements ErrorCode {
MODEL_009("Invalid input name"), MODEL_009("Invalid input name"),
MODEL_010("Form do not exist"), MODEL_010("Config do not exist"),
MODEL_011("Input do not exist"), MODEL_011("Input do not exist"),

View File

@ -17,14 +17,12 @@
*/ */
package org.apache.sqoop.utils; package org.apache.sqoop.utils;
import org.apache.log4j.Logger;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import org.apache.log4j.Logger;
public final class ClassUtils { public final class ClassUtils {

View File

@ -22,7 +22,7 @@
/** /**
* *
*/ */
public enum ValidationError implements ErrorCode { public enum ConfigValidationError implements ErrorCode {
VALIDATION_0000("Unknown error"), VALIDATION_0000("Unknown error"),
@ -30,7 +30,7 @@ public enum ValidationError implements ErrorCode {
VALIDATION_0002("Usage of missing field"), VALIDATION_0002("Usage of missing field"),
VALIDATION_0003("Invalid representation of form and input field"), VALIDATION_0003("Invalid representation of config and input field"),
VALIDATION_0004("Can't find validator class"), VALIDATION_0004("Can't find validator class"),
@ -38,7 +38,7 @@ public enum ValidationError implements ErrorCode {
private final String message; private final String message;
private ValidationError(String message) { private ConfigValidationError(String message) {
this.message = message; this.message = message;
} }

View File

@ -26,7 +26,7 @@
/** /**
* Result of validation execution. * Result of validation execution.
*/ */
public class ValidationResult { public class ConfigValidationResult {
/** /**
* All messages for each named item. * All messages for each named item.
@ -38,7 +38,7 @@ public class ValidationResult {
*/ */
Status status; Status status;
public ValidationResult() { public ConfigValidationResult() {
messages = new HashMap<String, List<Message>>(); messages = new HashMap<String, List<Message>>();
status = Status.getDefault(); status = Status.getDefault();
} }
@ -49,7 +49,7 @@ public ValidationResult() {
* @param name Full name of the validated object * @param name Full name of the validated object
* @param validator Executed validator * @param validator Executed validator
*/ */
public void addValidator(String name, AbstractValidator validator) { public void addValidatorResult(String name, AbstractValidator<String> validator) {
if(validator.getStatus() == Status.getDefault()) { if(validator.getStatus() == Status.getDefault()) {
return; return;
} }
@ -67,7 +67,7 @@ public void addValidator(String name, AbstractValidator validator) {
* *
* @param result Other validation result * @param result Other validation result
*/ */
public void merge(ValidationResult result) { public void mergeValidatorResult(ConfigValidationResult result) {
messages.putAll(result.messages); messages.putAll(result.messages);
status = Status.getWorstStatus(status, result.status); status = Status.getWorstStatus(status, result.status);
} }

View File

@ -19,9 +19,9 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.FormUtils; import org.apache.sqoop.model.ConfigUtils;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
import org.apache.sqoop.model.Validator; import org.apache.sqoop.model.Validator;
import org.apache.sqoop.utils.ClassUtils; import org.apache.sqoop.utils.ClassUtils;
@ -33,17 +33,18 @@
/** /**
* Validation runner that will run validators associated with given configuration * Validation runner that will run validators associated with given configuration
* class or form object. * class or config object.
* *
* Execution follows following rules: * Execution follows following rules:
* * Run children first (Inputs -> Form -> Class) * * Run children first (Inputs -> Config -> Class)
* * If any children is not suitable (canProceed = false), skip running parent * * If any children is not suitable (canProceed = false), skip running parent
* *
* Which means that form validator don't have to repeat it's input validators as it will * Which means that config validator don't have to repeat it's input validators as it will
* be never called if the input's are not valid. Similarly Class validators won't be called * be never called if the input's are not valid. Similarly Class validators won't be called
* unless all forms will pass validators. * unless all configs will pass validators.
*
*/ */
public class ValidationRunner { public class ConfigValidationRunner {
/** /**
* Private cache of instantiated validators. * Private cache of instantiated validators.
@ -54,7 +55,7 @@ public class ValidationRunner {
*/ */
private Map<Class<? extends AbstractValidator>, AbstractValidator> cache; private Map<Class<? extends AbstractValidator>, AbstractValidator> cache;
public ValidationRunner() { public ConfigValidationRunner() {
cache = new HashMap<Class<? extends AbstractValidator>, AbstractValidator>(); cache = new HashMap<Class<? extends AbstractValidator>, AbstractValidator>();
} }
@ -64,80 +65,80 @@ public ValidationRunner() {
* @param config Configuration instance * @param config Configuration instance
* @return * @return
*/ */
public ValidationResult validate(Object config) { public ConfigValidationResult validate(Object config) {
ValidationResult result = new ValidationResult(); ConfigValidationResult result = new ConfigValidationResult();
ConfigurationClass globalAnnotation = FormUtils.getConfigurationClassAnnotation(config, true); ConfigurationClass globalAnnotation = ConfigUtils.getConfigurationClassAnnotation(config, true);
// Iterate over all declared form and call their validators // Iterate over all declared config and call their validators
for (Field field : config.getClass().getDeclaredFields()) { for (Field field : config.getClass().getDeclaredFields()) {
field.setAccessible(true); field.setAccessible(true);
Form formAnnotation = FormUtils.getFormAnnotation(field, false); Config configAnnotation = ConfigUtils.getConfigAnnotation(field, false);
if(formAnnotation == null) { if(configAnnotation == null) {
continue; continue;
} }
String formName = FormUtils.getName(field, formAnnotation); String configName = ConfigUtils.getName(field, configAnnotation);
ValidationResult r = validateForm(formName, FormUtils.getFieldValue(field, config)); ConfigValidationResult r = validateConfig(configName, ConfigUtils.getFieldValue(field, config));
result.merge(r); result.mergeValidatorResult(r);
} }
// Call class validator only as long as we are in suitable state // Call class validator only as long as we are in suitable state
if(result.getStatus().canProceed()) { if(result.getStatus().canProceed()) {
ValidationResult r = validateArray("", config, globalAnnotation.validators()); ConfigValidationResult r = validateArray("", config, globalAnnotation.validators());
result.merge(r); result.mergeValidatorResult(r);
} }
return result; return result;
} }
/** /**
* Validate given form instance. * Validate given config instance.
* *
* @param formName Form's name to build full name for all inputs. * @param configName Config's name to build full name for all inputs.
* @param form Form instance * @param config Config instance
* @return * @return
*/ */
public ValidationResult validateForm(String formName, Object form) { public ConfigValidationResult validateConfig(String configName, Object config) {
ValidationResult result = new ValidationResult(); ConfigValidationResult result = new ConfigValidationResult();
FormClass formAnnotation = FormUtils.getFormClassAnnotation(form, true); ConfigClass configAnnotation = ConfigUtils.getConfigClassAnnotation(config, true);
// Iterate over all declared inputs and call their validators // Iterate over all declared inputs and call their validators
for (Field field : form.getClass().getDeclaredFields()) { for (Field field : config.getClass().getDeclaredFields()) {
Input inputAnnotation = FormUtils.getInputAnnotation(field, false); Input inputAnnotation = ConfigUtils.getInputAnnotation(field, false);
if(inputAnnotation == null) { if(inputAnnotation == null) {
continue; continue;
} }
String name = formName + "." + FormUtils.getName(field, inputAnnotation); String name = configName + "." + ConfigUtils.getName(field, inputAnnotation);
ValidationResult r = validateArray(name, FormUtils.getFieldValue(field, form), inputAnnotation.validators()); ConfigValidationResult r = validateArray(name, ConfigUtils.getFieldValue(field, config), inputAnnotation.validators());
result.merge(r); result.mergeValidatorResult(r);
} }
// Call form validator only as long as we are in suitable state // Call config validator only as long as we are in suitable state
if(result.getStatus().canProceed()) { if(result.getStatus().canProceed()) {
ValidationResult r = validateArray(formName, form, formAnnotation.validators()); ConfigValidationResult r = validateArray(configName, config, configAnnotation.validators());
result.merge(r); result.mergeValidatorResult(r);
} }
return result; return result;
} }
/** /**
* Execute array of validators on given object (can be input/form/class). * Execute array of validators on given object (can be input/config/class).
* *
* @param name Full name of the object * @param name Full name of the object
* @param object Input, Form or Class instance * @param object Input, Config or Class instance
* @param validators Validators array * @param validators Validators array
* @return * @return
*/ */
private ValidationResult validateArray(String name, Object object, Validator[] validators) { private ConfigValidationResult validateArray(String name, Object object, Validator[] validators) {
ValidationResult result = new ValidationResult(); ConfigValidationResult result = new ConfigValidationResult();
for (Validator validator : validators) { for (Validator validator : validators) {
AbstractValidator v = executeValidator(object, validator); AbstractValidator v = executeValidator(object, validator);
result.addValidator(name, v); result.addValidatorResult(name, v);
} }
return result; return result;
@ -146,7 +147,7 @@ private ValidationResult validateArray(String name, Object object, Validator[] v
/** /**
* Execute single validator. * Execute single validator.
* *
* @param object Input, Form or Class instance * @param object Input, Config or Class instance
* @param validator Validator annotation * @param validator Validator annotation
* @return * @return
*/ */
@ -159,7 +160,7 @@ private AbstractValidator executeValidator(Object object, Validator validator) {
// This could happen if we would be missing some connector's jars on our classpath // This could happen if we would be missing some connector's jars on our classpath
if(instance == null) { if(instance == null) {
throw new SqoopException(ValidationError.VALIDATION_0004, validator.value().getName()); throw new SqoopException(ConfigValidationError.VALIDATION_0004, validator.value().getName());
} }
cache.put(validator.value(), instance); cache.put(validator.value(), instance);

View File

@ -24,11 +24,11 @@
import java.util.Map; import java.util.Map;
/** /**
* Validation class. * Config validators.
* *
* This class represents validations to given configuration object. * This class represents validations for the sqoop objects
*/ */
public class Validation { public class ConfigValidator {
// Configuration class that belongs to this validation // Configuration class that belongs to this validation
Class klass; Class klass;
@ -37,15 +37,15 @@ public class Validation {
Status status; Status status;
// Status messages for various fields // Status messages for various fields
Map<FormInput, Message> messages; Map<ConfigInput, Message> messages;
public Validation(Class klass) { public ConfigValidator(Class klass) {
this.klass = klass; this.klass = klass;
status = Status.getDefault(); status = Status.getDefault();
messages = new HashMap<FormInput, Message>(); messages = new HashMap<ConfigInput, Message>();
} }
public Validation(Status status, Map<FormInput, Message> messages) { public ConfigValidator(Status status, Map<ConfigInput, Message> messages) {
this.status = status; this.status = status;
this.messages = messages; this.messages = messages;
} }
@ -54,68 +54,68 @@ public Status getStatus() {
return status; return status;
} }
public Map<FormInput, Message> getMessages() { public Map<ConfigInput, Message> getMessages() {
return messages; return messages;
} }
/** /**
* Add message to form. * Add message to config.
* *
* @param status Severity of the message * @param status Severity of the message
* @param form Form name, must be defined in the class * @param config Config name, must be defined in the class
* @param message Validation message * @param message Validation message
*/ */
public void addMessage(Status status, String form, String message) { public void addMessage(Status status, String config, String message) {
addMessage(status, form, null, message); addMessage(status, config, null, message);
} }
/** /**
* Add message to input in one of the forms. * Add message to input in one of the configs.
* *
* @param status Severity of the message * @param status Severity of the message
* @param form Form name, must be defined in the class * @param config Config name, must be defined in the class
* @param input Field name, must be defined in the form class * @param input Field name, must be defined in the config class
* @param message Validation message * @param message Validation message
*/ */
public void addMessage(Status status, String form, String input, String message ) { public void addMessage(Status status, String config, String input, String message ) {
if( klass == null) { if( klass == null) {
throw new SqoopException(ValidationError.VALIDATION_0001); throw new SqoopException(ConfigValidationError.VALIDATION_0001);
} }
assert form != null; assert config != null;
assert message != null; assert message != null;
// Field for specified form // Field for specified config
Field formField; Field configField;
// Load the form field and verify that it exists // Load the config field and verify that it exists
try { try {
formField = klass.getDeclaredField(form); configField = klass.getDeclaredField(config);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
throw new SqoopException(ValidationError.VALIDATION_0002, throw new SqoopException(ConfigValidationError.VALIDATION_0002,
"Can't get form " + form + " from " + klass.getName(), e); "Can't get config " + config + " from " + klass.getName(), e);
} }
// If this is form message, just save the message and continue // If this is config message, just save the message and continue
if(input == null) { if(input == null) {
setMessage(status, form, input, message); setMessage(status, config, input, message);
return; return;
} }
// Verify that specified input exists on the form // Verify that specified input exists on the config
try { try {
formField.getType().getDeclaredField(input); configField.getType().getDeclaredField(input);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
throw new SqoopException(ValidationError.VALIDATION_0002, throw new SqoopException(ConfigValidationError.VALIDATION_0002,
"Can't get input " + input + " from form" + formField.getType().getName(), e); "Can't get input " + input + " from config" + configField.getType().getName(), e);
} }
setMessage(status, form, input, message); setMessage(status, config, input, message);
} }
private void setMessage(Status status, String form, String input, String message) { private void setMessage(Status status, String config, String input, String message) {
this.status = Status.getWorstStatus(this.status, status); this.status = Status.getWorstStatus(this.status, status);
messages.put(new FormInput(form, input), new Message(status, message)); messages.put(new ConfigInput(config, input), new Message(status, message));
} }
public static class Message { public static class Message {
@ -162,32 +162,32 @@ public String toString() {
} }
} }
public static class FormInput { public static class ConfigInput{
private String form; private String config;
private String input; private String input;
public FormInput(String form, String input) { public ConfigInput(String config, String input) {
this.form = form; this.config = config;
this.input = input; this.input = input;
} }
public FormInput(String formInput) { public ConfigInput(String configInput) {
assert formInput != null; assert configInput != null;
String []parts = formInput.split("\\."); String []parts = configInput.split("\\.");
if(formInput.isEmpty() || (parts.length != 1 && parts.length != 2)) { if(configInput.isEmpty() || (parts.length != 1 && parts.length != 2)) {
throw new SqoopException(ValidationError.VALIDATION_0003, throw new SqoopException(ConfigValidationError.VALIDATION_0003,
"Specification " + formInput + " is not in valid format form.input"); "Specification " + configInput + " is not in valid configat config.input");
} }
this.form = parts[0]; this.config = parts[0];
if(parts.length == 2) { if(parts.length == 2) {
this.input = parts[1]; this.input = parts[1];
} }
} }
public String getForm() { public String getConfig() {
return form; return config;
} }
public String getInput() { public String getInput() {
@ -199,11 +199,11 @@ public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
FormInput formInput = (FormInput) o; ConfigInput configInput = (ConfigInput) o;
if (form != null ? !form.equals(formInput.form) : formInput.form != null) if (config != null ? !config.equals(configInput.config) : configInput.config != null)
return false; return false;
if (input != null ? !input.equals(formInput.input) : formInput.input != null) if (input != null ? !input.equals(configInput.input) : configInput.input != null)
return false; return false;
return true; return true;
@ -211,7 +211,7 @@ public boolean equals(Object o) {
@Override @Override
public int hashCode() { public int hashCode() {
int result = form != null ? form.hashCode() : 0; int result = config != null ? config.hashCode() : 0;
result = 31 * result + (input != null ? input.hashCode() : 0); result = 31 * result + (input != null ? input.hashCode() : 0);
return result; return result;
} }
@ -219,10 +219,10 @@ public int hashCode() {
@Override @Override
public String toString() { public String toString() {
if(input == null) { if(input == null) {
return form; return config;
} }
return form + "." + input; return config + "." + input;
} }
} }
} }

View File

@ -21,7 +21,7 @@
* Validation message. * Validation message.
* *
* Validation message have always two parts - severity and textual information about what * Validation message have always two parts - severity and textual information about what
* is wrong. It can be associated with Input, Form or Configuration class. * is wrong. It can be associated with Input, Config or ConfigurationGroup class.
*/ */
public class Message { public class Message {
private Status status; private Status status;

View File

@ -17,64 +17,83 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.common.Direction;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MConnectionForms;
import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.model.MForm;
import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MJobForms;
import org.apache.sqoop.model.MStringInput;
import org.apache.sqoop.utils.MapResourceBundle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.model.MDriver;
import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MFromConfig;
import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MIntegerInput;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MLinkConfig;
import org.apache.sqoop.model.MStringInput;
import org.apache.sqoop.model.MToConfig;
import org.apache.sqoop.utils.MapResourceBundle;
/** /**
* *
*/ */
public class TestUtil { public class ConfigTestUtil {
public static MConnector getConnector(String name) { public static MConnector getConnector(String name) {
return getConnector(name, true, true); return getConnector(name, true, true);
} }
public static MConnector getConnector(String name, boolean from, boolean to) { public static MConnector getConnector(String name, boolean from, boolean to) {
MJobForms fromJobForms = null; MFromConfig fromConfig = null;
MJobForms toJobForms = null; MToConfig toConfig = null;
if (from) { if (from) {
fromJobForms = getJobForms(); fromConfig = getFromConfig();
} }
if (to) { if (to) {
toJobForms = getJobForms(); toConfig = getToConfig();
} }
return new MConnector(name, name + ".class", "1.0-test", return new MConnector(name, name + ".class", "1.0-test",
getConnectionForms(), fromJobForms, toJobForms); getLinkConfig(), fromConfig, toConfig);
} }
public static MDriverConfig getDriverConfig() {
return new MDriverConfig(getConnectionForms(), getJobForms(), "1");
}
public static MLink getLink(String name) { public static MLink getLink(String name) {
return new MLink(1, getConnector(name).getConnectionForms(), getDriverConfig() return new MLink(1, getConnector(name).getLinkConfig());
.getConnectionForms());
} }
public static MJob getJob(String name) { public static MJob getJob(String name) {
return new MJob(1, 2, 1, 2, getConnector(name).getJobForms(Direction.FROM), getConnector(name) return new MJob(1, 2, 1, 2, getConnector(name).getFromConfig(), getConnector(name)
.getJobForms(Direction.TO), getDriverConfig().getJobForms()); .getToConfig(), getDriverConfig());
} }
public static MConnectionForms getConnectionForms() { public static MDriverConfig getDriverConfig() {
List<MInput<?>> inputs;
MIntegerInput input;
MConfig config;
List<MConfig> driverConfigs = new ArrayList<MConfig>();
inputs = new ArrayList<MInput<?>>();
input = new MIntegerInput("numExtractors", false);
input.setPersistenceId(1);
inputs.add(input);
input = new MIntegerInput("numLoaders", false);
input.setPersistenceId(2);
inputs.add(input);
config = new MConfig("driver", inputs);
config.setPersistenceId(10);
driverConfigs.add(config);
return new MDriverConfig(driverConfigs);
}
public static MLinkConfig getLinkConfig() {
List<MInput<?>> inputs; List<MInput<?>> inputs;
MStringInput input; MStringInput input;
MForm form; MConfig config;
List<MForm> connectionForms = new ArrayList<MForm>(); List<MConfig> linkConfig = new ArrayList<MConfig>();
inputs = new ArrayList<MInput<?>>(); inputs = new ArrayList<MInput<?>>();
input = new MStringInput("url", false, (short) 10); input = new MStringInput("url", false, (short) 10);
@ -91,18 +110,18 @@ public static MConnectionForms getConnectionForms() {
input.setValue("test"); input.setValue("test");
inputs.add(input); inputs.add(input);
form = new MForm("connection", inputs); config = new MConfig("connection", inputs);
form.setPersistenceId(10); config.setPersistenceId(10);
connectionForms.add(form); linkConfig.add(config);
return new MConnectionForms(connectionForms); return new MLinkConfig(linkConfig);
} }
public static MJobForms getJobForms() { static MFromConfig getFromConfig() {
List<MInput<?>> inputs; List<MInput<?>> inputs;
MStringInput input; MStringInput input;
MForm form; MConfig config;
List<MForm> jobForms = new ArrayList<MForm>(); List<MConfig> jobConfigs = new ArrayList<MConfig>();
inputs = new ArrayList<MInput<?>>(); inputs = new ArrayList<MInput<?>>();
@ -118,9 +137,9 @@ public static MJobForms getJobForms() {
input.setPersistenceId(6); input.setPersistenceId(6);
inputs.add(input); inputs.add(input);
form = new MForm("Z", inputs); config = new MConfig("Z", inputs);
form.setPersistenceId(11); config.setPersistenceId(11);
jobForms.add(form); jobConfigs.add(config);
inputs = new ArrayList<MInput<?>>(); inputs = new ArrayList<MInput<?>>();
@ -136,11 +155,56 @@ public static MJobForms getJobForms() {
input.setPersistenceId(9); input.setPersistenceId(9);
inputs.add(input); inputs.add(input);
form = new MForm("connection", inputs); config = new MConfig("from-table", inputs);
form.setPersistenceId(12); config.setPersistenceId(12);
jobForms.add(form); jobConfigs.add(config);
return new MJobForms(jobForms); return new MFromConfig(jobConfigs);
}
static MToConfig getToConfig() {
List<MInput<?>> inputs;
MStringInput input;
MConfig config;
List<MConfig> jobConfigs = new ArrayList<MConfig>();
inputs = new ArrayList<MInput<?>>();
input = new MStringInput("A", false, (short) 10);
input.setPersistenceId(4);
inputs.add(input);
input = new MStringInput("B", false, (short) 10);
input.setPersistenceId(5);
inputs.add(input);
input = new MStringInput("C", false, (short) 10);
input.setPersistenceId(6);
inputs.add(input);
config = new MConfig("Z", inputs);
config.setPersistenceId(11);
jobConfigs.add(config);
inputs = new ArrayList<MInput<?>>();
input = new MStringInput("D", false, (short) 10);
input.setPersistenceId(7);
inputs.add(input);
input = new MStringInput("E", false, (short) 10);
input.setPersistenceId(8);
inputs.add(input);
input = new MStringInput("F", false, (short) 10);
input.setPersistenceId(9);
inputs.add(input);
config = new MConfig("to-table", inputs);
config.setPersistenceId(12);
jobConfigs.add(config);
return new MToConfig(jobConfigs);
} }
public static ResourceBundle getResourceBundle() { public static ResourceBundle getResourceBundle() {

View File

@ -17,10 +17,9 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.model.MConnector; import static org.apache.sqoop.json.ConfigTestUtil.getConnector;
import org.json.simple.JSONObject; import static org.apache.sqoop.json.ConfigTestUtil.getResourceBundle;
import org.json.simple.JSONValue; import static org.junit.Assert.*;
import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
@ -28,8 +27,10 @@
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import static org.apache.sqoop.json.TestUtil.*; import org.apache.sqoop.model.MConnector;
import static org.junit.Assert.*; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test;
/** /**
* *
@ -48,26 +49,26 @@ public void testSerialization() {
connectors.add(getConnector("mysql")); connectors.add(getConnector("mysql"));
// Create testing bundles // Create testing bundles
Map<Long, ResourceBundle> bundles = new HashMap<Long, ResourceBundle>(); Map<Long, ResourceBundle> configBundles = new HashMap<Long, ResourceBundle>();
bundles.put(1L, getResourceBundle()); configBundles.put(1L, getResourceBundle());
bundles.put(2L, getResourceBundle()); configBundles.put(2L, getResourceBundle());
// Serialize it to JSON object // Serialize it to JSON object
ConnectorBean bean = new ConnectorBean(connectors, bundles); ConnectorBean connectorBean = new ConnectorBean(connectors, configBundles);
JSONObject json = bean.extract(false); JSONObject connectorJSON = connectorBean.extract(false);
// "Move" it across network in text form // "Move" it across network in text form
String string = json.toJSONString(); String connectorJSONString = connectorJSON.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject parsedConnector = (JSONObject) JSONValue.parse(connectorJSONString);
ConnectorBean retrievedBean = new ConnectorBean(); ConnectorBean parsedConnectorBean = new ConnectorBean();
retrievedBean.restore(retrievedJson); parsedConnectorBean.restore(parsedConnector);
assertEquals(connectors.size(), retrievedBean.getConnectors().size()); assertEquals(connectors.size(), parsedConnectorBean.getConnectors().size());
assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0)); assertEquals(connectors.get(0), parsedConnectorBean.getConnectors().get(0));
ResourceBundle retrievedBundle = retrievedBean.getResourceBundles().get(1L); ResourceBundle retrievedBundle = parsedConnectorBean.getResourceBundles().get(1L);
assertNotNull(retrievedBundle); assertNotNull(retrievedBundle);
assertEquals("a", retrievedBundle.getString("a")); assertEquals("a", retrievedBundle.getString("a"));
assertEquals("b", retrievedBundle.getString("b")); assertEquals("b", retrievedBundle.getString("b"));

View File

@ -17,31 +17,31 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.model.MDriverConfig; import static org.apache.sqoop.json.ConfigTestUtil.getResourceBundle;
import static org.junit.Assert.assertEquals;
import java.util.ResourceBundle;
import org.apache.sqoop.model.MDriver;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
import java.util.ResourceBundle;
import static org.apache.sqoop.json.TestUtil.*;
import static org.junit.Assert.*;
/** /**
* *
*/ */
public class TestDriverConfigBean { public class TestDriverBean {
/** /**
* Test that by JSON serialization followed by deserialization we will get * Test that by JSON serialization followed by deserialization we will get
* equal framework object. * equal drive config object.
*/ */
@Test @Test
public void testSerialization() { public void testSerialization() {
MDriverConfig driverConfig = getDriverConfig(); MDriver driver = new MDriver(ConfigTestUtil.getDriverConfig(), DriverBean.CURRENT_DRIVER_VERSION);
// Serialize it to JSON object // Serialize it to JSON object
DriverConfigBean bean = new DriverConfigBean(driverConfig, getResourceBundle()); DriverBean bean = new DriverBean(driver, getResourceBundle());
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);
// "Move" it across network in text form // "Move" it across network in text form
@ -49,12 +49,12 @@ public void testSerialization() {
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
DriverConfigBean retrievedBean = new DriverConfigBean(); DriverBean retrievedBean = new DriverBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);
assertEquals(driverConfig, retrievedBean.getDriverConfig()); assertEquals(driver, retrievedBean.getDriver());
ResourceBundle retrievedBundle = retrievedBean.getResourceBundle(); ResourceBundle retrievedBundle = retrievedBean.getDriverConfigResourceBundle();
assertEquals("a", retrievedBundle.getString("a")); assertEquals("a", retrievedBundle.getString("a"));
assertEquals("b", retrievedBundle.getString("b")); assertEquals("b", retrievedBundle.getString("b"));
} }

View File

@ -17,6 +17,11 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import static org.apache.sqoop.json.ConfigTestUtil.getJob;
import static org.junit.Assert.assertEquals;
import java.util.Date;
import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.Direction;
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
@ -25,11 +30,6 @@
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.junit.Test; import org.junit.Test;
import java.util.Date;
import static org.apache.sqoop.json.TestUtil.getJob;
import static org.junit.Assert.assertEquals;
/** /**
* *
*/ */
@ -46,25 +46,25 @@ public void testSerialization() throws ParseException {
job.setEnabled(false); job.setEnabled(false);
// Fill some data at the beginning // Fill some data at the beginning
MStringInput input = (MStringInput) job.getConnectorPart(Direction.FROM) MStringInput input = (MStringInput) job.getJobConfig(Direction.FROM)
.getForms().get(0).getInputs().get(0); .getConfigs().get(0).getInputs().get(0);
input.setValue("Hi there!"); input.setValue("Hi there!");
input = (MStringInput) job.getConnectorPart(Direction.TO) input = (MStringInput) job.getJobConfig(Direction.TO)
.getForms().get(0).getInputs().get(0); .getConfigs().get(0).getInputs().get(0);
input.setValue("Hi there again!"); input.setValue("Hi there again!");
// Serialize it to JSON object // Serialize it to JSON object
JobBean bean = new JobBean(job); JobBean jobBean = new JobBean(job);
JSONObject json = bean.extract(false); JSONObject jobJson = jobBean.extract(false);
// "Move" it across network in text form // "Move" it across network in text form
String string = json.toJSONString(); String jobJsonString = jobJson.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject)JSONValue.parseWithException(string); JSONObject parsedJobJson = (JSONObject)JSONValue.parseWithException(jobJsonString);
JobBean retrievedBean = new JobBean(); JobBean parsedJobBean = new JobBean();
retrievedBean.restore(retrievedJson); parsedJobBean.restore(parsedJobJson);
MJob target = retrievedBean.getJobs().get(0); MJob target = parsedJobBean.getJobs().get(0);
// Check id and name // Check id and name
assertEquals(666, target.getPersistenceId()); assertEquals(666, target.getPersistenceId());
@ -78,11 +78,11 @@ public void testSerialization() throws ParseException {
assertEquals(false, target.getEnabled()); assertEquals(false, target.getEnabled());
// Test that value was correctly moved // Test that value was correctly moved
MStringInput targetInput = (MStringInput) target.getConnectorPart(Direction.FROM) MStringInput targetInput = (MStringInput) target.getJobConfig(Direction.FROM)
.getForms().get(0).getInputs().get(0); .getConfigs().get(0).getInputs().get(0);
assertEquals("Hi there!", targetInput.getValue()); assertEquals("Hi there!", targetInput.getValue());
targetInput = (MStringInput) target.getConnectorPart(Direction.TO) targetInput = (MStringInput) target.getJobConfig(Direction.TO)
.getForms().get(0).getInputs().get(0); .getConfigs().get(0).getInputs().get(0);
assertEquals("Hi there again!", targetInput.getValue()); assertEquals("Hi there again!", targetInput.getValue());
} }
} }

View File

@ -17,19 +17,21 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import static org.apache.sqoop.json.ConfigTestUtil.getLink;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import org.apache.sqoop.json.util.ConfigSerialization;
import org.apache.sqoop.model.MLink; import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
import java.util.Date;
import static org.junit.Assert.*;
import static org.apache.sqoop.json.TestUtil.*;
/** /**
* *
*/ */
@ -48,31 +50,31 @@ public void testSerialization() {
link.setEnabled(false); link.setEnabled(false);
// Fill some data at the beginning // Fill some data at the beginning
MStringInput input = (MStringInput) link.getConnectorPart().getForms() MStringInput input = (MStringInput) link.getConnectorLinkConfig().getConfigs()
.get(0).getInputs().get(0); .get(0).getInputs().get(0);
input.setValue("Hi there!"); input.setValue("Hi there!");
// Serialize it to JSON object // Serialize it to JSON object
LinkBean bean = new LinkBean(link); LinkBean linkBean = new LinkBean(link);
JSONObject json = bean.extract(false); JSONObject json = linkBean.extract(false);
// Check for sensitivity // Check for sensitivity
JSONArray all = (JSONArray)json.get("all"); JSONArray all = (JSONArray)json.get(ConfigSerialization.ALL);
JSONObject allItem = (JSONObject)all.get(0); JSONObject allItem = (JSONObject)all.get(0);
JSONArray connectors = (JSONArray)allItem.get("connector"); JSONArray connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
JSONObject connector = (JSONObject)connectors.get(0); JSONObject connector = (JSONObject)connectors.get(0);
JSONArray inputs = (JSONArray)connector.get("inputs"); JSONArray inputs = (JSONArray)connector.get(ConfigSerialization.CONFIG_INPUTS);
for (Object input1 : inputs) { for (Object input1 : inputs) {
assertTrue(((JSONObject)input1).containsKey("sensitive")); assertTrue(((JSONObject)input1).containsKey(ConfigSerialization.CONFIG_INPUT_SENSITIVE));
} }
// "Move" it across network in text form // "Move" it across network in text form
String string = json.toJSONString(); String linkJsonString = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject parsedLinkJson = (JSONObject) JSONValue.parse(linkJsonString);
LinkBean retrievedBean = new LinkBean(); LinkBean retrievedBean = new LinkBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(parsedLinkJson);
MLink target = retrievedBean.getLinks().get(0); MLink target = retrievedBean.getLinks().get(0);
// Check id and name // Check id and name
@ -85,8 +87,8 @@ public void testSerialization() {
assertEquals(false, target.getEnabled()); assertEquals(false, target.getEnabled());
// Test that value was correctly moved // Test that value was correctly moved
MStringInput targetInput = (MStringInput) target.getConnectorPart() MStringInput targetInput = (MStringInput) target.getConnectorLinkConfig()
.getForms().get(0).getInputs().get(0); .getConfigs().get(0).getInputs().get(0);
assertEquals("Hi there!", targetInput.getValue()); assertEquals("Hi there!", targetInput.getValue());
} }
@ -104,7 +106,7 @@ public void testSensitivityFilter() {
link.setEnabled(true); link.setEnabled(true);
// Fill some data at the beginning // Fill some data at the beginning
MStringInput input = (MStringInput) link.getConnectorPart().getForms() MStringInput input = (MStringInput) link.getConnectorLinkConfig().getConfigs()
.get(0).getInputs().get(0); .get(0).getInputs().get(0);
input.setValue("Hi there!"); input.setValue("Hi there!");
@ -114,25 +116,25 @@ public void testSensitivityFilter() {
JSONObject jsonFiltered = bean.extract(true); JSONObject jsonFiltered = bean.extract(true);
// Sensitive values should exist // Sensitive values should exist
JSONArray all = (JSONArray)json.get("all"); JSONArray all = (JSONArray)json.get(ConfigSerialization.ALL);
JSONObject allItem = (JSONObject)all.get(0); JSONObject allItem = (JSONObject)all.get(0);
JSONArray connectors = (JSONArray)allItem.get("connector"); JSONArray connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
JSONObject connector = (JSONObject)connectors.get(0); JSONObject connector = (JSONObject)connectors.get(0);
JSONArray inputs = (JSONArray)connector.get("inputs"); JSONArray inputs = (JSONArray)connector.get(ConfigSerialization.CONFIG_INPUTS);
assertEquals(3, inputs.size()); assertEquals(3, inputs.size());
// Inputs are ordered when creating link // Inputs are ordered when creating link
JSONObject password = (JSONObject)inputs.get(2); JSONObject password = (JSONObject)inputs.get(2);
assertTrue(password.containsKey("value")); assertTrue(password.containsKey(ConfigSerialization.CONFIG_INPUT_VALUE));
// Sensitive values should not exist // Sensitive values should not exist
all = (JSONArray)jsonFiltered.get("all"); all = (JSONArray)jsonFiltered.get(ConfigSerialization.ALL);
allItem = (JSONObject)all.get(0); allItem = (JSONObject)all.get(0);
connectors = (JSONArray)allItem.get("connector"); connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
connector = (JSONObject)connectors.get(0); connector = (JSONObject)connectors.get(0);
inputs = (JSONArray)connector.get("inputs"); inputs = (JSONArray)connector.get(ConfigSerialization.CONFIG_INPUTS);
assertEquals(3, inputs.size()); assertEquals(3, inputs.size());
// Inputs are ordered when creating link // Inputs are ordered when creating link
password = (JSONObject)inputs.get(2); password = (JSONObject)inputs.get(2);
assertFalse(password.containsKey("value")); assertFalse(password.containsKey(ConfigSerialization.CONFIG_INPUT_VALUE));
} }
} }

View File

@ -17,17 +17,19 @@
*/ */
package org.apache.sqoop.json; package org.apache.sqoop.json;
import org.apache.sqoop.common.Direction; import static org.junit.Assert.assertEquals;
import org.apache.sqoop.validation.Status; import static org.junit.Assert.assertNull;
import org.apache.sqoop.validation.Validation; import static org.junit.Assert.assertTrue;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.*; import org.apache.sqoop.common.Direction;
import org.apache.sqoop.validation.ConfigValidator;
import org.apache.sqoop.validation.Status;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test;
/** /**
* *
@ -44,7 +46,7 @@ public void testJobValidationBeanSerialization() {
); );
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);
// "Move" it across network in text form // "Move" it across network in text config
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
@ -54,43 +56,43 @@ public void testJobValidationBeanSerialization() {
assertNull(retrievedBean.getId()); assertNull(retrievedBean.getId());
Validation.FormInput fa = new Validation.FormInput("f", "i"); ConfigValidator.ConfigInput fa = new ConfigValidator.ConfigInput("c", "i");
Validation.FormInput fb = new Validation.FormInput("f2", "i2"); ConfigValidator.ConfigInput fb = new ConfigValidator.ConfigInput("c2", "i2");
Validation fromConnector = retrievedBean.getConnectorValidation(Direction.FROM); ConfigValidator fromConnector = retrievedBean.getConnectorValidation(Direction.FROM);
assertEquals(Status.FINE, fromConnector.getStatus()); assertEquals(Status.FINE, fromConnector.getStatus());
assertEquals(2, fromConnector.getMessages().size()); assertEquals(2, fromConnector.getMessages().size());
assertTrue(fromConnector.getMessages().containsKey(fa)); assertTrue(fromConnector.getMessages().containsKey(fa));
assertEquals(new Validation.Message(Status.FINE, "d"), assertEquals(new ConfigValidator.Message(Status.FINE, "d"),
fromConnector.getMessages().get(fa)); fromConnector.getMessages().get(fa));
Validation toConnector = retrievedBean.getConnectorValidation(Direction.TO); ConfigValidator toConnector = retrievedBean.getConnectorValidation(Direction.TO);
assertEquals(Status.FINE, toConnector.getStatus()); assertEquals(Status.FINE, toConnector.getStatus());
assertEquals(2, toConnector.getMessages().size()); assertEquals(2, toConnector.getMessages().size());
assertTrue(toConnector.getMessages().containsKey(fa)); assertTrue(toConnector.getMessages().containsKey(fa));
assertEquals(new Validation.Message(Status.FINE, "d"), assertEquals(new ConfigValidator.Message(Status.FINE, "d"),
toConnector.getMessages().get(fa)); toConnector.getMessages().get(fa));
Validation framework = retrievedBean.getFrameworkValidation(); ConfigValidator framework = retrievedBean.getFrameworkValidation();
assertEquals(Status.UNACCEPTABLE, framework.getStatus()); assertEquals(Status.UNACCEPTABLE, framework.getStatus());
assertEquals(2, framework.getMessages().size()); assertEquals(2, framework.getMessages().size());
assertTrue(framework.getMessages().containsKey(fb)); assertTrue(framework.getMessages().containsKey(fb));
assertEquals(new Validation.Message(Status.UNACCEPTABLE, "c"), assertEquals(new ConfigValidator.Message(Status.UNACCEPTABLE, "c"),
framework.getMessages().get(fb)); framework.getMessages().get(fb));
} }
@Test @Test
public void testJobValidationBeanId() { public void testJobValidationBeanId() {
// Serialize it to JSON object // Serialize it to JSON object
JobValidationBean bean = new JobValidationBean( JobValidationBean jobValidatioBean = new JobValidationBean(
getValidation(Status.FINE), getValidation(Status.FINE),
getValidation(Status.FINE), getValidation(Status.FINE),
getValidation(Status.FINE) getValidation(Status.FINE)
); );
bean.setId((long) 10); jobValidatioBean.setId((long) 10);
JSONObject json = bean.extract(false); JSONObject json = jobValidatioBean.extract(false);
// "Move" it across network in text form // "Move" it across network in text config
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
@ -105,12 +107,10 @@ public void testJobValidationBeanId() {
public void testLinkValidationBeanSerialization() { public void testLinkValidationBeanSerialization() {
// Serialize it to JSON object // Serialize it to JSON object
LinkValidationBean bean = new LinkValidationBean( LinkValidationBean bean = new LinkValidationBean(
getValidation(Status.FINE), getValidation(Status.FINE));
getValidation(Status.UNACCEPTABLE)
);
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);
// "Move" it across network in text form // "Move" it across network in text config
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
@ -120,35 +120,25 @@ public void testLinkValidationBeanSerialization() {
assertNull(retrievedBean.getId()); assertNull(retrievedBean.getId());
Validation.FormInput fa = new Validation.FormInput("f", "i"); ConfigValidator.ConfigInput ca = new ConfigValidator.ConfigInput("c", "i");
Validation.FormInput fb = new Validation.FormInput("f2", "i2"); ConfigValidator connector = retrievedBean.getLinkConfigValidator();
Validation connector = retrievedBean.getConnectorValidation();
assertEquals(Status.FINE, connector.getStatus()); assertEquals(Status.FINE, connector.getStatus());
assertEquals(2, connector.getMessages().size()); assertEquals(2, connector.getMessages().size());
assertTrue(connector.getMessages().containsKey(fa)); assertTrue(connector.getMessages().containsKey(ca));
assertEquals(new Validation.Message(Status.FINE, "d"), assertEquals(new ConfigValidator.Message(Status.FINE, "d"),
connector.getMessages().get(fa)); connector.getMessages().get(ca));
Validation framework = retrievedBean.getFrameworkValidation();
assertEquals(Status.UNACCEPTABLE, framework.getStatus());
assertEquals(2, framework.getMessages().size());
assertTrue(framework.getMessages().containsKey(fb));
assertEquals(new Validation.Message(Status.UNACCEPTABLE, "c"),
framework.getMessages().get(fb));
} }
@Test @Test
public void testLinkValidationBeanId() { public void testLinkValidationBeanId() {
// Serialize it to JSON object // Serialize it to JSON object
LinkValidationBean bean = new LinkValidationBean( LinkValidationBean bean = new LinkValidationBean(
getValidation(Status.FINE),
getValidation(Status.FINE) getValidation(Status.FINE)
); );
bean.setId((long) 10); bean.setId((long) 10);
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);
// "Move" it across network in text form // "Move" it across network in text config
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
@ -159,17 +149,12 @@ public void testLinkValidationBeanId() {
assertEquals((Long)(long) 10, retrievedBean.getId()); assertEquals((Long)(long) 10, retrievedBean.getId());
} }
public Validation getValidation(Status status) { public ConfigValidator getValidation(Status status) {
Map<Validation.FormInput, Validation.Message> messages = Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
new HashMap<Validation.FormInput, Validation.Message>();
messages.put( messages.put(new ConfigValidator.ConfigInput("c", "i"), new ConfigValidator.Message(status, "d"));
new Validation.FormInput("f", "i"), messages.put(new ConfigValidator.ConfigInput("c2", "i2"), new ConfigValidator.Message(status, "c"));
new Validation.Message(status, "d"));
messages.put(
new Validation.FormInput("f2", "i2"),
new Validation.Message(status, "c"));
return new Validation(status, messages); return new ConfigValidator(status, messages);
} }
} }

View File

@ -19,7 +19,7 @@
import org.apache.sqoop.validation.Message; import org.apache.sqoop.validation.Message;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.ValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
@ -39,31 +39,31 @@ public class TestValidationResultBean {
@Test @Test
public void testEmptyTransfer() { public void testEmptyTransfer() {
ValidationResult []empty = new ValidationResult[0]; ConfigValidationResult []empty = new ConfigValidationResult[0];
ValidationResult []retrieved = transfer(empty); ConfigValidationResult []retrieved = transfer(empty);
assertEquals(0, retrieved.length); assertEquals(0, retrieved.length);
} }
@Test @Test
public void testOneMessage() { public void testOneMessage() {
ValidationResult []empty = new ValidationResult[] { ConfigValidationResult []empty = new ConfigValidationResult[] {
getResultA() getResultA()
}; };
ValidationResult []retrieved = transfer(empty); ConfigValidationResult []retrieved = transfer(empty);
assertEquals(1, retrieved.length); assertEquals(1, retrieved.length);
verifyResultA(retrieved[0]); verifyResultA(retrieved[0]);
} }
@Test @Test
public void testTwoMessages() { public void testTwoMessages() {
ValidationResult []empty = new ValidationResult[] { ConfigValidationResult []empty = new ConfigValidationResult[] {
getResultA(), getResultA(),
getResultA() getResultA()
}; };
ValidationResult []retrieved = transfer(empty); ConfigValidationResult []retrieved = transfer(empty);
assertEquals(2, retrieved.length); assertEquals(2, retrieved.length);
verifyResultA(retrieved[0]); verifyResultA(retrieved[0]);
@ -79,7 +79,7 @@ public void testId() {
assertNull(idNull); assertNull(idNull);
} }
public void verifyResultA(ValidationResult result) { public void verifyResultA(ConfigValidationResult result) {
assertNotNull(result); assertNotNull(result);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
@ -98,8 +98,8 @@ public void verifyResultA(ValidationResult result) {
assertEquals("B", messagesA.get(1).getMessage()); assertEquals("B", messagesA.get(1).getMessage());
} }
public ValidationResult getResultA() { public ConfigValidationResult getResultA() {
ValidationResult result = new ValidationResult(); ConfigValidationResult result = new ConfigValidationResult();
List<Message> messages = new LinkedList<Message>(); List<Message> messages = new LinkedList<Message>();
messages.add(new Message(Status.ACCEPTABLE, "A")); messages.add(new Message(Status.ACCEPTABLE, "A"));
messages.add(new Message(Status.UNACCEPTABLE, "B")); messages.add(new Message(Status.UNACCEPTABLE, "B"));
@ -109,7 +109,7 @@ public ValidationResult getResultA() {
private Long transfer(Long id) { private Long transfer(Long id) {
ValidationResultBean bean = new ValidationResultBean(new ValidationResult[0]); ValidationResultBean bean = new ValidationResultBean(new ConfigValidationResult[0]);
bean.setId(id); bean.setId(id);
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);
@ -122,7 +122,7 @@ private Long transfer(Long id) {
return retrievedBean.getId(); return retrievedBean.getId();
} }
private ValidationResult[] transfer(ValidationResult [] results) { private ConfigValidationResult[] transfer(ConfigValidationResult [] results) {
ValidationResultBean bean = new ValidationResultBean(results); ValidationResultBean bean = new ValidationResultBean(results);
JSONObject json = bean.extract(false); JSONObject json = bean.extract(false);

View File

@ -20,7 +20,7 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.model.MBooleanInput; import org.apache.sqoop.model.MBooleanInput;
import org.apache.sqoop.model.MEnumInput; import org.apache.sqoop.model.MEnumInput;
import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MInput; import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MIntegerInput; import org.apache.sqoop.model.MIntegerInput;
import org.apache.sqoop.model.MMapInput; import org.apache.sqoop.model.MMapInput;
@ -40,7 +40,7 @@
/** /**
* *
*/ */
public class TestFormSerialization { public class TestConfigSerialization {
@Test @Test
public void testAllDataTypes() { public void testAllDataTypes() {
@ -48,16 +48,16 @@ public void testAllDataTypes() {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("A", "B"); map.put("A", "B");
// Fill form with all values // Fill config with all values
MForm form = getForm(); MConfig config = getConfig();
form.getStringInput("String").setValue("A"); config.getStringInput("String").setValue("A");
form.getMapInput("Map").setValue(map); config.getMapInput("Map").setValue(map);
form.getIntegerInput("Integer").setValue(1); config.getIntegerInput("Integer").setValue(1);
form.getBooleanInput("Boolean").setValue(true); config.getBooleanInput("Boolean").setValue(true);
form.getEnumInput("Enum").setValue("YES"); config.getEnumInput("Enum").setValue("YES");
// Serialize that into JSON // Serialize that into JSON
JSONObject jsonObject = FormSerialization.extractForm(form, false); JSONObject jsonObject = ConfigSerialization.extractConfig(config, false);
assertNotNull(jsonObject); assertNotNull(jsonObject);
// Exchange the data on string level // Exchange the data on string level
@ -65,7 +65,7 @@ public void testAllDataTypes() {
JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson); JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
// And retrieve back from JSON representation // And retrieve back from JSON representation
MForm retrieved = FormSerialization.restoreForm(retrievedJson); MConfig retrieved = ConfigSerialization.restoreConfig(retrievedJson);
// Verify all expected values // Verify all expected values
assertEquals("A", retrieved.getStringInput("String").getValue()); assertEquals("A", retrieved.getStringInput("String").getValue());
@ -77,44 +77,44 @@ public void testAllDataTypes() {
@Test @Test
public void testMapDataType() { public void testMapDataType() {
MForm form = getMapForm(); MConfig config = getMapConfig();
// Inserted values // Inserted values
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("A", "B"); map.put("A", "B");
form.getMapInput("Map").setValue(map); config.getMapInput("Map").setValue(map);
// Serialize // Serialize
JSONObject jsonObject = FormSerialization.extractForm(form, false); JSONObject jsonObject = ConfigSerialization.extractConfig(config, false);
String serializedJson = jsonObject.toJSONString(); String serializedJson = jsonObject.toJSONString();
// Deserialize // Deserialize
JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson); JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
MForm retrieved = FormSerialization.restoreForm(retrievedJson); MConfig retrieved = ConfigSerialization.restoreConfig(retrievedJson);
assertEquals(map, retrieved.getMapInput("Map").getValue()); assertEquals(map, retrieved.getMapInput("Map").getValue());
} }
@Test(expected=SqoopException.class) @Test(expected=SqoopException.class)
public void testMapDataTypeException() { public void testMapDataTypeException() {
MForm form = getMapForm(); MConfig config = getMapConfig();
// Inserted values // Inserted values
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("A", "B"); map.put("A", "B");
form.getMapInput("Map").setValue(map); config.getMapInput("Map").setValue(map);
// Serialize // Serialize
JSONObject jsonObject = FormSerialization.extractForm(form, false); JSONObject jsonObject = ConfigSerialization.extractConfig(config, false);
String serializedJson = jsonObject.toJSONString(); String serializedJson = jsonObject.toJSONString();
// Replace map value with a fake string to force exception // Replace map value with a fake string to force exception
String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\""); String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\"");
System.out.println(badSerializedJson); System.out.println(badSerializedJson);
JSONObject retrievedJson = (JSONObject) JSONValue.parse(badSerializedJson); JSONObject retrievedJson = (JSONObject) JSONValue.parse(badSerializedJson);
FormSerialization.restoreForm(retrievedJson); ConfigSerialization.restoreConfig(retrievedJson);
} }
protected MForm getMapForm() { protected MConfig getMapConfig() {
List<MInput<?>> inputs; List<MInput<?>> inputs;
MInput input; MInput input;
@ -123,15 +123,15 @@ protected MForm getMapForm() {
input = new MMapInput("Map", false); input = new MMapInput("Map", false);
inputs.add(input); inputs.add(input);
return new MForm("f", inputs); return new MConfig("c", inputs);
} }
/** /**
* Return form with all data types. * Return config with all data types.
* *
* @return * @return
*/ */
protected MForm getForm() { protected MConfig getConfig() {
List<MInput<?>> inputs; List<MInput<?>> inputs;
MInput input; MInput input;
@ -152,6 +152,6 @@ protected MForm getForm() {
input = new MEnumInput("Enum", false, new String[] {"YES", "NO"}); input = new MEnumInput("Enum", false, new String[] {"YES", "NO"});
inputs.add(input); inputs.add(input);
return new MForm("f", inputs); return new MConfig("c", inputs);
} }
} }

View File

@ -0,0 +1,290 @@
/**
* 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.model;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.sqoop.common.SqoopException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Test config utils
*/
public class TestConfigUtils extends TestCase {
public void testConfigs() {
TestConfiguration config = new TestConfiguration();
config.aConfig.a1 = "value";
List<MConfig> configsByInstance = ConfigUtils.toConfigs(config);
assertEquals(getConfigs(), configsByInstance);
assertEquals("value", configsByInstance.get(0).getInputs().get(0).getValue());
List<MConfig> configsByClass = ConfigUtils.toConfigs(TestConfiguration.class);
assertEquals(getConfigs(), configsByClass);
List<MConfig> configsByBoth = ConfigUtils.toConfigs(TestConfiguration.class, config);
assertEquals(getConfigs(), configsByBoth);
assertEquals("value", configsByBoth.get(0).getInputs().get(0).getValue());
}
public void testConfigsMissingAnnotation() {
try {
ConfigUtils.toConfigs(ConfigWithout.class);
} catch(SqoopException ex) {
assertEquals(ModelError.MODEL_003, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testNonUniqueFormNameAttributes() {
try {
ConfigUtils.toConfigs(ConfigurationWithNonUniqueFormNameAttribute.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_012, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testInvalidFormNameAttribute() {
try {
ConfigUtils.toConfigs(ConfigurationWithInvalidFormNameAttribute.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_013, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testInvalidFormNameAttributeLength() {
try {
ConfigUtils.toConfigs(ConfigurationWithInvalidFormNameAttributeLength.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_014, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testFailureOnPrimitiveType() {
PrimitiveConfig config = new PrimitiveConfig();
try {
ConfigUtils.toConfigs(config);
fail("We were expecting exception for unsupported type.");
} catch(SqoopException ex) {
assertEquals(ModelError.MODEL_007, ex.getErrorCode());
}
}
public void testFillValues() {
List<MConfig> configs = getConfigs();
((MStringInput)configs.get(0).getInputs().get(0)).setValue("value");
TestConfiguration config = new TestConfiguration();
ConfigUtils.fromConfigs(configs, config);
assertEquals("value", config.aConfig.a1);
}
public void testFillValuesObjectReuse() {
List<MConfig> configs = getConfigs();
((MStringInput)configs.get(0).getInputs().get(0)).setValue("value");
TestConfiguration config = new TestConfiguration();
config.aConfig.a2 = "x";
config.bConfig.b1 = "y";
ConfigUtils.fromConfigs(configs, config);
assertEquals("value", config.aConfig.a1);
assertNull(config.aConfig.a2);
assertNull(config.bConfig.b2);
assertNull(config.bConfig.b2);
}
public void testJson() {
TestConfiguration config = new TestConfiguration();
config.aConfig.a1 = "A";
config.bConfig.b2 = "B";
config.cConfig.intValue = 4;
config.cConfig.map.put("C", "D");
config.cConfig.enumeration = Enumeration.X;
String json = ConfigUtils.toJson(config);
TestConfiguration targetConfig = new TestConfiguration();
// Old values from should be always removed
targetConfig.aConfig.a2 = "X";
targetConfig.bConfig.b1 = "Y";
// Nulls in configs shouldn't be an issue either
targetConfig.cConfig = null;
ConfigUtils.fillValues(json, targetConfig);
assertEquals("A", targetConfig.aConfig.a1);
assertNull(targetConfig.aConfig.a2);
assertNull(targetConfig.bConfig.b1);
assertEquals("B", targetConfig.bConfig.b2);
assertEquals((Integer)4, targetConfig.cConfig.intValue);
assertEquals(1, targetConfig.cConfig.map.size());
assertTrue(targetConfig.cConfig.map.containsKey("C"));
assertEquals("D", targetConfig.cConfig.map.get("C"));
assertEquals(Enumeration.X, targetConfig.cConfig.enumeration);
}
/**
* Config structure that corresponds to Config class declared below
* @return Config structure
*/
protected List<MConfig> getConfigs() {
List<MConfig> ret = new LinkedList<MConfig>();
List<MInput<?>> inputs;
// Config A
inputs = new LinkedList<MInput<?>>();
inputs.add(new MStringInput("aConfig.a1", false, (short)30));
inputs.add(new MStringInput("aConfig.a2", true, (short)-1));
ret.add(new MConfig("aConfig", inputs));
// Config B
inputs = new LinkedList<MInput<?>>();
inputs.add(new MStringInput("bConfig.b1", false, (short)2));
inputs.add(new MStringInput("bConfig.b2", false, (short)3));
ret.add(new MConfig("bConfig", inputs));
// Config C
inputs = new LinkedList<MInput<?>>();
inputs.add(new MIntegerInput("cConfig.intValue", false));
inputs.add(new MMapInput("cConfig.map", false));
inputs.add(new MEnumInput("cConfig.enumeration", false, new String[]{"X", "Y"}));
ret.add(new MConfig("cConfig", inputs));
return ret;
}
@ConfigurationClass
public static class ConfigurationWithNonUniqueFormNameAttribute {
public ConfigurationWithNonUniqueFormNameAttribute() {
aForm = new InvalidConfig();
bForm = new InvalidConfig();
}
@Config(name = "sameName")
InvalidConfig aForm;
@Config(name = "sameName")
InvalidConfig bForm;
}
@ConfigurationClass
public static class ConfigurationWithInvalidFormNameAttribute {
public ConfigurationWithInvalidFormNameAttribute() {
invalidForm = new InvalidConfig();
}
@Config(name = "#_form")
InvalidConfig invalidForm;
}
@ConfigurationClass
public static class ConfigurationWithInvalidFormNameAttributeLength {
public ConfigurationWithInvalidFormNameAttributeLength() {
invalidLengthForm = new InvalidConfig();
}
@Config(name = "longest_form_more_than_30_characers")
InvalidConfig invalidLengthForm;
}
@ConfigurationClass
public static class TestConfiguration {
public TestConfiguration() {
aConfig = new AConfig();
bConfig = new BConfig();
cConfig = new CConfig();
}
@Config AConfig aConfig;
@Config BConfig bConfig;
@Config CConfig cConfig;
}
@ConfigurationClass
public static class PrimitiveConfig {
@Config DConfig dConfig;
}
@ConfigClass
public static class AConfig {
@Input(size = 30) String a1;
@Input(sensitive = true) String a2;
}
@ConfigClass
public static class BConfig {
@Input(size = 2) String b1;
@Input(size = 3) String b2;
}
@ConfigClass
public static class CConfig {
@Input Integer intValue;
@Input Map<String, String> map;
@Input Enumeration enumeration;
public CConfig() {
map = new HashMap<String, String>();
}
}
@ConfigClass
public static class InvalidConfig {
}
@ConfigClass
public static class DConfig {
@Input int value;
}
public static class ConfigWithout {
}
enum Enumeration {
X,
Y,
}
}

View File

@ -1,295 +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.model;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.Validation;
import org.junit.Test;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
/**
* Test form utils
*/
public class TestFormUtils {
@Test
public void testToForms() {
Config config = new Config();
config.aForm.a1 = "value";
List<MForm> formsByInstance = FormUtils.toForms(config);
assertEquals(getForms(), formsByInstance);
assertEquals("value", formsByInstance.get(0).getInputs().get(0).getValue());
List<MForm> formsByClass = FormUtils.toForms(Config.class);
assertEquals(getForms(), formsByClass);
List<MForm> formsByBoth = FormUtils.toForms(Config.class, config);
assertEquals(getForms(), formsByBoth);
assertEquals("value", formsByBoth.get(0).getInputs().get(0).getValue());
}
@Test
public void testToFormsMissingAnnotation() {
try {
FormUtils.toForms(ConfigWithout.class);
} catch(SqoopException ex) {
assertEquals(ModelError.MODEL_003, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testNonUniqueFormNameAttributes() {
try {
FormUtils.toForms(ConfigurationWithNonUniqueFormNameAttribute.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_012, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testInvalidFormNameAttribute() {
try {
FormUtils.toForms(ConfigurationWithInvalidFormNameAttribute.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_013, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
public void testInvalidFormNameAttributeLength() {
try {
FormUtils.toForms(ConfigurationWithInvalidFormNameAttributeLength.class);
} catch (SqoopException ex) {
assertEquals(ModelError.MODEL_014, ex.getErrorCode());
return;
}
fail("Correct exception wasn't thrown");
}
@Test
public void testFailureOnPrimitiveType() {
PrimitiveConfig config = new PrimitiveConfig();
try {
FormUtils.toForms(config);
fail("We were expecting exception for unsupported type.");
} catch(SqoopException ex) {
assertEquals(ModelError.MODEL_007, ex.getErrorCode());
}
}
@Test
public void testFillValues() {
List<MForm> forms = getForms();
((MStringInput)forms.get(0).getInputs().get(0)).setValue("value");
Config config = new Config();
FormUtils.fromForms(forms, config);
assertEquals("value", config.aForm.a1);
}
@Test
public void testFillValuesObjectReuse() {
List<MForm> forms = getForms();
((MStringInput)forms.get(0).getInputs().get(0)).setValue("value");
Config config = new Config();
config.aForm.a2 = "x";
config.bForm.b1 = "y";
FormUtils.fromForms(forms, config);
assertEquals("value", config.aForm.a1);
assertNull(config.aForm.a2);
assertNull(config.bForm.b2);
assertNull(config.bForm.b2);
}
@Test
public void testJson() {
Config config = new Config();
config.aForm.a1 = "A";
config.bForm.b2 = "B";
config.cForm.intValue = 4;
config.cForm.map.put("C", "D");
config.cForm.enumeration = Enumeration.X;
String json = FormUtils.toJson(config);
Config targetConfig = new Config();
// Old values from should be always removed
targetConfig.aForm.a2 = "X";
targetConfig.bForm.b1 = "Y";
// Nulls in forms shouldn't be an issue either
targetConfig.cForm = null;
FormUtils.fillValues(json, targetConfig);
assertEquals("A", targetConfig.aForm.a1);
assertNull(targetConfig.aForm.a2);
assertNull(targetConfig.bForm.b1);
assertEquals("B", targetConfig.bForm.b2);
assertEquals((Integer)4, targetConfig.cForm.intValue);
assertEquals(1, targetConfig.cForm.map.size());
assertTrue(targetConfig.cForm.map.containsKey("C"));
assertEquals("D", targetConfig.cForm.map.get("C"));
assertEquals(Enumeration.X, targetConfig.cForm.enumeration);
}
/**
* Form structure that corresponds to Config class declared below
* @return Form structure
*/
protected List<MForm> getForms() {
List<MForm> ret = new LinkedList<MForm>();
List<MInput<?>> inputs;
// Form A
inputs = new LinkedList<MInput<?>>();
inputs.add(new MStringInput("aForm.a1", false, (short)30));
inputs.add(new MStringInput("aForm.a2", true, (short)-1));
ret.add(new MForm("aForm", inputs));
// Form B
inputs = new LinkedList<MInput<?>>();
inputs.add(new MStringInput("bForm.b1", false, (short)2));
inputs.add(new MStringInput("bForm.b2", false, (short)3));
ret.add(new MForm("bForm", inputs));
// Form C
inputs = new LinkedList<MInput<?>>();
inputs.add(new MIntegerInput("cForm.intValue", false));
inputs.add(new MMapInput("cForm.map", false));
inputs.add(new MEnumInput("cForm.enumeration", false, new String[]{"X", "Y"}));
ret.add(new MForm("cForm", inputs));
return ret;
}
@ConfigurationClass
public static class ConfigurationWithNonUniqueFormNameAttribute {
public ConfigurationWithNonUniqueFormNameAttribute() {
aForm = new InvalidForm();
bForm = new InvalidForm();
}
@Form(name = "sameName")
InvalidForm aForm;
@Form(name = "sameName")
InvalidForm bForm;
}
@ConfigurationClass
public static class ConfigurationWithInvalidFormNameAttribute {
public ConfigurationWithInvalidFormNameAttribute() {
invalidForm = new InvalidForm();
}
@Form(name = "#_form")
InvalidForm invalidForm;
}
@ConfigurationClass
public static class ConfigurationWithInvalidFormNameAttributeLength {
public ConfigurationWithInvalidFormNameAttributeLength() {
invalidLengthForm = new InvalidForm();
}
@Form(name = "longest_form_more_than_30_characers")
InvalidForm invalidLengthForm;
}
@ConfigurationClass
public static class Config {
public Config() {
aForm = new AForm();
bForm = new BForm();
cForm = new CForm();
}
@Form AForm aForm;
@Form BForm bForm;
@Form CForm cForm;
}
@ConfigurationClass
public static class PrimitiveConfig {
@Form DForm dForm;
}
@FormClass
public static class AForm {
@Input(size = 30) String a1;
@Input(sensitive = true) String a2;
}
@FormClass
public static class BForm {
@Input(size = 2) String b1;
@Input(size = 3) String b2;
}
@FormClass
public static class CForm {
@Input Integer intValue;
@Input Map<String, String> map;
@Input Enumeration enumeration;
public CForm() {
map = new HashMap<String, String>();
}
}
@FormClass
public static class InvalidForm {
}
@FormClass
public static class DForm {
@Input int value;
}
public static class ConfigWithout {
}
enum Enumeration {
X,
Y,
}
}

View File

@ -35,14 +35,13 @@ public class TestMAccountableEntity {
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
MForm form = new MForm("FORMNAME", list); MConfig config = new MConfig("CONFIGNAME", list);
forms.add(form); configs.add(config);
MAccountableEntity link = new MLink(123l, new MConnectionForms( MAccountableEntity link = new MLink(123l, new MLinkConfig(configs));
forms), new MConnectionForms(forms));
// Initially creation date and last update date is same // Initially creation date and last update date is same
assertEquals(link.getCreationDate(), link.getLastUpdateDate()); assertEquals(link.getCreationDate(), link.getLastUpdateDate());
Date testCreationDate = new Date(); Date testCreationDate = new Date();

View File

@ -24,10 +24,7 @@
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** public class TestMConfig {
* Test class for org.apache.sqoop.model.MForm
*/
public class TestMForm {
/** /**
* Test for initialization * Test for initialization
@ -40,10 +37,10 @@ public void testInitialization() {
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input1); list.add(input1);
list.add(input2); list.add(input2);
MForm mform = new MForm("form", list); MConfig mConfig = new MConfig("config", list);
assertEquals("form", mform.getName()); assertEquals("config", mConfig.getName());
assertEquals(2, mform.getInputs().size()); assertEquals(2, mConfig.getInputs().size());
} }
/** /**
@ -56,23 +53,23 @@ public void testEquals() {
List<MInput<?>> list1 = new ArrayList<MInput<?>>(); List<MInput<?>> list1 = new ArrayList<MInput<?>>();
list1.add(input1); list1.add(input1);
list1.add(input2); list1.add(input2);
MForm mform1 = new MForm("form", list1); MConfig mform1 = new MConfig("config", list1);
MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1", false); MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1", false);
MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2", false); MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2", false);
List<MInput<?>> list2 = new ArrayList<MInput<?>>(); List<MInput<?>> list2 = new ArrayList<MInput<?>>();
list2.add(input3); list2.add(input3);
list2.add(input4); list2.add(input4);
MForm mform2 = new MForm("form", list2); MConfig mform2 = new MConfig("config", list2);
assertEquals(mform2, mform1); assertEquals(mform2, mform1);
} }
@Test @Test
public void testGetInputs() { public void testGetInputs() {
MIntegerInput intInput = new MIntegerInput("Form.A", false); MIntegerInput intInput = new MIntegerInput("Config.A", false);
MMapInput mapInput = new MMapInput("Form.B", false); MMapInput mapInput = new MMapInput("Config.B", false);
MStringInput stringInput = new MStringInput("Form.C", false, (short)3); MStringInput stringInput = new MStringInput("Config.C", false, (short)3);
MEnumInput enumInput = new MEnumInput("Form.D", false, new String[] {"I", "V"}); MEnumInput enumInput = new MEnumInput("Config.D", false, new String[] {"I", "V"});
List<MInput<?>> inputs = new ArrayList<MInput<?>>(); List<MInput<?>> inputs = new ArrayList<MInput<?>>();
inputs.add(intInput); inputs.add(intInput);
@ -80,10 +77,10 @@ public void testGetInputs() {
inputs.add(stringInput); inputs.add(stringInput);
inputs.add(enumInput); inputs.add(enumInput);
MForm form = new MForm("Form", inputs); MConfig config = new MConfig("Config", inputs);
assertEquals(intInput, form.getIntegerInput("Form.A")); assertEquals(intInput, config.getIntegerInput("Config.A"));
assertEquals(mapInput, form.getMapInput("Form.B")); assertEquals(mapInput, config.getMapInput("Config.B"));
assertEquals(stringInput, form.getStringInput("Form.C")); assertEquals(stringInput, config.getStringInput("Config.C"));
assertEquals(enumInput, form.getEnumInput("Form.D")); assertEquals(enumInput, config.getEnumInput("Config.D"));
} }
} }

View File

@ -25,34 +25,31 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** public class TestMConfigList {
*
*/
public class TestMFormList {
@Test @Test
public void testGetInputs() { public void testGetInputs() {
List<MForm> forms = new LinkedList<MForm>(); List<MConfig> configs = new LinkedList<MConfig>();
MIntegerInput intInput = new MIntegerInput("Form1.A", false); MIntegerInput intInput = new MIntegerInput("Config1.A", false);
MMapInput mapInput = new MMapInput("Form1.B", false); MMapInput mapInput = new MMapInput("Config1.B", false);
List<MInput<?>> inputs = new ArrayList<MInput<?>>(); List<MInput<?>> inputs = new ArrayList<MInput<?>>();
inputs.add(intInput); inputs.add(intInput);
inputs.add(mapInput); inputs.add(mapInput);
forms.add(new MForm("Form1", inputs)); configs.add(new MConfig("Config1", inputs));
MStringInput stringInput = new MStringInput("Form2.C", false, (short)3); MStringInput stringInput = new MStringInput("Config2.C", false, (short)3);
MEnumInput enumInput = new MEnumInput("Form2.D", false, new String[] {"I", "V"}); MEnumInput enumInput = new MEnumInput("Config2.D", false, new String[] {"I", "V"});
inputs = new ArrayList<MInput<?>>(); inputs = new ArrayList<MInput<?>>();
inputs.add(stringInput); inputs.add(stringInput);
inputs.add(enumInput); inputs.add(enumInput);
forms.add(new MForm("Form2", inputs)); configs.add(new MConfig("Config2", inputs));
MFormList form = new MFormList(forms); MConfigList config = new MConfigList(configs);
assertEquals(intInput, form.getIntegerInput("Form1.A")); assertEquals(intInput, config.getIntegerInput("Config1.A"));
assertEquals(mapInput, form.getMapInput("Form1.B")); assertEquals(mapInput, config.getMapInput("Config1.B"));
assertEquals(stringInput, form.getStringInput("Form2.C")); assertEquals(stringInput, config.getStringInput("Config2.C"));
assertEquals(enumInput, form.getEnumInput("Form2.D")); assertEquals(enumInput, config.getEnumInput("Config2.D"));
} }
} }

View File

@ -17,6 +17,13 @@
*/ */
package org.apache.sqoop.model; package org.apache.sqoop.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -24,39 +31,34 @@
import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.Direction;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/**
* Test class for org.apache.sqoop.model.TestMConnector
*/
public class TestMConnector { public class TestMConnector {
private MConnector createConnector(List<Direction> supportedDirections) { private MConnector createConnector(List<Direction> supportedDirections) {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); MIntegerInput inputs = new MIntegerInput("INTEGER-INPUT", false);
input.setValue(100); inputs.setValue(100);
MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20);
strInput.setValue("TEST-VALUE"); strInput.setValue("TEST-VALUE");
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(inputs);
list.add(strInput); list.add(strInput);
MForm form = new MForm("FORMNAME", list); MConfig config = new MConfig("CONFIGNAME", list);
forms.add(form); configs.add(config);
MConnectionForms connectionForms1 = new MConnectionForms(forms); MLinkConfig linkConfig = new MLinkConfig(configs);
MJobForms fromForm = null; MFromConfig fromConfig = null;
MJobForms toForm = null; MToConfig toConfig = null;
if (supportedDirections.contains(Direction.FROM)) { if (supportedDirections.contains(Direction.FROM)) {
fromForm = new MJobForms(forms); fromConfig = new MFromConfig(configs);
} }
if (supportedDirections.contains(Direction.TO)) { if (supportedDirections.contains(Direction.TO)) {
toForm = new MJobForms(forms); toConfig = new MToConfig(configs);
} }
return new MConnector("NAME", "CLASSNAME", "1.0", return new MConnector("NAME", "CLASSNAME", "1.0",
connectionForms1, fromForm, toForm); linkConfig, fromConfig, toConfig);
} }
/** /**
@ -64,32 +66,32 @@ private MConnector createConnector(List<Direction> supportedDirections) {
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
List<MForm> fromJobForms = new ArrayList<MForm>(); List<MConfig> fromJobConfig = new ArrayList<MConfig>();
List<MForm> toJobForms = new ArrayList<MForm>(); List<MConfig> toJobConfig = new ArrayList<MConfig>();
MConnectionForms connectionForms1 = new MConnectionForms(fromJobForms); MLinkConfig linkConfig = new MLinkConfig(fromJobConfig);
MJobForms fromJobForm1 = new MJobForms(fromJobForms); MFromConfig fromConfig1 = new MFromConfig(fromJobConfig);
MJobForms toJobForm1 = new MJobForms(toJobForms); MToConfig toConfig1 = new MToConfig(toJobConfig);
MConnector connector1 = new MConnector("NAME", "CLASSNAME", "1.0", MConnector connector1 = new MConnector("NAME", "CLASSNAME", "1.0",
connectionForms1, fromJobForm1, toJobForm1); linkConfig, fromConfig1, toConfig1);
assertEquals("NAME", connector1.getUniqueName()); assertEquals("NAME", connector1.getUniqueName());
assertEquals("CLASSNAME", connector1.getClassName()); assertEquals("CLASSNAME", connector1.getClassName());
assertEquals("1.0", connector1.getVersion()); assertEquals("1.0", connector1.getVersion());
MConnector connector2 = new MConnector("NAME", "CLASSNAME", "1.0", MConnector connector2 = new MConnector("NAME", "CLASSNAME", "1.0",
connectionForms1, fromJobForm1, toJobForm1); linkConfig, fromConfig1, toConfig1);
assertEquals(connector2, connector1); assertEquals(connector2, connector1);
MConnector connector3 = new MConnector("NAME1", "CLASSNAME", "2.0", MConnector connector3 = new MConnector("NAME1", "CLASSNAME", "2.0",
connectionForms1, fromJobForm1, toJobForm1); linkConfig, fromConfig1, toConfig1);
assertFalse(connector1.equals(connector3)); assertFalse(connector1.equals(connector3));
try { try {
connector1 = new MConnector(null, "CLASSNAME", "1.0", connectionForms1, connector1 = new MConnector(null, "CLASSNAME", "1.0", linkConfig,
fromJobForm1, toJobForm1); // Expecting null pointer exception fromConfig1, toConfig1); // Expecting null pointer exception
} catch (NullPointerException e) { } catch (NullPointerException e) {
assertTrue(true); assertTrue(true);
} }
try { try {
connector1 = new MConnector("NAME", null, "1.0", connectionForms1, connector1 = new MConnector("NAME", null, "1.0", linkConfig,
fromJobForm1, toJobForm1); // Expecting null pointer exception fromConfig1, toConfig1); // Expecting null pointer exception
} catch (NullPointerException e) { } catch (NullPointerException e) {
assertTrue(true); assertTrue(true);
} }
@ -97,48 +99,48 @@ public void testInitialization() {
@Test @Test
public void testClone() { public void testClone() {
MConnector connector1 = createConnector(Arrays.asList(Direction.FROM, Direction.TO)); MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
assertEquals("NAME", connector1.getUniqueName()); assertEquals("NAME", connector.getUniqueName());
assertEquals("CLASSNAME", connector1.getClassName()); assertEquals("CLASSNAME", connector.getClassName());
assertEquals("1.0", connector1.getVersion()); assertEquals("1.0", connector.getVersion());
//Clone with values. Checking values copying after the cloning. But form values will be null //Clone with values. Checking values copying after the cloning. But config values will be null
MConnector clone1 = connector1.clone(true); MConnector cloneConnector1 = connector.clone(true);
assertEquals("NAME", clone1.getUniqueName()); assertEquals("NAME", cloneConnector1.getUniqueName());
assertEquals("CLASSNAME", clone1.getClassName()); assertEquals("CLASSNAME", cloneConnector1.getClassName());
assertEquals("1.0", clone1.getVersion()); assertEquals("1.0", cloneConnector1.getVersion());
MForm clonedForm1 = clone1.getConnectionForms().getForms().get(0); MConfig clonedLinkConfig = cloneConnector1.getLinkConfig().getConfigs().get(0);
assertNull(clonedForm1.getInputs().get(0).getValue()); assertNull(clonedLinkConfig.getInputs().get(0).getValue());
assertNull(clonedForm1.getInputs().get(1).getValue()); assertNull(clonedLinkConfig.getInputs().get(1).getValue());
MForm clonedForm2 = clone1.getJobForms(Direction.FROM).getForms().get(0); MConfig clonedFromConfig = cloneConnector1.getConfig(Direction.FROM).getConfigs().get(0);
assertNull(clonedForm2.getInputs().get(0).getValue()); assertNull(clonedFromConfig.getInputs().get(0).getValue());
assertNull(clonedForm2.getInputs().get(1).getValue()); assertNull(clonedFromConfig.getInputs().get(1).getValue());
MForm clonedForm3 = clone1.getJobForms(Direction.TO).getForms().get(0); MConfig clonedToConfig = cloneConnector1.getConfig(Direction.TO).getConfigs().get(0);
assertNull(clonedForm3.getInputs().get(0).getValue()); assertNull(clonedToConfig.getInputs().get(0).getValue());
assertNull(clonedForm3.getInputs().get(1).getValue()); assertNull(clonedToConfig.getInputs().get(1).getValue());
//Clone without values. Inputs value will be null after cloning. //Clone without values. Inputs value will be null after cloning.
MConnector clone2 = connector1.clone(false); MConnector clonedConnector2 = connector.clone(false);
clonedForm1 = clone2.getConnectionForms().getForms().get(0); clonedLinkConfig = clonedConnector2.getLinkConfig().getConfigs().get(0);
assertNull(clonedForm1.getInputs().get(0).getValue()); assertNull(clonedLinkConfig.getInputs().get(0).getValue());
assertNull(clonedForm1.getInputs().get(1).getValue()); assertNull(clonedLinkConfig.getInputs().get(1).getValue());
clonedForm2 = clone2.getJobForms(Direction.FROM).getForms().get(0); clonedFromConfig = clonedConnector2.getConfig(Direction.FROM).getConfigs().get(0);
assertNull(clonedForm2.getInputs().get(0).getValue()); assertNull(clonedFromConfig.getInputs().get(0).getValue());
assertNull(clonedForm2.getInputs().get(1).getValue()); assertNull(clonedFromConfig.getInputs().get(1).getValue());
clonedForm3 = clone2.getJobForms(Direction.TO).getForms().get(0); clonedToConfig = clonedConnector2.getConfig(Direction.TO).getConfigs().get(0);
assertNull(clonedForm3.getInputs().get(0).getValue()); assertNull(clonedToConfig.getInputs().get(0).getValue());
assertNull(clonedForm3.getInputs().get(1).getValue()); assertNull(clonedToConfig.getInputs().get(1).getValue());
} }
@Test @Test
public void testFromDirection() { public void testFromDirection() {
MConnector connector = createConnector(Arrays.asList(Direction.FROM)); MConnector connector = createConnector(Arrays.asList(Direction.FROM));
// Clone should clone only one job form. // Clone should clone only one job config.
MConnector clone = connector.clone(true); MConnector clone = connector.clone(true);
assertNotNull(clone.getJobForms(Direction.FROM)); assertNotNull(clone.getFromConfig());
assertNull(clone.getJobForms(Direction.TO)); assertNull(clone.getToConfig());
assertEquals(connector, clone); assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString()); assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode()); assertNotEquals(connector.hashCode(), clone.hashCode());
@ -148,10 +150,10 @@ public void testFromDirection() {
public void testToDirection() { public void testToDirection() {
MConnector connector = createConnector(Arrays.asList(Direction.TO)); MConnector connector = createConnector(Arrays.asList(Direction.TO));
// Clone should clone only one job form. // Clone should clone only one job config.
MConnector clone = connector.clone(true); MConnector clone = connector.clone(true);
assertNull(clone.getJobForms(Direction.FROM)); assertNull(clone.getFromConfig());
assertNotNull(clone.getJobForms(Direction.TO)); assertNotNull(clone.getToConfig());
assertEquals(connector, clone); assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString()); assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode()); assertNotEquals(connector.hashCode(), clone.hashCode());
@ -161,10 +163,10 @@ public void testToDirection() {
public void testNoDirection() { public void testNoDirection() {
MConnector connector = createConnector(Arrays.asList(new Direction[0])); MConnector connector = createConnector(Arrays.asList(new Direction[0]));
// Clone should clone only one job form. // Clone should clone only one job config.
MConnector clone = connector.clone(true); MConnector clone = connector.clone(true);
assertNull(clone.getJobForms(Direction.FROM)); assertNull(clone.getFromConfig());
assertNull(clone.getJobForms(Direction.TO)); assertNull(clone.getToConfig());
assertEquals(connector, clone); assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString()); assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode()); assertNotEquals(connector.hashCode(), clone.hashCode());
@ -174,10 +176,10 @@ public void testNoDirection() {
public void testBothDirections() { public void testBothDirections() {
MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO)); MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
// Clone should clone only one job form. // Clone should clone only one job config.
MConnector clone = connector.clone(true); MConnector clone = connector.clone(true);
assertNotNull(clone.getJobForms(Direction.FROM)); assertNotNull(clone.getFromConfig());
assertNotNull(clone.getJobForms(Direction.TO)); assertNotNull(clone.getToConfig());
assertEquals(connector, clone); assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString()); assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode()); assertNotEquals(connector.hashCode(), clone.hashCode());

View File

@ -0,0 +1,40 @@
/**
* 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.model;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.apache.sqoop.json.DriverBean;
import org.junit.Test;
public class TestMDriver {
@Test
public void testDriver() {
List<MConfig> driverConfig = new ArrayList<MConfig>();
driverConfig.add(new MConfig("driver-test", new ArrayList<MInput<?>>()));
MDriverConfig mDriverConfig = new MDriverConfig(driverConfig);
MDriver driver = new MDriver(mDriverConfig, DriverBean.CURRENT_DRIVER_VERSION);
assertEquals(1, driver.getDriverConfig().getConfigs().size());
assertEquals("driver-test", driver.getDriverConfig().getConfigs().get(0).getName());
}
}

View File

@ -1,47 +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.model;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
/**
*
*/
public class TestMDriverConfig {
@Test
public void testForms() {
List<MForm> connectionFormList = new ArrayList<MForm>();
List<MForm> jobFormList = new ArrayList<MForm>();
connectionFormList.add(new MForm("connection-test", new ArrayList<MInput<?>>()));
jobFormList.add(new MForm("job-test", new ArrayList<MInput<?>>()));
MConnectionForms connectionForms = new MConnectionForms(connectionFormList);
MJobForms jobForms = new MJobForms(jobFormList);
MDriverConfig driver = new MDriverConfig(connectionForms, jobForms, "1");
assertEquals(1, driver.getJobForms().getForms().size());
assertEquals("job-test", driver.getJobForms().getForms().get(0).getName());
assertEquals(1, driver.getConnectionForms().getForms().size());
assertEquals("connection-test", driver.getConnectionForms().getForms().get(0).getName());
}
}

View File

@ -17,17 +17,15 @@
*/ */
package org.apache.sqoop.model; package org.apache.sqoop.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.Direction;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/**
* Test class for org.apache.sqoop.model.MJob
*/
public class TestMJob { public class TestMJob {
/** /**
* Test class for initialization * Test class for initialization
@ -40,9 +38,9 @@ public void testInitialization() {
assertEquals(456l, job.getConnectorId(Direction.TO)); assertEquals(456l, job.getConnectorId(Direction.TO));
assertEquals("Buffy", job.getCreationUser()); assertEquals("Buffy", job.getCreationUser());
assertEquals("Vampire", job.getName()); assertEquals("Vampire", job.getName());
assertEquals(fromForms(), job.getConnectorPart(Direction.FROM)); assertEquals(fromConfig(), job.getJobConfig(Direction.FROM));
assertEquals(toForms(), job.getConnectorPart(Direction.TO)); assertEquals(toConfig(), job.getJobConfig(Direction.TO));
assertEquals(frameworkForms(), job.getFrameworkPart()); assertEquals(driverConfig(), job.getDriverConfig());
// Test copy constructor // Test copy constructor
MJob copy = new MJob(job); MJob copy = new MJob(job);
@ -50,19 +48,19 @@ public void testInitialization() {
assertEquals(456l, copy.getConnectorId(Direction.TO)); assertEquals(456l, copy.getConnectorId(Direction.TO));
assertEquals("Buffy", copy.getCreationUser()); assertEquals("Buffy", copy.getCreationUser());
assertEquals("Vampire", copy.getName()); assertEquals("Vampire", copy.getName());
assertEquals(fromForms(), copy.getConnectorPart(Direction.FROM)); assertEquals(fromConfig(), copy.getJobConfig(Direction.FROM));
assertEquals(toForms(), copy.getConnectorPart(Direction.TO)); assertEquals(toConfig(), copy.getJobConfig(Direction.TO));
assertEquals(frameworkForms(), copy.getFrameworkPart()); assertEquals(driverConfig(), copy.getDriverConfig());
// Test constructor for metadata upgrade (the order of forms is different) // Test constructor for metadata upgrade (the order of configs is different)
MJob upgradeCopy = new MJob(job, fromForms(), toForms(), frameworkForms()); MJob upgradeCopy = new MJob(job, fromConfig(), toConfig(), driverConfig());
assertEquals(123l, upgradeCopy.getConnectorId(Direction.FROM)); assertEquals(123l, upgradeCopy.getConnectorId(Direction.FROM));
assertEquals(456l, upgradeCopy.getConnectorId(Direction.TO)); assertEquals(456l, upgradeCopy.getConnectorId(Direction.TO));
assertEquals("Buffy", upgradeCopy.getCreationUser()); assertEquals("Buffy", upgradeCopy.getCreationUser());
assertEquals("Vampire", upgradeCopy.getName()); assertEquals("Vampire", upgradeCopy.getName());
assertEquals(fromForms(), upgradeCopy.getConnectorPart(Direction.FROM)); assertEquals(fromConfig(), upgradeCopy.getJobConfig(Direction.FROM));
assertEquals(toForms(), upgradeCopy.getConnectorPart(Direction.TO)); assertEquals(toConfig(), upgradeCopy.getJobConfig(Direction.TO));
assertEquals(frameworkForms(), upgradeCopy.getFrameworkPart()); assertEquals(driverConfig(), upgradeCopy.getDriverConfig());
} }
@Test @Test
@ -70,42 +68,42 @@ public void testClone() {
MJob job = job(); MJob job = job();
// Clone without value // Clone without value
MJob withoutValue = job.clone(false); MJob withoutJobValue = job.clone(false);
assertEquals(job, withoutValue); assertEquals(job, withoutJobValue);
assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutValue.getPersistenceId()); assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutJobValue.getPersistenceId());
assertNull(withoutValue.getName()); assertNull(withoutJobValue.getName());
assertNull(withoutValue.getCreationUser()); assertNull(withoutJobValue.getCreationUser());
assertEquals(fromForms(), withoutValue.getConnectorPart(Direction.FROM)); assertEquals(fromConfig(), withoutJobValue.getJobConfig(Direction.FROM));
assertEquals(toForms(), withoutValue.getConnectorPart(Direction.TO)); assertEquals(toConfig(), withoutJobValue.getJobConfig(Direction.TO));
assertEquals(frameworkForms(), withoutValue.getFrameworkPart()); assertEquals(driverConfig(), withoutJobValue.getDriverConfig());
assertNull(withoutValue.getConnectorPart(Direction.FROM) assertNull(withoutJobValue.getJobConfig(Direction.FROM)
.getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); .getConfig("CONFIGFROMNAME").getInput("INTEGER-INPUT").getValue());
assertNull(withoutValue.getConnectorPart(Direction.FROM) assertNull(withoutJobValue.getJobConfig(Direction.FROM)
.getForm("FORMNAME").getInput("STRING-INPUT").getValue()); .getConfig("CONFIGFROMNAME").getInput("STRING-INPUT").getValue());
// Clone with value // Clone with value
MJob withValue = job.clone(true); MJob withJobValue = job.clone(true);
assertEquals(job, withValue); assertEquals(job, withJobValue);
assertEquals(job.getPersistenceId(), withValue.getPersistenceId()); assertEquals(job.getPersistenceId(), withJobValue.getPersistenceId());
assertEquals(job.getName(), withValue.getName()); assertEquals(job.getName(), withJobValue.getName());
assertEquals(job.getCreationUser(), withValue.getCreationUser()); assertEquals(job.getCreationUser(), withJobValue.getCreationUser());
assertEquals(fromForms(), withValue.getConnectorPart(Direction.FROM)); assertEquals(fromConfig(), withJobValue.getJobConfig(Direction.FROM));
assertEquals(toForms(), withValue.getConnectorPart(Direction.TO)); assertEquals(toConfig(), withJobValue.getJobConfig(Direction.TO));
assertEquals(frameworkForms(), withValue.getFrameworkPart()); assertEquals(driverConfig(), withJobValue.getDriverConfig());
assertEquals(100, withValue.getConnectorPart(Direction.FROM) assertEquals(100, withJobValue.getJobConfig(Direction.FROM)
.getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); .getConfig("CONFIGFROMNAME").getInput("INTEGER-INPUT").getValue());
assertEquals("TEST-VALUE", withValue.getConnectorPart(Direction.FROM) assertEquals("TEST-VALUE", withJobValue.getJobConfig(Direction.FROM)
.getForm("FORMNAME").getInput("STRING-INPUT").getValue()); } .getConfig("CONFIGFROMNAME").getInput("STRING-INPUT").getValue()); }
private MJob job() { private MJob job() {
MJob job = new MJob(123l, 456l, 1L, 2L, fromForms(), toForms(), frameworkForms()); MJob job = new MJob(123l, 456l, 1L, 2L, fromConfig(), toConfig(), driverConfig());
job.setName("Vampire"); job.setName("Vampire");
job.setCreationUser("Buffy"); job.setCreationUser("Buffy");
return job; return job;
} }
private MJobForms fromForms() { private MFromConfig fromConfig() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
input.setValue(100); input.setValue(100);
MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20);
@ -113,28 +111,28 @@ private MJobForms fromForms() {
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
list.add(strInput); list.add(strInput);
MForm form = new MForm("FORMNAME", list); MConfig config = new MConfig("CONFIGFROMNAME", list);
forms.add(form); configs.add(config);
return new MJobForms(forms); return new MFromConfig(configs);
} }
private MJobForms toForms() { private MToConfig toConfig() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MMapInput input = new MMapInput("MAP-INPUT", false); MMapInput input = new MMapInput("MAP-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
MForm form = new MForm("form", list); MConfig config = new MConfig("CONFIGTONAME", list);
forms.add(form); configs.add(config);
return new MJobForms(forms); return new MToConfig(configs);
} }
private MJobForms frameworkForms() { private MDriverConfig driverConfig() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MMapInput input = new MMapInput("MAP-INPUT", false); MMapInput input = new MMapInput("MAP-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
MForm form = new MForm("form", list); MConfig config = new MConfig("CONFIGDRIVERNAME", list);
forms.add(form); configs.add(config);
return new MJobForms(forms); return new MDriverConfig(configs);
} }
} }

View File

@ -24,23 +24,19 @@
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** public class TestMJobConfig {
* Test class for org.apache.sqoop.model.MJobForms
*/
public class TestMJobForms {
/** /**
* Test for class initialization and values * Test for class initialization and values
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MJobForms jobform1 = new MJobForms(forms); MFromConfig fromJobConfig = new MFromConfig(configs);
List<MForm> forms2 = new ArrayList<MForm>(); List<MConfig> configs2 = new ArrayList<MConfig>();
MJobForms jobform2 = new MJobForms(forms2); MFromConfig fromJobConfig2 = new MFromConfig(configs2);
assertEquals(jobform2, jobform1); assertEquals(fromJobConfig2, fromJobConfig);
// Add a form to list for checking not equals MConfig c = new MConfig("test", null);
MForm m = new MForm("test", null); configs2.add(c);
forms2.add(m); assertFalse(fromJobConfig.equals(fromJobConfig2));
assertFalse(jobform1.equals(jobform2));
} }
} }

View File

@ -24,9 +24,6 @@
import static org.junit.Assert.*; import static org.junit.Assert.*;
/**
* Test class for org.apache.sqoop.model.MConnection
*/
public class TestMLink { public class TestMLink {
/** /**
@ -39,8 +36,7 @@ public void testInitialization() {
assertEquals(123l, link.getConnectorId()); assertEquals(123l, link.getConnectorId());
assertEquals("Vampire", link.getName()); assertEquals("Vampire", link.getName());
assertEquals("Buffy", link.getCreationUser()); assertEquals("Buffy", link.getCreationUser());
assertEquals(forms1(), link.getConnectorPart()); assertEquals(linkConfig(), link.getConnectorLinkConfig());
assertEquals(forms2(), link.getFrameworkPart());
// Test copy constructor // Test copy constructor
MLink copy = new MLink(link); MLink copy = new MLink(link);
@ -48,17 +44,7 @@ public void testInitialization() {
assertEquals("Vampire", copy.getName()); assertEquals("Vampire", copy.getName());
assertEquals("Buffy", copy.getCreationUser()); assertEquals("Buffy", copy.getCreationUser());
assertEquals(link.getCreationDate(), copy.getCreationDate()); assertEquals(link.getCreationDate(), copy.getCreationDate());
assertEquals(forms1(), copy.getConnectorPart()); assertEquals(linkConfig(), copy.getConnectorLinkConfig());
assertEquals(forms2(), copy.getFrameworkPart());
// Test constructor for metadata upgrade (the order of forms is different)
MLink upgradeCopy = new MLink(link, forms2(), forms1());
assertEquals(123l, upgradeCopy.getConnectorId());
assertEquals("Vampire", upgradeCopy.getName());
assertEquals("Buffy", upgradeCopy.getCreationUser());
assertEquals(link.getCreationDate(), upgradeCopy.getCreationDate());
assertEquals(forms2(), upgradeCopy.getConnectorPart());
assertEquals(forms1(), upgradeCopy.getFrameworkPart());
} }
@Test @Test
@ -66,37 +52,35 @@ public void testClone() {
MLink link = link(); MLink link = link();
// Clone without value // Clone without value
MLink withoutValue = link.clone(false); MLink withoutLinkValue = link.clone(false);
assertEquals(link, withoutValue); assertEquals(link, withoutLinkValue);
assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutValue.getPersistenceId()); assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutLinkValue.getPersistenceId());
assertNull(withoutValue.getName()); assertNull(withoutLinkValue.getName());
assertNull(withoutValue.getCreationUser()); assertNull(withoutLinkValue.getCreationUser());
assertEquals(forms1(), withoutValue.getConnectorPart()); assertEquals(linkConfig(), withoutLinkValue.getConnectorLinkConfig());
assertEquals(forms2(), withoutValue.getFrameworkPart()); assertNull(withoutLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("INTEGER-INPUT").getValue());
assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); assertNull(withoutLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("STRING-INPUT").getValue());
assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue());
// Clone with value // Clone with value
MLink withValue = link.clone(true); MLink withLinkValue = link.clone(true);
assertEquals(link, withValue); assertEquals(link, withLinkValue);
assertEquals(link.getPersistenceId(), withValue.getPersistenceId()); assertEquals(link.getPersistenceId(), withLinkValue.getPersistenceId());
assertEquals(link.getName(), withValue.getName()); assertEquals(link.getName(), withLinkValue.getName());
assertEquals(link.getCreationUser(), withValue.getCreationUser()); assertEquals(link.getCreationUser(), withLinkValue.getCreationUser());
assertEquals(forms1(), withValue.getConnectorPart()); assertEquals(linkConfig(), withLinkValue.getConnectorLinkConfig());
assertEquals(forms2(), withValue.getFrameworkPart()); assertEquals(100, withLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("INTEGER-INPUT").getValue());
assertEquals(100, withValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); assertEquals("TEST-VALUE", withLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("STRING-INPUT").getValue());
assertEquals("TEST-VALUE", withValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue());
} }
private MLink link() { private MLink link() {
MLink link = new MLink(123l, forms1(), forms2()); MLink link = new MLink(123l, linkConfig());
link.setName("Vampire"); link.setName("Vampire");
link.setCreationUser("Buffy"); link.setCreationUser("Buffy");
return link; return link;
} }
private MConnectionForms forms1() { private MLinkConfig linkConfig() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
input.setValue(100); input.setValue(100);
MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20);
@ -104,19 +88,9 @@ private MConnectionForms forms1() {
List<MInput<?>> list = new ArrayList<MInput<?>>(); List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input); list.add(input);
list.add(strInput); list.add(strInput);
MForm form = new MForm("FORMNAME", list); MConfig config = new MConfig("CONFIGNAME", list);
forms.add(form); configs.add(config);
return new MConnectionForms(forms); return new MLinkConfig(configs);
}
private MConnectionForms forms2() {
List<MForm> forms = new ArrayList<MForm>();
MMapInput input = new MMapInput("MAP-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input);
MForm form = new MForm("form", list);
forms.add(form);
return new MConnectionForms(forms);
} }
} }

View File

@ -24,25 +24,22 @@
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** public class TestMLinkConfig {
* Test class for org.apache.sqoop.model.MConnectionForms
*/
public class TestMConnectionForms {
/** /**
* Test for class initialization and values * Test for class initialization and values
*/ */
@Test @Test
public void testInitialization() { public void testInitialization() {
List<MForm> forms = new ArrayList<MForm>(); List<MConfig> configs = new ArrayList<MConfig>();
MConnectionForms connectionForms1 = new MConnectionForms(forms); MLinkConfig linkConfig = new MLinkConfig(configs);
List<MForm> testForms = new ArrayList<MForm>(); List<MConfig> testConfig = new ArrayList<MConfig>();
assertEquals(testForms, connectionForms1.getForms()); assertEquals(testConfig, linkConfig.getConfigs());
MConnectionForms connectionForms2 = new MConnectionForms(testForms); MLinkConfig linkConfig2 = new MLinkConfig(testConfig);
assertEquals(connectionForms2, connectionForms1); assertEquals(linkConfig2, linkConfig);
// Add a form to list for checking not equals // Add a config to list for checking not equals
MForm m = new MForm("test", null); MConfig c = new MConfig("test", null);
testForms.add(m); testConfig.add(c);
assertFalse(connectionForms1.equals(connectionForms2)); assertFalse(linkConfig.equals(linkConfig2));
} }
} }

View File

@ -17,16 +17,20 @@
*/ */
package org.apache.sqoop.validation; package org.apache.sqoop.validation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.validation.Validation.FormInput; import org.apache.sqoop.validation.ConfigValidator.ConfigInput;
import org.apache.sqoop.validation.Validation.Message; import org.apache.sqoop.validation.ConfigValidator.Message;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/** /**
* Test class for org.apache.sqoop.validation.Validation * Test class for org.apache.sqoop.validation.Validation
*/ */
@ -38,42 +42,42 @@ public class TestValidation {
@Test @Test
public void testInitialization() { public void testInitialization() {
/* Check initialization with class */ /* Check initialization with class */
Validation validation = new Validation(Class.class); ConfigValidator validation = new ConfigValidator(Class.class);
assertNotNull(validation); assertNotNull(validation);
assertEquals(Status.FINE, validation.getStatus()); assertEquals(Status.FINE, validation.getStatus());
assertEquals(0, validation.getMessages().size()); assertEquals(0, validation.getMessages().size());
/* Check initialization with status and message as null */ /* Check initialization with status and message as null */
Validation validationNull = new Validation(null, null); ConfigValidator validationNull = new ConfigValidator(null, null);
assertNotNull(validationNull); assertNotNull(validationNull);
assertNull(validationNull.getStatus()); assertNull(validationNull.getStatus());
assertNull(validationNull.getMessages()); assertNull(validationNull.getMessages());
/* Check initialization with status and message with values */ /* Check initialization with status and message with values */
Status s1 = Status.FINE; Status s1 = Status.FINE;
Map<FormInput, Message> msg1 = new HashMap<Validation.FormInput, Validation.Message>(); Map<ConfigInput, Message> msg1 = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
Validation validation1 = new Validation(s1, msg1); ConfigValidator validation1 = new ConfigValidator(s1, msg1);
assertNotNull(validation1); assertNotNull(validation1);
assertEquals(Status.FINE, validation1.getStatus()); assertEquals(Status.FINE, validation1.getStatus());
assertEquals(0, validation1.getMessages().size()); assertEquals(0, validation1.getMessages().size());
/* Check initialization with status and message with values */ /* Check initialization with status and message with values */
Status s2 = Status.ACCEPTABLE; Status s2 = Status.ACCEPTABLE;
Map<FormInput, Message> msg2 = new HashMap<Validation.FormInput, Validation.Message>(); Map<ConfigInput, Message> msg2 = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
Validation validation2 = new Validation(s2, msg2); ConfigValidator validation2 = new ConfigValidator(s2, msg2);
assertNotNull(validation2); assertNotNull(validation2);
assertEquals(Status.ACCEPTABLE, validation2.getStatus()); assertEquals(Status.ACCEPTABLE, validation2.getStatus());
assertEquals(0, validation2.getMessages().size()); assertEquals(0, validation2.getMessages().size());
/* Check initialization with status and message with values */ /* Check initialization with status and message with values */
Status s3 = Status.ACCEPTABLE; Status s3 = Status.ACCEPTABLE;
Map<FormInput, Message> msg3 = new HashMap<Validation.FormInput, Validation.Message>(); Map<ConfigInput, Message> msg3 = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
Validation.FormInput fi = new Validation.FormInput("form\\.input"); ConfigValidator.ConfigInput fi = new ConfigValidator.ConfigInput("config\\.input");
Validation.Message message = new Validation.Message(Status.FINE, "sqoop"); ConfigValidator.Message message = new ConfigValidator.Message(Status.FINE, "sqoop");
msg3.put(fi, message); msg3.put(fi, message);
Validation validation3 = new Validation(s3, msg3); ConfigValidator validation3 = new ConfigValidator(s3, msg3);
Validation.FormInput fiTest = new Validation.FormInput("form\\.input"); ConfigValidator.ConfigInput fiTest = new ConfigValidator.ConfigInput("config\\.input");
Validation.Message messageTest = new Validation.Message(Status.FINE, ConfigValidator.Message messageTest = new ConfigValidator.Message(Status.FINE,
"sqoop"); "sqoop");
assertEquals(messageTest, validation3.getMessages().get(fiTest)); assertEquals(messageTest, validation3.getMessages().get(fiTest));
assertEquals(Status.ACCEPTABLE, validation3.getStatus()); assertEquals(Status.ACCEPTABLE, validation3.getStatus());
@ -82,13 +86,13 @@ public void testInitialization() {
/** /**
* Test for Validation.ForInput * Test for Validation.ForInput
*/ */
public void testFormInput() { public void testConfigInput() {
Validation.FormInput fi = new Validation.FormInput("test\\.test"); ConfigValidator.ConfigInput fi = new ConfigValidator.ConfigInput("test\\.test");
assertNotNull(fi); assertNotNull(fi);
/* Passing null */ /* Passing null */
try { try {
new Validation.FormInput(null); new ConfigValidator.ConfigInput(null);
fail("Assert error is expected"); fail("Assert error is expected");
} catch (AssertionError e) { } catch (AssertionError e) {
assertTrue(true); assertTrue(true);
@ -96,31 +100,31 @@ public void testFormInput() {
/* Passing empty and check exception messages */ /* Passing empty and check exception messages */
try { try {
new Validation.FormInput(""); new ConfigValidator.ConfigInput("");
fail("SqoopException is expected"); fail("SqoopException is expected");
} catch (SqoopException e) { } catch (SqoopException e) {
assertEquals(ValidationError.VALIDATION_0003.getMessage(), e assertEquals(ConfigValidationError.VALIDATION_0003.getMessage(), e
.getErrorCode().getMessage()); .getErrorCode().getMessage());
} }
/* Passing value and check */ /* Passing value and check */
Validation.FormInput fi2 = new Validation.FormInput("form\\.input"); ConfigValidator.ConfigInput fi2 = new ConfigValidator.ConfigInput("config\\.input");
assertEquals("form\\", fi2.getForm()); assertEquals("config\\", fi2.getConfig());
assertEquals("input", fi2.getInput()); assertEquals("input", fi2.getInput());
/* Check equals */ /* Check equals */
Validation.FormInput fiOne = new Validation.FormInput("form\\.input"); ConfigValidator.ConfigInput fiOne = new ConfigValidator.ConfigInput("config\\.input");
Validation.FormInput fiTwo = new Validation.FormInput("form\\.input"); ConfigValidator.ConfigInput fiTwo = new ConfigValidator.ConfigInput("config\\.input");
assertEquals(fiOne, fiTwo); assertEquals(fiOne, fiTwo);
/* toString() method check */ /* toString() method check */
assertEquals("form\\.input", fiOne.toString()); assertEquals("config\\.input", fiOne.toString());
// Checking null as input field (form validation) // Checking null as input field (config validation)
Validation.FormInput fi3 = new FormInput("form"); ConfigValidator.ConfigInput fi3 = new ConfigInput("config");
assertEquals("form", fi3.getForm()); assertEquals("config", fi3.getConfig());
assertNull(fi3.getInput()); assertNull(fi3.getInput());
assertEquals("form", fi3.toString()); assertEquals("config", fi3.toString());
} }
@ -129,17 +133,17 @@ public void testFormInput() {
*/ */
public void testMessage() { public void testMessage() {
/* Passing null */ /* Passing null */
Validation.Message msg1 = new Validation.Message(null, null); ConfigValidator.Message msg1 = new ConfigValidator.Message(null, null);
assertNull(msg1.getStatus()); assertNull(msg1.getStatus());
assertNull(msg1.getMessage()); assertNull(msg1.getMessage());
/* Passing values */ /* Passing values */
Validation.Message msg2 = new Validation.Message(Status.FINE, "sqoop"); ConfigValidator.Message msg2 = new ConfigValidator.Message(Status.FINE, "sqoop");
assertEquals(Status.FINE, msg2.getStatus()); assertEquals(Status.FINE, msg2.getStatus());
assertEquals("sqoop", msg2.getMessage()); assertEquals("sqoop", msg2.getMessage());
/* Check for equal */ /* Check for equal */
Validation.Message msg3 = new Validation.Message(Status.FINE, "sqoop"); ConfigValidator.Message msg3 = new ConfigValidator.Message(Status.FINE, "sqoop");
assertEquals(msg2, msg3); assertEquals(msg2, msg3);
} }
} }

View File

@ -18,8 +18,8 @@
package org.apache.sqoop.validation; package org.apache.sqoop.validation;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
import org.apache.sqoop.model.Validator; import org.apache.sqoop.model.Validator;
import org.apache.sqoop.validation.validators.Contains; import org.apache.sqoop.validation.validators.Contains;
@ -35,18 +35,18 @@
*/ */
public class TestValidationRunner { public class TestValidationRunner {
@FormClass(validators = {@Validator(FormA.FormValidator.class)}) @ConfigClass(validators = {@Validator(ConfigA.ConfigValidator.class)})
public static class FormA { public static class ConfigA {
@Input(validators = {@Validator(NotNull.class)}) @Input(validators = {@Validator(NotNull.class)})
String notNull; String notNull;
public static class FormValidator extends AbstractValidator<FormA> { public static class ConfigValidator extends AbstractValidator<ConfigA> {
@Override @Override
public void validate(FormA form) { public void validate(ConfigA config) {
if(form.notNull == null) { if(config.notNull == null) {
addMessage(Status.UNACCEPTABLE, "null"); addMessage(Status.UNACCEPTABLE, "null");
} }
if("error".equals(form.notNull)) { if("error".equals(config.notNull)) {
addMessage(Status.UNACCEPTABLE, "error"); addMessage(Status.UNACCEPTABLE, "error");
} }
} }
@ -54,83 +54,83 @@ public void validate(FormA form) {
} }
@Test @Test
public void testValidateForm() { public void testValidateConfig() {
FormA form = new FormA(); ConfigA config = new ConfigA();
ValidationRunner runner = new ValidationRunner(); ConfigValidationRunner runner = new ConfigValidationRunner();
ValidationResult result; ConfigValidationResult result;
// Null string should fail on Input level and should not call form level validators // Null string should fail on Input level and should not call config level validators
form.notNull = null; config.notNull = null;
result = runner.validateForm("formName", form); result = runner.validateConfig("configName", config);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
assertEquals(1, result.getMessages().size()); assertEquals(1, result.getMessages().size());
assertTrue(result.getMessages().containsKey("formName.notNull")); assertTrue(result.getMessages().containsKey("configName.notNull"));
// String "error" should trigger form level error, but not Input level // String "error" should trigger config level error, but not Input level
form.notNull = "error"; config.notNull = "error";
result = runner.validateForm("formName", form); result = runner.validateConfig("configName", config);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
assertEquals(1, result.getMessages().size()); assertEquals(1, result.getMessages().size());
assertTrue(result.getMessages().containsKey("formName")); assertTrue(result.getMessages().containsKey("configName"));
// Acceptable state // Acceptable state
form.notNull = "This is truly random string"; config.notNull = "This is truly random string";
result = runner.validateForm("formName", form); result = runner.validateConfig("configName", config);
assertEquals(Status.FINE, result.getStatus()); assertEquals(Status.FINE, result.getStatus());
assertEquals(0, result.getMessages().size()); assertEquals(0, result.getMessages().size());
} }
@FormClass @ConfigClass
public static class FormB { public static class ConfigB {
@Input(validators = {@Validator(NotNull.class), @Validator(NotEmpty.class)}) @Input(validators = {@Validator(NotNull.class), @Validator(NotEmpty.class)})
String str; String str;
} }
@FormClass @ConfigClass
public static class FormC { public static class ConfigC {
@Input(validators = {@Validator(value = Contains.class, strArg = "findme")}) @Input(validators = {@Validator(value = Contains.class, strArg = "findme")})
String str; String str;
} }
@Test @Test
public void testMultipleValidatorsOnSingleInput() { public void testMultipleValidatorsOnSingleInput() {
FormB form = new FormB(); ConfigB config = new ConfigB();
ValidationRunner runner = new ValidationRunner(); ConfigValidationRunner runner = new ConfigValidationRunner();
ValidationResult result; ConfigValidationResult result;
form.str = null; config.str = null;
result = runner.validateForm("formName", form); result = runner.validateConfig("configName", config);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
assertEquals(1, result.getMessages().size()); assertEquals(1, result.getMessages().size());
assertTrue(result.getMessages().containsKey("formName.str")); assertTrue(result.getMessages().containsKey("configName.str"));
assertEquals(2, result.getMessages().get("formName.str").size()); assertEquals(2, result.getMessages().get("configName.str").size());
} }
@Test @Test
public void testValidatorWithParameters() { public void testValidatorWithParameters() {
FormC form = new FormC(); ConfigC config = new ConfigC();
ValidationRunner runner = new ValidationRunner(); ConfigValidationRunner runner = new ConfigValidationRunner();
ValidationResult result; ConfigValidationResult result;
// Sub string not found // Sub string not found
form.str = "Mordor"; config.str = "Mordor";
result = runner.validateForm("formName", form); result = runner.validateConfig("configName", config);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
assertEquals(1, result.getMessages().size()); assertEquals(1, result.getMessages().size());
assertTrue(result.getMessages().containsKey("formName.str")); assertTrue(result.getMessages().containsKey("configName.str"));
// Sub string found // Sub string found
form.str = "Morfindmedor"; config.str = "Morfindmedor";
result = runner.validateForm("formName", form); result = runner.validateConfig("configName", config);
assertEquals(Status.FINE, result.getStatus()); assertEquals(Status.FINE, result.getStatus());
assertEquals(0, result.getMessages().size()); assertEquals(0, result.getMessages().size());
} }
@ConfigurationClass(validators = {@Validator(ConfigurationA.ClassValidator.class)}) @ConfigurationClass(validators = {@Validator(ConfigurationA.ClassValidator.class)})
public static class ConfigurationA { public static class ConfigurationA {
@Form FormA formA; @Config ConfigA formA;
public ConfigurationA() { public ConfigurationA() {
formA = new FormA(); formA = new ConfigA();
} }
public static class ClassValidator extends AbstractValidator<ConfigurationA> { public static class ClassValidator extends AbstractValidator<ConfigurationA> {
@ -149,24 +149,24 @@ public void validate(ConfigurationA conf) {
@Test @Test
public void testValidate() { public void testValidate() {
ConfigurationA conf = new ConfigurationA(); ConfigurationA conf = new ConfigurationA();
ValidationRunner runner = new ValidationRunner(); ConfigValidationRunner runner = new ConfigValidationRunner();
ValidationResult result; ConfigValidationResult result;
// Null string should fail on Input level and should not call form nor class level validators // Null string should fail on Input level and should not call config nor class level validators
conf.formA.notNull = null; conf.formA.notNull = null;
result = runner.validate(conf); result = runner.validate(conf);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
assertEquals(1, result.getMessages().size()); assertEquals(1, result.getMessages().size());
assertTrue(result.getMessages().containsKey("formA.notNull")); assertTrue(result.getMessages().containsKey("formA.notNull"));
// String "error" should trigger form level error, but not Input nor class level // String "error" should trigger config level error, but not Input nor class level
conf.formA.notNull = "error"; conf.formA.notNull = "error";
result = runner.validate(conf); result = runner.validate(conf);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());
assertEquals(1, result.getMessages().size()); assertEquals(1, result.getMessages().size());
assertTrue(result.getMessages().containsKey("formA")); assertTrue(result.getMessages().containsKey("formA"));
// String "conf-error" should trigger class level error, but not Input nor Form level // String "conf-error" should trigger class level error, but not Input nor Config level
conf.formA.notNull = "conf-error"; conf.formA.notNull = "conf-error";
result = runner.validate(conf); result = runner.validate(conf);
assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(Status.UNACCEPTABLE, result.getStatus());

View File

@ -17,19 +17,17 @@
*/ */
package org.apache.sqoop.validation.validators; package org.apache.sqoop.validation.validators;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.apache.sqoop.validation.Message; import org.apache.sqoop.validation.Message;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.junit.Test; import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
*/
public class TestClassAvailable { public class TestClassAvailable {
AbstractValidator validator = new ClassAvailable(); AbstractValidator<String> validator = new ClassAvailable();
@Test @Test
public void test() { public void test() {

View File

@ -92,7 +92,7 @@ public To getTo() {
} }
@Override @Override
public Validator getValidator() { public Validator getConfigValidator() {
return genericJdbcValidator; return genericJdbcValidator;
} }

View File

@ -18,21 +18,20 @@
*/ */
package org.apache.sqoop.connector.jdbc; package org.apache.sqoop.connector.jdbc;
import org.apache.log4j.Logger;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.connector.spi.RepositoryUpgrader;
import org.apache.sqoop.model.MConnectionForms;
import org.apache.sqoop.model.MForm;
import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MJobForms;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.connector.spi.RepositoryUpgrader;
import org.apache.sqoop.model.MConfigList;
import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MLinkConfig;
public class GenericJdbcConnectorUpgrader extends RepositoryUpgrader { public class GenericJdbcConnectorUpgrader extends RepositoryUpgrader {
private static final Logger LOG = private static final Logger LOG = Logger.getLogger(GenericJdbcConnectorUpgrader.class);
Logger.getLogger(GenericJdbcConnectorUpgrader.class);
/* /*
* For now, there is no real upgrade. So copy all data over, * For now, there is no real upgrade. So copy all data over,
@ -41,41 +40,40 @@ public class GenericJdbcConnectorUpgrader extends RepositoryUpgrader {
*/ */
@Override @Override
public void upgrade(MConnectionForms original, public void upgrade(MLinkConfig original, MLinkConfig upgradeTarget) {
MConnectionForms upgradeTarget) { doUpgrade(original.getConfigs(), upgradeTarget.getConfigs());
doUpgrade(original.getForms(), upgradeTarget.getForms());
} }
@Override @Override
public void upgrade(MJobForms original, MJobForms upgradeTarget) { public void upgrade(MConfigList original, MConfigList upgradeTarget) {
doUpgrade(original.getForms(), upgradeTarget.getForms()); doUpgrade(original.getConfigs(), upgradeTarget.getConfigs());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void doUpgrade(List<MForm> original, List<MForm> target) { private void doUpgrade(List<MConfig> original, List<MConfig> target) {
// Easier to find the form in the original forms list if we use a map. // Easier to find the config in the original list if we use a map.
// Since the constructor of MJobForms takes a list, // Since the constructor takes a list,
// index is not guaranteed to be the same, so we need to look for // index is not guaranteed to be the same, so we need to look for
// equivalence // equivalence
Map<String, MForm> formMap = new HashMap<String, MForm>(); Map<String, MConfig> configMap = new HashMap<String, MConfig>();
for (MForm form : original) { for (MConfig config : original) {
formMap.put(form.getName(), form); configMap.put(config.getName(), config);
} }
for (MForm form : target) { for (MConfig config : target) {
List<MInput<?>> inputs = form.getInputs(); List<MInput<?>> inputs = config.getInputs();
MForm originalForm = formMap.get(form.getName()); MConfig orginalConfig = configMap.get(config.getName());
if (originalForm == null) { if (orginalConfig == null) {
LOG.warn("Form: '" + form.getName() + "' not present in old " + LOG.warn("Config: '" + config.getName() + "' not present in old " +
"connector. So it and its inputs will not be transferred by the upgrader."); "generic JDBC connector. So it and its inputs will not be transferred by the upgrader.");
continue; continue;
} }
for (MInput input : inputs) { for (MInput input : inputs) {
try { try {
MInput originalInput = originalForm.getInput(input.getName()); MInput originalInput = orginalConfig.getInput(input.getName());
input.setValue(originalInput.getValue()); input.setValue(originalInput.getValue());
} catch (SqoopException ex) { } catch (SqoopException ex) {
LOG.warn("Input: '" + input.getName() + "' not present in old " + LOG.warn("Input: '" + input.getName() + "' not present in old " +
"connector. So it will not be transferred by the upgrader."); "generic JDBC connector. So it will not be transferred by the upgrader.");
} }
} }
} }

View File

@ -34,12 +34,12 @@ public class GenericJdbcExtractor extends Extractor<LinkConfiguration, FromJobCo
private long rowsRead = 0; private long rowsRead = 0;
@Override @Override
public void extract(ExtractorContext context, LinkConfiguration linkConf, public void extract(ExtractorContext context, LinkConfiguration linkConfig,
FromJobConfiguration fromJobConf, GenericJdbcPartition partition) { FromJobConfiguration fromJobConfig, GenericJdbcPartition partition) {
String driver = linkConf.link.jdbcDriver; String driver = linkConfig.linkConfig.jdbcDriver;
String url = linkConf.link.connectionString; String url = linkConfig.linkConfig.connectionString;
String username = linkConf.link.username; String username = linkConfig.linkConfig.username;
String password = linkConf.link.password; String password = linkConfig.linkConfig.password;
GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password); GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password);
String query = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL); String query = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL);

View File

@ -29,7 +29,7 @@ public class GenericJdbcFromDestroyer extends Destroyer<LinkConfiguration, FromJ
Logger.getLogger(GenericJdbcFromDestroyer.class); Logger.getLogger(GenericJdbcFromDestroyer.class);
@Override @Override
public void destroy(DestroyerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { public void destroy(DestroyerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
LOG.info("Running generic JDBC connector destroyer"); LOG.info("Running generic JDBC connector destroyer");
} }

View File

@ -45,34 +45,34 @@ public class GenericJdbcFromInitializer extends Initializer<LinkConfiguration, F
private GenericJdbcExecutor executor; private GenericJdbcExecutor executor;
@Override @Override
public void initialize(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { public void initialize(InitializerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
configureJdbcProperties(context.getContext(), linkConf, fromJobConf); configureJdbcProperties(context.getContext(), linkConfig, fromJobConfig);
try { try {
configurePartitionProperties(context.getContext(), linkConf, fromJobConf); configurePartitionProperties(context.getContext(), linkConfig, fromJobConfig);
configureTableProperties(context.getContext(), linkConf, fromJobConf); configureTableProperties(context.getContext(), linkConfig, fromJobConfig);
} finally { } finally {
executor.close(); executor.close();
} }
} }
@Override @Override
public List<String> getJars(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { public List<String> getJars(InitializerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
List<String> jars = new LinkedList<String>(); List<String> jars = new LinkedList<String>();
jars.add(ClassUtils.jarForClass(linkConf.link.jdbcDriver)); jars.add(ClassUtils.jarForClass(linkConfig.linkConfig.jdbcDriver));
return jars; return jars;
} }
@Override @Override
public Schema getSchema(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { public Schema getSchema(InitializerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
configureJdbcProperties(context.getContext(), linkConf, fromJobConf); configureJdbcProperties(context.getContext(), linkConfig, fromJobConfig);
String schemaName = fromJobConf.fromJobConfig.tableName; String schemaName = fromJobConfig.fromJobConfig.tableName;
if(schemaName == null) { if(schemaName == null) {
schemaName = "Query"; schemaName = "Query";
} else if(fromJobConf.fromJobConfig.schemaName != null) { } else if(fromJobConfig.fromJobConfig.schemaName != null) {
schemaName = fromJobConf.fromJobConfig.schemaName + "." + schemaName; schemaName = fromJobConfig.fromJobConfig.schemaName + "." + schemaName;
} }
Schema schema = new Schema(schemaName); Schema schema = new Schema(schemaName);
@ -117,11 +117,11 @@ public Schema getSchema(InitializerContext context, LinkConfiguration linkConf,
} }
} }
private void configureJdbcProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
String driver = connectionConfig.link.jdbcDriver; String driver = linkConfig.linkConfig.jdbcDriver;
String url = connectionConfig.link.connectionString; String url = linkConfig.linkConfig.connectionString;
String username = connectionConfig.link.username; String username = linkConfig.linkConfig.username;
String password = connectionConfig.link.password; String password = linkConfig.linkConfig.password;
assert driver != null; assert driver != null;
assert url != null; assert url != null;
@ -129,7 +129,7 @@ private void configureJdbcProperties(MutableContext context, LinkConfiguration c
executor = new GenericJdbcExecutor(driver, url, username, password); executor = new GenericJdbcExecutor(driver, url, username, password);
} }
private void configurePartitionProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { private void configurePartitionProperties(MutableContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
// ----- configure column name ----- // ----- configure column name -----
String partitionColumnName = fromJobConfig.fromJobConfig.partitionColumn; String partitionColumnName = fromJobConfig.fromJobConfig.partitionColumn;
@ -234,7 +234,7 @@ private void configurePartitionProperties(MutableContext context, LinkConfigurat
} }
} }
private void configureTableProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { private void configureTableProperties(MutableContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
String dataSql; String dataSql;
String fieldNames; String fieldNames;

View File

@ -30,11 +30,11 @@ public class GenericJdbcLoader extends Loader<LinkConfiguration, ToJobConfigurat
private int batchesPerTransaction = DEFAULT_BATCHES_PER_TRANSACTION; private int batchesPerTransaction = DEFAULT_BATCHES_PER_TRANSACTION;
@Override @Override
public void load(LoaderContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) throws Exception{ public void load(LoaderContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) throws Exception{
String driver = linkConf.link.jdbcDriver; String driver = linkConfig.linkConfig.jdbcDriver;
String url = linkConf.link.connectionString; String url = linkConfig.linkConfig.connectionString;
String username = linkConf.link.username; String username = linkConfig.linkConfig.username;
String password = linkConf.link.password; String password = linkConfig.linkConfig.password;
GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password); GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password);
executor.setAutoCommit(false); executor.setAutoCommit(false);

View File

@ -47,7 +47,8 @@ public class GenericJdbcPartitioner extends Partitioner<LinkConfiguration, FromJ
private Boolean partitionColumnNull; private Boolean partitionColumnNull;
@Override @Override
public List<Partition> getPartitions(PartitionerContext context,LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { public List<Partition> getPartitions(PartitionerContext context, LinkConfiguration linkConfig,
FromJobConfiguration fromJobConfig) {
List<Partition> partitions = new LinkedList<Partition>(); List<Partition> partitions = new LinkedList<Partition>();
numberPartitions = context.getMaxPartitions(); numberPartitions = context.getMaxPartitions();
@ -56,7 +57,7 @@ public List<Partition> getPartitions(PartitionerContext context,LinkConfiguratio
partitionMinValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE); partitionMinValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE);
partitionMaxValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE); partitionMaxValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE);
partitionColumnNull = fromJobConf.fromJobConfig.partitionColumnNull; partitionColumnNull = fromJobConfig.fromJobConfig.partitionColumnNull;
if (partitionColumnNull == null) { if (partitionColumnNull == null) {
partitionColumnNull = false; partitionColumnNull = false;
} }

View File

@ -28,26 +28,26 @@ public class GenericJdbcToDestroyer extends Destroyer<LinkConfiguration, ToJobCo
private static final Logger LOG = Logger.getLogger(GenericJdbcToDestroyer.class); private static final Logger LOG = Logger.getLogger(GenericJdbcToDestroyer.class);
@Override @Override
public void destroy(DestroyerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { public void destroy(DestroyerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) {
LOG.info("Running generic JDBC connector destroyer"); LOG.info("Running generic JDBC connector destroyer");
final String tableName = toJobConf.toJobConfig.tableName; final String tableName = toJobConfig.toJobConfig.tableName;
final String stageTableName = toJobConf.toJobConfig.stageTableName; final String stageTableName = toJobConfig.toJobConfig.stageTableName;
final boolean stageEnabled = stageTableName != null && final boolean stageEnabled = stageTableName != null &&
stageTableName.length() > 0; stageTableName.length() > 0;
if(stageEnabled) { if(stageEnabled) {
moveDataToDestinationTable(linkConf, moveDataToDestinationTable(linkConfig,
context.isSuccess(), stageTableName, tableName); context.isSuccess(), stageTableName, tableName);
} }
} }
private void moveDataToDestinationTable(LinkConfiguration linkConf, private void moveDataToDestinationTable(LinkConfiguration linkConfig,
boolean success, String stageTableName, String tableName) { boolean success, String stageTableName, String tableName) {
GenericJdbcExecutor executor = GenericJdbcExecutor executor =
new GenericJdbcExecutor(linkConf.link.jdbcDriver, new GenericJdbcExecutor(linkConfig.linkConfig.jdbcDriver,
linkConf.link.connectionString, linkConfig.linkConfig.connectionString,
linkConf.link.username, linkConfig.linkConfig.username,
linkConf.link.password); linkConfig.linkConfig.password);
try { try {
if(success) { if(success) {
LOG.info("Job completed, transferring data from stage fromTable to " + LOG.info("Job completed, transferring data from stage fromTable to " +

View File

@ -43,35 +43,35 @@ public class GenericJdbcToInitializer extends Initializer<LinkConfiguration, ToJ
Logger.getLogger(GenericJdbcToInitializer.class); Logger.getLogger(GenericJdbcToInitializer.class);
@Override @Override
public void initialize(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { public void initialize(InitializerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) {
configureJdbcProperties(context.getContext(), linkConf, toJobConf); configureJdbcProperties(context.getContext(), linkConfig, toJobConfig);
try { try {
configureTableProperties(context.getContext(), linkConf, toJobConf); configureTableProperties(context.getContext(), linkConfig, toJobConfig);
} finally { } finally {
executor.close(); executor.close();
} }
} }
@Override @Override
public List<String> getJars(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { public List<String> getJars(InitializerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) {
List<String> jars = new LinkedList<String>(); List<String> jars = new LinkedList<String>();
jars.add(ClassUtils.jarForClass(linkConf.link.jdbcDriver)); jars.add(ClassUtils.jarForClass(linkConfig.linkConfig.jdbcDriver));
return jars; return jars;
} }
@Override @Override
public Schema getSchema(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { public Schema getSchema(InitializerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) {
configureJdbcProperties(context.getContext(), linkConf, toJobConf); configureJdbcProperties(context.getContext(), linkConfig, toJobConfig);
String schemaName = toJobConf.toJobConfig.tableName; String schemaName = toJobConfig.toJobConfig.tableName;
if (schemaName == null) { if (schemaName == null) {
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0019, throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0019,
"Table name extraction not supported yet."); "Table name extraction not supported yet.");
} }
if(toJobConf.toJobConfig.schemaName != null) { if(toJobConfig.toJobConfig.schemaName != null) {
schemaName = toJobConf.toJobConfig.schemaName + "." + schemaName; schemaName = toJobConfig.toJobConfig.schemaName + "." + schemaName;
} }
Schema schema = new Schema(schemaName); Schema schema = new Schema(schemaName);
@ -110,11 +110,11 @@ public Schema getSchema(InitializerContext context, LinkConfiguration linkConf,
} }
} }
private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) {
String driver = linkConf.link.jdbcDriver; String driver = linkConfig.linkConfig.jdbcDriver;
String url = linkConf.link.connectionString; String url = linkConfig.linkConfig.connectionString;
String username = linkConf.link.username; String username = linkConfig.linkConfig.username;
String password = linkConf.link.password; String password = linkConfig.linkConfig.password;
assert driver != null; assert driver != null;
assert url != null; assert url != null;
@ -122,7 +122,7 @@ private void configureJdbcProperties(MutableContext context, LinkConfiguration l
executor = new GenericJdbcExecutor(driver, url, username, password); executor = new GenericJdbcExecutor(driver, url, username, password);
} }
private void configureTableProperties(MutableContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConfig) { private void configureTableProperties(MutableContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) {
String dataSql; String dataSql;
String schemaName = toJobConfig.toJobConfig.schemaName; String schemaName = toJobConfig.toJobConfig.schemaName;

View File

@ -22,7 +22,7 @@
import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration;
import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.Validation; import org.apache.sqoop.validation.ConfigValidator;
import org.apache.sqoop.validation.Validator; import org.apache.sqoop.validation.Validator;
import java.sql.DriverManager; import java.sql.DriverManager;
@ -34,30 +34,30 @@
public class GenericJdbcValidator extends Validator { public class GenericJdbcValidator extends Validator {
@Override @Override
public Validation validateLink(Object configuration) { public ConfigValidator validateConfigForLink(Object configuration) {
Validation validation = new Validation(LinkConfiguration.class); ConfigValidator validation = new ConfigValidator(LinkConfiguration.class);
LinkConfiguration linkConf = (LinkConfiguration)configuration; LinkConfiguration linkConfig = (LinkConfiguration)configuration;
if(linkConf.link.jdbcDriver == null) { if(linkConfig.linkConfig.jdbcDriver == null) {
validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Driver can't be empty"); validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Driver can't be empty");
} else { } else {
try { try {
Class.forName(linkConf.link.jdbcDriver); Class.forName(linkConfig.linkConfig.jdbcDriver);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Can't load specified driver"); validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Can't load specified driver");
} }
} }
if(linkConf.link.connectionString == null) { if(linkConfig.linkConfig.connectionString == null) {
validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "JDBC URL can't be empty"); validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "JDBC URL can't be empty");
} else if(!linkConf.link.connectionString.startsWith("jdbc:")) { } else if(!linkConfig.linkConfig.connectionString.startsWith("jdbc:")) {
validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "This do not seem as a valid JDBC URL"); validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "This do not seem as a valid JDBC URL");
} }
// See if we can connect to the database // See if we can connect to the database
try { try {
DriverManager.getConnection(linkConf.link.connectionString, DriverManager.getConnection(linkConfig.linkConfig.connectionString,
linkConf.link.username, linkConf.link.password); linkConfig.linkConfig.username, linkConfig.linkConfig.password);
} catch (SQLException e) { } catch (SQLException e) {
validation.addMessage(Status.ACCEPTABLE, "link", "Can't connect to the database with given credentials: " + e.getMessage()); validation.addMessage(Status.ACCEPTABLE, "link", "Can't connect to the database with given credentials: " + e.getMessage());
} }
@ -67,7 +67,7 @@ public Validation validateLink(Object configuration) {
} }
@Override @Override
public Validation validateJob(Object jobConfiguration) { public ConfigValidator validateConfigForJob(Object jobConfiguration) {
if (jobConfiguration instanceof FromJobConfiguration) { if (jobConfiguration instanceof FromJobConfiguration) {
return validateFromJobConfiguration((FromJobConfiguration)jobConfiguration); return validateFromJobConfiguration((FromJobConfiguration)jobConfiguration);
} else if (jobConfiguration instanceof ToJobConfiguration) { } else if (jobConfiguration instanceof ToJobConfiguration) {
@ -78,8 +78,8 @@ public Validation validateJob(Object jobConfiguration) {
} }
} }
private Validation validateToJobConfiguration(ToJobConfiguration configuration) { private ConfigValidator validateToJobConfiguration(ToJobConfiguration configuration) {
Validation validation = new Validation(FromJobConfiguration.class); ConfigValidator validation = new ConfigValidator(FromJobConfiguration.class);
if(configuration.toJobConfig.tableName == null && configuration.toJobConfig.sql == null) { if(configuration.toJobConfig.tableName == null && configuration.toJobConfig.sql == null) {
validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Either table name or SQL must be specified"); validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Either table name or SQL must be specified");
@ -102,8 +102,8 @@ private Validation validateToJobConfiguration(ToJobConfiguration configuration)
return validation; return validation;
} }
private Validation validateFromJobConfiguration(FromJobConfiguration configuration) { private ConfigValidator validateFromJobConfiguration(FromJobConfiguration configuration) {
Validation validation = new Validation(FromJobConfiguration.class); ConfigValidator validation = new ConfigValidator(FromJobConfiguration.class);
if(configuration.fromJobConfig.tableName == null && configuration.fromJobConfig.sql == null) { if(configuration.fromJobConfig.tableName == null && configuration.fromJobConfig.sql == null) {
validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "Either table name or SQL must be specified"); validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "Either table name or SQL must be specified");

View File

@ -18,7 +18,7 @@
package org.apache.sqoop.connector.jdbc.configuration; package org.apache.sqoop.connector.jdbc.configuration;
import org.apache.sqoop.connector.jdbc.GenericJdbcConnectorConstants; import org.apache.sqoop.connector.jdbc.GenericJdbcConnectorConstants;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
import org.apache.sqoop.model.Validator; import org.apache.sqoop.model.Validator;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
@ -28,7 +28,7 @@
/** /**
* *
*/ */
@FormClass( validators = {@Validator(FromJobConfig.FormValidator.class)}) @ConfigClass( validators = {@Validator(FromJobConfig.ConfigValidator.class)})
public class FromJobConfig { public class FromJobConfig {
@Input(size = 50) @Input(size = 50)
public String schemaName; public String schemaName;
@ -51,16 +51,16 @@ public class FromJobConfig {
@Input(size = 50) @Input(size = 50)
public String boundaryQuery; public String boundaryQuery;
public static class FormValidator extends AbstractValidator<FromJobConfig> { public static class ConfigValidator extends AbstractValidator<FromJobConfig> {
@Override @Override
public void validate(FromJobConfig form) { public void validate(FromJobConfig config) {
if(form.tableName == null && form.sql == null) { if(config.tableName == null && config.sql == null) {
addMessage(Status.UNACCEPTABLE, "Either table name or SQL must be specified"); addMessage(Status.UNACCEPTABLE, "Either table name or SQL must be specified");
} }
if(form.tableName != null && form.sql != null) { if(config.tableName != null && config.sql != null) {
addMessage(Status.UNACCEPTABLE, "Both table name and SQL cannot be specified"); addMessage(Status.UNACCEPTABLE, "Both table name and SQL cannot be specified");
} }
if(form.schemaName != null && form.sql != null) { if(config.schemaName != null && config.sql != null) {
addMessage(Status.UNACCEPTABLE, "Both schema name and SQL cannot be specified"); addMessage(Status.UNACCEPTABLE, "Both schema name and SQL cannot be specified");
} }
} }

View File

@ -18,14 +18,14 @@
package org.apache.sqoop.connector.jdbc.configuration; package org.apache.sqoop.connector.jdbc.configuration;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
/** /**
* *
*/ */
@ConfigurationClass @ConfigurationClass
public class FromJobConfiguration { public class FromJobConfiguration {
@Form public FromJobConfig fromJobConfig; @Config public FromJobConfig fromJobConfig;
public FromJobConfiguration() { public FromJobConfiguration() {
fromJobConfig = new FromJobConfig(); fromJobConfig = new FromJobConfig();

View File

@ -17,7 +17,7 @@
*/ */
package org.apache.sqoop.connector.jdbc.configuration; package org.apache.sqoop.connector.jdbc.configuration;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
import org.apache.sqoop.model.Validator; import org.apache.sqoop.model.Validator;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
@ -33,7 +33,7 @@
/** /**
* *
*/ */
@FormClass(validators = {@Validator(LinkConfig.FormValidator.class)}) @ConfigClass(validators = {@Validator(LinkConfig.ConfigValidator.class)})
public class LinkConfig { public class LinkConfig {
@Input(size = 128, validators = {@Validator(NotEmpty.class), @Validator(ClassAvailable.class)} ) @Input(size = 128, validators = {@Validator(NotEmpty.class), @Validator(ClassAvailable.class)} )
public String jdbcDriver; public String jdbcDriver;
@ -50,7 +50,7 @@ public class LinkConfig {
@Input @Input
public Map<String, String> jdbcProperties; public Map<String, String> jdbcProperties;
public static class FormValidator extends AbstractValidator<LinkConfig> { public static class ConfigValidator extends AbstractValidator<LinkConfig> {
@Override @Override
public void validate(LinkConfig linkConfig) { public void validate(LinkConfig linkConfig) {
// See if we can connect to the database // See if we can connect to the database

View File

@ -18,7 +18,7 @@
package org.apache.sqoop.connector.jdbc.configuration; package org.apache.sqoop.connector.jdbc.configuration;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
/** /**
* *
@ -26,9 +26,9 @@
@ConfigurationClass @ConfigurationClass
public class LinkConfiguration { public class LinkConfiguration {
@Form public LinkConfig link; @Config public LinkConfig linkConfig;
public LinkConfiguration() { public LinkConfiguration() {
link = new LinkConfig(); linkConfig = new LinkConfig();
} }
} }

View File

@ -17,7 +17,7 @@
*/ */
package org.apache.sqoop.connector.jdbc.configuration; package org.apache.sqoop.connector.jdbc.configuration;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
import org.apache.sqoop.model.Validator; import org.apache.sqoop.model.Validator;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
@ -26,7 +26,7 @@
/** /**
* *
*/ */
@FormClass(validators = {@Validator(ToJobConfig.FormValidator.class)}) @ConfigClass(validators = {@Validator(ToJobConfig.ConfigValidator.class)})
public class ToJobConfig { public class ToJobConfig {
@Input(size = 50) public String schemaName; @Input(size = 50) public String schemaName;
@Input(size = 2000) public String tableName; @Input(size = 2000) public String tableName;
@ -35,19 +35,19 @@ public class ToJobConfig {
@Input(size = 2000) public String stageTableName; @Input(size = 2000) public String stageTableName;
@Input public Boolean clearStageTable; @Input public Boolean clearStageTable;
public static class FormValidator extends AbstractValidator<ToJobConfig> { public static class ConfigValidator extends AbstractValidator<ToJobConfig> {
@Override @Override
public void validate(ToJobConfig form) { public void validate(ToJobConfig config) {
if(form.tableName == null && form.sql == null) { if(config.tableName == null && config.sql == null) {
addMessage(Status.UNACCEPTABLE, "Either table name or SQL must be specified"); addMessage(Status.UNACCEPTABLE, "Either table name or SQL must be specified");
} }
if(form.tableName != null && form.sql != null) { if(config.tableName != null && config.sql != null) {
addMessage(Status.UNACCEPTABLE, "Both table name and SQL cannot be specified"); addMessage(Status.UNACCEPTABLE, "Both table name and SQL cannot be specified");
} }
if(form.tableName == null && form.stageTableName != null) { if(config.tableName == null && config.stageTableName != null) {
addMessage(Status.UNACCEPTABLE, "Stage table name cannot be specified without specifying table name"); addMessage(Status.UNACCEPTABLE, "Stage table name cannot be specified without specifying table name");
} }
if(form.stageTableName == null && form.clearStageTable != null) { if(config.stageTableName == null && config.clearStageTable != null) {
addMessage(Status.UNACCEPTABLE, "Clear stage table cannot be specified without specifying name of the stage table."); addMessage(Status.UNACCEPTABLE, "Clear stage table cannot be specified without specifying name of the stage table.");
} }
} }

View File

@ -18,14 +18,14 @@
package org.apache.sqoop.connector.jdbc.configuration; package org.apache.sqoop.connector.jdbc.configuration;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
/** /**
* *
*/ */
@ConfigurationClass @ConfigurationClass
public class ToJobConfiguration { public class ToJobConfiguration {
@Form public ToJobConfig toJobConfig; @Config public ToJobConfig toJobConfig;
public ToJobConfiguration() { public ToJobConfiguration() {
toJobConfig = new ToJobConfig(); toJobConfig = new ToJobConfig();

View File

@ -18,33 +18,33 @@
############################ ############################
# Link Config # Link Config
# #
link.label = Link configuration linkConfig.label = Link configuration
link.help = You must supply the information requested in order to \ linkConfig.help = You must supply the information requested in order to \
create a connection object. create a connection object.
# jdbc driver # jdbc driver
link.jdbcDriver.label = JDBC Driver Class linkConfig.jdbcDriver.label = JDBC Driver Class
link.jdbcDriver.help = Enter the fully qualified class name of the JDBC \ linkConfig.jdbcDriver.help = Enter the fully qualified class name of the JDBC \
driver that will be used for establishing this connection. driver that will be used for establishing this connection.
# connect string # connect string
link.connectionString.label = JDBC Connection String linkConfig.connectionString.label = JDBC Connection String
link.connectionString.help = Enter the value of JDBC connection string to be \ linkConfig.connectionString.help = Enter the value of JDBC connection string to be \
used by this connector for creating connections. used by this connector for creating connections.
# username string # username string
link.username.label = Username linkConfig.username.label = Username
link.username.help = Enter the username to be used for connecting to the \ linkConfig.username.help = Enter the username to be used for connecting to the \
database. database.
# password string # password string
link.password.label = Password linkConfig.password.label = Password
link.password.help = Enter the password to be used for connecting to the \ linkConfig.password.help = Enter the password to be used for connecting to the \
database. database.
# jdbc properties # jdbc properties
link.jdbcProperties.label = JDBC Connection Properties linkConfig.jdbcProperties.label = JDBC Connection Properties
link.jdbcProperties.help = Enter any JDBC properties that should be \ linkConfig.jdbcProperties.help = Enter any JDBC properties that should be \
supplied during the creation of connection. supplied during the creation of connection.
# From Job Config # From Job Config

View File

@ -60,7 +60,6 @@ public void setUp() {
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testDeleteTableData() throws Exception { public void testDeleteTableData() throws Exception {
executor.deleteTableData(table); executor.deleteTableData(table);
assertEquals("Table " + table + " is expected to be empty.", assertEquals("Table " + table + " is expected to be empty.",
@ -68,7 +67,6 @@ public void testDeleteTableData() throws Exception {
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testMigrateData() throws Exception { public void testMigrateData() throws Exception {
assertEquals("Table " + emptyTable + " is expected to be empty.", assertEquals("Table " + emptyTable + " is expected to be empty.",
0, executor.getTableRowCount(emptyTable)); 0, executor.getTableRowCount(emptyTable));
@ -86,7 +84,6 @@ public void testMigrateData() throws Exception {
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testGetTableRowCount() throws Exception { public void testGetTableRowCount() throws Exception {
assertEquals("Table " + table + " is expected to be empty.", assertEquals("Table " + table + " is expected to be empty.",
NUMBER_OF_ROWS, executor.getTableRowCount(table)); NUMBER_OF_ROWS, executor.getTableRowCount(table));

View File

@ -74,10 +74,10 @@ public void tearDown() {
public void testQuery() throws Exception { public void testQuery() throws Exception {
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
LinkConfiguration connectionConfig = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
connectionConfig.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connectionConfig.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
FromJobConfiguration jobConfig = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
@ -92,25 +92,25 @@ public void testQuery() throws Exception {
partition = new GenericJdbcPartition(); partition = new GenericJdbcPartition();
partition.setConditions("-50.0 <= DCOL AND DCOL < -16.6666666666666665"); partition.setConditions("-50.0 <= DCOL AND DCOL < -16.6666666666666665");
extractor.extract(extractorContext, connectionConfig, jobConfig, partition); extractor.extract(extractorContext, linkConfig, jobConfig, partition);
partition = new GenericJdbcPartition(); partition = new GenericJdbcPartition();
partition.setConditions("-16.6666666666666665 <= DCOL AND DCOL < 16.666666666666667"); partition.setConditions("-16.6666666666666665 <= DCOL AND DCOL < 16.666666666666667");
extractor.extract(extractorContext, connectionConfig, jobConfig, partition); extractor.extract(extractorContext, linkConfig, jobConfig, partition);
partition = new GenericJdbcPartition(); partition = new GenericJdbcPartition();
partition.setConditions("16.666666666666667 <= DCOL AND DCOL <= 50.0"); partition.setConditions("16.666666666666667 <= DCOL AND DCOL <= 50.0");
extractor.extract(extractorContext, connectionConfig, jobConfig, partition); extractor.extract(extractorContext, linkConfig, jobConfig, partition);
} }
@Test @Test
public void testSubquery() throws Exception { public void testSubquery() throws Exception {
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
LinkConfiguration connectionConfig = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
connectionConfig.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connectionConfig.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
FromJobConfiguration jobConfig = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
@ -127,15 +127,15 @@ public void testSubquery() throws Exception {
partition = new GenericJdbcPartition(); partition = new GenericJdbcPartition();
partition.setConditions("-50 <= ICOL AND ICOL < -16"); partition.setConditions("-50 <= ICOL AND ICOL < -16");
extractor.extract(extractorContext, connectionConfig, jobConfig, partition); extractor.extract(extractorContext, linkConfig, jobConfig, partition);
partition = new GenericJdbcPartition(); partition = new GenericJdbcPartition();
partition.setConditions("-16 <= ICOL AND ICOL < 17"); partition.setConditions("-16 <= ICOL AND ICOL < 17");
extractor.extract(extractorContext, connectionConfig, jobConfig, partition); extractor.extract(extractorContext, linkConfig, jobConfig, partition);
partition = new GenericJdbcPartition(); partition = new GenericJdbcPartition();
partition.setConditions("17 <= ICOL AND ICOL < 50"); partition.setConditions("17 <= ICOL AND ICOL < 50");
extractor.extract(extractorContext, connectionConfig, jobConfig, partition); extractor.extract(extractorContext, linkConfig, jobConfig, partition);
} }
public class DummyWriter extends DataWriter { public class DummyWriter extends DataWriter {

View File

@ -116,19 +116,19 @@ public void tearDown() {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableName() throws Exception { public void testTableName() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.tableName = schemalessTableName; jobConfig.fromJobConfig.tableName = schemalessTableName;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT * FROM " + executor.delimitIdentifier(schemalessTableName) "SELECT * FROM " + executor.delimitIdentifier(schemalessTableName)
@ -143,20 +143,20 @@ public void testTableName() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableNameWithTableColumns() throws Exception { public void testTableNameWithTableColumns() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.tableName = schemalessTableName; jobConfig.fromJobConfig.tableName = schemalessTableName;
jobConf.fromJobConfig.columns = tableColumns; jobConfig.fromJobConfig.columns = tableColumns;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT ICOL,VCOL FROM " + executor.delimitIdentifier(schemalessTableName) "SELECT ICOL,VCOL FROM " + executor.delimitIdentifier(schemalessTableName)
@ -171,20 +171,20 @@ public void testTableNameWithTableColumns() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableSql() throws Exception { public void testTableSql() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.sql = schemalessTableSql; jobConfig.fromJobConfig.sql = schemalessTableSql;
jobConf.fromJobConfig.partitionColumn = "DCOL"; jobConfig.fromJobConfig.partitionColumn = "DCOL";
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT * FROM " + executor.delimitIdentifier(schemalessTableName) "SELECT * FROM " + executor.delimitIdentifier(schemalessTableName)
@ -199,21 +199,21 @@ public void testTableSql() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableSqlWithTableColumns() throws Exception { public void testTableSqlWithTableColumns() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.sql = schemalessTableSql; jobConfig.fromJobConfig.sql = schemalessTableSql;
jobConf.fromJobConfig.columns = tableColumns; jobConfig.fromJobConfig.columns = tableColumns;
jobConf.fromJobConfig.partitionColumn = "DCOL"; jobConfig.fromJobConfig.partitionColumn = "DCOL";
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT SQOOP_SUBQUERY_ALIAS.ICOL,SQOOP_SUBQUERY_ALIAS.VCOL FROM " "SELECT SQOOP_SUBQUERY_ALIAS.ICOL,SQOOP_SUBQUERY_ALIAS.VCOL FROM "
@ -229,22 +229,22 @@ public void testTableSqlWithTableColumns() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableNameWithSchema() throws Exception { public void testTableNameWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName); String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.schemaName = schemaName; jobConfig.fromJobConfig.schemaName = schemaName;
jobConf.fromJobConfig.tableName = tableName; jobConfig.fromJobConfig.tableName = tableName;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT * FROM " + fullTableName "SELECT * FROM " + fullTableName
@ -259,23 +259,23 @@ public void testTableNameWithSchema() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableNameWithTableColumnsWithSchema() throws Exception { public void testTableNameWithTableColumnsWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName); String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.schemaName = schemaName; jobConfig.fromJobConfig.schemaName = schemaName;
jobConf.fromJobConfig.tableName = tableName; jobConfig.fromJobConfig.tableName = tableName;
jobConf.fromJobConfig.columns = tableColumns; jobConfig.fromJobConfig.columns = tableColumns;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT ICOL,VCOL FROM " + fullTableName "SELECT ICOL,VCOL FROM " + fullTableName
@ -290,23 +290,23 @@ public void testTableNameWithTableColumnsWithSchema() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableSqlWithSchema() throws Exception { public void testTableSqlWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName); String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.schemaName = schemaName; jobConfig.fromJobConfig.schemaName = schemaName;
jobConf.fromJobConfig.sql = tableSql; jobConfig.fromJobConfig.sql = tableSql;
jobConf.fromJobConfig.partitionColumn = "DCOL"; jobConfig.fromJobConfig.partitionColumn = "DCOL";
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT * FROM " + fullTableName "SELECT * FROM " + fullTableName
@ -321,68 +321,68 @@ public void testTableSqlWithSchema() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testGetSchemaForTable() throws Exception { public void testGetSchemaForTable() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.schemaName = schemaName; jobConfig.fromJobConfig.schemaName = schemaName;
jobConf.fromJobConfig.tableName = tableName; jobConfig.fromJobConfig.tableName = tableName;
jobConf.fromJobConfig.partitionColumn = "DCOL"; jobConfig.fromJobConfig.partitionColumn = "DCOL";
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
Schema schema = initializer.getSchema(initializerContext, connConf, jobConf); Schema schema = initializer.getSchema(initializerContext, linkConfig, jobConfig);
assertEquals(getSchema(jobConf.fromJobConfig.schemaName + "." + tableName), schema); assertEquals(getSchema(jobConfig.fromJobConfig.schemaName + "." + tableName), schema);
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testGetSchemaForSql() throws Exception { public void testGetSchemaForSql() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.schemaName = schemaName; jobConfig.fromJobConfig.schemaName = schemaName;
jobConf.fromJobConfig.sql = tableSql; jobConfig.fromJobConfig.sql = tableSql;
jobConf.fromJobConfig.partitionColumn = "DCOL"; jobConfig.fromJobConfig.partitionColumn = "DCOL";
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
Schema schema = initializer.getSchema(initializerContext, connConf, jobConf); Schema schema = initializer.getSchema(initializerContext, linkConfig, jobConfig);
assertEquals(getSchema("Query"), schema); assertEquals(getSchema("Query"), schema);
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableSqlWithTableColumnsWithSchema() throws Exception { public void testTableSqlWithTableColumnsWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName); String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.fromJobConfig.schemaName = schemaName; jobConfig.fromJobConfig.schemaName = schemaName;
jobConf.fromJobConfig.sql = tableSql; jobConfig.fromJobConfig.sql = tableSql;
jobConf.fromJobConfig.columns = tableColumns; jobConfig.fromJobConfig.columns = tableColumns;
jobConf.fromJobConfig.partitionColumn = "DCOL"; jobConfig.fromJobConfig.partitionColumn = "DCOL";
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcFromInitializer(); Initializer initializer = new GenericJdbcFromInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, verifyResult(context,
"SELECT SQOOP_SUBQUERY_ALIAS.ICOL,SQOOP_SUBQUERY_ALIAS.VCOL FROM " "SELECT SQOOP_SUBQUERY_ALIAS.ICOL,SQOOP_SUBQUERY_ALIAS.VCOL FROM "

View File

@ -82,10 +82,10 @@ public void tearDown() {
public void testInsert() throws Exception { public void testInsert() throws Exception {
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
LinkConfiguration connectionConfig = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
connectionConfig.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connectionConfig.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
ToJobConfiguration jobConfig = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
@ -95,7 +95,7 @@ public void testInsert() throws Exception {
Loader loader = new GenericJdbcLoader(); Loader loader = new GenericJdbcLoader();
DummyReader reader = new DummyReader(); DummyReader reader = new DummyReader();
LoaderContext loaderContext = new LoaderContext(context, reader, null); LoaderContext loaderContext = new LoaderContext(context, reader, null);
loader.load(loaderContext, connectionConfig, jobConfig); loader.load(loaderContext, linkConfig, jobConfig);
int index = START; int index = START;
ResultSet rs = executor.executeQuery("SELECT * FROM " ResultSet rs = executor.executeQuery("SELECT * FROM "

View File

@ -58,12 +58,12 @@ public void testIntegerEvenPartition() throws Exception {
GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE,
String.valueOf(START + NUMBER_OF_ROWS - 1)); String.valueOf(START + NUMBER_OF_ROWS - 1));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 5, null); PartitionerContext partitionerContext = new PartitionerContext(context, 5, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"-5 <= ICOL AND ICOL < -3", "-5 <= ICOL AND ICOL < -3",
@ -90,12 +90,12 @@ public void testIntegerUnevenPartition() throws Exception {
GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE,
String.valueOf(START + NUMBER_OF_ROWS - 1)); String.valueOf(START + NUMBER_OF_ROWS - 1));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"-5 <= ICOL AND ICOL < -1", "-5 <= ICOL AND ICOL < -1",
@ -120,12 +120,12 @@ public void testIntegerOverPartition() throws Exception {
GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE,
String.valueOf(START + NUMBER_OF_ROWS - 1)); String.valueOf(START + NUMBER_OF_ROWS - 1));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 13, null); PartitionerContext partitionerContext = new PartitionerContext(context, 13, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"-5 <= ICOL AND ICOL < -4", "-5 <= ICOL AND ICOL < -4",
@ -157,12 +157,12 @@ public void testFloatingPointEvenPartition() throws Exception {
GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE,
String.valueOf((double)(START + NUMBER_OF_ROWS - 1))); String.valueOf((double)(START + NUMBER_OF_ROWS - 1)));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 5, null); PartitionerContext partitionerContext = new PartitionerContext(context, 5, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"-5.0 <= DCOL AND DCOL < -3.0", "-5.0 <= DCOL AND DCOL < -3.0",
@ -189,12 +189,12 @@ public void testFloatingPointUnevenPartition() throws Exception {
GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE,
String.valueOf((double)(START + NUMBER_OF_ROWS - 1))); String.valueOf((double)(START + NUMBER_OF_ROWS - 1)));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"-5.0 <= DCOL AND DCOL < -1.6666666666666665", "-5.0 <= DCOL AND DCOL < -1.6666666666666665",
@ -211,12 +211,12 @@ public void testNumericEvenPartition() throws Exception {
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE, String.valueOf(START)); context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE, String.valueOf(START));
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, String.valueOf(START + NUMBER_OF_ROWS - 1)); context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, String.valueOf(START + NUMBER_OF_ROWS - 1));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 5, null); PartitionerContext partitionerContext = new PartitionerContext(context, 5, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"-5 <= ICOL AND ICOL < -3", "-5 <= ICOL AND ICOL < -3",
@ -235,12 +235,12 @@ public void testNumericUnevenPartition() throws Exception {
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE, String.valueOf(new BigDecimal(START))); context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE, String.valueOf(new BigDecimal(START)));
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, String.valueOf(new BigDecimal(START + NUMBER_OF_ROWS - 1))); context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, String.valueOf(new BigDecimal(START + NUMBER_OF_ROWS - 1)));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[]{ verifyResult(partitions, new String[]{
"-5 <= DCOL AND DCOL < -2", "-5 <= DCOL AND DCOL < -2",
@ -257,12 +257,12 @@ public void testNumericSinglePartition() throws Exception {
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE, String.valueOf(new BigDecimal(START))); context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE, String.valueOf(new BigDecimal(START)));
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, String.valueOf(new BigDecimal(START))); context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, String.valueOf(new BigDecimal(START)));
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[]{ verifyResult(partitions, new String[]{
"DCOL = -5", "DCOL = -5",
@ -282,12 +282,12 @@ public void testDatePartition() throws Exception {
.toString()); .toString());
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[]{ verifyResult(partitions, new String[]{
@ -311,12 +311,12 @@ public void testTimePartition() throws Exception {
Time.valueOf("10:40:50").toString()); Time.valueOf("10:40:50").toString());
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[]{ verifyResult(partitions, new String[]{
"'01:01:01' <= TCOL AND TCOL < '04:14:17'", "'01:01:01' <= TCOL AND TCOL < '04:14:17'",
@ -337,12 +337,12 @@ public void testTimestampPartition() throws Exception {
context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE, context.setString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE,
Timestamp.valueOf("2013-12-31 10:40:50.654").toString()); Timestamp.valueOf("2013-12-31 10:40:50.654").toString());
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[]{ verifyResult(partitions, new String[]{
"'2013-01-01 01:01:01.123' <= TSCOL AND TSCOL < '2013-05-02 12:14:17.634'", "'2013-01-01 01:01:01.123' <= TSCOL AND TSCOL < '2013-05-02 12:14:17.634'",
"'2013-05-02 12:14:17.634' <= TSCOL AND TSCOL < '2013-08-31 23:27:34.144'", "'2013-05-02 12:14:17.634' <= TSCOL AND TSCOL < '2013-08-31 23:27:34.144'",
@ -362,12 +362,12 @@ public void testBooleanPartition() throws Exception {
context.setString(GenericJdbcConnectorConstants context.setString(GenericJdbcConnectorConstants
.CONNECTOR_JDBC_PARTITION_MAXVALUE, "1"); .CONNECTOR_JDBC_PARTITION_MAXVALUE, "1");
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 3, null); PartitionerContext partitionerContext = new PartitionerContext(context, 3, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[]{ verifyResult(partitions, new String[]{
"BCOL = TRUE", "BCOL = TRUE",
"BCOL = FALSE", "BCOL = FALSE",
@ -386,12 +386,12 @@ public void testVarcharPartition() throws Exception {
context.setString(GenericJdbcConnectorConstants context.setString(GenericJdbcConnectorConstants
.CONNECTOR_JDBC_PARTITION_MAXVALUE, "Z"); .CONNECTOR_JDBC_PARTITION_MAXVALUE, "Z");
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 25, null); PartitionerContext partitionerContext = new PartitionerContext(context, 25, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"'A' <= VCCOL AND VCCOL < 'B'", "'A' <= VCCOL AND VCCOL < 'B'",
@ -434,11 +434,11 @@ public void testVarcharPartition2() throws Exception {
context.setString(GenericJdbcConnectorConstants context.setString(GenericJdbcConnectorConstants
.CONNECTOR_JDBC_PARTITION_MAXVALUE, "Warty Warthog"); .CONNECTOR_JDBC_PARTITION_MAXVALUE, "Warty Warthog");
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 5, null); PartitionerContext partitionerContext = new PartitionerContext(context, 5, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
assertEquals(partitions.size(), 5); assertEquals(partitions.size(), 5);
// First partition needs to contain entire upper bound // First partition needs to contain entire upper bound
assertTrue(partitions.get(0).toString().contains("Breezy Badger")); assertTrue(partitions.get(0).toString().contains("Breezy Badger"));
@ -458,13 +458,13 @@ public void testVarcharPartitionWithCommonPrefix() throws Exception {
context.setString(GenericJdbcConnectorConstants context.setString(GenericJdbcConnectorConstants
.CONNECTOR_JDBC_PARTITION_MAXVALUE, "AAF"); .CONNECTOR_JDBC_PARTITION_MAXVALUE, "AAF");
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 5, null); PartitionerContext partitionerContext = new PartitionerContext(context, 5, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"'AAA' <= VCCOL AND VCCOL < 'AAB'", "'AAA' <= VCCOL AND VCCOL < 'AAB'",
@ -488,14 +488,14 @@ public void testPatitionWithNullValues() throws Exception {
context.setString(GenericJdbcConnectorConstants context.setString(GenericJdbcConnectorConstants
.CONNECTOR_JDBC_PARTITION_MAXVALUE, "AAE"); .CONNECTOR_JDBC_PARTITION_MAXVALUE, "AAE");
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
FromJobConfiguration jobConf = new FromJobConfiguration(); FromJobConfiguration jobConfig = new FromJobConfiguration();
jobConf.fromJobConfig.partitionColumnNull = true; jobConfig.fromJobConfig.partitionColumnNull = true;
Partitioner partitioner = new GenericJdbcPartitioner(); Partitioner partitioner = new GenericJdbcPartitioner();
PartitionerContext partitionerContext = new PartitionerContext(context, 5, null); PartitionerContext partitionerContext = new PartitionerContext(context, 5, null);
List<Partition> partitions = partitioner.getPartitions(partitionerContext, connConf, jobConf); List<Partition> partitions = partitioner.getPartitions(partitionerContext, linkConfig, jobConfig);
verifyResult(partitions, new String[] { verifyResult(partitions, new String[] {
"VCCOL IS NULL", "VCCOL IS NULL",

View File

@ -17,6 +17,10 @@
*/ */
package org.apache.sqoop.connector.jdbc; package org.apache.sqoop.connector.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.apache.sqoop.common.MutableContext; import org.apache.sqoop.common.MutableContext;
import org.apache.sqoop.common.MutableMapContext; import org.apache.sqoop.common.MutableMapContext;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
@ -24,17 +28,13 @@
import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration;
import org.apache.sqoop.job.etl.Initializer; import org.apache.sqoop.job.etl.Initializer;
import org.apache.sqoop.job.etl.InitializerContext; import org.apache.sqoop.job.etl.InitializerContext;
import org.apache.sqoop.validation.ConfigValidationResult;
import org.apache.sqoop.validation.ConfigValidationRunner;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.ValidationResult;
import org.apache.sqoop.validation.ValidationRunner;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class TestToInitializer { public class TestToInitializer {
private final String schemaName; private final String schemaName;
private final String tableName; private final String tableName;
@ -82,21 +82,21 @@ public void tearDown() {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableName() throws Exception { public void testTableName() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemalessTableName); String fullTableName = executor.delimitIdentifier(schemalessTableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + fullTableName + " VALUES (?,?,?)"); verifyResult(context, "INSERT INTO " + fullTableName + " VALUES (?,?,?)");
} }
@ -104,22 +104,22 @@ public void testTableName() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableNameWithTableColumns() throws Exception { public void testTableNameWithTableColumns() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemalessTableName); String fullTableName = executor.delimitIdentifier(schemalessTableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
jobConf.toJobConfig.columns = tableColumns; jobConfig.toJobConfig.columns = tableColumns;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + fullTableName + " (" + tableColumns + ") VALUES (?,?)"); verifyResult(context, "INSERT INTO " + fullTableName + " (" + tableColumns + ") VALUES (?,?)");
} }
@ -127,19 +127,19 @@ public void testTableNameWithTableColumns() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableSql() throws Exception { public void testTableSql() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.sql = schemalessTableSql; jobConfig.toJobConfig.sql = schemalessTableSql;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + executor.delimitIdentifier(schemalessTableName) + " VALUES (?,?,?)"); verifyResult(context, "INSERT INTO " + executor.delimitIdentifier(schemalessTableName) + " VALUES (?,?,?)");
} }
@ -147,22 +147,22 @@ public void testTableSql() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableNameWithSchema() throws Exception { public void testTableNameWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName); String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.schemaName = schemaName; jobConfig.toJobConfig.schemaName = schemaName;
jobConf.toJobConfig.tableName = tableName; jobConfig.toJobConfig.tableName = tableName;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + fullTableName + " VALUES (?,?,?)"); verifyResult(context, "INSERT INTO " + fullTableName + " VALUES (?,?,?)");
} }
@ -170,23 +170,23 @@ public void testTableNameWithSchema() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableNameWithTableColumnsWithSchema() throws Exception { public void testTableNameWithTableColumnsWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName); String fullTableName = executor.delimitIdentifier(schemaName) + "." + executor.delimitIdentifier(tableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.schemaName = schemaName; jobConfig.toJobConfig.schemaName = schemaName;
jobConf.toJobConfig.tableName = tableName; jobConfig.toJobConfig.tableName = tableName;
jobConf.toJobConfig.columns = tableColumns; jobConfig.toJobConfig.columns = tableColumns;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + fullTableName + " (" + tableColumns + ") VALUES (?,?)"); verifyResult(context, "INSERT INTO " + fullTableName + " (" + tableColumns + ") VALUES (?,?)");
} }
@ -194,20 +194,20 @@ public void testTableNameWithTableColumnsWithSchema() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testTableSqlWithSchema() throws Exception { public void testTableSqlWithSchema() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.schemaName = schemaName; jobConfig.toJobConfig.schemaName = schemaName;
jobConf.toJobConfig.sql = tableSql; jobConfig.toJobConfig.sql = tableSql;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + executor.delimitIdentifier(tableName) + " VALUES (?,?,?)"); verifyResult(context, "INSERT INTO " + executor.delimitIdentifier(tableName) + " VALUES (?,?,?)");
} }
@ -229,13 +229,13 @@ private void createTable(String tableName) {
@Test @Test
public void testNonExistingStageTable() throws Exception { public void testNonExistingStageTable() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
jobConf.toJobConfig.stageTableName = stageTableName; jobConfig.toJobConfig.stageTableName = stageTableName;
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@ -243,7 +243,7 @@ public void testNonExistingStageTable() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
try { try {
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
fail("Initialization should fail for non-existing stage table."); fail("Initialization should fail for non-existing stage table.");
} catch(SqoopException se) { } catch(SqoopException se) {
//expected //expected
@ -253,15 +253,15 @@ public void testNonExistingStageTable() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testNonEmptyStageTable() throws Exception { public void testNonEmptyStageTable() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullStageTableName = executor.delimitIdentifier(stageTableName); String fullStageTableName = executor.delimitIdentifier(stageTableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
jobConf.toJobConfig.stageTableName = stageTableName; jobConfig.toJobConfig.stageTableName = stageTableName;
createTable(fullStageTableName); createTable(fullStageTableName);
executor.executeUpdate("INSERT INTO " + fullStageTableName + executor.executeUpdate("INSERT INTO " + fullStageTableName +
" VALUES(1, 1.1, 'one')"); " VALUES(1, 1.1, 'one')");
@ -271,7 +271,7 @@ public void testNonEmptyStageTable() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
try { try {
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
fail("Initialization should fail for non-empty stage table."); fail("Initialization should fail for non-empty stage table.");
} catch(SqoopException se) { } catch(SqoopException se) {
//expected //expected
@ -280,17 +280,17 @@ public void testNonEmptyStageTable() throws Exception {
@Test @Test
public void testClearStageTableValidation() throws Exception { public void testClearStageTableValidation() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
//specifying clear stage table flag without specifying name of //specifying clear stage table flag without specifying name of
// the stage table // the stage table
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
jobConf.toJobConfig.clearStageTable = false; jobConfig.toJobConfig.clearStageTable = false;
ValidationRunner validationRunner = new ValidationRunner(); ConfigValidationRunner validationRunner = new ConfigValidationRunner();
ValidationResult result = validationRunner.validate(jobConf); ConfigValidationResult result = validationRunner.validate(jobConfig);
assertEquals("User should not specify clear stage table flag without " + assertEquals("User should not specify clear stage table flag without " +
"specifying name of the stage table", "specifying name of the stage table",
Status.UNACCEPTABLE, Status.UNACCEPTABLE,
@ -298,8 +298,8 @@ public void testClearStageTableValidation() throws Exception {
assertTrue(result.getMessages().containsKey( assertTrue(result.getMessages().containsKey(
"toJobConfig")); "toJobConfig"));
jobConf.toJobConfig.clearStageTable = true; jobConfig.toJobConfig.clearStageTable = true;
result = validationRunner.validate(jobConf); result = validationRunner.validate(jobConfig);
assertEquals("User should not specify clear stage table flag without " + assertEquals("User should not specify clear stage table flag without " +
"specifying name of the stage table", "specifying name of the stage table",
Status.UNACCEPTABLE, Status.UNACCEPTABLE,
@ -310,17 +310,17 @@ public void testClearStageTableValidation() throws Exception {
@Test @Test
public void testStageTableWithoutTable() throws Exception { public void testStageTableWithoutTable() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
//specifying stage table without specifying table name //specifying stage table without specifying table name
jobConf.toJobConfig.stageTableName = stageTableName; jobConfig.toJobConfig.stageTableName = stageTableName;
jobConf.toJobConfig.sql = ""; jobConfig.toJobConfig.sql = "";
ValidationRunner validationRunner = new ValidationRunner(); ConfigValidationRunner validationRunner = new ConfigValidationRunner();
ValidationResult result = validationRunner.validate(jobConf); ConfigValidationResult result = validationRunner.validate(jobConfig);
assertEquals("Stage table name cannot be specified without specifying " + assertEquals("Stage table name cannot be specified without specifying " +
"table name", Status.UNACCEPTABLE, result.getStatus()); "table name", Status.UNACCEPTABLE, result.getStatus());
assertTrue(result.getMessages().containsKey( assertTrue(result.getMessages().containsKey(
@ -330,16 +330,16 @@ public void testStageTableWithoutTable() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testClearStageTable() throws Exception { public void testClearStageTable() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullStageTableName = executor.delimitIdentifier(stageTableName); String fullStageTableName = executor.delimitIdentifier(stageTableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
jobConf.toJobConfig.stageTableName = stageTableName; jobConfig.toJobConfig.stageTableName = stageTableName;
jobConf.toJobConfig.clearStageTable = true; jobConfig.toJobConfig.clearStageTable = true;
createTable(fullStageTableName); createTable(fullStageTableName);
executor.executeUpdate("INSERT INTO " + fullStageTableName + executor.executeUpdate("INSERT INTO " + fullStageTableName +
" VALUES(1, 1.1, 'one')"); " VALUES(1, 1.1, 'one')");
@ -348,7 +348,7 @@ public void testClearStageTable() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
assertEquals("Stage table should have been cleared", 0, assertEquals("Stage table should have been cleared", 0,
executor.getTableRowCount(stageTableName)); executor.getTableRowCount(stageTableName));
} }
@ -356,22 +356,22 @@ public void testClearStageTable() throws Exception {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testStageTable() throws Exception { public void testStageTable() throws Exception {
LinkConfiguration connConf = new LinkConfiguration(); LinkConfiguration linkConfig = new LinkConfiguration();
ToJobConfiguration jobConf = new ToJobConfiguration(); ToJobConfiguration jobConfig = new ToJobConfiguration();
String fullStageTableName = executor.delimitIdentifier(stageTableName); String fullStageTableName = executor.delimitIdentifier(stageTableName);
connConf.link.jdbcDriver = GenericJdbcTestConstants.DRIVER; linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
connConf.link.connectionString = GenericJdbcTestConstants.URL; linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
jobConf.toJobConfig.tableName = schemalessTableName; jobConfig.toJobConfig.tableName = schemalessTableName;
jobConf.toJobConfig.stageTableName = stageTableName; jobConfig.toJobConfig.stageTableName = stageTableName;
createTable(fullStageTableName); createTable(fullStageTableName);
MutableContext context = new MutableMapContext(); MutableContext context = new MutableMapContext();
InitializerContext initializerContext = new InitializerContext(context); InitializerContext initializerContext = new InitializerContext(context);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Initializer initializer = new GenericJdbcToInitializer(); Initializer initializer = new GenericJdbcToInitializer();
initializer.initialize(initializerContext, connConf, jobConf); initializer.initialize(initializerContext, linkConfig, jobConfig);
verifyResult(context, "INSERT INTO " + fullStageTableName + verifyResult(context, "INSERT INTO " + fullStageTableName +
" VALUES (?,?,?)"); " VALUES (?,?,?)");

View File

@ -18,21 +18,20 @@
*/ */
package org.apache.sqoop.connector.hdfs; package org.apache.sqoop.connector.hdfs;
import org.apache.log4j.Logger;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.connector.spi.RepositoryUpgrader;
import org.apache.sqoop.model.MConnectionForms;
import org.apache.sqoop.model.MForm;
import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MJobForms;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.connector.spi.RepositoryUpgrader;
import org.apache.sqoop.model.MConfigList;
import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MLinkConfig;
public class HdfsConfigUpgrader extends RepositoryUpgrader { public class HdfsConfigUpgrader extends RepositoryUpgrader {
private static final Logger LOG = private static final Logger LOG = Logger.getLogger(HdfsConfigUpgrader.class);
Logger.getLogger(HdfsConfigUpgrader.class);
/* /*
* For now, there is no real upgrade. So copy all data over, * For now, there is no real upgrade. So copy all data over,
@ -41,37 +40,36 @@ public class HdfsConfigUpgrader extends RepositoryUpgrader {
*/ */
@Override @Override
public void upgrade(MConnectionForms original, public void upgrade(MLinkConfig original, MLinkConfig upgradeTarget) {
MConnectionForms upgradeTarget) { doUpgrade(original.getConfigs(), upgradeTarget.getConfigs());
doUpgrade(original.getForms(), upgradeTarget.getForms());
} }
@Override @Override
public void upgrade(MJobForms original, MJobForms upgradeTarget) { public void upgrade(MConfigList original, MConfigList upgradeTarget) {
doUpgrade(original.getForms(), upgradeTarget.getForms()); doUpgrade(original.getConfigs(), upgradeTarget.getConfigs());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void doUpgrade(List<MForm> original, List<MForm> target) { private void doUpgrade(List<MConfig> original, List<MConfig> target) {
// Easier to find the form in the original forms list if we use a map. // Easier to find the config in the original list if we use a map.
// Since the constructor of MJobForms takes a list, // Since the constructor takes a list,
// index is not guaranteed to be the same, so we need to look for // index is not guaranteed to be the same, so we need to look for
// equivalence // equivalence
Map<String, MForm> formMap = new HashMap<String, MForm>(); Map<String, MConfig> configMap = new HashMap<String, MConfig>();
for (MForm form : original) { for (MConfig config : original) {
formMap.put(form.getName(), form); configMap.put(config.getName(), config);
} }
for (MForm form : target) { for (MConfig config : target) {
List<MInput<?>> inputs = form.getInputs(); List<MInput<?>> inputs = config.getInputs();
MForm originalForm = formMap.get(form.getName()); MConfig originalConfig = configMap.get(config.getName());
if (originalForm == null) { if (originalConfig == null) {
LOG.warn("Form: '" + form.getName() + "' not present in old " + LOG.warn("Config: '" + config.getName() + "' not present in old " +
"connector. So it and its inputs will not be transferred by the upgrader."); "connector. So it and its inputs will not be transferred by the upgrader.");
continue; continue;
} }
for (MInput input : inputs) { for (MInput input : inputs) {
try { try {
MInput originalInput = originalForm.getInput(input.getName()); MInput originalInput = originalConfig.getInput(input.getName());
input.setValue(originalInput.getValue()); input.setValue(originalInput.getValue());
} catch (SqoopException ex) { } catch (SqoopException ex) {
LOG.warn("Input: '" + input.getName() + "' not present in old " + LOG.warn("Input: '" + input.getName() + "' not present in old " +

View File

@ -118,7 +118,7 @@ public To getTo() {
* @return Validator object * @return Validator object
*/ */
@Override @Override
public Validator getValidator() { public Validator getConfigValidator() {
return hdfsValidator; return hdfsValidator;
} }

View File

@ -52,8 +52,8 @@ public class HdfsExtractor extends Extractor<LinkConfiguration, FromJobConfigura
@Override @Override
public void extract(ExtractorContext context, public void extract(ExtractorContext context,
LinkConfiguration connectionConfiguration, LinkConfiguration linkConfig,
FromJobConfiguration jobConfiguration, HdfsPartition partition) { FromJobConfiguration fromJobConfig, HdfsPartition partition) {
conf = ((PrefixContext) context.getContext()).getConfiguration(); conf = ((PrefixContext) context.getContext()).getConfiguration();
dataWriter = context.getDataWriter(); dataWriter = context.getDataWriter();

View File

@ -29,16 +29,16 @@ public class HdfsInitializer extends Initializer {
* promoted to all other part of the workflow automatically. * promoted to all other part of the workflow automatically.
* *
* @param context Initializer context object * @param context Initializer context object
* @param linkConf Connector's link configuration object * @param linkConfig Connector's link configuration object
* @param jobConf Connector's job configuration object * @param jobConf Connector's job configuration object
*/ */
@Override @Override
public void initialize(InitializerContext context, Object linkConf, Object jobConf) { public void initialize(InitializerContext context, Object linkConfig, Object jobConf) {
} }
@Override @Override
public Schema getSchema(InitializerContext context, Object linkConf, Object jobConf) { public Schema getSchema(InitializerContext context, Object linkConfig, Object jobConfig) {
return new Schema("HDFS file"); return new Schema("HDFS file");
} }
} }

View File

@ -42,19 +42,19 @@ public class HdfsLoader extends Loader<LinkConfiguration, ToJobConfiguration> {
* Load data to target. * Load data to target.
* *
* @param context Loader context object * @param context Loader context object
* @param linkConf Link configuration * @param linkConfig Link configuration
* @param toJobConf Job configuration * @param toJobConfig Job configuration
* @throws Exception * @throws Exception
*/ */
@Override @Override
public void load(LoaderContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) throws Exception { public void load(LoaderContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) throws Exception {
DataReader reader = context.getDataReader(); DataReader reader = context.getDataReader();
Configuration conf = ((PrefixContext)context.getContext()).getConfiguration(); Configuration conf = ((PrefixContext)context.getContext()).getConfiguration();
String directoryName = toJobConf.toJobConfig.outputDirectory; String directoryName = toJobConfig.toJobConfig.outputDirectory;
String codecname = getCompressionCodecName(toJobConf); String codecname = getCompressionCodecName(toJobConfig);
CompressionCodec codec = null; CompressionCodec codec = null;
if (codecname != null) { if (codecname != null) {
@ -73,12 +73,12 @@ public void load(LoaderContext context, LinkConfiguration linkConf, ToJobConfigu
} }
} }
String filename = directoryName + "/" + UUID.randomUUID() + getExtension(toJobConf,codec); String filename = directoryName + "/" + UUID.randomUUID() + getExtension(toJobConfig,codec);
try { try {
Path filepath = new Path(filename); Path filepath = new Path(filename);
GenericHdfsWriter filewriter = getWriter(toJobConf); GenericHdfsWriter filewriter = getWriter(toJobConfig);
filewriter.initialize(filepath,conf,codec); filewriter.initialize(filepath,conf,codec);

View File

@ -68,12 +68,12 @@ public class HdfsPartitioner extends Partitioner<LinkConfiguration, FromJobConfi
@Override @Override
public List<Partition> getPartitions(PartitionerContext context, public List<Partition> getPartitions(PartitionerContext context,
LinkConfiguration linkConfiguration, FromJobConfiguration jobConfiguration) { LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) {
Configuration conf = ((PrefixContext)context.getContext()).getConfiguration(); Configuration conf = ((PrefixContext)context.getContext()).getConfiguration();
try { try {
long numInputBytes = getInputSize(conf, jobConfiguration.fromJobConfig.inputDirectory); long numInputBytes = getInputSize(conf, fromJobConfig.fromJobConfig.inputDirectory);
maxSplitSize = numInputBytes / context.getMaxPartitions(); maxSplitSize = numInputBytes / context.getMaxPartitions();
if(numInputBytes % context.getMaxPartitions() != 0 ) { if(numInputBytes % context.getMaxPartitions() != 0 ) {
@ -118,7 +118,7 @@ public List<Partition> getPartitions(PartitionerContext context,
} }
// all the files in input set // all the files in input set
String indir = jobConfiguration.fromJobConfig.inputDirectory; String indir = fromJobConfig.fromJobConfig.inputDirectory;
FileSystem fs = FileSystem.get(conf); FileSystem fs = FileSystem.get(conf);
List<Path> paths = new LinkedList<Path>(); List<Path> paths = new LinkedList<Path>();

View File

@ -19,7 +19,7 @@
import org.apache.sqoop.connector.hdfs.configuration.*; import org.apache.sqoop.connector.hdfs.configuration.*;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.Validation; import org.apache.sqoop.validation.ConfigValidator;
import org.apache.sqoop.validation.Validator; import org.apache.sqoop.validation.Validator;
/** /**
@ -28,54 +28,45 @@
public class HdfsValidator extends Validator { public class HdfsValidator extends Validator {
@Override @Override
public Validation validateLink(Object connectionConfiguration) { public ConfigValidator validateConfigForJob(Object jobConfiguration) {
Validation validation = new Validation(LinkConfiguration.class); return super.validateConfigForJob(jobConfiguration);
// No validation on connection object
return validation;
}
@Override
public Validation validateJob(Object jobConfiguration) {
//TODO: I'm pretty sure this needs to call either validateExportJob or validateImportJob, depending on context
return super.validateJob(jobConfiguration);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Validation validateFromJob(Object jobConfiguration) { private ConfigValidator validateFromJob(Object jobConfiguration) {
Validation validation = new Validation(FromJobConfiguration.class); ConfigValidator validation = new ConfigValidator(FromJobConfiguration.class);
FromJobConfiguration configuration = (FromJobConfiguration)jobConfiguration; FromJobConfiguration configuration = (FromJobConfiguration)jobConfiguration;
validateInputForm(validation, configuration.fromJobConfig); validateInputConfig(validation, configuration.fromJobConfig);
return validation; return validation;
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Validation validateToJob(Object jobConfiguration) { private ConfigValidator validateToJob(Object jobConfiguration) {
Validation validation = new Validation(ToJobConfiguration.class); ConfigValidator validation = new ConfigValidator(ToJobConfiguration.class);
ToJobConfiguration configuration = (ToJobConfiguration)jobConfiguration; ToJobConfiguration configuration = (ToJobConfiguration)jobConfiguration;
validateOutputForm(validation, configuration.toJobConfig); validateOutputConfig(validation, configuration.toJobConfig);
return validation; return validation;
} }
private void validateInputForm(Validation validation, FromJobConfig input) { private void validateInputConfig(ConfigValidator validation, FromJobConfig inputConfig) {
if(input.inputDirectory == null || input.inputDirectory.isEmpty()) { if(inputConfig.inputDirectory == null || inputConfig.inputDirectory.isEmpty()) {
validation.addMessage(Status.UNACCEPTABLE, "input", "inputDirectory", "Input directory is empty"); validation.addMessage(Status.UNACCEPTABLE, "input", "inputDirectory", "Input directory is empty");
} }
} }
private void validateOutputForm(Validation validation, ToJobConfig output) { private void validateOutputConfig(ConfigValidator validation, ToJobConfig outputConfig) {
if(output.outputDirectory == null || output.outputDirectory.isEmpty()) { if(outputConfig.outputDirectory == null || outputConfig.outputDirectory.isEmpty()) {
validation.addMessage(Status.UNACCEPTABLE, "output", "outputDirectory", "Output directory is empty"); validation.addMessage(Status.UNACCEPTABLE, "output", "outputDirectory", "Output directory is empty");
} }
if(output.customCompression != null && if(outputConfig.customCompression != null &&
output.customCompression.trim().length() > 0 && outputConfig.customCompression.trim().length() > 0 &&
output.compression != ToCompression.CUSTOM) { outputConfig.compression != ToCompression.CUSTOM) {
validation.addMessage(Status.UNACCEPTABLE, "output", "compression", validation.addMessage(Status.UNACCEPTABLE, "output", "compression",
"custom compression should be blank as " + output.compression + " is being used."); "custom compression should be blank as " + outputConfig.compression + " is being used.");
} }
if(output.compression == ToCompression.CUSTOM && if(outputConfig.compression == ToCompression.CUSTOM &&
(output.customCompression == null || (outputConfig.customCompression == null ||
output.customCompression.trim().length() == 0) outputConfig.customCompression.trim().length() == 0)
) { ) {
validation.addMessage(Status.UNACCEPTABLE, "output", "compression", validation.addMessage(Status.UNACCEPTABLE, "output", "compression",
"custom compression is blank."); "custom compression is blank.");

View File

@ -17,13 +17,13 @@
*/ */
package org.apache.sqoop.connector.hdfs.configuration; package org.apache.sqoop.connector.hdfs.configuration;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
/** /**
* *
*/ */
@FormClass @ConfigClass
public class FromJobConfig { public class FromJobConfig {
@Input(size = 255) public String inputDirectory; @Input(size = 255) public String inputDirectory;

View File

@ -18,11 +18,11 @@
package org.apache.sqoop.connector.hdfs.configuration; package org.apache.sqoop.connector.hdfs.configuration;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
@ConfigurationClass @ConfigurationClass
public class FromJobConfiguration { public class FromJobConfiguration {
@Form public FromJobConfig fromJobConfig; @Config public FromJobConfig fromJobConfig;
public FromJobConfiguration() { public FromJobConfiguration() {
fromJobConfig = new FromJobConfig(); fromJobConfig = new FromJobConfig();

View File

@ -17,13 +17,13 @@
*/ */
package org.apache.sqoop.connector.hdfs.configuration; package org.apache.sqoop.connector.hdfs.configuration;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
@FormClass @ConfigClass
public class LinkConfig { public class LinkConfig {
//Todo: Didn't find anything that belongs here... //Todo: Didn't find anything that belongs here...
// Since empty forms don't work (DERBYREPO_0008:The form contains no input metadata), I'm putting a dummy form here // Since empty forms don't work (DERBYREPO_0008:The config contains no input metadata), I'm putting a dummy config here
@Input(size = 255) public String dummy; @Input(size = 255) public String dummy;
} }

View File

@ -18,14 +18,14 @@
package org.apache.sqoop.connector.hdfs.configuration; package org.apache.sqoop.connector.hdfs.configuration;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
@ConfigurationClass @ConfigurationClass
public class LinkConfiguration { public class LinkConfiguration {
@Form @Config
public LinkConfig link; public LinkConfig linkConfig;
public LinkConfiguration() { public LinkConfiguration() {
link = new LinkConfig(); linkConfig = new LinkConfig();
} }
} }

View File

@ -17,13 +17,13 @@
*/ */
package org.apache.sqoop.connector.hdfs.configuration; package org.apache.sqoop.connector.hdfs.configuration;
import org.apache.sqoop.model.FormClass; import org.apache.sqoop.model.ConfigClass;
import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Input;
/** /**
* *
*/ */
@FormClass @ConfigClass
public class ToJobConfig { public class ToJobConfig {
@Input public ToFormat outputFormat; @Input public ToFormat outputFormat;

View File

@ -18,11 +18,11 @@
package org.apache.sqoop.connector.hdfs.configuration; package org.apache.sqoop.connector.hdfs.configuration;
import org.apache.sqoop.model.ConfigurationClass; import org.apache.sqoop.model.ConfigurationClass;
import org.apache.sqoop.model.Form; import org.apache.sqoop.model.Config;
@ConfigurationClass @ConfigurationClass
public class ToJobConfiguration { public class ToJobConfiguration {
@Form @Config
public ToJobConfig toJobConfig; public ToJobConfig toJobConfig;
public ToJobConfiguration() { public ToJobConfiguration() {

View File

@ -18,12 +18,12 @@
############################ ############################
# Link Config # Link Config
# #
link.label = Link configuration linkConfig.label = Link configuration
link.help = You must supply the information requested in order to \ linkConfig.help = You must supply the information requested in order to \
create a connection object. create a connection object.
link.dummy.label = Dummy parameter needed to get HDFS connector to register linkConfig.dummy.label = Dummy parameter needed to get HDFS connector to register
link.dummy.help = You can write anything here. Doesn't matter. linkConfig.dummy.help = You can write anything here. Doesn't matter.
# To Job Config # To Job Config
# #

View File

@ -18,6 +18,13 @@
*/ */
package org.apache.sqoop.connector.idf; package org.apache.sqoop.connector.idf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.schema.Schema; import org.apache.sqoop.schema.Schema;
import org.apache.sqoop.schema.type.Binary; import org.apache.sqoop.schema.type.Binary;
@ -26,13 +33,6 @@
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class TestCSVIntermediateDataFormat { public class TestCSVIntermediateDataFormat {
private final String BYTE_FIELD_ENCODING = "ISO-8859-1"; private final String BYTE_FIELD_ENCODING = "ISO-8859-1";

Some files were not shown because too many files have changed in this diff Show More