@Test(expected=NoSuchJobException.class) public void testGetNoRunningExecutions() { Set<JobExecution> executions = new HashSet<>(); when(jobExplorer.findRunningJobExecutions("myJob")).thenReturn(executions); jsrJobOperator.getRunningExecutions("myJob"); }
@Test public void testGetRunningExecutions() { Set<JobExecution> executions = new HashSet<>(); executions.add(new JobExecution(5L)); when(jobExplorer.findRunningJobExecutions("myJob")).thenReturn(executions); assertEquals(5L, jsrJobOperator.getRunningExecutions("myJob").get(0).longValue()); }
public List<Long> getRunningExecutions(String jobName) throws NoSuchJobException, JobSecurityException { return jobOp.getRunningExecutions(jobName); }
@Override public Long[] getRunningExecutions(final String jobName) { try { final List<Long> runningExecutions = operator.getRunningExecutions(jobName); return runningExecutions.toArray(new Long[runningExecutions.size()]); } catch (final NoSuchJobException nsje) { return new Long[0]; } }
@GET @Path("executions/running/{name}") public Long[] getRunningExecutions(final @PathParam("name") String jobName) { final List<Long> runningExecutions = operator.getRunningExecutions(jobName); return runningExecutions.toArray(runningExecutions.toArray(new Long[runningExecutions.size()])); }
@Override public List<Long> getRunningExecutions(final String jobName) throws NoSuchJobException, JobSecurityException { return getDelegate().getRunningExecutions(jobName); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { final List<Long> running = getOrCreateOperator().getRunningExecutions(jobName); getLog().info("Running executions (" + running.size() + "):"); for (final Long instance : running) { getLog().info(" - #" + instance); } } }
@Override public List<Long> getRunningExecutions(String jobName) throws NoSuchJobException, JobSecurityException { Transaction tran = suspendTran(); try { return jobOperator.getRunningExecutions(jobName); } finally { resumeTran(tran); } }
/** * {@inheritDoc} * <p> * This does not throw a {@link javax.batch.operations.NoSuchJobException} if the repository does not contain the * job, but the job is allowed. If this case is true an empty list is returned. * </p> */ @Override public List<Long> getRunningExecutions(final String jobName) throws NoSuchJobException, JobSecurityException { checkState(jobName); final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader); try { return delegate.getRunningExecutions(jobName); } catch (NoSuchJobException ignore) { } return Collections.emptyList(); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(current); } }
@Override public void beforeJob() throws Exception { JobContextWrapper jobContextWrapper = new JobContextWrapper(jobContext); LOG.info("JOB {} - {} - Running before job...", jobContextWrapper.getJobId(), jobContextWrapper.getJobName()); JobExecutionCreator jobExecutionCreator = JOB_EXECUTION_FACTORY.newCreator(jobContextWrapper.getScopeId()); jobExecutionCreator.setJobId(jobContextWrapper.getJobId()); jobExecutionCreator.setStartedOn(new Date()); jobExecutionCreator.getEntityAttributes().put(JBATCH_EXECUTION_ID, Long.toString(jobContextWrapper.getExecutionId())); JobExecution jobExecution = KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.create(jobExecutionCreator)); jobContextWrapper.setKapuaExecutionId(jobExecution.getId()); // prevent another instance running for the same job name (once a job is submitted its status is changed to STARTING by jbatch so, // at that point, if there are more than 1 job execution in running state (so STARTING, STARTED, STOPPING) it means that another instance is already running. List<Long> runningExecutionsIds = BatchRuntime.getJobOperator().getRunningExecutions(jobContextWrapper.getJobName()); if (runningExecutionsIds != null && runningExecutionsIds.size() > 1) { throw new KapuaIllegalStateException(String.format("Cannot start job [%s]. Another instance of this job is running.", jobContextWrapper.getJobName())); } LOG.info("JOB {} - {} - Running before job... DONE!", jobContextWrapper.getJobId(), jobContextWrapper.getJobName()); }
@Override public void beforeJob() throws Exception { JobContextWrapper jobContextWrapper = new JobContextWrapper(jobContext); LOG.info("JOB {} - {} - Running before job...", jobContextWrapper.getJobId(), jobContextWrapper.getJobName()); JobExecutionCreator jobExecutionCreator = JOB_EXECUTION_FACTORY.newCreator(jobContextWrapper.getScopeId()); jobExecutionCreator.setJobId(jobContextWrapper.getJobId()); jobExecutionCreator.setStartedOn(new Date()); jobExecutionCreator.getEntityAttributes().put(JBATCH_EXECUTION_ID, Long.toString(jobContextWrapper.getExecutionId())); JobExecution jobExecution = KapuaSecurityUtils.doPrivileged(() -> JOB_EXECUTION_SERVICE.create(jobExecutionCreator)); jobContextWrapper.setKapuaExecutionId(jobExecution.getId()); // prevent another instance running for the same job name (once a job is submitted its status is changed to STARTING by jbatch so, // at that point, if there are more than 1 job execution in running state (so STARTING, STARTED, STOPPING) it means that another instance is already running. List<Long> runningExecutionsIds = BatchRuntime.getJobOperator().getRunningExecutions(jobContextWrapper.getJobName()); if (runningExecutionsIds != null && runningExecutionsIds.size() > 1) { throw new KapuaIllegalStateException(String.format("Cannot start job [%s]. Another instance of this job is running.", jobContextWrapper.getJobName())); } LOG.info("JOB {} - {} - Running before job... DONE!", jobContextWrapper.getJobId(), jobContextWrapper.getJobName()); }
/** * */ @Test public void testGetRunningExecutionsNoTran() throws Exception { final JobOperator mockJobOperator = mockery.mock(JobOperator.class); final TransactionManager mockTranMgr = mockery.mock(TransactionManager.class); final List<Long> retMe = new ArrayList<Long>(); mockery.checking( new Expectations() { { oneOf(mockTranMgr).suspend(); will(returnValue(null)); oneOf(mockJobOperator).getRunningExecutions(null); will(returnValue(retMe)); } }); assertEquals(retMe, buildJobOperator(mockJobOperator, mockTranMgr).getRunningExecutions(null) ); }
/** * */ @Test(expected = IllegalArgumentException.class) public void testGetRunningExecutionsFail() throws Exception { final JobOperator mockJobOperator = mockery.mock(JobOperator.class); final TransactionManager mockTranMgr = mockery.mock(TransactionManager.class); final Transaction mockTran = mockery.mock(Transaction.class); mockery.checking( new Expectations() { { oneOf(mockTranMgr).suspend(); will(returnValue(mockTran)); oneOf(mockJobOperator).getRunningExecutions(null); will(throwException(new IllegalArgumentException())); oneOf(mockTranMgr).resume(mockTran); } }); buildJobOperator(mockJobOperator, mockTranMgr).getRunningExecutions(null); }
/** * */ @Test public void testGetRunningExecutions() throws Exception { final JobOperator mockJobOperator = mockery.mock(JobOperator.class); final TransactionManager mockTranMgr = mockery.mock(TransactionManager.class); final Transaction mockTran = mockery.mock(Transaction.class); final List<Long> retMe = new ArrayList<Long>(); mockery.checking( new Expectations() { { oneOf(mockTranMgr).suspend(); will(returnValue(mockTran)); oneOf(mockJobOperator).getRunningExecutions(null); will(returnValue(retMe)); oneOf(mockTranMgr).resume(mockTran); } }); assertEquals(retMe, buildJobOperator(mockJobOperator, mockTranMgr).getRunningExecutions(null) ); }