-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Showing
22 changed files
with
1,152 additions
and
18 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
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
72 changes: 72 additions & 0 deletions
72
src/main/java/org/elasticsearch/action/ParsedDocWriteResponse.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,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
package org.elasticsearch.action; | ||
|
||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* A base class for the response of a write operation that involves a single doc | ||
*/ | ||
public abstract class ParsedDocWriteResponse { | ||
|
||
/** | ||
* Parse the output of the {@link #innerToXContent(XContentBuilder, Params)} method. | ||
* | ||
* This method is intended to be called by subclasses and must be called multiple times to parse all the information concerning | ||
* {@link DocWriteResponse} objects. It always parses the current token, updates the given parsing context accordingly | ||
* if needed and then immediately returns. | ||
*/ | ||
public static void parseInnerToXContent(XContentParser parser, DocWriteResponse.Builder context) throws IOException { | ||
XContentParser.Token token = parser.currentToken(); | ||
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); | ||
|
||
String currentFieldName = parser.currentName(); | ||
token = parser.nextToken(); | ||
|
||
if (token.isValue()) { | ||
if (DocWriteResponse._INDEX.equals(currentFieldName)) { | ||
// index uuid and shard id are unknown and can't be parsed back for now. | ||
context.setShardId(new ShardId(new Index(parser.text(), IndexMetadata.INDEX_UUID_NA_VALUE), -1)); | ||
} else if (DocWriteResponse._ID.equals(currentFieldName)) { | ||
context.setId(parser.text()); | ||
} else if (DocWriteResponse._VERSION.equals(currentFieldName)) { | ||
context.setVersion(parser.longValue()); | ||
} else if (DocWriteResponse.RESULT.equals(currentFieldName)) { | ||
String result = parser.text(); | ||
for (DocWriteResponse.Result r : DocWriteResponse.Result.values()) { | ||
if (r.getLowercase().equals(result)) { | ||
context.setResult(r); | ||
break; | ||
} | ||
} | ||
} else if (DocWriteResponse.FORCED_REFRESH.equals(currentFieldName)) { | ||
context.setForcedRefresh(parser.booleanValue()); | ||
} else if (DocWriteResponse._SEQ_NO.equals(currentFieldName)) { | ||
context.setSeqNo(parser.longValue()); | ||
} else if (DocWriteResponse._PRIMARY_TERM.equals(currentFieldName)) { | ||
context.setPrimaryTerm(parser.longValue()); | ||
} | ||
} else if (token == XContentParser.Token.START_OBJECT) { | ||
if (DocWriteResponse._SHARDS.equals(currentFieldName)) { | ||
context.setShardInfo(DocWriteResponse.ShardInfo.fromXContent(parser)); | ||
} else { | ||
parser.skipChildren(); // skip potential inner objects for forward compatibility | ||
} | ||
} else if (token == XContentParser.Token.START_ARRAY) { | ||
parser.skipChildren(); // skip potential inner arrays for forward compatibility | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../org/elasticsearch/action/admin/cluster/settings/ParsedClusterUpdateSettingsResponse.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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.settings; | ||
|
||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
/** | ||
* A response for a cluster update settings action. | ||
*/ | ||
public class ParsedClusterUpdateSettingsResponse { | ||
|
||
private static final ConstructingObjectParser<ClusterUpdateSettingsResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"cluster_update_settings_response", | ||
true, | ||
args -> { | ||
return new ClusterUpdateSettingsResponse((boolean) args[0], (Settings) args[1], (Settings) args[2]); | ||
} | ||
); | ||
|
||
static { | ||
AcknowledgedResponse.declareAcknowledgedField(PARSER); | ||
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), ClusterUpdateSettingsResponse.TRANSIENT); | ||
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), ClusterUpdateSettingsResponse.PERSISTENT); | ||
} | ||
|
||
public static ClusterUpdateSettingsResponse fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/elasticsearch/action/delete/ParsedDeleteResponse.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,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.delete; | ||
|
||
import org.elasticsearch.action.ParsedDocWriteResponse; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* The response of the delete action. | ||
* | ||
* @see org.elasticsearch.action.delete.DeleteRequest | ||
* @see org.elasticsearch.client.internal.Client#delete(DeleteRequest) | ||
*/ | ||
public class ParsedDeleteResponse { | ||
|
||
public static DeleteResponse fromXContent(XContentParser parser) throws IOException { | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
|
||
DeleteResponse.Builder context = new DeleteResponse.Builder(); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
parseXContentFields(parser, context); | ||
} | ||
return context.build(); | ||
} | ||
|
||
/** | ||
* Parse the current token and update the parsing context appropriately. | ||
*/ | ||
public static void parseXContentFields(XContentParser parser, DeleteResponse.Builder context) throws IOException { | ||
ParsedDocWriteResponse.parseInnerToXContent(parser, context); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/elasticsearch/action/index/ParsedIndexResponse.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,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.index; | ||
|
||
import org.elasticsearch.action.ParsedDocWriteResponse; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* A response of an index operation, | ||
* | ||
* @see org.elasticsearch.action.index.IndexRequest | ||
* @see org.elasticsearch.client.internal.Client#index(IndexRequest) | ||
*/ | ||
public class ParsedIndexResponse { | ||
|
||
public static IndexResponse fromXContent(XContentParser parser) throws IOException { | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
|
||
IndexResponse.Builder context = new IndexResponse.Builder(); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
parseXContentFields(parser, context); | ||
} | ||
return context.build(); | ||
} | ||
|
||
/** | ||
* Parse the current token and update the parsing context appropriately. | ||
*/ | ||
public static void parseXContentFields(XContentParser parser, IndexResponse.Builder context) throws IOException { | ||
ParsedDocWriteResponse.parseInnerToXContent(parser, context); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
src/main/java/org/elasticsearch/action/update/ParsedUpdateResponse.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,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.update; | ||
|
||
import org.elasticsearch.action.ParsedDocWriteResponse; | ||
import org.elasticsearch.index.get.GetResult; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
public class ParsedUpdateResponse { | ||
|
||
public static UpdateResponse fromXContent(XContentParser parser) throws IOException { | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
|
||
UpdateResponse.Builder context = new UpdateResponse.Builder(); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
parseXContentFields(parser, context); | ||
} | ||
return context.build(); | ||
} | ||
|
||
/** | ||
* Parse the current token and update the parsing context appropriately. | ||
*/ | ||
public static void parseXContentFields(XContentParser parser, UpdateResponse.Builder context) throws IOException { | ||
XContentParser.Token token = parser.currentToken(); | ||
String currentFieldName = parser.currentName(); | ||
|
||
if (UpdateResponse.GET.equals(currentFieldName)) { | ||
if (token == XContentParser.Token.START_OBJECT) { | ||
context.setGetResult(GetResult.fromXContentEmbedded(parser)); | ||
} | ||
} else { | ||
ParsedDocWriteResponse.parseInnerToXContent(parser, context); | ||
} | ||
} | ||
} |
Oops, something went wrong.