Skip to content

Commit

Permalink
fix(JobEngine): Improved error message for device target processors
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise authored and Coduz committed Oct 4, 2023
1 parent fde490a commit a6c5733
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
public abstract class AbstractDeviceTargetProcessor extends AbstractTargetProcessor {
protected static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
protected static final DeviceRegistryService DEVICE_REGISTRY_SERVICE = LOCATOR.getService(DeviceRegistryService.class);


@Override
protected String getTargetDisplayName(JobTarget jobTarget) throws KapuaException {
Device device = KapuaSecurityUtils.doPrivileged(() -> DEVICE_REGISTRY_SERVICE.find(jobTarget.getScopeId(), jobTarget.getJobTargetId()));;
Device device = KapuaSecurityUtils.doPrivileged(() -> DEVICE_REGISTRY_SERVICE.find(jobTarget.getScopeId(), jobTarget.getJobTargetId()));
if (device == null) {
return "N/A";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,29 @@ public final Object processItem(Object item) throws Exception {

jobLogger.info("Processing target:{} (id:{}) - DONE!", getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());
} catch (Exception e) {
jobLogger.error(e, "Processing target:{} (id:{}) - Error!", getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());

logErrorToJobLogger(stepContextWrapper.getKapuaStepName(), jobLogger, jobTarget, e);
jobTarget.setStatus(getFailedStatus(jobTarget));
wrappedJobTarget.setProcessingException(e);
}

return wrappedJobTarget;
}


/**
* Prints an error message into the given job logger
*
* @param stepName The name of the step that fails
* @param jobLogger The {@link JobLogger} where to print the error message
* @param jobTarget The {@link JobTarget} that was being processed
* @param e The exception that occurred
* @throws KapuaException
*/
protected void logErrorToJobLogger(String stepName, JobLogger jobLogger, JobTarget jobTarget, Exception e) throws KapuaException {
jobLogger.error(e, "Executing {} on device: {} (id: {}) - ", stepName, getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());
}


protected abstract String getTargetDisplayName(JobTarget jobTarget) throws KapuaException;

/**
Expand Down

0 comments on commit a6c5733

Please sign in to comment.