@@ -213,7 +213,7 @@ public long submitAsyncJob(AsyncJobVO job, boolean scheduleJobExecutionInContext
213213 job .setSyncSource (null );
214214 scheduleExecution (job , scheduleJobExecutionInContext );
215215 if (s_logger .isDebugEnabled ()) {
216- s_logger .debug ("submit async job-" + job .getId () + ", details: " + job .toString ());
216+ s_logger .debug ("submit async job-" + job .getId () + " = [ " + job . getUuid () + " ] , details: " + job .toString ());
217217 }
218218 publishOnEventBus (job , "submit" );
219219 return job .getId ();
@@ -227,25 +227,25 @@ public long submitAsyncJob(AsyncJobVO job, boolean scheduleJobExecutionInContext
227227
228228 @ Override @ DB
229229 public void completeAsyncJob (long jobId , int jobStatus , int resultCode , Object resultObject ) {
230- if (s_logger .isDebugEnabled ()) {
231- s_logger .debug ("Complete async job-" + jobId + ", jobStatus: " + jobStatus +
232- ", resultCode: " + resultCode + ", result: " + resultObject );
230+ AsyncJobVO job = _jobDao .findById (jobId );
231+ String jobUuid = null ;
232+ if (job != null ) {
233+ jobUuid = job .getUuid ();
234+ if (s_logger .isDebugEnabled ()) {
235+ s_logger .debug ("Complete async job-" + jobId + " = [ " + jobUuid + " ], jobStatus: " + jobStatus +
236+ ", resultCode: " + resultCode + ", result: " + resultObject );
237+ }
238+ } else {
239+ if (s_logger .isDebugEnabled ()) {
240+ s_logger .debug ("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus +
241+ ", resultCode: " + resultCode + ", result: " + resultObject );
242+ }
243+ return ;
233244 }
234245
235246 Transaction txt = Transaction .currentTxn ();
236247 try {
237248 txt .start ();
238- AsyncJobVO job = _jobDao .findById (jobId );
239- if (job == null ) {
240- if (s_logger .isDebugEnabled ()) {
241- s_logger .debug ("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus +
242- ", resultCode: " + resultCode + ", result: " + resultObject );
243- }
244-
245- txt .rollback ();
246- return ;
247- }
248-
249249 job .setCompleteMsid (getMsid ());
250250 job .setStatus (jobStatus );
251251 job .setResultCode (resultCode );
@@ -264,31 +264,31 @@ public void completeAsyncJob(long jobId, int jobStatus, int resultCode, Object r
264264 _jobDao .update (jobId , job );
265265 txt .commit ();
266266 } catch (Exception e ) {
267- s_logger .error ("Unexpected exception while completing async job-" + jobId , e );
267+ s_logger .error ("Unexpected exception while completing async job-" + jobId + " = [ " + jobUuid + " ]" , e );
268268 txt .rollback ();
269269 }
270270 }
271271
272272 @ Override @ DB
273273 public void updateAsyncJobStatus (long jobId , int processStatus , Object resultObject ) {
274- if (s_logger .isDebugEnabled ()) {
275- s_logger .debug ("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus +
276- ", result: " + resultObject );
274+ AsyncJobVO job = _jobDao .findById (jobId );
275+ String jobUuid = null ;
276+ if (job != null ) {
277+ jobUuid = job .getUuid ();
278+ if (s_logger .isDebugEnabled ()) {
279+ s_logger .debug ("Update async-job progress, job-" + jobId + " = [ " + jobUuid + " ], processStatus: " + processStatus +
280+ ", result: " + resultObject );
281+ }
282+ } else {
283+ if (s_logger .isDebugEnabled ()) {
284+ s_logger .debug ("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus );
285+ }
286+ return ;
277287 }
278288
279289 Transaction txt = Transaction .currentTxn ();
280290 try {
281291 txt .start ();
282- AsyncJobVO job = _jobDao .findById (jobId );
283- if (job == null ) {
284- if (s_logger .isDebugEnabled ()) {
285- s_logger .debug ("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus );
286- }
287-
288- txt .rollback ();
289- return ;
290- }
291-
292292 job .setProcessStatus (processStatus );
293293 if (resultObject != null ) {
294294 job .setResult (ApiSerializerHelper .toSerializedStringOld (resultObject ));
@@ -298,31 +298,40 @@ public void updateAsyncJobStatus(long jobId, int processStatus, Object resultObj
298298 publishOnEventBus (job , "update" );
299299 txt .commit ();
300300 } catch (Exception e ) {
301- s_logger .error ("Unexpected exception while updating async job-" + jobId + " status: " , e );
301+ s_logger .error ("Unexpected exception while updating async job-" + jobId + " = [ " + jobUuid + " ] status: " , e );
302302 txt .rollback ();
303303 }
304304 }
305305
306306 @ Override @ DB
307307 public void updateAsyncJobAttachment (long jobId , String instanceType , Long instanceId ) {
308- if (s_logger .isDebugEnabled ()) {
309- s_logger .debug ("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType +
310- ", instanceId: " + instanceId );
308+ AsyncJobVO job = _jobDao .findById (jobId );
309+ String jobUuid = null ;
310+ if (job != null ) {
311+ jobUuid = job .getUuid ();
312+ if (s_logger .isDebugEnabled ()) {
313+ s_logger .debug ("Update async-job attachment, job-" + jobId + " = [ " + jobUuid + " ], instanceType: "
314+ + instanceType + ", instanceId: " + instanceId );
315+ }
316+ } else {
317+ if (s_logger .isDebugEnabled ()) {
318+ s_logger .debug ("job-" + jobId + " no longer exists, instanceType: " + instanceType + ", instanceId: "
319+ + instanceId );
320+ }
321+ return ;
311322 }
312323
313324 Transaction txt = Transaction .currentTxn ();
314325 try {
315326 txt .start ();
316-
317- AsyncJobVO job = _jobDao .createForUpdate ();
318327 //job.setInstanceType(instanceType);
319328 job .setInstanceId (instanceId );
320329 job .setLastUpdated (DateUtil .currentGMTTime ());
321330 _jobDao .update (jobId , job );
322331
323332 txt .commit ();
324333 } catch (Exception e ) {
325- s_logger .error ("Unexpected exception while updating async job-" + jobId + " attachment: " , e );
334+ s_logger .error ("Unexpected exception while updating async job-" + jobId + " = [ " + jobUuid + " ] attachment: " , e );
326335 txt .rollback ();
327336 }
328337 }
@@ -339,7 +348,7 @@ public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObj
339348 }
340349
341350 if (s_logger .isDebugEnabled ()) {
342- s_logger .debug ("Sync job-" + job .getId () + " execution on object " + syncObjType + "." + syncObjId );
351+ s_logger .debug ("Sync job-" + job .getId () + " = [ " + job . getUuid () + " ] execution on object " + syncObjType + "." + syncObjId );
343352 }
344353
345354 SyncQueueVO queue = null ;
@@ -363,7 +372,7 @@ public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObj
363372 if (queue == null ) {
364373 throw new CloudRuntimeException ("Unable to insert queue item into database, DB is full?" );
365374 } else {
366- throw new AsyncCommandQueued (queue , "job-" + job .getId () + " queued" );
375+ throw new AsyncCommandQueued (queue , "job-" + job .getId () + " = [ " + job . getUuid () + " ] queued" );
367376 }
368377 }
369378
@@ -383,7 +392,7 @@ public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
383392 if (caller .getType () == Account .ACCOUNT_TYPE_NORMAL ) {
384393 //regular user can see only jobs he owns
385394 if (caller .getId () != jobOwner .getId ()) {
386- throw new PermissionDeniedException ("Account " + caller + " is not authorized to see job id= " + job .getId () );
395+ throw new PermissionDeniedException ("Account " + caller + " is not authorized to see job-" + job . getId () + " = [ " + job .getUuid () + " ]" );
387396 }
388397 } else if (caller .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN ) {
389398 _accountMgr .checkAccess (caller , null , true , jobOwner );
@@ -396,16 +405,24 @@ public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
396405
397406 @ Override @ DB
398407 public AsyncJobResult queryAsyncJobResult (long jobId ) {
399- if (s_logger .isTraceEnabled ()) {
400- s_logger .trace ("Query async-job status, job-" + jobId );
408+ AsyncJobVO job = _jobDao .findById (jobId );
409+ String jobUuid = null ;
410+ if (job != null ) {
411+ jobUuid = job .getUuid ();
412+ if (s_logger .isTraceEnabled ()) {
413+ s_logger .trace ("Query async-job status, job-" + jobId + " = [ " + jobUuid + " ]" );
414+ }
415+ } else {
416+ if (s_logger .isDebugEnabled ()) {
417+ s_logger .debug ("Async job-" + jobId + " does not exist, invalid job id?" );
418+ }
401419 }
402420
403421 Transaction txt = Transaction .currentTxn ();
404422 AsyncJobResult jobResult = new AsyncJobResult (jobId );
405423
406424 try {
407425 txt .start ();
408- AsyncJobVO job = _jobDao .findById (jobId );
409426 if (job != null ) {
410427 jobResult .setCmdOriginator (job .getCmdOriginator ());
411428 jobResult .setJobStatus (job .getStatus ());
@@ -418,23 +435,23 @@ public AsyncJobResult queryAsyncJobResult(long jobId) {
418435 job .getStatus () == AsyncJobResult .STATUS_FAILED ) {
419436
420437 if (s_logger .isDebugEnabled ()) {
421- s_logger .debug ("Async job-" + jobId + " completed" );
438+ s_logger .debug ("Async job-" + jobId + " = [ " + jobUuid + " ] completed" );
422439 }
423440 } else {
424441 job .setLastPolled (DateUtil .currentGMTTime ());
425442 _jobDao .update (jobId , job );
426443 }
427444 } else {
428- if (s_logger .isDebugEnabled ()) {
429- s_logger .debug ("Async job-" + jobId + " does not exist, invalid job id?" );
430- }
431-
432445 jobResult .setJobStatus (AsyncJobResult .STATUS_FAILED );
433446 jobResult .setResult ("job-" + jobId + " does not exist" );
434447 }
435448 txt .commit ();
436449 } catch (Exception e ) {
437- s_logger .error ("Unexpected exception while querying async job-" + jobId + " status: " , e );
450+ if (jobUuid == null ) {
451+ s_logger .error ("Unexpected exception while querying async job-" + jobId + " status: " , e );
452+ } else {
453+ s_logger .error ("Unexpected exception while querying async job-" + jobId + " = [ " + jobUuid + " ] status: " , e );
454+ }
438455
439456 jobResult .setJobStatus (AsyncJobResult .STATUS_FAILED );
440457 jobResult .setResult ("Exception: " + e .toString ());
@@ -471,17 +488,18 @@ public void run() {
471488 try {
472489 JmxUtil .registerMBean ("AsyncJobManager" , "Active Job " + job .getId (), new AsyncJobMBeanImpl (job ));
473490 } catch (Exception e ) {
474- s_logger .warn ("Unable to register active job " + job .getId () + " to JMX monitoring due to exception " + ExceptionUtil .toString (e ));
491+ s_logger .warn ("Unable to register active job [ " + job .getId () + " ] = [ " + job . getUuid () + " ] to JMX monitoring due to exception " + ExceptionUtil .toString (e ));
475492 }
476493
477494 BaseAsyncCmd cmdObj = null ;
478495 Transaction txn = Transaction .open (Transaction .CLOUD_DB );
479496 try {
480497 jobId = job .getId ();
481- NDC .push ("job-" + jobId );
498+ String jobUuid = job .getUuid ();
499+ NDC .push ("job-" + jobId + " = [ " + jobUuid + " ]" );
482500
483501 if (s_logger .isDebugEnabled ()) {
484- s_logger .debug ("Executing " + job .getCmd () + " for job-" + jobId );
502+ s_logger .debug ("Executing " + job .getCmd () + " for job-" + jobId + " = [ " + jobUuid + " ]" );
485503 }
486504
487505 Class <?> cmdClass = Class .forName (job .getCmd ());
@@ -526,13 +544,13 @@ public void run() {
526544 }
527545
528546 if (s_logger .isDebugEnabled ()) {
529- s_logger .debug ("Done executing " + job .getCmd () + " for job-" + jobId );
547+ s_logger .debug ("Done executing " + job .getCmd () + " for job-" + job . getId () + " = [ " + jobUuid + " ]" );
530548 }
531549
532550 } catch (Throwable e ) {
533551 if (e instanceof AsyncCommandQueued ) {
534552 if (s_logger .isDebugEnabled ()) {
535- s_logger .debug ("job " + job .getCmd () + " for job-" + jobId + " was queued, processing the queue." );
553+ s_logger .debug ("job " + job .getCmd () + " for job-" + jobId + " = [ " + job . getUuid () + " ] was queued, processing the queue." );
536554 }
537555 checkQueue (((AsyncCommandQueued )e ).getQueue ().getId ());
538556 } else {
@@ -571,7 +589,7 @@ public void run() {
571589 try {
572590 JmxUtil .unregisterMBean ("AsyncJobManager" , "Active Job " + job .getId ());
573591 } catch (Exception e ) {
574- s_logger .warn ("Unable to unregister active job " + job .getId () + " from JMX monitoring" );
592+ s_logger .warn ("Unable to unregister active job [ " + job .getId () + " ] = [ " + job . getUuid () + " ] from JMX monitoring" );
575593 }
576594
577595 txn .close ();
@@ -588,10 +606,12 @@ public void run() {
588606 }
589607
590608 private void executeQueueItem (SyncQueueItemVO item , boolean fromPreviousSession ) {
609+ long jobId = item .getContentId ();
591610 AsyncJobVO job = _jobDao .findById (item .getContentId ());
592611 if (job != null ) {
612+ String jobUuid = job .getUuid ();
593613 if (s_logger .isDebugEnabled ()) {
594- s_logger .debug ("Schedule queued job-" + job . getId () );
614+ s_logger .debug ("Schedule queued job-" + jobId + " = [ " + jobUuid + " ]" );
595615 }
596616
597617 job .setFromPreviousSession (fromPreviousSession );
@@ -603,7 +623,7 @@ private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession)
603623 try {
604624 scheduleExecution (job );
605625 } catch (RejectedExecutionException e ) {
606- s_logger .warn ("Execution for job-" + job . getId () + " is rejected, return it to the queue for next turn" );
626+ s_logger .warn ("Execution for job-" + jobId + " = [ " + jobUuid + " ] is rejected, return it to the queue for next turn" );
607627 _queueMgr .returnItem (item .getId ());
608628 }
609629
@@ -620,7 +640,7 @@ private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession)
620640 public void releaseSyncSource (AsyncJobExecutor executor ) {
621641 if (executor .getSyncSource () != null ) {
622642 if (s_logger .isDebugEnabled ()) {
623- s_logger .debug ("Release sync source for job-" + executor .getJob ().getId () + " sync source: "
643+ s_logger .debug ("Release sync source for job-" + executor .getJob ().getId () + " = [ " + executor . getJob (). getUuid () + " ] sync source: "
624644 + executor .getSyncSource ().getContentType () + "-"
625645 + executor .getSyncSource ().getContentId ());
626646 }
0 commit comments