8
8
9
9
package org .opensearch .remotemigration ;
10
10
11
- import org .opensearch .action .admin .cluster .allocation .ClusterAllocationExplanation ;
12
11
import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsRequest ;
13
12
import org .opensearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
14
- import org .opensearch .action .support .ActiveShardCount ;
15
13
import org .opensearch .cluster .metadata .IndexMetadata ;
16
14
import org .opensearch .cluster .node .DiscoveryNode ;
17
15
import org .opensearch .cluster .node .DiscoveryNodes ;
18
16
import org .opensearch .cluster .routing .IndexShardRoutingTable ;
19
17
import org .opensearch .cluster .routing .ShardRouting ;
20
- import org .opensearch .cluster .routing .ShardRoutingState ;
21
- import org .opensearch .cluster .routing .allocation .AllocateUnassignedDecision ;
22
- import org .opensearch .cluster .routing .allocation .MoveDecision ;
23
- import org .opensearch .cluster .routing .allocation .NodeAllocationResult ;
24
- import org .opensearch .cluster .routing .allocation .decider .Decision ;
25
- import org .opensearch .common .Nullable ;
26
18
import org .opensearch .common .settings .Settings ;
27
19
import org .opensearch .core .rest .RestStatus ;
28
20
import org .opensearch .index .IndexSettings ;
29
21
import org .opensearch .indices .replication .common .ReplicationType ;
30
22
import org .opensearch .snapshots .SnapshotInfo ;
31
23
import org .opensearch .snapshots .SnapshotState ;
32
24
33
- import java .util .List ;
34
25
import java .util .Map ;
35
26
import java .util .Optional ;
36
27
@@ -56,7 +47,7 @@ protected void setClusterMode(String mode) {
56
47
}
57
48
58
49
// set the migration direction for cluster [remote_store, docrep, none]
59
- protected void setDirection (String direction ) {
50
+ public void setDirection (String direction ) {
60
51
updateSettingsRequest .persistentSettings (Settings .builder ().put (MIGRATION_DIRECTION_SETTING .getKey (), direction ));
61
52
assertAcked (internalCluster ().client ().admin ().cluster ().updateSettings (updateSettingsRequest ).actionGet ());
62
53
}
@@ -88,7 +79,7 @@ protected String allNodesExcept(String except) {
88
79
return exclude .toString ();
89
80
}
90
81
91
- // create a new test index with un-allocated primary and no replicas
82
+ // create a new test index
92
83
protected void prepareIndexWithoutReplica (Optional <String > name ) {
93
84
String indexName = name .orElse (TEST_INDEX );
94
85
internalCluster ().client ()
@@ -105,33 +96,6 @@ protected void prepareIndexWithoutReplica(Optional<String> name) {
105
96
.actionGet ();
106
97
}
107
98
108
- // create a new test index with allocated primary and 1 unallocated replica
109
- public void prepareIndexWithAllocatedPrimary (DiscoveryNode primaryShardNode , Optional <String > name ) {
110
- String indexName = name .orElse (TEST_INDEX );
111
- internalCluster ().client ()
112
- .admin ()
113
- .indices ()
114
- .prepareCreate (indexName )
115
- .setSettings (
116
- Settings .builder ()
117
- .put ("index.number_of_shards" , 1 )
118
- .put ("index.number_of_replicas" , 1 )
119
- .put ("index.routing.allocation.include._name" , primaryShardNode .getName ())
120
- .put ("index.routing.allocation.exclude._name" , allNodesExcept (primaryShardNode .getName ()))
121
- )
122
- .setWaitForActiveShards (ActiveShardCount .ONE )
123
- .execute ()
124
- .actionGet ();
125
-
126
- ensureYellowAndNoInitializingShards (TEST_INDEX );
127
-
128
- logger .info (" --> verify allocation of primary shard" );
129
- assertAllocation (true , primaryShardNode );
130
-
131
- logger .info (" --> verify non-allocation of replica shard" );
132
- assertNonAllocation (false );
133
- }
134
-
135
99
protected ShardRouting getShardRouting (boolean isPrimary ) {
136
100
IndexShardRoutingTable table = internalCluster ().client ()
137
101
.admin ()
@@ -146,108 +110,6 @@ protected ShardRouting getShardRouting(boolean isPrimary) {
146
110
return (isPrimary ? table .primaryShard () : table .replicaShards ().get (0 ));
147
111
}
148
112
149
- // obtain decision for allocation/relocation of a shard to a given node
150
- protected Decision getDecisionForTargetNode (
151
- DiscoveryNode targetNode ,
152
- boolean isPrimary ,
153
- boolean includeYesDecisions ,
154
- boolean isRelocation
155
- ) {
156
- ClusterAllocationExplanation explanation = internalCluster ().client ()
157
- .admin ()
158
- .cluster ()
159
- .prepareAllocationExplain ()
160
- .setIndex (TEST_INDEX )
161
- .setShard (0 )
162
- .setPrimary (isPrimary )
163
- .setIncludeYesDecisions (includeYesDecisions )
164
- .get ()
165
- .getExplanation ();
166
-
167
- Decision requiredDecision = null ;
168
- List <NodeAllocationResult > nodeAllocationResults ;
169
- if (isRelocation ) {
170
- MoveDecision moveDecision = explanation .getShardAllocationDecision ().getMoveDecision ();
171
- nodeAllocationResults = moveDecision .getNodeDecisions ();
172
- } else {
173
- AllocateUnassignedDecision allocateUnassignedDecision = explanation .getShardAllocationDecision ().getAllocateDecision ();
174
- nodeAllocationResults = allocateUnassignedDecision .getNodeDecisions ();
175
- }
176
-
177
- for (NodeAllocationResult nodeAllocationResult : nodeAllocationResults ) {
178
- if (nodeAllocationResult .getNode ().equals (targetNode )) {
179
- for (Decision decision : nodeAllocationResult .getCanAllocateDecision ().getDecisions ()) {
180
- if (decision .label ().equals (NAME )) {
181
- requiredDecision = decision ;
182
- break ;
183
- }
184
- }
185
- }
186
- }
187
-
188
- assertNotNull (requiredDecision );
189
- return requiredDecision ;
190
- }
191
-
192
- // get allocation and relocation decisions for all nodes
193
- protected void prepareDecisions () {
194
- internalCluster ().client ()
195
- .admin ()
196
- .indices ()
197
- .prepareUpdateSettings (TEST_INDEX )
198
- .setSettings (Settings .builder ().put ("index.routing.allocation.exclude._name" , allNodesExcept (null )))
199
- .execute ()
200
- .actionGet ();
201
- }
202
-
203
- protected void attemptAllocation (@ Nullable String targetNodeName ) {
204
- Settings .Builder settingsBuilder ;
205
- if (targetNodeName != null ) {
206
- settingsBuilder = Settings .builder ()
207
- .put ("index.routing.allocation.include._name" , targetNodeName )
208
- .put ("index.routing.allocation.exclude._name" , allNodesExcept (targetNodeName ));
209
- } else {
210
- String clusterManagerNodeName = internalCluster ().client ()
211
- .admin ()
212
- .cluster ()
213
- .prepareState ()
214
- .execute ()
215
- .actionGet ()
216
- .getState ()
217
- .getNodes ()
218
- .getClusterManagerNode ()
219
- .getName ();
220
- // to allocate freely among all nodes other than cluster-manager node
221
- settingsBuilder = Settings .builder ()
222
- .put ("index.routing.allocation.include._name" , allNodesExcept (clusterManagerNodeName ))
223
- .put ("index.routing.allocation.exclude._name" , clusterManagerNodeName );
224
- }
225
- internalCluster ().client ().admin ().indices ().prepareUpdateSettings (TEST_INDEX ).setSettings (settingsBuilder ).execute ().actionGet ();
226
- }
227
-
228
- // verify that shard does not exist at targetNode
229
- protected void assertNonAllocation (boolean isPrimary ) {
230
- if (isPrimary ) {
231
- ensureRed (TEST_INDEX );
232
- } else {
233
- ensureYellowAndNoInitializingShards (TEST_INDEX );
234
- }
235
- ShardRouting shardRouting = getShardRouting (isPrimary );
236
- assertFalse (shardRouting .active ());
237
- assertNull (shardRouting .currentNodeId ());
238
- assertEquals (ShardRoutingState .UNASSIGNED , shardRouting .state ());
239
- }
240
-
241
- // verify that shard exists at targetNode
242
- protected void assertAllocation (boolean isPrimary , @ Nullable DiscoveryNode targetNode ) {
243
- ShardRouting shardRouting = getShardRouting (isPrimary );
244
- assertTrue (shardRouting .active ());
245
- assertNotNull (shardRouting .currentNodeId ());
246
- if (targetNode != null ) {
247
- assertEquals (shardRouting .currentNodeId (), targetNode .getId ());
248
- }
249
- }
250
-
251
113
// create a snapshot
252
114
public static SnapshotInfo createSnapshot (String snapshotRepoName , String snapshotName , String ... indices ) {
253
115
SnapshotInfo snapshotInfo = internalCluster ().client ()
@@ -332,5 +194,4 @@ public static void assertRemoteStoreBackedIndex(String indexName) {
332
194
INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING .get (indexSettings )
333
195
);
334
196
}
335
-
336
197
}
0 commit comments