Search in sources :

Example 1 with Fit3DJob

use of bio.fkaiser.fit3d.web.model.Fit3DJob in project fit3d by fkaiserbio.

the class SubmitJobView method submit.

public String submit() {
    // determine if too many jobs were submitted in current session
    int jobCount = getJobCountOfCurrentSession();
    if (jobCount > Fit3DWebConstants.JOB_LIMIT) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Too many jobs submitted. Please wait until until some jobs are finished.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        return null;
    }
    // determine if too many exchanges were defined
    if (exchangeDefinitions != null) {
        int exchangeCount = (int) exchangeDefinitions.stream().map(ExchangeDefinition::getExchangeAminoAcids).mapToLong(Collection::size).sum();
        if (exchangeCount > Fit3DWebConstants.EXCHANGE_LIMIT) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Only " + Fit3DWebConstants.EXCHANGE_LIMIT + " PSEs are allowed. Please use the command line or API version for more complex calculations.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return null;
        }
    }
    // motif file upload is mandatory
    if (!motifFileUploaded) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "A motif file is required.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        return null;
    }
    // use predefined target list if no one was provided
    if (!targetListFileUploaded) {
        if (predefinedList == PredefinedList.NONE) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Please select or upload a target list.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return null;
        } else {
            targetListPath = predefinedList.getPath();
            chainTargetList = true;
        }
    }
    Fit3DJobParameters jobParameters = new Fit3DJobParameters();
    jobParameters.setAtomFilterType(atomFilterType);
    jobParameters.setChainTargetList(chainTargetList);
    jobParameters.setPdbTargetList(pdbTargetList);
    if (motifPath.endsWith("4cha_motif.pdb")) {
        targetListPath = motifPath.getParent().resolve("targets.txt");
        logger.info("example run detected, using short target list {}", targetListPath);
        motifPath = motifPath.getParent().resolve("4cha_motif.pdb");
    }
    jobParameters.setMotifPath(motifPath);
    jobParameters.setTargetListPath(targetListPath);
    jobParameters.setRmsdLimit(rmsdLimit);
    jobParameters.setExchangeDefinitions(exchangeDefinitions);
    jobParameters.setStatisticalModelType(statisticalModelType);
    Fit3DJob job = new Fit3DJob(jobIdentifier, sessionManager.getSessionIdentifier(), determineIpAddress(), description, email, jobPath, jobParameters);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Flash flash = facesContext.getExternalContext().getFlash();
    flash.put("job", job);
    return "success";
}
Also used : Fit3DJobParameters(bio.fkaiser.fit3d.web.model.Fit3DJobParameters) FacesContext(javax.faces.context.FacesContext) Collection(java.util.Collection) Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob) Flash(javax.faces.context.Flash) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with Fit3DJob

use of bio.fkaiser.fit3d.web.model.Fit3DJob in project fit3d by fkaiserbio.

the class JobManager method cancelJob.

public void cancelJob(Fit3DJob job) {
    UUID jobIdentifier = job.getJobIdentifier();
    Optional<Fit3DJob> optionalJob = managedJobs.values().stream().flatMap(Collection::stream).filter(managedJob -> managedJob.getJobIdentifier().equals(jobIdentifier)).findFirst();
    optionalJob.ifPresent(Fit3DJob::cancel);
    if (optionalJob.isPresent()) {
        Fit3DJob managedJob = optionalJob.get();
        managedJob.cancel();
        logger.info("sent cancel signal to job {}", managedJob);
    } else {
        logger.info("job with identifier not found {}", job.getJobIdentifier());
    }
}
Also used : JobConverter(bio.fkaiser.fit3d.web.converter.JobConverter) Document(org.bson.Document) java.util(java.util) Logger(org.slf4j.Logger) MongoCollection(com.mongodb.client.MongoCollection) LoggerFactory(org.slf4j.LoggerFactory) Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob) IOException(java.io.IOException) Fit3DWebConstants(bio.fkaiser.fit3d.web.Fit3DWebConstants) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Future(java.util.concurrent.Future) MongoClient(com.mongodb.MongoClient) PostConstruct(javax.annotation.PostConstruct) Filters.eq(com.mongodb.client.model.Filters.eq) MongoCollection(com.mongodb.client.MongoCollection) Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob)

Example 3 with Fit3DJob

use of bio.fkaiser.fit3d.web.model.Fit3DJob in project fit3d by fkaiserbio.

the class JobManager method addJob.

public void addJob(Fit3DJob job) {
    Document jobObject = JobConverter.toDocument(job);
    mongoCollection.insertOne(jobObject);
    jobLoadManager.updateTotalJobs();
    logger.info("new job {} added to database", job);
    // add jobs to existing jobs of current session
    UUID sessionIdentifier = job.getSessionIdentifier();
    if (managedJobs.containsKey(sessionIdentifier)) {
        managedJobs.get(sessionIdentifier).add(job);
    } else {
        List<Fit3DJob> jobs = new ArrayList<>();
        jobs.add(job);
        managedJobs.put(sessionIdentifier, jobs);
    }
    // enqueue new job for execution
    Future<?> future = jobExecutor.enqueue(job);
    job.setFuture(future);
}
Also used : Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob) Document(org.bson.Document)

