@Override protected final Document encode(final JobInfo job) { final Document document = new Document() .append(JobStructure.ID.key(), job.getJobId()) .append(JobStructure.JOB_TYPE.key(), job.getJobType()) .append(JobStructure.STARTED.key(), Date.from(job.getStarted().toInstant())) .append(JobStructure.LAST_UPDATED.key(), Date.from(job.getLastUpdated().toInstant())) .append(JobStructure.MESSAGES.key(), job.getMessages().stream() .map(MongoJobRepository::encodeJobMessage) .collect(toList())) .append(JobStructure.STATUS.key(), job.getStatus().name()) .append(JobStructure.HOSTNAME.key(), job.getHostname()); if (job.isStopped()) { document.append(JobStructure.STOPPED.key(), Date.from(job.getStopped().get().toInstant())); } return document; }
/** * Returns the number of failed jobs. * * @param jobInfos list of job infos * @return num failed jobs */ protected final long getNumFailedJobs(final List<JobInfo> jobInfos) { return jobInfos .stream() .filter(job -> JobStatus.ERROR.equals(job.getStatus())) .count(); }
@Override public int hashCode() { int result = jobId != null ? jobId.hashCode() : 0; result = 31 * result + (jobType != null ? jobType.hashCode() : 0); result = 31 * result + (started != null ? started.hashCode() : 0); result = 31 * result + (stopped != null ? stopped.hashCode() : 0); result = 31 * result + (messages != null ? messages.hashCode() : 0); result = 31 * result + (status != null ? status.hashCode() : 0); result = 31 * result + (lastUpdated != null ? lastUpdated.hashCode() : 0); result = 31 * result + (hostname != null ? hostname.hashCode() : 0); return result; }
@Test public void shouldNotFailInCaseLogMessageHasNoText() throws Exception { //given final Map<String, Object> infoLog = new HashMap<String, Object>() {{ put(MSG_LEVEL.key(), "INFO"); put(MSG_TEXT.key(), "Some text"); put(MSG_TS.key(), new Date()); }}; final Map<String, Object> errorLog = new HashMap<String, Object>() {{ put(MSG_LEVEL.key(), "ERROR"); put(MSG_TEXT.key(), null); put(MSG_TS.key(), new Date()); }}; final Document infoLogDocument = new Document(infoLog); final Document errorLogDocument = new Document(errorLog); final Map<String, Object> jobLogs = new HashMap<String, Object>() {{ put(MESSAGES.key(), asList(infoLogDocument, errorLogDocument)); put(JOB_TYPE.key(), "SomeType"); put(ID.key(), "/SomeType/ID"); put(STATUS.key(), ERROR.toString()); }}; //when final JobInfo jobInfo = repo.decode(new Document(jobLogs)); //then assertThat(jobInfo.getMessages().size(), is(2)); }
@Override protected final Document encode(final JobInfo job) { final Document document = new Document() .append(JobStructure.ID.key(), job.getJobId()) .append(JobStructure.JOB_TYPE.key(), job.getJobType()) .append(JobStructure.STARTED.key(), DateTimeConverters.toDate(job.getStarted())) .append(JobStructure.LAST_UPDATED.key(), DateTimeConverters.toDate(job.getLastUpdated())) .append(JobStructure.MESSAGES.key(), job.getMessages().stream() .map(MongoJobRepository::encodeJobMessage) .collect(toList())) .append(JobStructure.STATUS.key(), job.getStatus().name()) .append(JobStructure.HOSTNAME.key(), job.getHostname()); if (job.isStopped()) { document.append(JobStructure.STOPPED.key(), DateTimeConverters.toDate(job.getStopped().get())); } return document; }
private Document byTypeAndStatus(final String type, final JobStatus status) { return new Document(JobStructure.JOB_TYPE.key(), type).append(JobStructure.STATUS.key(), status.name()); }
@Override public void setJobStatus(final String jobId, final JobStatus jobStatus) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), set(JobStructure.STATUS.key(), jobStatus.name())); }
public String getStatus() { return job.getStatus().name(); }
@Override protected final JobInfo decode(final Document document) { return newJobInfo( document.getString(JobStructure.ID.key()), document.getString(JobStructure.JOB_TYPE.key()), DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.STARTED.key())), DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.LAST_UPDATED.key())), ofNullable(DateTimeConverters.toOffsetDateTime(document.getDate(JobStructure.STOPPED.key()))), JobStatus.valueOf(document.getString(JobStructure.STATUS.key())), getMessagesFrom(document), clock, document.getString(JobStructure.HOSTNAME.key())); }
@Override public void setJobStatus(final String jobId, final JobStatus jobStatus) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), set(JobStructure.STATUS.key(), jobStatus.name())); }
@Override protected final JobInfo decode(final Document document) { return newJobInfo( document.getString(JobStructure.ID.key()), document.getString(JobStructure.JOB_TYPE.key()), toOffsetDateTime(document.getDate(JobStructure.STARTED.key())), toOffsetDateTime(document.getDate(JobStructure.LAST_UPDATED.key())), ofNullable(toOffsetDateTime(document.getDate(JobStructure.STOPPED.key()))), JobStatus.valueOf(document.getString(JobStructure.STATUS.key())), getMessagesFrom(document), clock, document.getString(JobStructure.HOSTNAME.key())); }
@Override public JobStatus findStatus(final String jobId) { return JobStatus.valueOf(collection() .find(eq(ID, jobId)) .projection(new Document(JobStructure.STATUS.key(), true)) .maxTime(mongoProperties.getDefaultReadTimeout(), TimeUnit.MILLISECONDS) .first().getString(JobStructure.STATUS.key())); }
@Override public JobStatus findStatus(final String jobId) { return JobStatus.valueOf(collection() .find(eq(ID, jobId)) .projection(new Document(JobStructure.STATUS.key(), true)) .maxTime(mongoProperties.getDefaultReadTimeout(), TimeUnit.MILLISECONDS) .first().getString(JobStructure.STATUS.key())); }