Java Code Examples for org.apache.sqoop.model.MJob#setPersistenceId()
The following examples show how to use
org.apache.sqoop.model.MJob#setPersistenceId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJobManager.java From sqoop-on-spark with Apache License 2.0 | 6 votes |
@Test public void testDisabledJob() { MJob testJob = job(123l, 456l); testJob.setEnabled(false); testJob.setPersistenceId(1111); SqoopException exception = new SqoopException(DriverError.DRIVER_0009, "Job id: " + testJob.getPersistenceId()); MJob mJobSpy = org.mockito.Mockito.spy(testJob); when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock); when(jdbcRepoMock.findJob(123l)).thenReturn(mJobSpy); try { jobManager.getJob(123l); } catch (SqoopException ex) { assertEquals(ex.getMessage(), exception.getMessage()); verify(repositoryManagerMock, times(1)).getRepository(); verify(jdbcRepoMock, times(1)).findJob(123l); } }
Example 2
Source File: TestJobHandling.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
@Test(expectedExceptions=SqoopException.class) public void testCreateDuplicateJob() throws Exception { // Duplicate jobs MJob job = getJob(); fillJob(job); job.setName("test"); handler.createJob(job, getDerbyDatabaseConnection()); assertEquals(1, job.getPersistenceId()); job.setPersistenceId(MJob.PERSISTANCE_ID_DEFAULT); handler.createJob(job, getDerbyDatabaseConnection()); }
Example 3
Source File: TestJobHandling.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SqoopException.class) public void testCreateDuplicateJob() throws Exception { // Duplicate jobs MJob job = handler.findJob(JOB_A_NAME, provider.getConnection()); job.setPersistenceId(MJob.PERSISTANCE_ID_DEFAULT); handler.createJob(job, provider.getConnection()); }
Example 4
Source File: JobBean.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
private MJob restoreJob(Object obj) { JSONObject object = (JSONObject) obj; long fromConnectorId = (Long) object.get(FROM_CONNECTOR_ID); long toConnectorId = (Long) object.get(TO_CONNECTOR_ID); long fromConnectionId = (Long) object.get(FROM_LINK_ID); long toConnectionId = (Long) object.get(TO_LINK_ID); JSONArray fromConfigJson = (JSONArray) object.get(FROM_CONFIG_VALUES); JSONArray toConfigJson = (JSONArray) object.get(TO_CONFIG_VALUES); JSONArray driverConfigJson = (JSONArray) object.get(DRIVER_CONFIG_VALUES); List<MConfig> fromConfig = restoreConfigList(fromConfigJson); List<MConfig> toConfig = restoreConfigList(toConfigJson); List<MConfig> driverConfig = restoreConfigList(driverConfigJson); MJob job = new MJob( fromConnectorId, toConnectorId, fromConnectionId, toConnectionId, new MFromConfig(fromConfig), new MToConfig(toConfig), new MDriverConfig(driverConfig) ); job.setPersistenceId((Long) object.get(ID)); job.setName((String) object.get(NAME)); job.setEnabled((Boolean) object.get(ENABLED)); job.setCreationUser((String) object.get(CREATION_USER)); job.setCreationDate(new Date((Long) object.get(CREATION_DATE))); job.setLastUpdateUser((String) object.get(UPDATE_USER)); job.setLastUpdateDate(new Date((Long) object.get(UPDATE_DATE))); return job; }
Example 5
Source File: BeanTestUtil.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
public static MJob createJob(String connectorName, String jobName, Long jobId, Date created, Date updated) { MJob job = BeanTestUtil.getJob(connectorName); job.setName(jobName); job.setPersistenceId(jobId); job.setCreationDate(created); job.setLastUpdateDate(updated); job.setEnabled(false); return job; }
Example 6
Source File: CommonRepositoryHandler.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public void createJob(MJob job, Connection conn) { PreparedStatement stmt = null; int result; try { stmt = conn.prepareStatement(crudQueries.getStmtInsertJob(), Statement.RETURN_GENERATED_KEYS); stmt.setString(1, job.getName()); stmt.setLong(2, job.getLinkId(Direction.FROM)); stmt.setLong(3, job.getLinkId(Direction.TO)); stmt.setBoolean(4, job.getEnabled()); stmt.setString(5, job.getCreationUser()); stmt.setTimestamp(6, new Timestamp(job.getCreationDate().getTime())); stmt.setString(7, job.getLastUpdateUser()); stmt.setTimestamp(8, new Timestamp(job.getLastUpdateDate().getTime())); result = stmt.executeUpdate(); if (result != 1) { throw new SqoopException(CommonRepositoryError.COMMON_0009, Integer.toString(result)); } ResultSet rsetJobId = stmt.getGeneratedKeys(); if (!rsetJobId.next()) { throw new SqoopException(CommonRepositoryError.COMMON_0010); } long jobId = rsetJobId.getLong(1); // from config for the job createInputValues(crudQueries.getStmtInsertJobInput(), jobId, job.getJobConfig(Direction.FROM).getConfigs(), conn); // to config for the job createInputValues(crudQueries.getStmtInsertJobInput(), jobId, job.getJobConfig(Direction.TO).getConfigs(), conn); // driver config per job createInputValues(crudQueries.getStmtInsertJobInput(), jobId, job.getDriverConfig().getConfigs(), conn); job.setPersistenceId(jobId); } catch (SQLException ex) { logException(ex, job); throw new SqoopException(CommonRepositoryError.COMMON_0023, ex); } finally { closeStatements(stmt); } }
Example 7
Source File: CommonRepositoryHandler.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
private List<MJob> loadJobs(PreparedStatement stmt, Connection conn) throws SQLException { List<MJob> jobs = new ArrayList<MJob>(); ResultSet rsJob = null; PreparedStatement fromConfigFetchStmt = null; PreparedStatement toConfigFetchStmt = null; PreparedStatement driverConfigfetchStmt = null; PreparedStatement jobInputFetchStmt = null; try { rsJob = stmt.executeQuery(); // Note: Job does not hold a explicit reference to the driver since every // job has the same driver long driverId = this.findDriver(MDriver.DRIVER_NAME, conn).getPersistenceId(); fromConfigFetchStmt = conn.prepareStatement(crudQueries.getStmtSelectConfigForConfigurable()); toConfigFetchStmt = conn.prepareStatement(crudQueries.getStmtSelectConfigForConfigurable()); driverConfigfetchStmt = conn.prepareStatement(crudQueries.getStmtSelectConfigForConfigurable()); jobInputFetchStmt = conn.prepareStatement(crudQueries.getStmtFetchJobInput()); while(rsJob.next()) { long fromConnectorId = rsJob.getLong(1); long toConnectorId = rsJob.getLong(2); long id = rsJob.getLong(3); String name = rsJob.getString(4); long fromLinkId = rsJob.getLong(5); long toLinkId = rsJob.getLong(6); boolean enabled = rsJob.getBoolean(7); String createBy = rsJob.getString(8); Date creationDate = rsJob.getTimestamp(9); String updateBy = rsJob.getString(10); Date lastUpdateDate = rsJob.getTimestamp(11); fromConfigFetchStmt.setLong(1, fromConnectorId); toConfigFetchStmt.setLong(1,toConnectorId); driverConfigfetchStmt.setLong(1, driverId); jobInputFetchStmt.setLong(1, id); jobInputFetchStmt.setLong(3, id); // FROM entity configs List<MConfig> fromConnectorLinkConfig = new ArrayList<MConfig>(); List<MConfig> fromConnectorFromJobConfig = new ArrayList<MConfig>(); List<MConfig> fromConnectorToJobConfig = new ArrayList<MConfig>(); loadConnectorConfigs(fromConnectorLinkConfig, fromConnectorFromJobConfig, fromConnectorToJobConfig, fromConfigFetchStmt, jobInputFetchStmt, 2, conn); // TO entity configs List<MConfig> toConnectorLinkConfig = new ArrayList<MConfig>(); List<MConfig> toConnectorFromJobConfig = new ArrayList<MConfig>(); List<MConfig> toConnectorToJobConfig = new ArrayList<MConfig>(); List<MConfig> driverConfig = new ArrayList<MConfig>(); loadConnectorConfigs(toConnectorLinkConfig, toConnectorFromJobConfig, toConnectorToJobConfig, toConfigFetchStmt, jobInputFetchStmt, 2, conn); loadDriverConfigs(driverConfig, driverConfigfetchStmt, jobInputFetchStmt, 2, conn); MJob job = new MJob( fromConnectorId, toConnectorId, fromLinkId, toLinkId, new MFromConfig(fromConnectorFromJobConfig), new MToConfig(toConnectorToJobConfig), new MDriverConfig(driverConfig)); job.setPersistenceId(id); job.setName(name); job.setCreationUser(createBy); job.setCreationDate(creationDate); job.setLastUpdateUser(updateBy); job.setLastUpdateDate(lastUpdateDate); job.setEnabled(enabled); jobs.add(job); } } finally { closeResultSets(rsJob); closeStatements(fromConfigFetchStmt, toConfigFetchStmt, driverConfigfetchStmt, jobInputFetchStmt); } return jobs; }
Example 8
Source File: CloneJobFunction.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
private Status cloneJob(Long jobId, List<String> args, boolean isInteractive) throws IOException { printlnResource(Constants.RES_CLONE_CLONING_JOB, jobId); ConsoleReader reader = new ConsoleReader(); MJob job = client.getJob(jobId); job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT); ResourceBundle fromConnectorBundle = client.getConnectorConfigBundle( job.getConnectorId(Direction.FROM)); ResourceBundle toConnectorBundle = client.getConnectorConfigBundle( job.getConnectorId(Direction.TO)); ResourceBundle driverConfigBundle = client.getDriverConfigBundle(); Status status = Status.OK; // Remove persistent id as we're making a clone job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT); if (isInteractive) { printlnResource(Constants.RES_PROMPT_UPDATE_JOB_CONFIG); do { // Print error introduction if needed if( !status.canProceed() ) { errorIntroduction(); } // Fill in data from user if(!fillJobWithBundle(reader, job, fromConnectorBundle, toConnectorBundle, driverConfigBundle)) { return null; } // Try to create status = client.saveJob(job); } while(!status.canProceed()); } else { JobDynamicConfigOptions options = new JobDynamicConfigOptions(); options.prepareOptions(job); CommandLine line = ConfigOptions.parseOptions(options, 0, args, false); if (fillJob(line, job)) { status = client.saveJob(job); if (!status.canProceed()) { printJobValidationMessages(job); return null; } } else { printJobValidationMessages(job); return null; } } printlnResource(Constants.RES_CLONE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId()); return status; }