throw new SqoopException(ServerError.SERVER_0003,
"Expected one job metadata but got " + jobs.size());
}
// Job object
MJob job = jobs.get(0);
// Verify that user is not trying to spoof us
MJobForms connectorForms
= ConnectorManager.getConnectorMetadata(job.getConnectorId())
.getJobForms(job.getType());
MJobForms frameworkForms = FrameworkManager.getFramework()
.getJobForms(job.getType());
if(!connectorForms.equals(job.getConnectorPart())
|| !frameworkForms.equals(job.getFrameworkPart())) {
throw new SqoopException(ServerError.SERVER_0003,
"Detected incorrect form structure");
}
// Responsible connector for this session
SqoopConnector connector =
ConnectorManager.getConnector(job.getConnectorId());
// Get validator objects
Validator connectorValidator = connector.getValidator();
Validator frameworkValidator = FrameworkManager.getValidator();
// We need translate forms to configuration objects
Object connectorConfig = ClassUtils.instantiate(
connector.getJobConfigurationClass(job.getType()));
Object frameworkConfig = ClassUtils.instantiate(
FrameworkManager.getJobConfigurationClass(job.getType()));
FormUtils.fromForms(job.getConnectorPart().getForms(), connectorConfig);
FormUtils.fromForms(job.getFrameworkPart().getForms(), frameworkConfig);
// Validate both parts
Validation connectorValidation =
connectorValidator.validateJob(job.getType(), connectorConfig);
Validation frameworkValidation =
frameworkValidator.validateJob(job.getType(), frameworkConfig);
Status finalStatus = Status.getWorstStatus(connectorValidation.getStatus(),
frameworkValidation.getStatus());
// Return back validations in all cases
ValidationBean outputBean =
new ValidationBean(connectorValidation, frameworkValidation);
// If we're good enough let's perform the action
if(finalStatus.canProceed()) {
if(update) {
RepositoryManager.getRepository().updateJob(job);
} else {
RepositoryManager.getRepository().createJob(job);
outputBean.setId(job.getPersistenceId());
}
}
return outputBean;