Skip to content

Commit

Permalink
update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpit-Bandejiya committed Nov 26, 2022
1 parent 51991e0 commit 44ee92f
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/gradle-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ jobs:
### Gradle Check (Jenkins) Run Completed with:
* **RESULT:** ${{ env.result }} :x:
* **FAILURES:**
```
${{ env.test_failures }}
```
* **URL:** ${{ env.workflow_url }}
* **CommitID:** ${{ env.pr_from_sha }}
Please examine the workflow log, locate, and copy-paste the failure below, then iterate to green.
Expand Down
6 changes: 5 additions & 1 deletion .idea/runConfigurations/Debug_OpenSearch.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@
import org.opensearch.action.get.GetRequest;
import org.opensearch.action.get.MultiGetRequest;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.CreatePitRequest;
import org.opensearch.action.search.DeletePitRequest;
import org.opensearch.action.search.MultiSearchRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchScrollRequest;
import org.opensearch.action.search.*;
import org.opensearch.action.support.ActiveShardCount;
import org.opensearch.action.support.IndicesOptions;
import org.opensearch.action.support.WriteRequest;
Expand Down Expand Up @@ -502,6 +497,11 @@ static Request getAllPits() {
return new Request(HttpGet.METHOD_NAME, "/_search/point_in_time/_all");
}

static Request updatePit(UpdatePitRequest updatePitRequest) throws IOException {
Request request = new Request(HttpDelete.METHOD_NAME, "/_search/point_in_time");
request.setEntity(createEntity(updatePitRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
static Request multiSearch(MultiSearchRequest multiSearchRequest) throws IOException {
Request request = new Request(HttpPost.METHOD_NAME, "/_msearch");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,7 @@
import org.opensearch.action.get.MultiGetResponse;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.ClearScrollResponse;
import org.opensearch.action.search.CreatePitRequest;
import org.opensearch.action.search.CreatePitResponse;
import org.opensearch.action.search.DeletePitRequest;
import org.opensearch.action.search.DeletePitResponse;
import org.opensearch.action.search.GetAllPitNodesResponse;
import org.opensearch.action.search.MultiSearchRequest;
import org.opensearch.action.search.MultiSearchResponse;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.action.search.SearchScrollRequest;
import org.opensearch.action.search.*;
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.action.update.UpdateRequest;
import org.opensearch.action.update.UpdateResponse;
Expand Down Expand Up @@ -1403,6 +1392,16 @@ public final Cancellable getAllPitsAsync(RequestOptions options, ActionListener<
);
}

public final UpdatePitResponse updatePit(UpdatePitRequest updatePitRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(
updatePitRequest,
RequestConverters::updatePit,
options,
UpdatePitResponse::fromXContent,
emptySet()
);
}

/**
* Clears one or more scroll ids using the Clear Scroll API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Tests point in time API with rest high level client
*/
public class PitIT extends OpenSearchRestHighLevelClientTestCase {

//--this is is PITIT
@Before
public void indexDocuments() throws IOException {
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/_doc/1");
Expand Down
18 changes: 3 additions & 15 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,7 @@
import org.opensearch.action.ingest.SimulatePipelineTransportAction;
import org.opensearch.action.main.MainAction;
import org.opensearch.action.main.TransportMainAction;
import org.opensearch.action.search.ClearScrollAction;
import org.opensearch.action.search.CreatePitAction;
import org.opensearch.action.search.DeletePitAction;
import org.opensearch.action.search.MultiSearchAction;
import org.opensearch.action.search.GetAllPitsAction;
import org.opensearch.action.search.SearchAction;
import org.opensearch.action.search.SearchScrollAction;
import org.opensearch.action.search.TransportClearScrollAction;
import org.opensearch.action.search.TransportCreatePitAction;
import org.opensearch.action.search.TransportDeletePitAction;
import org.opensearch.action.search.TransportGetAllPitsAction;
import org.opensearch.action.search.TransportMultiSearchAction;
import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.search.TransportSearchScrollAction;
import org.opensearch.action.search.*;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.AutoCreateIndex;
import org.opensearch.action.support.DestructiveOperations;
Expand Down Expand Up @@ -699,7 +686,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(DeletePitAction.INSTANCE, TransportDeletePitAction.class);
actions.register(PitSegmentsAction.INSTANCE, TransportPitSegmentsAction.class);
actions.register(GetAllPitsAction.INSTANCE, TransportGetAllPitsAction.class);

// TODO: register the api here
// Remote Store
actions.register(RestoreRemoteStoreAction.INSTANCE, TransportRestoreRemoteStoreAction.class);

Expand Down Expand Up @@ -890,6 +877,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestGetAllPitsAction(nodesInCluster));
registerHandler.accept(new RestPitSegmentsAction(nodesInCluster));
registerHandler.accept(new RestDeleteDecommissionStateAction());
// TODO: add update api here

for (ActionPlugin plugin : actionPlugins) {
for (RestHandler handler : plugin.getRestHandlers(
Expand Down
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);
}
}
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");
}

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

0 comments on commit 44ee92f

Please sign in to comment.