Skip to content

Commit

Permalink
Fix dcm4che#2041 : Monitoring Retrieve Tasks services : dicomDeviceNa…
Browse files Browse the repository at this point in the history
…me and dcmQueueName query parameters ineffective for tasks with TO_SCHEDULE status
  • Loading branch information
vrindanayak committed Jun 19, 2019
1 parent aa23624 commit a2dfeeb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public void matchExportTask(List<Predicate> predicates, TaskQueryParam taskQuery
}

public void matchRetrieveTask(List<Predicate> predicates, TaskQueryParam taskQueryParam, Path<RetrieveTask> retrieveTask) {
if (!taskQueryParam.getQueueName().isEmpty())
predicates.add(cb.and(retrieveTask.get(RetrieveTask_.queueName).in(taskQueryParam.getQueueName())));
if (taskQueryParam.getDeviceName() != null)
predicates.add(cb.equal(retrieveTask.get(RetrieveTask_.deviceName), taskQueryParam.getDeviceName()));
if (taskQueryParam.getLocalAET() != null)
predicates.add(cb.equal(retrieveTask.get(RetrieveTask_.localAET), taskQueryParam.getLocalAET()));
if (taskQueryParam.getRemoteAET() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public Response listRetrieveTasks(@QueryParam("accept") String accept) {

try {
return Response.ok(output.entity(mgr.listRetrieveTasks(
queueTaskQueryParam(deviceName, status()),
retrieveTaskQueryParam(updatedTime),
queueTaskQueryParam(status()),
retrieveTaskQueryParam(deviceName, updatedTime),
parseInt(offset),
parseInt(limit))),
output.type)
Expand All @@ -223,8 +223,8 @@ public Response countRetrieveTasks() {
logRequest();
try {
return count(mgr.countTasks(
queueTaskQueryParam(deviceName, status()),
retrieveTaskQueryParam(updatedTime)));
queueTaskQueryParam(status()),
retrieveTaskQueryParam(deviceName, updatedTime)));
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
Expand Down Expand Up @@ -262,9 +262,9 @@ public Response cancelRetrieveTasks() {
BulkQueueMessageEvent queueEvent = new BulkQueueMessageEvent(request, QueueMessageOperation.CancelTasks);
try {
LOG.info("Cancel processing of Retrieve Tasks with Status {}", status);
TaskQueryParam queueTaskQueryParam = queueTaskQueryParam(deviceName, status);
TaskQueryParam queueTaskQueryParam = queueTaskQueryParam(status);
queueTaskQueryParam.setUpdatedTime(updatedTime);
long count = mgr.cancelRetrieveTasks(queueTaskQueryParam, retrieveTaskQueryParam(null));
long count = mgr.cancelRetrieveTasks(queueTaskQueryParam, retrieveTaskQueryParam(deviceName, null));
queueEvent.setCount(count);
return count(count);
} catch (Exception e) {
Expand Down Expand Up @@ -335,30 +335,30 @@ public Response rescheduleRetrieveTasks() {
if (devName != null && !devName.equals(device.getDeviceName()))
return rsClient.forward(request, devName, "");

TaskQueryParam retrieveTaskQueryParam = retrieveTaskQueryParam(updatedTime);

return newDeviceName != null
? rescheduleValidTasks(queueTaskQueryParam(null, status), retrieveTaskQueryParam)
? rescheduleValidTasks(queueTaskQueryParam(status), retrieveTaskQueryParam(null, updatedTime))
: count(devName == null
? rescheduleOnDistinctDevices(retrieveTaskQueryParam, status)
? rescheduleOnDistinctDevices(status)
: rescheduleTasks(
queueTaskQueryParam(devName, status),
retrieveTaskQueryParam));
queueTaskQueryParam(status),
retrieveTaskQueryParam(devName, updatedTime)));
} catch (IllegalStateException e) {
return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
}

private int rescheduleOnDistinctDevices(TaskQueryParam retrieveTaskQueryParam, QueueMessage.Status status)
private int rescheduleOnDistinctDevices(QueueMessage.Status status)
throws Exception {
List<String> distinctDeviceNames = mgr.listDistinctDeviceNames(retrieveTaskQueryParam);
List<String> distinctDeviceNames = mgr.listDistinctDeviceNames(retrieveTaskQueryParam(null, updatedTime));
int count = 0;
for (String devName : distinctDeviceNames)
count += devName.equals(device.getDeviceName())
? rescheduleTasks(
queueTaskQueryParam(devName, status),
retrieveTaskQueryParam)
queueTaskQueryParam(status),
retrieveTaskQueryParam(devName, updatedTime))
: count(rsClient.forward(request, devName, "&dicomDeviceName=" + devName), devName);
return count;
}
Expand Down Expand Up @@ -463,8 +463,8 @@ public Response deleteTasks() {
int deleteTasksFetchSize = queueTasksFetchSize();
do {
count = mgr.deleteTasks(
queueTaskQueryParam(deviceName, status()),
retrieveTaskQueryParam(updatedTime),
queueTaskQueryParam(status()),
retrieveTaskQueryParam(deviceName, updatedTime),
deleteTasksFetchSize);
deleted += count;
} while (count >= deleteTasksFetchSize);
Expand Down Expand Up @@ -637,16 +637,16 @@ private ArchiveDeviceExtension arcDev() {
return device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
}

private TaskQueryParam queueTaskQueryParam(String deviceName, QueueMessage.Status status) {
private TaskQueryParam queueTaskQueryParam(QueueMessage.Status status) {
TaskQueryParam taskQueryParam = new TaskQueryParam();
taskQueryParam.setStatus(status);
taskQueryParam.setDeviceName(deviceName);
taskQueryParam.setQueueName(dcmQueueName);
return taskQueryParam;
}

private TaskQueryParam retrieveTaskQueryParam(String updatedTime) {
private TaskQueryParam retrieveTaskQueryParam(String deviceName, String updatedTime) {
TaskQueryParam taskQueryParam = new TaskQueryParam();
taskQueryParam.setDeviceName(deviceName);
taskQueryParam.setQueueName(dcmQueueName);
taskQueryParam.setLocalAET(localAET);
taskQueryParam.setRemoteAET(remoteAET);
taskQueryParam.setBatchID(batchID);
Expand Down

0 comments on commit a2dfeeb

Please sign in to comment.