use of ubic.gemma.core.job.TaskResult in project Gemma by PavlidisLab.
the class CharacteristicUpdateTaskImpl method doRemove.
private TaskResult doRemove() {
Collection<AnnotationValueObject> chars = taskCommand.getAnnotationValueObjects();
log.info("Delete " + chars.size() + " characteristics...");
Collection<Characteristic> asChars = convertToCharacteristic(chars);
if (asChars.size() == 0) {
log.info("No characteristic objects were received");
return new TaskResult(taskCommand, false);
}
Map<Characteristic, Object> charToParent = characteristicService.getParents(asChars);
for (Characteristic cFromClient : asChars) {
Characteristic cFromDatabase = characteristicService.load(cFromClient.getId());
Object parent = charToParent.get(cFromDatabase);
removeFromParent(cFromDatabase, parent);
characteristicService.remove(cFromDatabase);
log.info("Characteristic deleted: " + cFromDatabase + " (associated with " + parent + ")");
}
return new TaskResult(taskCommand, true);
}
use of ubic.gemma.core.job.TaskResult in project Gemma by PavlidisLab.
the class ExpressionExperimentLoadTaskImpl method execute.
@SuppressWarnings("unchecked")
@Override
public TaskResult execute() {
String accession = taskCommand.getAccession();
boolean loadPlatformOnly = taskCommand.isLoadPlatformOnly();
boolean doSampleMatching = !taskCommand.isSuppressMatching();
boolean splitByPlatform = taskCommand.isSplitByPlatform();
boolean allowSuperSeriesLoad = taskCommand.isAllowSuperSeriesLoad();
boolean allowSubSeriesLoad = true;
TaskResult result;
if (loadPlatformOnly) {
Collection<ArrayDesign> arrayDesigns = (Collection<ArrayDesign>) geoDatasetService.fetchAndLoad(accession, true, doSampleMatching, splitByPlatform);
ArrayList<ArrayDesign> minimalDesigns = null;
if (arrayDesigns != null) {
/* Don't send the full array designs to space. Instead, create a minimal result. */
minimalDesigns = new ArrayList<>();
for (ArrayDesign ad : arrayDesigns) {
ArrayDesign minimalDesign = ArrayDesign.Factory.newInstance();
minimalDesign.setId(ad.getId());
minimalDesign.setName(ad.getName());
minimalDesign.setDescription(ad.getDescription());
minimalDesigns.add(minimalDesign);
}
}
result = new TaskResult(this.taskCommand, minimalDesigns);
} else {
// Better readability
@SuppressWarnings("ConstantConditions") Collection<ExpressionExperiment> datasets = (Collection<ExpressionExperiment>) geoDatasetService.fetchAndLoad(accession, loadPlatformOnly, doSampleMatching, splitByPlatform, allowSuperSeriesLoad, allowSubSeriesLoad);
if (datasets == null || datasets.isEmpty()) {
// can happen with cancellation.
throw new IllegalStateException("Failed to load anything");
}
log.info("Loading done, starting postprocessing");
this.postProcess(datasets);
/* Don't send the full experiments to space. Instead, create a minimal result. */
ArrayList<ExpressionExperiment> minimalDatasets = new ArrayList<>();
for (ExpressionExperiment ee : datasets) {
ExpressionExperiment minimalDataset = ExpressionExperiment.Factory.newInstance();
minimalDataset.setId(ee.getId());
minimalDataset.setName(ee.getName());
minimalDataset.setDescription(ee.getDescription());
minimalDatasets.add(minimalDataset);
}
result = new TaskResult(this.taskCommand, minimalDatasets);
}
return result;
}
use of ubic.gemma.core.job.TaskResult in project Gemma by PavlidisLab.
the class ProgressStatusServiceImpl method checkResult.
@Override
public Object checkResult(String taskId) throws Exception {
SubmittedTask<?> submittedTask = taskRunningService.getSubmittedTask(taskId);
if (submittedTask == null)
return null;
TaskResult result = submittedTask.getResult();
if (result == null)
return null;
Object answer = result.getAnswer();
if (answer instanceof ModelAndView) {
View view = ((ModelAndView) answer).getView();
if (view instanceof RedirectView) {
return ((RedirectView) view).getUrl();
}
return null;
}
if (answer instanceof Exception) {
throw (Exception) answer;
}
return answer;
}
use of ubic.gemma.core.job.TaskResult in project Gemma by PavlidisLab.
the class SubmittedTaskLocal method addEmailAlert.
@SuppressWarnings("unchecked")
@Override
public synchronized void addEmailAlert() {
if (emailAlert)
return;
emailAlert = true;
assert taskPostProcessing != null : "Task postprocessing was null";
taskPostProcessing.addEmailNotification((ListenableFuture<TaskResult>) future, new EmailNotificationContext(taskCommand.getTaskId(), taskCommand.getSubmitter(), taskCommand.getTaskClass().getSimpleName()));
}
use of ubic.gemma.core.job.TaskResult in project Gemma by PavlidisLab.
the class SubmittedTasksMaintenance method doSubmittedTasksMaintenance.
/**
* Check if a task has been running or queued for too long, and cancel it if necessary. Email alert will always be
* sent in that case.
*/
@Scheduled(fixedDelay = 120000)
public void doSubmittedTasksMaintenance() {
// Assumes collection implementing weakly consistent iterator with remove support.
Collection<SubmittedTask<? extends TaskResult>> tasks = taskRunningService.getSubmittedTasks();
int numQueued = 0;
int numRunning = 0;
int numDone = 0;
int numCancelled = 0;
for (SubmittedTask<?> task : tasks) {
if (!task.getStatus().equals(SubmittedTask.Status.COMPLETED)) {
SubmittedTasksMaintenance.log.info("Checking task: " + task.getTaskCommand().getClass().getSimpleName() + task.getTaskId() + " started=" + task.getStartTime() + " status=" + task.getStatus());
}
switch(task.getStatus()) {
case QUEUED:
numQueued++;
Date submissionTime = task.getSubmissionTime();
Integer maxQueueWait = task.getTaskCommand().getMaxQueueMinutes();
assert submissionTime != null;
assert maxQueueWait != null;
if (submissionTime.before(DateUtils.addMinutes(new Date(), -maxQueueWait))) {
SubmittedTasksMaintenance.log.warn("Submitted task " + task.getTaskCommand().getClass().getSimpleName() + " has been queued for too long (max=" + maxQueueWait + "minutes), attempting to cancel: " + task.getTaskId());
task.addEmailAlert();
// -> email admin? is worker dead?
task.requestCancellation();
}
break;
case RUNNING:
numRunning++;
Date startTime = task.getStartTime();
int maxRunTime = task.getTaskCommand().getMaxRuntime();
assert startTime != null;
if (startTime.before(DateUtils.addMinutes(new Date(), -maxRunTime))) {
SubmittedTasksMaintenance.log.warn("Running task is taking too long, attempting to cancel: " + task.getTaskId() + " " + task.getTaskCommand().getClass().getSimpleName());
task.addEmailAlert();
task.requestCancellation();
}
break;
case CANCELLING:
numCancelled++;
break;
case FAILED:
// fall through
case COMPLETED:
numDone++;
if (task.getFinishTime().before(DateUtils.addMinutes(new Date(), -SubmittedTasksMaintenance.MAX_KEEP_TRACK_AFTER_COMPLETED_MINUTES))) {
SubmittedTasksMaintenance.log.debug(task.getStatus().name() + " task result not retrieved, timing out: " + task.getTaskId() + " " + task.getTaskCommand().getClass().getSimpleName());
// concurrent modification.
tasks.remove(task);
}
break;
case UNKNOWN:
break;
default:
break;
}
}
if (tasks.size() > 0 && numDone != tasks.size())
SubmittedTasksMaintenance.log.info(tasks.size() + " tasks monitored; Done: " + numDone + "; Running: " + numRunning + "; Cancelled: " + numCancelled + "; Queued: " + numQueued);
}
Aggregations