Search in sources :

Example 1 with NoSuchJobExecutionException

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"));
    }
}
Also used : JobExecution(javax.batch.runtime.JobExecution) JobOperator(javax.batch.operations.JobOperator) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with NoSuchJobExecutionException

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;
}
Also used : JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) JobOperator(javax.batch.operations.JobOperator) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException) StepExecution(javax.batch.runtime.StepExecution)

Example 3 with NoSuchJobExecutionException

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException) IOException(java.io.IOException) Properties(java.util.Properties) ObjectInputStream(java.io.ObjectInputStream) TCCLObjectInputStream(com.ibm.jbatch.container.util.TCCLObjectInputStream)

Example 4 with NoSuchJobExecutionException

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException)

Example 5 with NoSuchJobExecutionException

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(com.ibm.jbatch.container.exception.PersistenceException) PreparedStatement(java.sql.PreparedStatement) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException)

Aggregations

NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)5 PersistenceException (com.ibm.jbatch.container.exception.PersistenceException)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)2 JobOperator (javax.batch.operations.JobOperator)2 JobExecution (javax.batch.runtime.JobExecution)2 TCCLObjectInputStream (com.ibm.jbatch.container.util.TCCLObjectInputStream)1 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 StepExecution (javax.batch.runtime.StepExecution)1 Test (org.junit.Test)1