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);
}
}
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);
}
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);
}
Aggregations