Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.core.xcontent.XContentParserUtils;
import org.opensearch.index.seqno.SequenceNumbers;

import java.io.IOException;
import java.time.Instant;
Expand All @@ -35,36 +34,20 @@ public final class StatusHistoryModel implements ToXContentObject, Writeable {
private final Instant startTime;
private final Instant endTime;
private final int status;
private final long seqNo;
private final long primaryTerm;

public StatusHistoryModel(String jobIndexName, String jobId, Instant startTime, Instant endTime, int status) {
this(jobIndexName, jobId, startTime, endTime, status, SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM);
}

public StatusHistoryModel(
String jobIndexName,
String jobId,
Instant startTime,
Instant endTime,
int status,
long seqNo,
long primaryTerm
) {
this.jobIndexName = jobIndexName;
this.jobId = jobId;
this.startTime = startTime;
this.endTime = endTime;
this.status = status;
this.seqNo = seqNo;
this.primaryTerm = primaryTerm;
}

public StatusHistoryModel(StreamInput in) throws IOException {
this(in.readString(), in.readString(), in.readInstant(), in.readOptionalInstant(), in.readInt(), in.readLong(), in.readLong());
this(in.readString(), in.readString(), in.readInstant(), in.readOptionalInstant(), in.readInt());
}

public static StatusHistoryModel parse(final XContentParser parser, long seqNo, long primaryTerm) throws IOException {
public static StatusHistoryModel parse(final XContentParser parser) throws IOException {
String jobIndexName = null;
String jobId = null;
Instant startTime = null;
Expand Down Expand Up @@ -103,9 +86,7 @@ public static StatusHistoryModel parse(final XContentParser parser, long seqNo,
requireNonNull(jobId, "JobId cannot be null"),
requireNonNull(startTime, "startTime cannot be null"),
endTime,
requireNonNull(status, "status cannot be null"),
seqNo,
primaryTerm
requireNonNull(status, "status cannot be null")
);
}

Expand Down Expand Up @@ -146,22 +127,12 @@ public int getStatus() {
return status;
}

public long getSeqNo() {
return seqNo;
}

public long getPrimaryTerm() {
return primaryTerm;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StatusHistoryModel that = (StatusHistoryModel) o;
return seqNo == that.seqNo
&& primaryTerm == that.primaryTerm
&& jobIndexName.equals(that.jobIndexName)
return jobIndexName.equals(that.jobIndexName)
&& jobId.equals(that.jobId)
&& startTime.equals(that.startTime)
&& Objects.equals(endTime, that.endTime)
Expand All @@ -170,7 +141,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(jobIndexName, jobId, startTime, endTime, status, seqNo, primaryTerm);
return Objects.hash(jobIndexName, jobId, startTime, endTime, status);
}

@Override
Expand All @@ -180,7 +151,5 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInstant(this.startTime);
out.writeOptionalInstant(this.endTime);
out.writeInt(this.status);
out.writeLong(this.seqNo);
out.writeLong(this.primaryTerm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,7 @@ public void recordJobHistory(
findHistoryRecord(jobIndexName, jobId, startTime, ActionListener.wrap(existingRecord -> {
if (existingRecord != null) {
// Update existing record
StatusHistoryModel updatedModel = new StatusHistoryModel(
jobIndexName,
jobId,
startTime,
endTime,
status,
existingRecord.getSeqNo(),
existingRecord.getPrimaryTerm()
);
StatusHistoryModel updatedModel = new StatusHistoryModel(jobIndexName, jobId, startTime, endTime, status);
updateHistoryRecord(
updatedModel,
ActionListener.wrap(updated -> listener.onResponse(updated != null), listener::onFailure)
Expand Down Expand Up @@ -181,8 +173,6 @@ public void updateHistoryRecord(final StatusHistoryModel historyModelupdate, Act

UpdateRequest updateRequest = new UpdateRequest().index(JOB_HISTORY_INDEX_NAME)
.id(documentId)
.setIfSeqNo(historyModelupdate.getSeqNo())
.setIfPrimaryTerm(historyModelupdate.getPrimaryTerm())
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.doc(historyModelupdate.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS))
.fetchSource(true);
Expand All @@ -196,9 +186,7 @@ public void updateHistoryRecord(final StatusHistoryModel historyModelupdate, Act
historyModelupdate.getJobId(),
historyModelupdate.getStartTime(),
historyModelupdate.getEndTime(),
historyModelupdate.getStatus(),
response.getSeqNo(),
response.getPrimaryTerm()
historyModelupdate.getStatus()
)
),
exception -> {
Expand Down Expand Up @@ -231,7 +219,7 @@ public void findHistoryRecord(
XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getSourceAsString());
parser.nextToken();
listener.onResponse(StatusHistoryModel.parse(parser, response.getSeqNo(), response.getPrimaryTerm()));
listener.onResponse(StatusHistoryModel.parse(parser));
} catch (IOException e) {
logger.error("IOException occurred parsing history record", e);
listener.onResponse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,7 @@ public void testUpdateHistoryRecordDirectly() throws Exception {
historyService.findHistoryRecord(jobIndexName, jobId, startTime, ActionListener.wrap(historyModel -> {
assertNotNull("History record should exist", historyModel);
// Create updated model
StatusHistoryModel updatedModel = new StatusHistoryModel(
jobIndexName,
jobId,
startTime,
Instant.now(),
3,
historyModel.getSeqNo(),
historyModel.getPrimaryTerm()
);
StatusHistoryModel updatedModel = new StatusHistoryModel(jobIndexName, jobId, startTime, Instant.now(), 3);
// Update directly
historyService.updateHistoryRecord(updatedModel, ActionListener.wrap(updatedHistoryModel -> {
assertNotNull("Updated history model should not be null", updatedHistoryModel);
Expand Down
Loading