/** * Updates the passed in Document metadata with details of the passed in TaskSourceInfo. * * @param document Document to update metadata on. * @param sourceInfo The TaskSourceInfo to use in updating the metadata. */ public static void addProcessingWorkerInformation(DocumentInterface document, TaskSourceInfo sourceInfo) { if (sourceInfo == null) { logger.warn("No TaskSourceInfo was provided, unable to add Processing Worker Version to document."); return; } try { PolicyReprocessingVersionTagging.addProcessingWorkerVersion( document, new WorkerProcessingInfo(sourceInfo.getVersion(), sourceInfo.getName())); } catch (PolicyReprocessingVersionTaggingException e) { logger.warn("Failed to add Processing Worker Version to document.", e); } }
/** * Obtain the name of the worker, that performed the operation. * @param workerTaskData * @return */ private static String getWorkerName(WorkerTaskData workerTaskData) { final TaskSourceInfo sourceInfo = workerTaskData.getSourceInfo(); if (sourceInfo == null || Strings.isNullOrEmpty(sourceInfo.getName())) { return "Unknown"; } return sourceInfo.getName(); }
@Override public void setResponse(final InvalidTaskException invalidTaskException) { if (invalidTaskException == null) { throw new IllegalArgumentException(); } incrementResponseCount(true); LOG.error("Task data is invalid for {}, returning status {}", taskMessage.getTaskId(), TaskStatus.INVALID_TASK, invalidTaskException); final String taskClassifier = MoreObjects.firstNonNull(taskMessage.getTaskClassifier(), ""); final String invalidTaskExceptionMessage = invalidTaskException.getMessage(); final byte[] taskData = invalidTaskExceptionMessage == null ? new byte[]{} : invalidTaskExceptionMessage.getBytes(StandardCharsets.UTF_8); final Map<String, byte[]> context = MoreObjects.firstNonNull( taskMessage.getContext(), Collections.<String, byte[]>emptyMap()); final TaskMessage invalidResponse = new TaskMessage( MoreObjects.firstNonNull(taskMessage.getTaskId(), ""), taskClassifier, taskMessage.getTaskApiVersion(), taskData, TaskStatus.INVALID_TASK, context, workerFactory.getInvalidTaskQueue(), taskMessage.getTracking(), new TaskSourceInfo(getWorkerName(taskClassifier), getWorkerVersion())); completeResponse(invalidResponse); }
/** * Returns the worker name from the source information in the task message or an "Unknown" string if it is * not present. * * @param taskMessage the task message to be examined * @return the name of the worker that created the task message */ private static String getWorkerName(final TaskMessage taskMessage) { final TaskSourceInfo sourceInfo = taskMessage.getSourceInfo(); if (sourceInfo == null) { return "Unknown - no source info"; } final String workerName = sourceInfo.getName(); if (workerName == null) { return "Unknown - worker name not set"; } return workerName; }
private TaskMessage createResponseMessage(final boolean includeTaskContext, final WorkerResponse response) { final Map<String, byte[]> responseContext = createFullResponseContext(includeTaskContext, response.getContext()); final String responseMessageType = response.getMessageType(); // Check if a tracking change is required. If empty string then no further changes required. final TrackingInfo trackingInfo; if ("".equals(response.getTrackTo())) { // No tracking changes required. trackingInfo = taskMessage.getTracking(); } else { // Set trackTo field to the specified value. trackingInfo = getTrackingInfoWithChanges(response.getTrackTo()); } final TaskMessage responseMessage = new TaskMessage( taskMessage.getTaskId(), responseMessageType, response.getApiVersion(), response.getData(), response.getTaskStatus(), responseContext, response.getQueueReference(), trackingInfo, new TaskSourceInfo(getWorkerName(responseMessageType), getWorkerVersion())); responseMessage.setPriority(priorityManager.getResponsePriority(taskMessage)); return responseMessage; }