gmantele / vollt

Java libraries implementing the IVOA protocol: ADQL, UWS and TAP
http://cdsportal.u-strasbg.fr/taptuto/
30 stars 29 forks source link

how to reload former jobs at startup. #93

Open marcdexet-cnrs opened 6 years ago

marcdexet-cnrs commented 6 years ago

Hi

I succed to put all data from past UWSjob into a mongodb database. How can I make UWS reload all these informations to make all not destructed data (results, parameters, status, ...) available again through the nominal API ? Thanks.

marcdexet-cnrs commented 6 years ago

I presume I can get inspiration from uws.service.backup.DefaultUWSBackupManager ?

marcdexet-cnrs commented 6 years ago

And if I go directly to the last interaction with jobList in uws.service.backup.DefaultUWSBackupManager.restoreJob(JSONObject, Map<String, JobOwner>) all I have to do is to addNewJob :

 return (uws.getJobList(jobListName).addNewJob(job) != null);

Is it right ?

marcdexet-cnrs commented 6 years ago

Ok. I succeed to reload from mongo all COMPLETED jobs.

I just convert back my recorded job definitions as UWSJob and add this to the right jobList.

Don't forget to enforce executionPhase, otherwise it would be PENDING by default

/**
 * Creates a {@link UWSJob} Job from data recorded into DB 
 * @param job
 * @return a UWS job
 */
public static UWSJob createUWSJob(Job job) {
    long creationTime = Helper.toTime(job.getCreationTime());
    long startTime = Helper.toTime(job.getStartTime());
    long endTime = Helper.toTime(job.getEndTime());
    String jobID = job.getJobId();
    UWSParameters uwsParams = createParametersFromRecordedParameters(job.getParameters());
    long quote = 0;
    JobOwner uwsOwner = createOwnerFromUserId(job.getOwner());
    List<uws.job.Result> uwsResults = createUwsResultsFromRecordedResultList(job.getResults());
    ErrorSummary uwsError = createErrorSummaryFromRecordedError(job.getError());

    UWSJob uwsJob =new UWSJob(jobID, creationTime, uwsOwner, uwsParams, quote, startTime, endTime, uwsResults, uwsError);
    try {
        uwsJob.setPhase(ExecutionPhase.valueOf(job.getPhase()), true);
    } catch (UWSException e) {
        LOGGER.error("Error", e);
    }
    return uwsJob;
}