8
8
9
9
package org .opensearch .remotestore ;
10
10
11
+ import org .opensearch .action .admin .cluster .configuration .AddVotingConfigExclusionsAction ;
12
+ import org .opensearch .action .admin .cluster .configuration .AddVotingConfigExclusionsRequest ;
11
13
import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsRequest ;
14
+ import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsResponse ;
15
+ import org .opensearch .action .admin .indices .alias .Alias ;
12
16
import org .opensearch .action .admin .indices .datastream .DataStreamRolloverIT ;
13
17
import org .opensearch .action .admin .indices .settings .put .UpdateSettingsRequest ;
18
+ import org .opensearch .action .admin .indices .template .put .PutComponentTemplateAction ;
19
+ import org .opensearch .action .admin .indices .template .put .PutComposableIndexTemplateAction ;
14
20
import org .opensearch .action .admin .indices .template .put .PutIndexTemplateRequest ;
21
+ import org .opensearch .action .support .master .AcknowledgedResponse ;
15
22
import org .opensearch .cluster .ClusterState ;
16
23
import org .opensearch .cluster .block .ClusterBlockException ;
24
+ import org .opensearch .cluster .metadata .ComponentTemplate ;
25
+ import org .opensearch .cluster .metadata .ComponentTemplateMetadata ;
26
+ import org .opensearch .cluster .metadata .ComposableIndexTemplate ;
27
+ import org .opensearch .cluster .metadata .ComposableIndexTemplateMetadata ;
17
28
import org .opensearch .cluster .metadata .IndexMetadata ;
18
29
import org .opensearch .cluster .metadata .IndexTemplateMetadata ;
19
30
import org .opensearch .cluster .metadata .Metadata ;
20
31
import org .opensearch .cluster .metadata .RepositoriesMetadata ;
32
+ import org .opensearch .cluster .metadata .Template ;
33
+ import org .opensearch .common .action .ActionFuture ;
34
+ import org .opensearch .common .settings .Setting ;
21
35
import org .opensearch .common .settings .Settings ;
22
36
import org .opensearch .gateway .remote .ClusterMetadataManifest ;
23
37
import org .opensearch .gateway .remote .ClusterMetadataManifest .UploadedIndexMetadata ;
29
43
import java .nio .file .Files ;
30
44
import java .nio .file .Path ;
31
45
import java .util .Arrays ;
46
+ import java .util .Collections ;
32
47
import java .util .List ;
33
48
import java .util .Locale ;
34
49
import java .util .Map ;
35
50
import java .util .Objects ;
36
51
import java .util .concurrent .ExecutionException ;
52
+ import java .util .stream .Collectors ;
37
53
38
54
import static org .opensearch .cluster .coordination .ClusterBootstrapService .INITIAL_CLUSTER_MANAGER_NODES_SETTING ;
39
55
import static org .opensearch .cluster .metadata .IndexMetadata .INDEX_READ_ONLY_SETTING ;
46
62
47
63
@ OpenSearchIntegTestCase .ClusterScope (scope = OpenSearchIntegTestCase .Scope .TEST , numDataNodes = 0 )
48
64
public class RemoteStoreClusterStateRestoreIT extends BaseRemoteStoreRestoreIT {
65
+ static final String TEMPLATE_NAME = "remote-store-test-template" ;
66
+ static final String COMPONENT_TEMPLATE_NAME = "remote-component-template1" ;
67
+ static final String COMPOSABLE_TEMPLATE_NAME = "remote-composable-template1" ;
68
+ static final Setting <String > MOCK_SETTING = Setting .simpleString ("mock-setting" );
69
+ static final String [] EXCLUDED_NODES = { "ex-1" , "ex-2" };
49
70
50
71
@ Override
51
72
protected Settings nodeSettings (int nodeOrdinal ) {
@@ -87,6 +108,45 @@ public void testFullClusterRestore() throws Exception {
87
108
Map <String , Long > indexStats = initialTestSetup (shardCount , replicaCount , dataNodeCount , 1 );
88
109
String prevClusterUUID = clusterService ().state ().metadata ().clusterUUID ();
89
110
long prevClusterStateVersion = clusterService ().state ().version ();
111
+ // Step - 1.1 Add some cluster state elements
112
+ ActionFuture <AcknowledgedResponse > response = client ().admin ()
113
+ .indices ()
114
+ .preparePutTemplate (TEMPLATE_NAME )
115
+ .addAlias (new Alias (INDEX_NAME ))
116
+ .setPatterns (Arrays .stream (INDEX_NAMES_WILDCARD .split ("," )).collect (Collectors .toList ()))
117
+ .execute ();
118
+ assertTrue (response .get ().isAcknowledged ());
119
+ ActionFuture <ClusterUpdateSettingsResponse > clusterUpdateSettingsResponse = client ().admin ()
120
+ .cluster ()
121
+ .prepareUpdateSettings ()
122
+ .setPersistentSettings (Settings .builder ().put (SETTING_READ_ONLY_SETTING .getKey (), false ).build ())
123
+ .execute ();
124
+ assertTrue (clusterUpdateSettingsResponse .get ().isAcknowledged ());
125
+ // update coordination metadata
126
+ client ().execute (AddVotingConfigExclusionsAction .INSTANCE , new AddVotingConfigExclusionsRequest (EXCLUDED_NODES ));
127
+ // Add a custom metadata as component index template
128
+ ActionFuture <AcknowledgedResponse > componentTemplateResponse = client ().execute (
129
+ PutComponentTemplateAction .INSTANCE ,
130
+ new PutComponentTemplateAction .Request (COMPONENT_TEMPLATE_NAME ).componentTemplate (
131
+ new ComponentTemplate (new Template (Settings .EMPTY , null , Collections .emptyMap ()), 1L , Collections .emptyMap ())
132
+ )
133
+ );
134
+ assertTrue (componentTemplateResponse .get ().isAcknowledged ());
135
+ ActionFuture <AcknowledgedResponse > composableTemplateResponse = client ().execute (
136
+ PutComposableIndexTemplateAction .INSTANCE ,
137
+ new PutComposableIndexTemplateAction .Request (COMPOSABLE_TEMPLATE_NAME ).indexTemplate (
138
+ new ComposableIndexTemplate (
139
+ Arrays .stream (INDEX_NAMES_WILDCARD .split ("," )).collect (Collectors .toList ()),
140
+ new Template (Settings .EMPTY , null , Collections .emptyMap ()),
141
+ Collections .singletonList (COMPONENT_TEMPLATE_NAME ),
142
+ 1L ,
143
+ 1L ,
144
+ Collections .emptyMap (),
145
+ null
146
+ )
147
+ )
148
+ );
149
+ assertTrue (composableTemplateResponse .get ().isAcknowledged ());
90
150
91
151
// Step - 2 Replace all nodes in the cluster with new nodes. This ensures new cluster state doesn't have previous index metadata
92
152
resetCluster (dataNodeCount , clusterManagerNodeCount );
@@ -104,7 +164,24 @@ public void testFullClusterRestore() throws Exception {
104
164
);
105
165
validateMetadata (List .of (INDEX_NAME ));
106
166
verifyRedIndicesAndTriggerRestore (indexStats , INDEX_NAME , true );
107
-
167
+ clusterService ().state ()
168
+ .metadata ()
169
+ .coordinationMetadata ()
170
+ .getVotingConfigExclusions ()
171
+ .stream ()
172
+ .forEach (config -> assertTrue (Arrays .stream (EXCLUDED_NODES ).anyMatch (node -> node .equals (config .getNodeId ()))));
173
+ assertFalse (clusterService ().state ().metadata ().templates ().isEmpty ());
174
+ assertTrue (clusterService ().state ().metadata ().templates ().containsKey (TEMPLATE_NAME ));
175
+ assertFalse (clusterService ().state ().metadata ().settings ().isEmpty ());
176
+ assertFalse (clusterService ().state ().metadata ().settings ().getAsBoolean (SETTING_READ_ONLY_SETTING .getKey (), true ));
177
+ assertNotNull (clusterService ().state ().metadata ().custom ("component_template" ));
178
+ ComponentTemplateMetadata componentTemplateMetadata = clusterService ().state ().metadata ().custom ("component_template" );
179
+ assertFalse (componentTemplateMetadata .componentTemplates ().isEmpty ());
180
+ assertTrue (componentTemplateMetadata .componentTemplates ().containsKey (COMPONENT_TEMPLATE_NAME ));
181
+ assertNotNull (clusterService ().state ().metadata ().custom ("index_template" ));
182
+ ComposableIndexTemplateMetadata composableIndexTemplate = clusterService ().state ().metadata ().custom ("index_template" );
183
+ assertFalse (composableIndexTemplate .indexTemplates ().isEmpty ());
184
+ assertTrue (composableIndexTemplate .indexTemplates ().containsKey (COMPOSABLE_TEMPLATE_NAME ));
108
185
}
109
186
110
187
/**
0 commit comments