@Override public TrackingInfo getTrackingInfo() { return taskMessage.getTracking(); }
private static String getTrackingPipe(final List<TaskMessage> taskMessages) { // Return the first tracking pipe. All task messages are expected to comprise the same // tracking pipe. return taskMessages.get(0).getTracking().getTrackingPipe(); }
/** * Add a new message onto the buffer. */ public void add(final TaskMessage taskMessage) { Objects.requireNonNull(taskMessage); // Ignore if no tracking information and tracking pipe is available. if (taskMessage.getTracking() != null && taskMessage.getTracking().getTrackingPipe() != null && !taskMessage.getTracking().getTrackingPipe().isEmpty()) { addOrFlush(taskMessage); } }
private void debugCurrentQueueItems() { logger.warn("Message queue currently contains: " + consumerImpl.getDelivery().size()); // do we have any items on the queue at all, if so, output what we have? for (Map.Entry<String, Delivery> deliveredItem : consumerImpl.getDelivery().entrySet()) { Delivery tmpDel = deliveredItem.getValue(); TaskMessage tm = getTaskMessageFromDelivery(tmpDel); logger.warn( String.format("Queue contains other item: {%s} TrackingInfo jobTaskId: {%s}", tm.getTaskId(), tm.getTracking() == null ? "null" : tm.getTracking().getJobTaskId())); } }
private TrackingInfo getTrackingInfoWithChanges(final String trackTo) { TrackingInfo trackingInfo = null; final TrackingInfo taskMessageTracking = taskMessage.getTracking(); if (taskMessageTracking != null) { trackingInfo = new TrackingInfo(taskMessageTracking); trackingInfo.setTrackTo(trackTo); } return trackingInfo; }
tm.getTaskId(), tm.getTracking() == null ? "null" : tm.getTracking().getJobTaskId())); if (tm.getTracking() == null) { continue; if (!tm.getTracking().getJobTaskId().contains(expectedTaskId)) { continue; logger.debug("Queue contains match in tracking info: " + tm.getTracking().getJobTaskId() + " with actual taskId:" + tm.getTaskId()); delivery.remove(tm.getTaskId()); return del;
/** * Checks whether tracking of this task message should end when publishing to the specified queue. If tracking is to end then this * method removes and returns the tracking info from the task message. * * @param queueMsgId the reference to the message this task arrived on * @param queueToSend the queue to which the message is to be published * @param tm task message whose tracking info is to be checked * @return if tracking of the message terminates on publishing to the specified queue then the removed tracking info is returned; * otherwise null is returned and the tracking info is not removed from the message */ private TrackingInfo checkForTrackingTermination(final String queueMsgId, final String queueToSend, TaskMessage tm) { Objects.requireNonNull(queueMsgId); Objects.requireNonNull(tm); // queueToSend can be null for a dead end worker final TrackingInfo tracking = tm.getTracking(); if (tracking != null) { final String trackTo = tracking.getTrackTo(); if ((trackTo == null && queueToSend == null) || (trackTo != null && trackTo.equalsIgnoreCase(queueToSend))) { LOG.debug("Task {} (message id: {}): removing tracking info from this message as tracking ends on publishing to the queue {}.", tm.getTaskId(), queueMsgId, queueToSend); tm.setTracking(null); } } return tracking; } }
/** * Checks whether a task is still active. If a status check cannot be performed then the task is assumed to be active. Checking * status may result in a change to the tracking info on the supplied task message. * * @param tm task message to be checked to verify whether the task is still active * @return true if the task is still active, false otherwise */ private boolean checkStatus(TaskMessage tm) throws InvalidJobTaskIdException { Objects.requireNonNull(tm); TrackingInfo tracking = tm.getTracking(); if (tracking != null) { Date statusCheckTime = tracking.getStatusCheckTime(); if (statusCheckTime == null || statusCheckTime.getTime() <= System.currentTimeMillis()) { return performJobStatusCheck(tm); } LOG.debug("Task {} active status is not being checked - it is not yet time for the status check to be performed: status check due at {}", tm.getTaskId(), statusCheckTime); } else { LOG.debug("Task {} active status is not being checked - the task message does not have tracking info", tm.getTaskId()); } //By default a task is considered to be active. return true; }
if (resultMessage.getTracking() == null || !resultMessage.getTracking().getJobTaskId().contains(taskIdFilter)) { logger.warn("Received message which wasn't expected by this test case -> throwing it away taskId: " + resultMessage.getTaskId() + " jobTracking: " + (resultMessage.getTracking() == null ? "null" : resultMessage.getTracking().getJobTaskId())); " jobTracking: " + (resultMessage.getTracking() == null ? "null" : resultMessage.getTracking().getJobTaskId()));
/** * Updates the specified {@link TaskMessage} with the specified subtask identifier. */ private static void updateTaskId(final TaskMessage responseMessage, final int subtaskId, final boolean isFinalResponse) { // Put together the suffix to be added final String subtaskSuffix; { final StringBuilder builder = new StringBuilder(); builder.append('.'); builder.append(subtaskId); if (isFinalResponse) { builder.append('*'); } subtaskSuffix = builder.toString(); } // Update the task id responseMessage.setTaskId(responseMessage.getTaskId() + subtaskSuffix); // Update the tracking info final TrackingInfo taskMessageTracking = responseMessage.getTracking(); if (taskMessageTracking != null) { final String trackingTaskId = taskMessageTracking.getJobTaskId(); if (trackingTaskId != null) { final TrackingInfo trackingInfo = new TrackingInfo(taskMessageTracking); trackingInfo.setJobTaskId(trackingTaskId + subtaskSuffix); responseMessage.setTracking(trackingInfo); } } }
/** * Checks the current active status of the job to which the task belongs. If this check can be made successfully then the status * check time of the supplied task message is updated. * * @param tm the task message whose job status will be verified * @return true if the task's job is active or the job status could not be checked, false if the status could be checked and the * job is found to be inactive (aborted, cancelled, etc.) */ private boolean performJobStatusCheck(TaskMessage tm) throws InvalidJobTaskIdException { Objects.requireNonNull(tm); TrackingInfo tracking = tm.getTracking(); Objects.requireNonNull(tracking); String statusCheckUrl = tracking.getStatusCheckUrl(); if (statusCheckUrl == null) { //If statusCheckUrl is null then we can't perform the status check so we have to assume the job is active. return true; } String jobId = tracking.getJobId(); LOG.debug("Task {} (job {}) - attempting to check job status", tm.getTaskId(), jobId); JobStatusResponse jobStatus = getJobStatus(jobId, statusCheckUrl); long newStatusCheckTime = System.currentTimeMillis() + jobStatus.getStatusCheckIntervalMillis(); LOG.debug("Task {} (job {}) - updating status check time from {} to {}", tm.getTaskId(), jobId, tracking.getStatusCheckTime(), new Date(newStatusCheckTime)); tracking.setStatusCheckTime(new Date(newStatusCheckTime)); return jobStatus.isActive(); }
trackingReport.jobTaskId = tm.getTracking().getJobTaskId(); final String trackToPipe = tm.getTracking().getTrackTo(); final String toPipe = tm.getTo();
@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); }
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; }