Example 4 with Fit3DJob

use of bio.fkaiser.fit3d.web.model.Fit3DJob in project fit3d by fkaiserbio.

the class AdminView method init.

@PostConstruct
public void init() {
    MongoClient mongoClient = new MongoClient(Fit3DWebConstants.Database.DB_HOST, Fit3DWebConstants.Database.DB_PORT);
    MongoCollection<Document> mongoCollection = mongoClient.getDatabase(Fit3DWebConstants.Database.DB_NAME).getCollection(Fit3DWebConstants.Database.DB_COLLECTION_NAME);
    FindIterable<Document> documents = mongoCollection.find();
    jobs = new ArrayList<>();
    for (Document document : documents) {
        Fit3DJob job = JobConverter.toFit3DJob(document);
        jobs.add(job);
    }
}
Also used : MongoClient(com.mongodb.MongoClient) Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob) Document(org.bson.Document) PostConstruct(javax.annotation.PostConstruct)

Example 5 with Fit3DJob

use of bio.fkaiser.fit3d.web.model.Fit3DJob in project fit3d by fkaiserbio.

the class JobConverter method toFit3DJob.

@SuppressWarnings("unchecked")
public static Fit3DJob toFit3DJob(Document jobDocument) {
    Document parametersObject = (Document) jobDocument.get("parameters");
    List<ExchangeDefinition> exchangeDefinitions = ((List<String>) parametersObject.get("exchangeDefinitions")).stream().map(ExchangeDefinition::fromString).collect(Collectors.toList());
    Fit3DJobParameters parameters = new Fit3DJobParameters();
    parameters.setAtomFilterType(AtomFilterType.valueOf((String) parametersObject.get("atomFilterType")));
    parameters.setPdbTargetList((boolean) parametersObject.get("pdbTargetList"));
    parameters.setChainTargetList((boolean) parametersObject.get("chainTargetList"));
    parameters.setTargetListPath(Paths.get((String) parametersObject.get("targetListPath")));
    parameters.setMotifPath(Paths.get((String) parametersObject.get("motifPath")));
    parameters.setStatisticalModelType(StatisticalModelType.valueOf((String) parametersObject.get("statisticalModel")));
    parameters.setRmsdLimit((double) parametersObject.get("rmsdLimit"));
    parameters.setExchangeDefinitions(exchangeDefinitions);
    Fit3DJob fit3dJob = new Fit3DJob();
    fit3dJob.setTimeStamp(LocalDateTime.parse((String) jobDocument.get("timeStamp")));
    fit3dJob.setSessionIdentifier((UUID.fromString((String) jobDocument.get("sessionIdentifier"))));
    fit3dJob.setIpAddress((String) jobDocument.get("ipAddress"));
    fit3dJob.setJobIdentifier(UUID.fromString((String) jobDocument.get("jobIdentifier")));
    fit3dJob.setJobPath(Paths.get((String) jobDocument.get("jobPath")));
    fit3dJob.setDescription((String) jobDocument.get("description"));
    fit3dJob.setEmail((String) jobDocument.get("email"));
    fit3dJob.setEnqueued((boolean) jobDocument.get("enqueued"));
    fit3dJob.setRunning((boolean) jobDocument.get("running"));
    fit3dJob.setFinished((boolean) jobDocument.get("finished"));
    fit3dJob.setFailed((boolean) jobDocument.get("failed"));
    fit3dJob.setSendMail((boolean) jobDocument.get("sendMail"));
    fit3dJob.setErrorMessage((String) jobDocument.get("errorMessage"));
    fit3dJob.setParameters(parameters);
    return fit3dJob;
}
Also used : Fit3DJobParameters(bio.fkaiser.fit3d.web.model.Fit3DJobParameters) ExchangeDefinition(bio.fkaiser.fit3d.web.model.ExchangeDefinition) List(java.util.List) Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob) Document(org.bson.Document)

Aggregations

Fit3DJob (bio.fkaiser.fit3d.web.model.Fit3DJob)6 Document (org.bson.Document)5 MongoClient (com.mongodb.MongoClient)3 PostConstruct (javax.annotation.PostConstruct)3 Fit3DWebConstants (bio.fkaiser.fit3d.web.Fit3DWebConstants)2 JobConverter (bio.fkaiser.fit3d.web.converter.JobConverter)2 Fit3DJobParameters (bio.fkaiser.fit3d.web.model.Fit3DJobParameters)2 MongoCollection (com.mongodb.client.MongoCollection)2 Filters.eq (com.mongodb.client.model.Filters.eq)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 java.util (java.util)2 Future (java.util.concurrent.Future)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ExchangeDefinition (bio.fkaiser.fit3d.web.model.ExchangeDefinition)1 Collection (java.util.Collection)1 List (java.util.List)1 FacesMessage (javax.faces.application.FacesMessage)1