Search in sources :

Example 1 with InvalidJobException

use of io.mantisrx.server.master.persistence.exceptions.InvalidJobException in project mantis by Netflix.

the class SimpleCachedFileStorageProvider method updateJob.

@Override
public void updateJob(IMantisJobMetadata jobMetadata) throws InvalidJobException, IOException {
    File jobFile = new File(getJobFileName(SPOOL_DIR, jobMetadata.getJobId().getId()));
    if (!jobFile.exists()) {
        throw new InvalidJobException(jobMetadata.getJobId().getId());
    }
    jobFile.delete();
    jobFile.createNewFile();
    try (PrintWriter pwrtr = new PrintWriter(jobFile)) {
        mapper.writeValue(pwrtr, jobMetadata);
    }
}
Also used : InvalidJobException(io.mantisrx.server.master.persistence.exceptions.InvalidJobException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 2 with InvalidJobException

use of io.mantisrx.server.master.persistence.exceptions.InvalidJobException in project mantis by Netflix.

the class SimpleCachedFileStorageProvider method storeAndUpdateWorkers.

@Override
public void storeAndUpdateWorkers(IMantisWorkerMetadata existingWorker, IMantisWorkerMetadata newWorker) throws InvalidJobException, IOException {
    if (!existingWorker.getJobId().equals(newWorker.getJobId()))
        throw new InvalidJobException(existingWorker.getJobId());
    // As the name indicates, this is a simple storage implementation that does not actually have the
    // atomicity. Instead, we update worker2, followed by storing worker1
    updateWorker(existingWorker);
    storeWorker(newWorker);
    // now move the terminated worker to archived state
    archiveWorker(existingWorker);
}
Also used : InvalidJobException(io.mantisrx.server.master.persistence.exceptions.InvalidJobException)

Example 3 with InvalidJobException

use of io.mantisrx.server.master.persistence.exceptions.InvalidJobException in project mantis by Netflix.

the class SimpleCachedFileStorageProvider method loadJob.

private Optional<IMantisJobMetadata> loadJob(String dir, String jobId) throws IOException {
    File jobFile = new File(getJobFileName(dir, jobId));
    IMantisJobMetadata job = null;
    if (jobFile.exists()) {
        try (FileInputStream fis = new FileInputStream(jobFile)) {
            job = mapper.readValue(fis, MantisJobMetadataImpl.class);
        }
        for (IMantisStageMetadata stage : readStagesFor(new File(dir), jobId)) ((MantisJobMetadataImpl) job).addJobStageIfAbsent(stage);
        for (IMantisWorkerMetadata worker : readWorkersFor(new File(dir), jobId)) {
            try {
                JobWorker jobWorker = new JobWorker.Builder().from(worker).withLifecycleEventsPublisher(eventPublisher).build();
                ((MantisJobMetadataImpl) job).addWorkerMetadata(worker.getStageNum(), jobWorker);
            } catch (InvalidJobException e) {
                logger.warn("Unexpected error adding worker index=" + worker.getWorkerIndex() + ", number=" + worker.getWorkerNumber() + " for job " + jobId + ": " + e.getMessage(), e);
            }
        }
    }
    return Optional.ofNullable(job);
}
Also used : IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) InvalidJobException(io.mantisrx.server.master.persistence.exceptions.InvalidJobException) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) File(java.io.File) FileInputStream(java.io.FileInputStream) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker)

Aggregations

InvalidJobException (io.mantisrx.server.master.persistence.exceptions.InvalidJobException)3 File (java.io.File)2 IMantisJobMetadata (io.mantisrx.master.jobcluster.job.IMantisJobMetadata)1 IMantisStageMetadata (io.mantisrx.master.jobcluster.job.IMantisStageMetadata)1 MantisJobMetadataImpl (io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl)1 IMantisWorkerMetadata (io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata)1 JobWorker (io.mantisrx.master.jobcluster.job.worker.JobWorker)1 FileInputStream (java.io.FileInputStream)1 PrintWriter (java.io.PrintWriter)1