Skip to content

Commit 9f2fbab

Browse files
fix: remove required check on indices.stats.ShardStats.shards (#1177) (#1200)
* fix: remove required check on indices.stats.ShardStats.shards Signed-off-by: Liam Macpherson <[email protected]> Signed-off-by: Liam Macpherson <[email protected]> * address review comments re: imports and changelog Signed-off-by: Liam Macpherson <[email protected]> * add test and remove check in constructor Signed-off-by: Liam Macpherson <[email protected]> Signed-off-by: Liam Macpherson <[email protected]> * re-remove auto import organisation Signed-off-by: Liam Macpherson <[email protected]> Signed-off-by: Liam Macpherson <[email protected]> * chore: correct changelog link Signed-off-by: Liam Macpherson <[email protected]> * spotlessApply tidyup Signed-off-by: Liam Macpherson <[email protected]> Signed-off-by: Liam Macpherson <[email protected]> --------- Signed-off-by: Liam Macpherson <[email protected]> Signed-off-by: Liam Macpherson <[email protected]> (cherry picked from commit 8a37f3f) Co-authored-by: Liam Macpherson <[email protected]>
1 parent 4128648 commit 9f2fbab

File tree

3 files changed

+210
-8
lines changed

3 files changed

+210
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1717

1818
### Fixed
1919
- Fix queries not preserving boost and name when converted to builders ([#1181](https://github.com/opensearch-project/opensearch-java/pull/1181))
20+
- Remove required check on ShardStats.shards ([#1177](https://github.com/opensearch-project/opensearch-java/pull/1177))
2021

2122
### Security
2223

java-client/src/main/java/org/opensearch/client/opensearch/indices/stats/ShardStats.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public class ShardStats implements PlainJsonSerializable {
110110
@Nullable
111111
private final BulkStats bulk;
112112

113+
@Nullable
113114
private final ShardsTotalStats shards;
114115

115116
// ---------------------------------------------------------------------------------------------
@@ -138,8 +139,7 @@ private ShardStats(Builder builder) {
138139
this.translog = ApiTypeHelper.requireNonNull(builder.translog, this, "translog");
139140
this.warmer = ApiTypeHelper.requireNonNull(builder.warmer, this, "warmer");
140141
this.bulk = builder.bulk;
141-
this.shards = ApiTypeHelper.requireNonNull(builder.shards, this, "shards");
142-
142+
this.shards = builder.shards;
143143
}
144144

145145
public static ShardStats of(Function<Builder, ObjectBuilder<ShardStats>> fn) {
@@ -302,8 +302,9 @@ public final BulkStats bulk() {
302302
}
303303

304304
/**
305-
* Required - API name: {@code shards}
305+
* API name: {@code shards}
306306
*/
307+
@Nullable
307308
public final ShardsTotalStats shards() {
308309
return this.shards;
309310
}
@@ -387,9 +388,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
387388
this.bulk.serialize(generator, mapper);
388389

389390
}
390-
generator.writeKey("shards");
391-
this.shards.serialize(generator, mapper);
392-
391+
if (this.shards != null) {
392+
generator.writeKey("shards");
393+
this.shards.serialize(generator, mapper);
394+
}
393395
}
394396

395397
// ---------------------------------------------------------------------------------------------
@@ -444,6 +446,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<S
444446
@Nullable
445447
private BulkStats bulk;
446448

449+
@Nullable
447450
private ShardsTotalStats shards;
448451

449452
/**
@@ -777,15 +780,15 @@ public final Builder bulk(Function<BulkStats.Builder, ObjectBuilder<BulkStats>>
777780
}
778781

779782
/**
780-
* Required - API name: {@code shards}
783+
* API name: {@code shards}
781784
*/
782785
public final Builder shards(ShardsTotalStats value) {
783786
this.shards = value;
784787
return this;
785788
}
786789

787790
/**
788-
* Required - API name: {@code shards}
791+
* API name: {@code shards}
789792
*/
790793
public final Builder shards(Function<ShardsTotalStats.Builder, ObjectBuilder<ShardsTotalStats>> fn) {
791794
return this.shards(fn.apply(new ShardsTotalStats.Builder()).build());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/*
10+
* Licensed to Elasticsearch B.V. under one or more contributor
11+
* license agreements. See the NOTICE file distributed with
12+
* this work for additional information regarding copyright
13+
* ownership. Elasticsearch B.V. licenses this file to you under
14+
* the Apache License, Version 2.0 (the "License"); you may
15+
* not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing,
21+
* software distributed under the License is distributed on an
22+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23+
* KIND, either express or implied. See the License for the
24+
* specific language governing permissions and limitations
25+
* under the License.
26+
*/
27+
28+
/*
29+
* Modifications Copyright OpenSearch Contributors. See
30+
* GitHub history for details.
31+
*/
32+
33+
package org.opensearch.client.opensearch.model;
34+
35+
import static java.util.Collections.emptyList;
36+
37+
import java.util.HashMap;
38+
import org.junit.Assert;
39+
import org.junit.Test;
40+
import org.opensearch.client.opensearch._types.CompletionStats;
41+
import org.opensearch.client.opensearch._types.DocStats;
42+
import org.opensearch.client.opensearch._types.FielddataStats;
43+
import org.opensearch.client.opensearch._types.FlushStats;
44+
import org.opensearch.client.opensearch._types.GetStats;
45+
import org.opensearch.client.opensearch._types.IndexingStats;
46+
import org.opensearch.client.opensearch._types.MergesStats;
47+
import org.opensearch.client.opensearch._types.RecoveryStats;
48+
import org.opensearch.client.opensearch._types.RefreshStats;
49+
import org.opensearch.client.opensearch._types.RequestCacheStats;
50+
import org.opensearch.client.opensearch._types.SearchStats;
51+
import org.opensearch.client.opensearch._types.SegmentsStats;
52+
import org.opensearch.client.opensearch._types.StoreStats;
53+
import org.opensearch.client.opensearch._types.TranslogStats;
54+
import org.opensearch.client.opensearch._types.WarmerStats;
55+
import org.opensearch.client.opensearch.indices.stats.ShardCommit;
56+
import org.opensearch.client.opensearch.indices.stats.ShardPath;
57+
import org.opensearch.client.opensearch.indices.stats.ShardQueryCache;
58+
import org.opensearch.client.opensearch.indices.stats.ShardRetentionLeases;
59+
import org.opensearch.client.opensearch.indices.stats.ShardRouting;
60+
import org.opensearch.client.opensearch.indices.stats.ShardRoutingState;
61+
import org.opensearch.client.opensearch.indices.stats.ShardSequenceNumber;
62+
import org.opensearch.client.opensearch.indices.stats.ShardStats;
63+
import org.opensearch.client.util.MissingRequiredPropertyException;
64+
65+
public class ShardStatsTest extends Assert {
66+
67+
@Test
68+
public void testShardStatsBulkAndShardsPropertiesNotRequired() {
69+
70+
ShardStats.Builder builder = createShardsStatsBuilderWithRequiredFields();
71+
72+
try {
73+
builder.build();
74+
} catch (MissingRequiredPropertyException e) {
75+
fail(e.getClass().getSimpleName() + " was thrown: " + e.getMessage());
76+
}
77+
}
78+
79+
private ShardStats.Builder createShardsStatsBuilderWithRequiredFields() {
80+
ShardCommit commit = new ShardCommit.Builder().id("").generation(0).numDocs(0).userData(new HashMap<>()).build();
81+
CompletionStats completion = new CompletionStats.Builder().sizeInBytes(0).build();
82+
DocStats docs = new DocStats.Builder().count(0).deleted(0).build();
83+
FielddataStats fielddata = new FielddataStats.Builder().memorySizeInBytes(0).build();
84+
FlushStats flush = new FlushStats.Builder().periodic(0).total(0).totalTimeInMillis(0).build();
85+
GetStats get = new GetStats.Builder().current(0)
86+
.existsTimeInMillis(0)
87+
.existsTotal(0)
88+
.missingTimeInMillis(0)
89+
.missingTotal(0)
90+
.timeInMillis(0)
91+
.total(0)
92+
.build();
93+
IndexingStats indexing = new IndexingStats.Builder().indexCurrent(0)
94+
.deleteCurrent(0)
95+
.deleteTimeInMillis(0)
96+
.deleteTotal(0)
97+
.isThrottled(false)
98+
.noopUpdateTotal(0)
99+
.throttleTimeInMillis(0)
100+
.indexTimeInMillis(0)
101+
.indexTotal(0)
102+
.indexFailed(0)
103+
.types(new HashMap<>())
104+
.build();
105+
MergesStats merges = new MergesStats.Builder().current(0)
106+
.currentDocs(0)
107+
.currentSizeInBytes(0)
108+
.total(0)
109+
.totalAutoThrottleInBytes(0)
110+
.totalDocs(0)
111+
.totalSizeInBytes(0)
112+
.totalStoppedTimeInMillis(0)
113+
.totalThrottledTimeInMillis(0)
114+
.totalTimeInMillis(0)
115+
.build();
116+
ShardPath shardPath = new ShardPath.Builder().dataPath("").isCustomDataPath(false).statePath("").build();
117+
ShardQueryCache queryCache = new ShardQueryCache.Builder().cacheCount(0)
118+
.cacheSize(0)
119+
.evictions(0)
120+
.hitCount(0)
121+
.memorySizeInBytes(0)
122+
.missCount(0)
123+
.totalCount(0)
124+
.build();
125+
RecoveryStats recovery = new RecoveryStats.Builder().currentAsSource(0).currentAsTarget(0).throttleTimeInMillis(0).build();
126+
RefreshStats refresh = new RefreshStats.Builder().externalTotal(0)
127+
.externalTotalTimeInMillis(0)
128+
.listeners(0)
129+
.total(0)
130+
.totalTimeInMillis(0)
131+
.build();
132+
RequestCacheStats requestCache = new RequestCacheStats.Builder().evictions(0).hitCount(0).memorySizeInBytes(0).missCount(0).build();
133+
ShardRetentionLeases retentionLeases = new ShardRetentionLeases.Builder().primaryTerm(0).version(0).leases(emptyList()).build();
134+
ShardRouting routing = new ShardRouting.Builder().node("").primary(false).state(ShardRoutingState.Unassigned).build();
135+
SearchStats search = new SearchStats.Builder().fetchCurrent(0)
136+
.fetchTimeInMillis(0)
137+
.fetchTotal(0)
138+
.queryCurrent(0)
139+
.queryTimeInMillis(0)
140+
.queryTotal(0)
141+
.scrollCurrent(0)
142+
.scrollTimeInMillis(0)
143+
.scrollTotal(0)
144+
.suggestCurrent(0)
145+
.suggestTimeInMillis(0)
146+
.suggestTotal(0)
147+
.build();
148+
SegmentsStats segments = new SegmentsStats.Builder().count(0)
149+
.docValuesMemoryInBytes(0)
150+
.fileSizes(new HashMap<>())
151+
.fixedBitSetMemoryInBytes(0)
152+
.indexWriterMemoryInBytes(0)
153+
.maxUnsafeAutoIdTimestamp(0)
154+
.memoryInBytes(0)
155+
.normsMemoryInBytes(0)
156+
.pointsMemoryInBytes(0)
157+
.storedFieldsMemoryInBytes(0)
158+
.termsMemoryInBytes(0)
159+
.termVectorsMemoryInBytes(0)
160+
.versionMapMemoryInBytes(0)
161+
.build();
162+
ShardSequenceNumber seqNo = new ShardSequenceNumber.Builder().globalCheckpoint(0).localCheckpoint(0).maxSeqNo(0).build();
163+
StoreStats store = new StoreStats.Builder().sizeInBytes(0).reservedInBytes(0).build();
164+
TranslogStats translog = new TranslogStats.Builder().earliestLastModifiedAge(0)
165+
.operations(0)
166+
.sizeInBytes(0)
167+
.uncommittedOperations(0)
168+
.uncommittedSizeInBytes(0)
169+
.build();
170+
WarmerStats warmer = new WarmerStats.Builder().current(0).total(0).totalTimeInMillis(0).build();
171+
172+
ShardStats.Builder builder = new ShardStats.Builder();
173+
174+
builder.commit(commit)
175+
.completion(completion)
176+
.docs(docs)
177+
.fielddata(fielddata)
178+
.flush(flush)
179+
.get(get)
180+
.indexing(indexing)
181+
.merges(merges)
182+
.shardPath(shardPath)
183+
.queryCache(queryCache)
184+
.recovery(recovery)
185+
.refresh(refresh)
186+
.requestCache(requestCache)
187+
.retentionLeases(retentionLeases)
188+
.routing(routing)
189+
.search(search)
190+
.segments(segments)
191+
.seqNo(seqNo)
192+
.store(store)
193+
.translog(translog)
194+
.warmer(warmer);
195+
196+
return builder;
197+
}
198+
}

0 commit comments

Comments
 (0)