Java Code Examples for org.elasticsearch.cluster.metadata.IndexMetaData#INDEX_UUID_NA_VALUE
The following examples show how to use
org.elasticsearch.cluster.metadata.IndexMetaData#INDEX_UUID_NA_VALUE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShardStateMetaData.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ShardStateMetaData fromXContent(XContentParser parser) throws IOException { XContentParser.Token token = parser.nextToken(); if (token == null) { return null; } long version = -1; Boolean primary = null; String currentFieldName = null; String indexUUID = IndexMetaData.INDEX_UUID_NA_VALUE; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (VERSION_KEY.equals(currentFieldName)) { version = parser.longValue(); } else if (PRIMARY_KEY.equals(currentFieldName)) { primary = parser.booleanValue(); } else if (INDEX_UUID_KEY.equals(currentFieldName)) { indexUUID = parser.text(); } else { throw new CorruptStateException("unexpected field in shard state [" + currentFieldName + "]"); } } else { throw new CorruptStateException("unexpected token in shard state [" + token.name() + "]"); } } if (primary == null) { throw new CorruptStateException("missing value for [primary] in shard state"); } if (version == -1) { throw new CorruptStateException("missing value for [version] in shard state"); } return new ShardStateMetaData(version, primary, indexUUID); }
Example 2
Source File: ShardId.java From crate with Apache License 2.0 | 5 votes |
/** * Parse the string representation of this shardId back to an object. * We lose index uuid information here, but since we use toString in * rest responses, this is the best we can do to reconstruct the object * on the client side. */ public static ShardId fromString(String shardIdString) { int splitPosition = shardIdString.indexOf("]["); if (splitPosition <= 0 || shardIdString.charAt(0) != '[' || shardIdString.charAt(shardIdString.length() - 1) != ']') { throw new IllegalArgumentException("Unexpected shardId string format, expected [indexName][shardId] but got " + shardIdString); } String indexName = shardIdString.substring(1, splitPosition); int shardId = Integer.parseInt(shardIdString.substring(splitPosition + 2, shardIdString.length() - 1)); return new ShardId(new Index(indexName, IndexMetaData.INDEX_UUID_NA_VALUE), shardId); }
Example 3
Source File: ShardStateMetaData.java From crate with Apache License 2.0 | 5 votes |
@Override public ShardStateMetaData fromXContent(XContentParser parser) throws IOException { XContentParser.Token token = parser.nextToken(); if (token == null) { return null; } Boolean primary = null; String currentFieldName = null; String indexUUID = IndexMetaData.INDEX_UUID_NA_VALUE; AllocationId allocationId = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (PRIMARY_KEY.equals(currentFieldName)) { primary = parser.booleanValue(); } else if (INDEX_UUID_KEY.equals(currentFieldName)) { indexUUID = parser.text(); } else if (VERSION_KEY.equals(currentFieldName)) { // ES versions before 6.0 wrote this for legacy reasons, just ignore for now and remove in 7.0 } else { throw new CorruptStateException("unexpected field in shard state [" + currentFieldName + "]"); } } else if (token == XContentParser.Token.START_OBJECT) { if (ALLOCATION_ID_KEY.equals(currentFieldName)) { allocationId = AllocationId.fromXContent(parser); } else { throw new CorruptStateException("unexpected object in shard state [" + currentFieldName + "]"); } } else { throw new CorruptStateException("unexpected token in shard state [" + token.name() + "]"); } } if (primary == null) { throw new CorruptStateException("missing value for [primary] in shard state"); } return new ShardStateMetaData(primary, indexUUID, allocationId); }
Example 4
Source File: SnapshotShardFailure.java From crate with Apache License 2.0 | 5 votes |
private static SnapshotShardFailure constructSnapshotShardFailure(Object[] args) { String index = (String) args[0]; String indexUuid = (String) args[1]; final String nodeId = (String) args[2]; String reason = (String) args[3]; Integer intShardId = (Integer) args[4]; final String status = (String) args[5]; if (index == null) { throw new ElasticsearchParseException("index name was not set"); } if (intShardId == null) { throw new ElasticsearchParseException("index shard was not set"); } ShardId shardId = new ShardId(index, indexUuid != null ? indexUuid : IndexMetaData.INDEX_UUID_NA_VALUE, intShardId); // Workaround for https://github.com/elastic/elasticsearch/issues/25878 // Some old snapshot might still have null in shard failure reasons String nonNullReason; if (reason != null) { nonNullReason = reason; } else { nonNullReason = ""; } RestStatus restStatus; if (status != null) { restStatus = RestStatus.valueOf(status); } else { restStatus = RestStatus.INTERNAL_SERVER_ERROR; } return new SnapshotShardFailure(nodeId, shardId, nonNullReason, restStatus); }
Example 5
Source File: ReplicationResponse.java From crate with Apache License 2.0 | 5 votes |
public static Failure fromXContent(XContentParser parser) throws IOException { XContentParser.Token token = parser.currentToken(); ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation); String shardIndex = null, nodeId = null; int shardId = -1; boolean primary = false; RestStatus status = null; ElasticsearchException reason = null; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (INDEX.equals(currentFieldName)) { shardIndex = parser.text(); } else if (SHARD.equals(currentFieldName)) { shardId = parser.intValue(); } else if (NODE.equals(currentFieldName)) { nodeId = parser.text(); } else if (STATUS.equals(currentFieldName)) { status = RestStatus.valueOf(parser.text()); } else if (PRIMARY.equals(currentFieldName)) { primary = parser.booleanValue(); } } else if (token == XContentParser.Token.START_OBJECT) { if (REASON.equals(currentFieldName)) { reason = ElasticsearchException.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 } } return new Failure(new ShardId(shardIndex, IndexMetaData.INDEX_UUID_NA_VALUE, shardId), nodeId, reason, status, primary); }