Search in sources :

Example 6 with JobExecution

use of javax.batch.runtime.JobExecution in project wildfly by wildfly.

the class JobControlTestCase method testStop.

@Test
public void testStop() throws Exception {
    final ModelNode address = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet");
    ModelNode op = Operations.createOperation("start-job", address);
    op.get("job-xml-name").set("test-chunk");
    final ModelNode properties = op.get("properties");
    properties.get("reader.end").set("20");
    // We're adding a long wait time to ensure we can stop, 1 seconds should be okay
    properties.get("writer.sleep.time").set(Integer.toString(TimeoutUtil.adjust(1000)));
    final ModelNode result = executeOperation(op);
    final long executionId = result.asLong();
    Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
    // Test the stop operation
    op = Operations.createOperation("stop-job", address);
    op.get("execution-id").set(executionId);
    executeOperation(op);
    // Validate that the job as executed
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final JobExecution execution = jobOperator.getJobExecution(executionId);
    Assert.assertNotNull(execution);
    // Wait for 1 seconds max for the execution to finish.
    waitForTermination(execution, 3);
    // Reset the counter as we're not sure how many were actually written
    currentCount = countingItemWriter.getWrittenItemSize();
    // Check that the status is stopped
    Assert.assertEquals(BatchStatus.STOPPED, execution.getBatchStatus());
}
Also used : JobExecution(javax.batch.runtime.JobExecution) JobOperator(javax.batch.operations.JobOperator) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 7 with JobExecution

use of javax.batch.runtime.JobExecution in project wildfly by wildfly.

the class JobControlTestCase method testStart.

@Test
public void testStart() throws Exception {
    final ModelNode address = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet");
    final ModelNode op = Operations.createOperation("start-job", address);
    op.get("job-xml-name").set("test-chunk");
    final ModelNode properties = op.get("properties");
    properties.get("reader.end").set("5");
    final ModelNode result = executeOperation(op);
    currentCount += 5;
    final long executionId = result.asLong();
    Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
    // Validate that the job as executed
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final JobExecution execution = jobOperator.getJobExecution(executionId);
    Assert.assertNotNull(execution);
    // Wait for 3 seconds max for the execution to finish.
    waitForTermination(execution, 3);
    // Check that we have 5 items
    Assert.assertEquals(currentCount, countingItemWriter.getWrittenItemSize());
}
Also used : JobExecution(javax.batch.runtime.JobExecution) JobOperator(javax.batch.operations.JobOperator) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 8 with JobExecution

use of javax.batch.runtime.JobExecution in project wildfly by wildfly.

the class JobControlTestCase method testStopOnExecutionResource.

@Test
public void testStopOnExecutionResource() throws Exception {
    final ModelNode address = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet");
    ModelNode op = Operations.createOperation("start-job", address);
    op.get("job-xml-name").set("test-chunk");
    final ModelNode properties = op.get("properties");
    properties.get("reader.end").set("20");
    // We're adding a long wait time to ensure we can stop, 1 seconds should be okay
    properties.get("writer.sleep.time").set(Integer.toString(TimeoutUtil.adjust(1000)));
    final ModelNode result = executeOperation(op);
    final long executionId = result.asLong();
    Assert.assertTrue("Execution id should be greater than 0", executionId > 0L);
    // Test the stop operation
    final ModelNode executionAddress = Operations.createAddress("deployment", DEPLOYMENT_NAME, "subsystem", "batch-jberet", "job", "test-chunk", "execution", Long.toString(executionId));
    executeOperation(Operations.createOperation("stop-job", executionAddress));
    // Validate that the job as executed
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final JobExecution execution = jobOperator.getJobExecution(executionId);
    Assert.assertNotNull(execution);
    // Wait for 1 seconds max for the execution to finish.
    waitForTermination(execution, 3);
    // Reset the counter as we're not sure how many were actually written
    currentCount = countingItemWriter.getWrittenItemSize();
    // Check that the status is stopped
    Assert.assertEquals(BatchStatus.STOPPED, execution.getBatchStatus());
}
Also used : JobExecution(javax.batch.runtime.JobExecution) JobOperator(javax.batch.operations.JobOperator) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 9 with JobExecution

use of javax.batch.runtime.JobExecution 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 10 with JobExecution

use of javax.batch.runtime.JobExecution in project Payara by payara.

the class ListBatchJobs method findJobExecutions.

private List<JobExecution> findJobExecutions() throws JobSecurityException, NoSuchJobException, NoSuchJobInstanceException {
    List<JobExecution> jobExecutions = new ArrayList<>();
    JobOperator jobOperator = AbstractListCommand.getJobOperatorFromBatchRuntime();
    if (jobName != null) {
        List<JobInstance> exe = jobOperator.getJobInstances(jobName, 0, Integer.MAX_VALUE - 1);
        if (exe != null) {
            for (JobInstance ji : exe) {
                jobExecutions.addAll(jobOperator.getJobExecutions(ji));
            }
        }
    } else {
        Set<String> jobNames = jobOperator.getJobNames();
        if (jobNames != null) {
            for (String jn : jobOperator.getJobNames()) {
                List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
                if (exe != null) {
                    for (JobInstance ji : exe) {
                        jobExecutions.addAll(jobOperator.getJobExecutions(ji));
                    }
                }
            }
        }
    }
    return jobExecutions;
}
Also used : JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) JobInstance(javax.batch.runtime.JobInstance)

Aggregations

JobExecution (javax.batch.runtime.JobExecution)25 JobOperator (javax.batch.operations.JobOperator)13 Test (org.junit.Test)12 Properties (java.util.Properties)8 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)6 JobInstance (javax.batch.runtime.JobInstance)5 ModelNode (org.jboss.dmr.ModelNode)5 ArrayList (java.util.ArrayList)3 StepExecution (javax.batch.runtime.StepExecution)3 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 NoSuchJobException (javax.batch.operations.NoSuchJobException)1