forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51991e0
commit 44ee92f
Showing
13 changed files
with
396 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
server/src/main/java/org/opensearch/action/search/UpdatePitAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.search; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class UpdatePitAction extends ActionType<UpdatePitResponse> { | ||
public static final UpdatePitAction INSTANCE = new UpdatePitAction(); | ||
public static final String NAME = "indices:data/read/point_in_time/update"; | ||
|
||
private UpdatePitAction(){ | ||
super(NAME, UpdatePitResponse::new); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
server/src/main/java/org/opensearch/action/search/UpdatePitRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.search; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.common.xcontent.ToXContent; | ||
import org.opensearch.common.xcontent.ToXContentObject; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
import org.opensearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.opensearch.action.ValidateActions.addValidationError; | ||
|
||
public class UpdatePitRequest extends ActionRequest implements ToXContentObject { | ||
// TODO: update the pit reqyest to handle not just array | ||
private final List<UpdatePitRequestInfo> updatePitRequests; | ||
|
||
public UpdatePitRequest(StreamInput in) throws IOException { | ||
super(in); | ||
int size = in.readVInt(); | ||
updatePitRequests = new ArrayList<>(); | ||
for(int i=0;i<size;i++){ | ||
updatePitRequests.add(new UpdatePitRequestInfo(in)); | ||
} | ||
} | ||
|
||
public List<UpdatePitRequestInfo> getUpdatePitRequests() { | ||
return updatePitRequests; | ||
} | ||
|
||
public UpdatePitRequest(UpdatePitRequestInfo... updatePitRequests){ | ||
this.updatePitRequests = (Arrays.asList(updatePitRequests)); | ||
} | ||
|
||
public UpdatePitRequest(List<UpdatePitRequestInfo> updatePitRequests){ | ||
this.updatePitRequests = updatePitRequests; | ||
} | ||
|
||
public UpdatePitRequest() {} | ||
|
||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (keepAlive == null) { | ||
validationException = addValidationError("keep alive not specified", validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.field("keep_alive", keepAlive); | ||
builder.field("pit_id", pit_id); | ||
return builder; | ||
} | ||
|
||
public void fromXContent(XContentParser parser) throws IOException { | ||
if(parser.nextToken() != XContentParser.Token.START_OBJECT){ | ||
throw new IllegalArgumentException("Malformed content, must start with an object"); | ||
} else { | ||
XContentParser.Token token; | ||
String currentFieldName = null; | ||
while((token = parser.nextToken()) != XContentParser.Token.END_OBJECT){ | ||
if (token == XContentParser.Token.FIELD_NAME){ | ||
currentFieldName = parser.currentName(); | ||
} else if("keep_alive".equals(currentFieldName)){ | ||
if(token.isValue() == false){ | ||
throw new IllegalArgumentException("keep_alive should only contain a time value"); | ||
} | ||
keepAlive = TimeValue.parseTimeValue(parser.text(),"keep_alive"); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
server/src/main/java/org/opensearch/action/search/UpdatePitRequestInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.search; | ||
|
||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.unit.TimeValue; | ||
|
||
import java.io.IOException; | ||
|
||
public class UpdatePitRequestInfo { | ||
private final String pitId; | ||
private final TimeValue keepAlive; | ||
|
||
public UpdatePitRequestInfo(String pitId, TimeValue keepAlive){ | ||
this.pitId = pitId; | ||
this.keepAlive = keepAlive; | ||
} | ||
|
||
public UpdatePitRequestInfo(StreamInput in) throws IOException { | ||
pitId = in.readString(); | ||
keepAlive = in.readTimeValue(); | ||
} | ||
|
||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(pitId); | ||
out.writeTimeValue(keepAlive); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
server/src/main/java/org/opensearch/action/search/UpdatePitResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.search; | ||
|
||
import org.opensearch.action.ActionResponse; | ||
import org.opensearch.common.ParseField; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.xcontent.*; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.opensearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.opensearch.rest.RestStatus.NOT_FOUND; | ||
import static org.opensearch.rest.RestStatus.OK; | ||
|
||
public class UpdatePitResponse extends ActionResponse implements StatusToXContentObject { | ||
private final List<UpdatePitResponseInfo> updatePitResults; | ||
|
||
public UpdatePitResponse(List<UpdatePitResponseInfo> updatePitResults){ | ||
this.updatePitResults = updatePitResults; | ||
} | ||
public UpdatePitResponse(StreamInput in) throws IOException{ | ||
super(in); | ||
int size = in.readVInt(); | ||
updatePitResults = new ArrayList<>(); | ||
for (int i=0; i < size; i++) { | ||
updatePitResults.add(new UpdatePitResponseInfo(in)); | ||
} | ||
} | ||
|
||
public List<UpdatePitResponseInfo> getUpdatePitResults() { | ||
return updatePitResults; | ||
} | ||
|
||
@Override | ||
public RestStatus status() { | ||
if (updatePitResults.isEmpty()) return NOT_FOUND; | ||
return OK; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVInt(updatePitResults.size()); | ||
for (UpdatePitResponseInfo updatePitResult : updatePitResults) { | ||
updatePitResult.writeTo(out); | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startArray("pits"); | ||
for (UpdatePitResponseInfo response: updatePitResults) { | ||
response.toXContent(builder,params); | ||
} | ||
builder.endArray(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
private static final ConstructingObjectParser<UpdatePitResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"update_pit_response", | ||
true, | ||
(Object[] parsedObjects) -> { | ||
@SuppressWarnings("unchecked") | ||
List<UpdatePitResponseInfo> updatePitResponseInfoList = (List<UpdatePitResponseInfo>) parsedObjects[0]; | ||
return new UpdatePitResponse(updatePitResponseInfoList); | ||
} | ||
); | ||
|
||
static { | ||
PARSER.declareObjectArray(constructorArg(), UpdatePitResponseInfo.PARSER, new ParseField("pits")); | ||
} | ||
|
||
public static UpdatePitResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
} |
Oops, something went wrong.