@@ -212,7 +212,7 @@ public long submitAsyncJob(AsyncJobVO job, boolean scheduleJobExecutionInContext
212212 job .setSyncSource (null );
213213 scheduleExecution (job , scheduleJobExecutionInContext );
214214 if (s_logger .isDebugEnabled ()) {
215- s_logger .debug ("submit async job-" + job .getId () + ", details: " + job .toString ());
215+ s_logger .debug ("submit async job-" + job .getId () + " = [ " + job . getUuid () + " ] , details: " + job .toString ());
216216 }
217217 publishOnEventBus (job , "submit" );
218218 return job .getId ();
@@ -226,25 +226,25 @@ public long submitAsyncJob(AsyncJobVO job, boolean scheduleJobExecutionInContext
226226
227227 @ Override @ DB
228228 public void completeAsyncJob (long jobId , int jobStatus , int resultCode , Object resultObject ) {
229- if (s_logger .isDebugEnabled ()) {
230- s_logger .debug ("Complete async job-" + jobId + ", jobStatus: " + jobStatus +
231- ", resultCode: " + resultCode + ", result: " + resultObject );
229+ AsyncJobVO job = _jobDao .findById (jobId );
230+ String jobUuid = null ;
231+ if (job != null ) {
232+ jobUuid = job .getUuid ();
233+ if (s_logger .isDebugEnabled ()) {
234+ s_logger .debug ("Complete async job-" + jobId + " = [ " + jobUuid + " ], jobStatus: " + jobStatus +
235+ ", resultCode: " + resultCode + ", result: " + resultObject );
236+ }
237+ } else {
238+ if (s_logger .isDebugEnabled ()) {
239+ s_logger .debug ("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus +
240+ ", resultCode: " + resultCode + ", result: " + resultObject );
241+ }
242+ return ;
232243 }
233244
234245 Transaction txt = Transaction .currentTxn ();
235246 try {
236247 txt .start ();
237- AsyncJobVO job = _jobDao .findById (jobId );
238- if (job == null ) {
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-
244- txt .rollback ();
245- return ;
246- }
247-
248248 job .setCompleteMsid (getMsid ());
249249 job .setStatus (jobStatus );
250250 job .setResultCode (resultCode );
@@ -263,31 +263,31 @@ public void completeAsyncJob(long jobId, int jobStatus, int resultCode, Object r
263263 _jobDao .update (jobId , job );
264264 txt .commit ();
265265 } catch (Exception e ) {
266- s_logger .error ("Unexpected exception while completing async job-" + jobId , e );
266+ s_logger .error ("Unexpected exception while completing async job-" + jobId + " = [ " + jobUuid + " ]" , e );
267267 txt .rollback ();
268268 }
269269 }
270270
271271 @ Override @ DB
272272 public void updateAsyncJobStatus (long jobId , int processStatus , Object resultObject ) {
273- if (s_logger .isDebugEnabled ()) {
274- s_logger .debug ("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus +
275- ", result: " + resultObject );
273+ AsyncJobVO job = _jobDao .findById (jobId );
274+ String jobUuid = null ;
275+ if (job != null ) {
276+ jobUuid = job .getUuid ();
277+ if (s_logger .isDebugEnabled ()) {
278+ s_logger .debug ("Update async-job progress, job-" + jobId + " = [ " + jobUuid + " ], processStatus: " + processStatus +
279+ ", result: " + resultObject );
280+ }
281+ } else {
282+ if (s_logger .isDebugEnabled ()) {
283+ s_logger .debug ("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus );
284+ }
285+ return ;
276286 }
277287
278288 Transaction txt = Transaction .currentTxn ();
279289 try {
280290 txt .start ();
281- AsyncJobVO job = _jobDao .findById (jobId );
282- if (job == null ) {
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-
287- txt .rollback ();
288- return ;
289- }
290-
291291 job .setProcessStatus (processStatus );
292292 if (resultObject != null ) {
293293 job .setResult (ApiSerializerHelper .toSerializedStringOld (resultObject ));
@@ -297,31 +297,40 @@ public void updateAsyncJobStatus(long jobId, int processStatus, Object resultObj
297297 publishOnEventBus (job , "update" );
298298 txt .commit ();
299299 } catch (Exception e ) {
300- s_logger .error ("Unexpected exception while updating async job-" + jobId + " status: " , e );
300+ s_logger .error ("Unexpected exception while updating async job-" + jobId + " = [ " + jobUuid + " ] status: " , e );
301301 txt .rollback ();
302302 }
303303 }
304304
305305 @ Override @ DB
306306 public void updateAsyncJobAttachment (long jobId , String instanceType , Long instanceId ) {
307- if (s_logger .isDebugEnabled ()) {
308- s_logger .debug ("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType +
309- ", instanceId: " + instanceId );
307+ AsyncJobVO job = _jobDao .findById (jobId );
308+ String jobUuid = null ;
309+ if (job != null ) {
310+ jobUuid = job .getUuid ();
311+ if (s_logger .isDebugEnabled ()) {
312+ s_logger .debug ("Update async-job attachment, job-" + jobId + " = [ " + jobUuid + " ], instanceType: "
313+ + instanceType + ", instanceId: " + instanceId );
314+ }
315+ } else {
316+ if (s_logger .isDebugEnabled ()) {
317+ s_logger .debug ("job-" + jobId + " no longer exists, instanceType: " + instanceType + ", instanceId: "
318+ + instanceId );
319+ }
320+ return ;
310321 }
311322
312323 Transaction txt = Transaction .currentTxn ();
313324 try {
314325 txt .start ();
315-
316- AsyncJobVO job = _jobDao .createForUpdate ();
317326 //job.setInstanceType(instanceType);
318327 job .setInstanceId (instanceId );
319328 job .setLastUpdated (DateUtil .currentGMTTime ());
320329 _jobDao .update (jobId , job );
321330
322331 txt .commit ();
323332 } catch (Exception e ) {
324- s_logger .error ("Unexpected exception while updating async job-" + jobId + " attachment: " , e );
333+ s_logger .error ("Unexpected exception while updating async job-" + jobId + " = [ " + jobUuid + " ] attachment: " , e );
325334 txt .rollback ();
326335 }
327336 }
@@ -338,7 +347,7 @@ public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObj
338347 }
339348
340349 if (s_logger .isDebugEnabled ()) {
341- s_logger .debug ("Sync job-" + job .getId () + " execution on object " + syncObjType + "." + syncObjId );
350+ s_logger .debug ("Sync job-" + job .getId () + " = [ " + job . getUuid () + " ] execution on object " + syncObjType + "." + syncObjId );
342351 }
343352
344353 SyncQueueVO queue = null ;
@@ -362,7 +371,7 @@ public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObj
362371 if (queue == null ) {
363372 throw new CloudRuntimeException ("Unable to insert queue item into database, DB is full?" );
364373 } else {
365- throw new AsyncCommandQueued (queue , "job-" + job .getId () + " queued" );
374+ throw new AsyncCommandQueued (queue , "job-" + job .getId () + " = [ " + job . getUuid () + " ] queued" );
366375 }
367376 }
368377
@@ -382,7 +391,7 @@ public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
382391 if (caller .getType () == Account .ACCOUNT_TYPE_NORMAL ) {
383392 //regular user can see only jobs he owns
384393 if (caller .getId () != jobOwner .getId ()) {
385- throw new PermissionDeniedException ("Account " + caller + " is not authorized to see job id= " + job .getId () );
394+ throw new PermissionDeniedException ("Account " + caller + " is not authorized to see job-" + job . getId () + " = [ " + job .getUuid () + " ]" );
386395 }
387396 } else if (caller .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN ) {
388397 _accountMgr .checkAccess (caller , null , true , jobOwner );
@@ -395,16 +404,24 @@ public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
395404
396405 @ Override @ DB
397406 public AsyncJobResult queryAsyncJobResult (long jobId ) {
398- if (s_logger .isTraceEnabled ()) {
399- s_logger .trace ("Query async-job status, job-" + jobId );
407+ AsyncJobVO job = _jobDao .findById (jobId );
408+ String jobUuid = null ;
409+ if (job != null ) {
410+ jobUuid = job .getUuid ();
411+ if (s_logger .isTraceEnabled ()) {
412+ s_logger .trace ("Query async-job status, job-" + jobId + " = [ " + jobUuid + " ]" );
413+ }
414+ } else {
415+ if (s_logger .isDebugEnabled ()) {
416+ s_logger .debug ("Async job-" + jobId + " does not exist, invalid job id?" );
417+ }
400418 }
401419
402420 Transaction txt = Transaction .currentTxn ();
403421 AsyncJobResult jobResult = new AsyncJobResult (jobId );
404422
405423 try {
406424 txt .start ();
407- AsyncJobVO job = _jobDao .findById (jobId );
408425 if (job != null ) {
409426 jobResult .setCmdOriginator (job .getCmdOriginator ());
410427 jobResult .setJobStatus (job .getStatus ());
@@ -417,23 +434,23 @@ public AsyncJobResult queryAsyncJobResult(long jobId) {
417434 job .getStatus () == AsyncJobResult .STATUS_FAILED ) {
418435
419436 if (s_logger .isDebugEnabled ()) {
420- s_logger .debug ("Async job-" + jobId + " completed" );
437+ s_logger .debug ("Async job-" + jobId + " = [ " + jobUuid + " ] completed" );
421438 }
422439 } else {
423440 job .setLastPolled (DateUtil .currentGMTTime ());
424441 _jobDao .update (jobId , job );
425442 }
426443 } else {
427- if (s_logger .isDebugEnabled ()) {
428- s_logger .debug ("Async job-" + jobId + " does not exist, invalid job id?" );
429- }
430-
431444 jobResult .setJobStatus (AsyncJobResult .STATUS_FAILED );
432445 jobResult .setResult ("job-" + jobId + " does not exist" );
433446 }
434447 txt .commit ();
435448 } catch (Exception e ) {
436- s_logger .error ("Unexpected exception while querying async job-" + jobId + " status: " , e );
449+ if (jobUuid == null ) {
450+ s_logger .error ("Unexpected exception while querying async job-" + jobId + " status: " , e );
451+ } else {
452+ s_logger .error ("Unexpected exception while querying async job-" + jobId + " = [ " + jobUuid + " ] status: " , e );
453+ }
437454
438455 jobResult .setJobStatus (AsyncJobResult .STATUS_FAILED );
439456 jobResult .setResult ("Exception: " + e .toString ());
@@ -470,17 +487,18 @@ public void run() {
470487 try {
471488 JmxUtil .registerMBean ("AsyncJobManager" , "Active Job " + job .getId (), new AsyncJobMBeanImpl (job ));
472489 } catch (Exception e ) {
473- s_logger .warn ("Unable to register active job " + job .getId () + " to JMX monitoring due to exception " + ExceptionUtil .toString (e ));
490+ s_logger .warn ("Unable to register active job [ " + job .getId () + " ] = [ " + job . getUuid () + " ] to JMX monitoring due to exception " + ExceptionUtil .toString (e ));
474491 }
475492
476493 BaseAsyncCmd cmdObj = null ;
477494 Transaction txn = Transaction .open (Transaction .CLOUD_DB );
478495 try {
479496 jobId = job .getId ();
480- NDC .push ("job-" + jobId );
497+ String jobUuid = job .getUuid ();
498+ NDC .push ("job-" + jobId + " = [ " + jobUuid + " ]" );
481499
482500 if (s_logger .isDebugEnabled ()) {
483- s_logger .debug ("Executing " + job .getCmd () + " for job-" + jobId );
501+ s_logger .debug ("Executing " + job .getCmd () + " for job-" + jobId + " = [ " + jobUuid + " ]" );
484502 }
485503
486504 Class <?> cmdClass = Class .forName (job .getCmd ());
@@ -525,13 +543,13 @@ public void run() {
525543 }
526544
527545 if (s_logger .isDebugEnabled ()) {
528- s_logger .debug ("Done executing " + job .getCmd () + " for job-" + jobId );
546+ s_logger .debug ("Done executing " + job .getCmd () + " for job-" + job . getId () + " = [ " + jobUuid + " ]" );
529547 }
530548
531549 } catch (Throwable e ) {
532550 if (e instanceof AsyncCommandQueued ) {
533551 if (s_logger .isDebugEnabled ()) {
534- s_logger .debug ("job " + job .getCmd () + " for job-" + jobId + " was queued, processing the queue." );
552+ s_logger .debug ("job " + job .getCmd () + " for job-" + jobId + " = [ " + job . getUuid () + " ] was queued, processing the queue." );
535553 }
536554 checkQueue (((AsyncCommandQueued )e ).getQueue ().getId ());
537555 } else {
@@ -570,7 +588,7 @@ public void run() {
570588 try {
571589 JmxUtil .unregisterMBean ("AsyncJobManager" , "Active Job " + job .getId ());
572590 } catch (Exception e ) {
573- s_logger .warn ("Unable to unregister active job " + job .getId () + " from JMX monitoring" );
591+ s_logger .warn ("Unable to unregister active job [ " + job .getId () + " ] = [ " + job . getUuid () + " ] from JMX monitoring" );
574592 }
575593
576594 txn .close ();
@@ -587,10 +605,12 @@ public void run() {
587605 }
588606
589607 private void executeQueueItem (SyncQueueItemVO item , boolean fromPreviousSession ) {
608+ long jobId = item .getContentId ();
590609 AsyncJobVO job = _jobDao .findById (item .getContentId ());
591610 if (job != null ) {
611+ String jobUuid = job .getUuid ();
592612 if (s_logger .isDebugEnabled ()) {
593- s_logger .debug ("Schedule queued job-" + job . getId () );
613+ s_logger .debug ("Schedule queued job-" + jobId + " = [ " + jobUuid + " ]" );
594614 }
595615
596616 job .setFromPreviousSession (fromPreviousSession );
@@ -602,7 +622,7 @@ private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession)
602622 try {
603623 scheduleExecution (job );
604624 } catch (RejectedExecutionException e ) {
605- s_logger .warn ("Execution for job-" + job . getId () + " is rejected, return it to the queue for next turn" );
625+ s_logger .warn ("Execution for job-" + jobId + " = [ " + jobUuid + " ] is rejected, return it to the queue for next turn" );
606626 _queueMgr .returnItem (item .getId ());
607627 }
608628
@@ -619,7 +639,7 @@ private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession)
619639 public void releaseSyncSource (AsyncJobExecutor executor ) {
620640 if (executor .getSyncSource () != null ) {
621641 if (s_logger .isDebugEnabled ()) {
622- s_logger .debug ("Release sync source for job-" + executor .getJob ().getId () + " sync source: "
642+ s_logger .debug ("Release sync source for job-" + executor .getJob ().getId () + " = [ " + executor . getJob (). getUuid () + " ] sync source: "
623643 + executor .getSyncSource ().getContentType () + "-"
624644 + executor .getSyncSource ().getContentId ());
625645 }
0 commit comments