Skip to content

Commit

Permalink
Merge pull request #124 from italiangrid/issue-STOR-1175
Browse files Browse the repository at this point in the history
Removed recallBuckets internal map
  • Loading branch information
enricovianello authored May 7, 2020
2 parents 43cc11c + 88a244b commit 134375f
Showing 1 changed file with 6 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;


public class TapeRecallCatalog {
Expand All @@ -53,8 +49,6 @@ public class TapeRecallCatalog {

private final TapeRecallDAO tapeRecallDAO;

private static Map<UUID, Collection<Suspendedable>> recallBuckets = new ConcurrentHashMap<>();

/**
* Default constructor
*
Expand Down Expand Up @@ -338,19 +332,6 @@ public UUID insertTask(Suspendedable chunk, String voName, String absoluteFileNa

synchronized (this) {
groupTaskId = this.insertNewTask(task);
/*
* Add to the map this task, if a task for the same group is available, add the task to
* its bucket
*/
if (recallBuckets.containsKey(groupTaskId)) {
// add to the bucket
recallBuckets.get(groupTaskId).add(chunk);
} else {
// create a new bucket
Collection<Suspendedable> chunkBucket = new ConcurrentLinkedQueue<>();
chunkBucket.add(chunk);
recallBuckets.put(groupTaskId, chunkBucket);
}
}
return groupTaskId;
}
Expand All @@ -377,7 +358,7 @@ public UUID insertNewTask(TapeRecallTO task) throws DataAccessException {

if (newGroupTaskId != groupTaskId) {
log.debug(
"Task with taskId {} of request with token {} has benn added to an existent group : ",
"Task with taskId {} of request with token {} has benn added to an existent group: {}",
task.getTaskId(), task.getRequestToken().getValue(), groupTaskId);
}
return groupTaskId;
Expand Down Expand Up @@ -428,78 +409,16 @@ private TapeRecallTO getTaskFromChunk(RequestData chunkData) throws DataAccessEx
public boolean changeGroupTaskStatus(UUID groupTaskId, TapeRecallStatus status, Date timestamp)
throws DataAccessException {

Collection<Suspendedable> chunkBucket = null;

synchronized (this) {

if (!tapeRecallDAO.setGroupTaskStatus(groupTaskId, status.getStatusId(), timestamp)) {
log.debug("Updating to status {} at {} didn't affect groupTask {}", status,
timestamp, groupTaskId);
return false;
}

if (!status.isFinalStatus()) {
return true;
}
boolean response = tapeRecallDAO.setGroupTaskStatus(groupTaskId, status.getStatusId(), timestamp);

if (recallBuckets.containsKey(groupTaskId)) {
chunkBucket = recallBuckets.remove(groupTaskId);
} else {
List<TapeRecallTO> recallTasks = getRecallTasksFromGroupTaskId(groupTaskId);
if (containsAnyBolOrPtg(recallTasks)) {
// recallBuckets should not be empty in case request is a Bol or a Ptg
String errorMessage = String.format(
"Unable to perform the final status update. No bucket found for Recall Group Task ID %s",
groupTaskId);
log.error(errorMessage);
throw new DataAccessException(errorMessage);
}
if (!response) {
log.debug("Updating to status {} at {} didn't affect groupTask {}", status,
timestamp, groupTaskId);
}
}

if (chunkBucket != null) {
updateChuncksStatus(chunkBucket, status);
}
return true;
}

/**
* @param taskId @param recallTaskStatus @throws IllegalArgumentException
*/
private void updateChuncksStatus(Collection<Suspendedable> chunkBucket,
TapeRecallStatus recallTaskStatus) {
return response;

if (chunkBucket == null || chunkBucket.isEmpty() || recallTaskStatus == null) {
log.error("Unable to perform the final status update. Provided invalid arguments");
throw new IllegalArgumentException(
"Unable to perform the final status update. Provided invalid arguments");
}
for (Suspendedable chunk : chunkBucket) {
chunk.completeRequest(recallTaskStatus);
}
}

private List<TapeRecallTO> getRecallTasksFromGroupTaskId(UUID groupTaskId)
throws DataAccessException {

List<TapeRecallTO> recallTasks = tapeRecallDAO.getGroupTasks(groupTaskId);
if (recallTasks.isEmpty()) {
String errorMessage = String.format(
"Unable to perform the final status update. No recall tasks found for Recall Group Task ID %s",
groupTaskId);
log.error(errorMessage);
throw new DataAccessException(errorMessage);
}
return recallTasks;
}

private boolean containsAnyBolOrPtg(List<TapeRecallTO> recallTasks) {

for (TapeRecallTO t : recallTasks) {
if (BOL.equals(t.getRequestType()) || PTG.equals(t.getRequestType())) {
return true;
}
}
return false;
}
}

0 comments on commit 134375f

Please sign in to comment.