Search in sources :

Example 6 with TaskResult

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);
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) TaskResult(ubic.gemma.core.job.TaskResult) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject)

Example 7 with TaskResult

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;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayList(java.util.ArrayList) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) TaskResult(ubic.gemma.core.job.TaskResult) Collection(java.util.Collection)

Example 8 with TaskResult

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) TaskResult(ubic.gemma.core.job.TaskResult) ModelAndView(org.springframework.web.servlet.ModelAndView) View(org.springframework.web.servlet.View) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 9 with TaskResult

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()));
}
Also used : EmailNotificationContext(ubic.gemma.core.job.EmailNotificationContext) TaskResult(ubic.gemma.core.job.TaskResult)

Example 10 with TaskResult

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);
}
Also used : TaskResult(ubic.gemma.core.job.TaskResult) SubmittedTask(ubic.gemma.core.job.SubmittedTask) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

TaskResult (ubic.gemma.core.job.TaskResult)14 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)2 Characteristic (ubic.gemma.model.common.description.Characteristic)2 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Queue (java.util.Queue)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 View (org.springframework.web.servlet.View)1 RepeatScan (ubic.gemma.core.analysis.sequence.RepeatScan)1 EmailNotificationContext (ubic.gemma.core.job.EmailNotificationContext)1 SubmittedTask (ubic.gemma.core.job.SubmittedTask)1