33
33
import org .elasticsearch .common .settings .Settings ;
34
34
import org .elasticsearch .common .util .concurrent .ThreadContext ;
35
35
import org .elasticsearch .common .util .set .Sets ;
36
+ import org .elasticsearch .core .internal .io .IOUtils ;
36
37
import org .elasticsearch .index .query .QueryBuilders ;
37
38
import org .elasticsearch .search .SearchHit ;
38
39
import org .elasticsearch .search .builder .SearchSourceBuilder ;
@@ -71,10 +72,22 @@ protected static RestHighLevelClient highLevelClient(RestClient client) {
71
72
};
72
73
}
73
74
74
- @ SuppressWarnings ("removal" )
75
75
public void testOldRepoAccess () throws IOException {
76
+ runTest (false );
77
+ }
78
+
79
+ public void testOldSourceOnlyRepoAccess () throws IOException {
80
+ runTest (true );
81
+ }
82
+
83
+ @ SuppressWarnings ("removal" )
84
+ public void runTest (boolean sourceOnlyRepository ) throws IOException {
76
85
String repoLocation = System .getProperty ("tests.repo.location" );
77
86
Version oldVersion = Version .fromString (System .getProperty ("tests.es.version" ));
87
+ assumeTrue (
88
+ "source only repositories only supported since ES 6.5.0" ,
89
+ sourceOnlyRepository == false || oldVersion .onOrAfter (Version .fromString ("6.5.0" ))
90
+ );
78
91
79
92
int oldEsPort = Integer .parseInt (System .getProperty ("tests.es.port" ));
80
93
int numDocs = 5 ;
@@ -89,38 +102,43 @@ public void testOldRepoAccess() throws IOException {
89
102
createIndex .setJsonEntity ("""
90
103
{"settings":{"number_of_shards": %s}}
91
104
""" .formatted (numberOfShards ));
92
- oldEs .performRequest (createIndex );
105
+ assertOK ( oldEs .performRequest (createIndex ) );
93
106
94
107
for (int i = 0 ; i < numDocs ; i ++) {
95
108
String id = "testdoc" + i ;
96
109
expectedIds .add (id );
97
110
Request doc = new Request ("PUT" , "/test/doc/" + id );
98
111
doc .addParameter ("refresh" , "true" );
99
112
doc .setJsonEntity (sourceForDoc (i ));
100
- oldEs .performRequest (doc );
113
+ assertOK ( oldEs .performRequest (doc ) );
101
114
}
102
115
103
116
// register repo on old ES and take snapshot
104
117
Request createRepoRequest = new Request ("PUT" , "/_snapshot/testrepo" );
105
- createRepoRequest .setJsonEntity ("""
118
+ createRepoRequest .setJsonEntity (sourceOnlyRepository ? """
119
+ {"type":"source","settings":{"location":"%s","delegate_type":"fs"}}
120
+ """ .formatted (repoLocation ) : """
106
121
{"type":"fs","settings":{"location":"%s"}}
107
122
""" .formatted (repoLocation ));
108
- oldEs .performRequest (createRepoRequest );
123
+ assertOK ( oldEs .performRequest (createRepoRequest ) );
109
124
110
125
Request createSnapshotRequest = new Request ("PUT" , "/_snapshot/testrepo/snap1" );
111
126
createSnapshotRequest .addParameter ("wait_for_completion" , "true" );
112
127
createSnapshotRequest .setJsonEntity ("{\" indices\" :\" test\" }" );
113
- oldEs .performRequest (createSnapshotRequest );
128
+ assertOK ( oldEs .performRequest (createSnapshotRequest ) );
114
129
115
130
// register repo on new ES
116
131
Settings .Builder repoSettingsBuilder = Settings .builder ().put ("location" , repoLocation );
132
+ if (sourceOnlyRepository ) {
133
+ repoSettingsBuilder .put ("delegate_type" , "fs" );
134
+ }
117
135
if (Build .CURRENT .isSnapshot ()) {
118
136
repoSettingsBuilder .put ("allow_bwc_indices" , true );
119
137
}
120
138
ElasticsearchAssertions .assertAcked (
121
139
client .snapshot ()
122
140
.createRepository (
123
- new PutRepositoryRequest ("testrepo" ).type ("fs" ).settings (repoSettingsBuilder ),
141
+ new PutRepositoryRequest ("testrepo" ).type (sourceOnlyRepository ? "source" : "fs" ).settings (repoSettingsBuilder ),
124
142
RequestOptions .DEFAULT
125
143
)
126
144
);
@@ -193,7 +211,19 @@ public void testOldRepoAccess() throws IOException {
193
211
restoreMountAndVerify (numDocs , expectedIds , client , numberOfShards );
194
212
}
195
213
} finally {
196
- oldEs .performRequest (new Request ("DELETE" , "/test" ));
214
+ IOUtils .closeWhileHandlingException (
215
+ () -> oldEs .performRequest (new Request ("DELETE" , "/test" )),
216
+ () -> oldEs .performRequest (new Request ("DELETE" , "/_snapshot/testrepo/snap1" )),
217
+ () -> oldEs .performRequest (new Request ("DELETE" , "/_snapshot/testrepo" ))
218
+ );
219
+ if (Build .CURRENT .isSnapshot ()) {
220
+ IOUtils .closeWhileHandlingException (
221
+ () -> client ().performRequest (new Request ("DELETE" , "/restored_test" )),
222
+ () -> client ().performRequest (new Request ("DELETE" , "/mounted_full_copy_test" )),
223
+ () -> client ().performRequest (new Request ("DELETE" , "/mounted_shared_cache_test" ))
224
+ );
225
+ }
226
+ IOUtils .closeWhileHandlingException (() -> client ().performRequest (new Request ("DELETE" , "/_snapshot/testrepo" )));
197
227
}
198
228
}
199
229
}
0 commit comments