Skip to content

Commit

Permalink
Merge pull request #4175 from Coduz/fix-jobNpeWhenCheckingStatus
Browse files Browse the repository at this point in the history
🐛 [Job Engine] Fixed NPE when checking running status for Job
  • Loading branch information
Coduz authored Jan 17, 2025
2 parents 9b90d26 + c22d214 commit 88f427b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ public Timestamp jobOperatorQueryJobExecutionTimestamp(long jobExecutionId, Time
}

return txManager.execute(tx -> executionInstanceDataRepository.getJobExecutionField(tx, jobExecutionId, selectField));
} catch (NoSuchJobExecutionException nsjee) {
throw nsjee;
} catch (Exception e) {
throw new PersistenceException(e);
}
Expand All @@ -364,6 +366,8 @@ public Timestamp jobOperatorQueryJobExecutionTimestamp(long jobExecutionId, Time
public String jobOperatorQueryJobExecutionBatchStatus(long jobExecutionId) {
try {
return txManager.execute(tx -> executionInstanceDataRepository.<BatchStatus>getJobExecutionField(tx, jobExecutionId, JpaExecutionInstanceDataFields.BATCH_STATUS)).name();
} catch (NoSuchJobExecutionException nsjee) {
throw nsjee;
} catch (Exception e) {
throw new PersistenceException(e);
}
Expand All @@ -373,6 +377,8 @@ public String jobOperatorQueryJobExecutionBatchStatus(long jobExecutionId) {
public String jobOperatorQueryJobExecutionExitStatus(long key) {
try {
return txManager.execute(tx -> executionInstanceDataRepository.getJobExecutionField(tx, key, JpaExecutionInstanceDataFields.EXIT_STATUS));
} catch (NoSuchJobExecutionException nsjee) {
throw nsjee;
} catch (Exception e) {
throw new PersistenceException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.kapua.commons.jpa.JpaAwareTxContext;
import org.eclipse.kapua.storage.TxContext;

import javax.batch.operations.NoSuchJobExecutionException;
import javax.batch.runtime.BatchStatus;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
Expand Down Expand Up @@ -155,6 +156,10 @@ public <T> T getJobExecutionField(TxContext tx, long jobExecutionId, JpaExecutio
final EntityManager em = JpaAwareTxContext.extractEntityManager(tx);
JpaExecutionInstanceData jpaExecutionInstanceData = em.find(JpaExecutionInstanceData.class, jobExecutionId);

if (jpaExecutionInstanceData == null) {
throw new NoSuchJobExecutionException("No ExecutionInstanceData found for id: " + jobExecutionId);
}

switch (field) {
case JOB_EXEC_ID:
return (T) Long.valueOf(jpaExecutionInstanceData.getId());
Expand Down

0 comments on commit 88f427b

Please sign in to comment.