use of javax.batch.operations.NoSuchJobExecutionException in project wildfly by wildfly.
the class ChunkPartitionTestCase method testSuspend.
@Test
public void testSuspend() throws Exception {
try {
final Properties jobProperties = new Properties();
jobProperties.setProperty("reader.end", "10");
final JobOperator jobOperator = BatchRuntime.getJobOperator();
// Start the first job
long executionId = jobOperator.start("chunk-suspend", jobProperties);
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
// Wait until the job is complete for a maximum of 5 seconds
waitForTermination(jobExecution, 5);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
// Check that count
Assert.assertEquals(10, countingItemWriter.getWrittenItemSize());
// Suspend the server
managementClient.getControllerClient().execute(Operations.createOperation("suspend"));
// Submit another job which should be queued, should be safe with an InMemoryJobRepository (the default)
executionId = jobOperator.start("chunk-suspend", jobProperties);
// The job should not exist yet as the server is suspended
try {
jobOperator.getJobExecution(executionId);
} catch (NoSuchJobExecutionException expected) {
Assert.fail("Job should not exist as the server is suspended: " + executionId);
}
// Resume the server which should kick of queued jobs
managementClient.getControllerClient().execute(Operations.createOperation("resume"));
// Get the execution
jobExecution = jobOperator.getJobExecution(executionId);
// Wait until the job is complete for a maximum of 5 seconds
waitForTermination(jobExecution, 5);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
// Check that count
Assert.assertEquals(20, countingItemWriter.getWrittenItemSize());
} finally {
managementClient.getControllerClient().execute(Operations.createOperation("resume"));
}
}
use of javax.batch.operations.NoSuchJobExecutionException in project Payara by payara.
the class ListBatchJobSteps method findStepExecutions.
private List<StepExecution> findStepExecutions() throws JobSecurityException, NoSuchJobExecutionException {
JobOperator jobOperator = AbstractListCommand.getJobOperatorFromBatchRuntime();
JobExecution je = jobOperator.getJobExecution(Long.parseLong(executionId));
if (!glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
throw new NoSuchJobExecutionException("No job execution exists for job execution id: " + executionId);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(Long.parseLong(executionId));
if (stepExecutions == null || stepExecutions.size() == 0)
throw new NoSuchJobExecutionException("No job execution exists for job execution id: " + executionId);
return stepExecutions;
}
use of javax.batch.operations.NoSuchJobExecutionException in project Payara by payara.
the class JBatchJDBCPersistenceManager method getParameters.
@Override
public Properties getParameters(long executionId) throws NoSuchJobExecutionException {
Connection conn = null;
PreparedStatement statement = null;
ResultSet rs = null;
Properties props = null;
ObjectInputStream objectIn = null;
try {
conn = getConnection();
statement = conn.prepareStatement(queryStrings.get(GET_PARAMETERS));
statement.setLong(1, executionId);
rs = statement.executeQuery();
if (rs.next()) {
// get the object based data
byte[] buf = rs.getBytes("parameters");
props = (Properties) deserializeObject(buf);
} else {
String msg = "Did not find table entry for executionID =" + executionId;
logger.fine(msg);
throw new NoSuchJobExecutionException(msg);
}
} catch (SQLException e) {
throw new PersistenceException(e);
} catch (IOException e) {
throw new PersistenceException(e);
} catch (ClassNotFoundException e) {
throw new PersistenceException(e);
} finally {
if (objectIn != null) {
try {
objectIn.close();
} catch (IOException e) {
throw new PersistenceException(e);
}
}
cleanupConnection(conn, rs, statement);
}
return props;
}
use of javax.batch.operations.NoSuchJobExecutionException in project Payara by payara.
the class JBatchJDBCPersistenceManager method jobOperatorQueryJobExecutionJobInstanceId.
@Override
public long jobOperatorQueryJobExecutionJobInstanceId(long executionID) throws NoSuchJobExecutionException {
Connection conn = null;
PreparedStatement statement = null;
ResultSet rs = null;
long jobinstanceID = 0;
try {
conn = getConnection();
statement = conn.prepareStatement(queryStrings.get(JOB_OPERATOR_QUERY_JOB_EXECUTION_JOB_ID));
statement.setLong(1, executionID);
rs = statement.executeQuery();
if (rs.next()) {
jobinstanceID = rs.getLong("jobinstanceid");
} else {
String msg = "Did not find job instance associated with executionID =" + executionID;
logger.fine(msg);
throw new NoSuchJobExecutionException(msg);
}
} catch (SQLException e) {
throw new PersistenceException(e);
} finally {
cleanupConnection(conn, rs, statement);
}
return jobinstanceID;
}
use of javax.batch.operations.NoSuchJobExecutionException in project Payara by payara.
the class JBatchJDBCPersistenceManager method getJobInstanceIdByExecutionId.
public long getJobInstanceIdByExecutionId(long executionId) throws NoSuchJobExecutionException {
long instanceId = 0;
Connection conn = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
conn = getConnection();
statement = conn.prepareStatement(queryStrings.get(JOB_INSTANCE_ID_BY_EXECUTION_ID));
statement.setObject(1, executionId);
rs = statement.executeQuery();
if (rs.next()) {
instanceId = rs.getLong("jobinstanceid");
} else {
String msg = "Did not find job instance associated with executionID =" + executionId;
logger.fine(msg);
throw new NoSuchJobExecutionException(msg);
}
} catch (SQLException e) {
throw new PersistenceException(e);
} finally {
cleanupConnection(conn, rs, statement);
}
return instanceId;
}
Aggregations