Skip to content

Commit

Permalink
ActionResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Nov 7, 2024
1 parent 6f031cf commit c5ce0c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,41 @@
*/
package org.opensearch.jobscheduler.transport.schedule;

import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.core.action.ActionResponse;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

/**
* Response class used to facilitate serialization/deserialization of the GetLock response
*/
public class GetScheduleResponse extends AcknowledgedResponse implements ToXContentObject {
public class GetScheduleResponse extends ActionResponse implements ToXContentObject {

public GetScheduleResponse(boolean status) {
super(status);
private Map<String, String> jobTypeToIndexMap;

public GetScheduleResponse(Map<String, String> jobTypeToIndexMap) {
this.jobTypeToIndexMap = jobTypeToIndexMap;
}

public GetScheduleResponse(StreamInput in) throws IOException {
super(in);
jobTypeToIndexMap = in.readMap(StreamInput::readString, StreamInput::readString);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field("job_type_to_index_map", jobTypeToIndexMap);
builder.endObject();
return builder;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(jobTypeToIndexMap, StreamOutput::writeString, StreamOutput::writeString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public TransportGetScheduleAction(
protected void doExecute(Task task, GetScheduleRequest request, ActionListener<GetScheduleResponse> actionListener) {
System.out.println("ScheduledJobInfo: " + scheduledJobInfo);
System.out.println("jobTypeToIndex: " + scheduledJobInfo.getJobTypeToIndexMap());
actionListener.onResponse(new GetScheduleResponse(true));
actionListener.onResponse(new GetScheduleResponse(scheduledJobInfo.getJobTypeToIndexMap()));
}
}

0 comments on commit c5ce0c8

Please sign in to comment.