}
public static MSubmission submit(long jobId) {
Repository repository = RepositoryManager.getRepository();
MJob job = repository.findJob(jobId);
if(job == null) {
throw new SqoopException(FrameworkError.FRAMEWORK_0004,
"Unknown job id " + jobId);
}
MConnection connection = repository.findConnection(job.getConnectionId());
SqoopConnector connector =
ConnectorManager.getConnector(job.getConnectorId());
// Transform forms to connector specific classes
Object connectorConnection = ClassUtils.instantiate(
connector.getConnectionConfigurationClass());
FormUtils.fromForms(connection.getConnectorPart().getForms(),
connectorConnection);
Object connectorJob = ClassUtils.instantiate(
connector.getJobConfigurationClass(job.getType()));
FormUtils.fromForms(job.getConnectorPart().getForms(), connectorJob);
// Transform framework specific forms
Object frameworkConnection = ClassUtils.instantiate(
getConnectionConfigurationClass());
FormUtils.fromForms(connection.getFrameworkPart().getForms(),
frameworkConnection);
Object frameworkJob = ClassUtils.instantiate(
getJobConfigurationClass(job.getType()));
FormUtils.fromForms(job.getFrameworkPart().getForms(), frameworkJob);
// Create request object
MSubmission summary = new MSubmission(jobId);
SubmissionRequest request = executionEngine.createSubmissionRequest();
// Save important variables to the submission request
request.setSummary(summary);
request.setConnector(connector);
request.setConfigConnectorConnection(connectorConnection);
request.setConfigConnectorJob(connectorJob);
request.setConfigFrameworkConnection(frameworkConnection);
request.setConfigFrameworkJob(frameworkJob);
request.setJobType(job.getType());
request.setJobName(job.getName());
request.setJobId(job.getPersistenceId());
request.setNotificationUrl(notificationBaseUrl + jobId);
// Let's register all important jars
// sqoop-common
request.addJarForClass(MapContext.class);
// sqoop-core
request.addJarForClass(FrameworkManager.class);
// sqoop-spi
request.addJarForClass(SqoopConnector.class);
// Execution engine jar
request.addJarForClass(executionEngine.getClass());
// Connector in use
request.addJarForClass(connector.getClass());
// Extra libraries that Sqoop code requires
request.addJarForClass(JSONValue.class);
// Get connector callbacks
switch (job.getType()) {
case IMPORT:
request.setConnectorCallbacks(connector.getImporter());
break;
case EXPORT:
request.setConnectorCallbacks(connector.getExporter());
break;
default:
throw new SqoopException(FrameworkError.FRAMEWORK_0005,
"Unsupported job type " + job.getType().name());
}
LOG.debug("Using callbacks: " + request.getConnectorCallbacks());
// Initialize submission from connector perspective
CallbackBase baseCallbacks = request.getConnectorCallbacks();
Class<? extends Initializer> initializerClass = baseCallbacks.getInitializer();
Initializer initializer = (Initializer) ClassUtils.instantiate(initializerClass);
if(initializer == null) {
throw new SqoopException(FrameworkError.FRAMEWORK_0006,
"Can't create initializer instance: " + initializerClass.getName());
}
// Initialize submission from connector perspective
initializer.initialize(request.getConnectorContext(),
request.getConfigConnectorConnection(),
request.getConfigConnectorJob());
// Add job specific jars to
request.addJars(initializer.getJars(request.getConnectorContext(),
request.getConfigConnectorConnection(),
request.getConfigConnectorJob()));
// Bootstrap job from framework perspective
switch (job.getType()) {
case IMPORT:
prepareImportSubmission(request);
break;
case EXPORT:
prepareExportSubmission(request);
break;
default:
throw new SqoopException(FrameworkError.FRAMEWORK_0005,
"Unsupported job type " + job.getType().name());
}
// Make sure that this job id is not currently running and submit the job
// only if it's not.
synchronized (submissionMutex) {