3333import java .util .Base64 ;
3434import java .util .List ;
3535import java .util .Locale ;
36- import java .util .concurrent .TimeUnit ;
3736import java .util .stream .Collectors ;
3837import org .apache .commons .cli .CommandLine ;
3938import org .apache .commons .cli .HelpFormatter ;
4039import org .apache .commons .cli .Option ;
4140import org .apache .lucene .util .Constants ;
42- import org .apache .solr .client .solrj .impl .SolrZkClientTimeout ;
4341import org .apache .solr .common .cloud .SolrZkClient ;
4442import org .apache .solr .common .util .StrUtils ;
4543import org .apache .solr .core .SolrCore ;
@@ -186,12 +184,7 @@ private int handleKerberos(CommandLine cli) throws Exception {
186184
187185 // check if security is already enabled or not
188186 if (!zkInaccessible ) {
189- try (SolrZkClient zkClient =
190- new SolrZkClient .Builder ()
191- .withUrl (zkHost )
192- .withTimeout (
193- SolrZkClientTimeout .DEFAULT_ZK_CLIENT_TIMEOUT , TimeUnit .MILLISECONDS )
194- .build ()) {
187+ try (SolrZkClient zkClient = SolrCLI .getSolrZkClient (cli , zkHost )) {
195188 checkSecurityJsonExists (zkClient );
196189 } catch (Exception ex ) {
197190 CLIO .out (
@@ -206,12 +199,7 @@ private int handleKerberos(CommandLine cli) throws Exception {
206199 if (!updateIncludeFileOnly ) {
207200 if (!zkInaccessible ) {
208201 echoIfVerbose ("Uploading following security.json: " + securityJson , cli );
209- try (SolrZkClient zkClient =
210- new SolrZkClient .Builder ()
211- .withUrl (zkHost )
212- .withTimeout (
213- SolrZkClientTimeout .DEFAULT_ZK_CLIENT_TIMEOUT , TimeUnit .MILLISECONDS )
214- .build ()) {
202+ try (SolrZkClient zkClient = SolrCLI .getSolrZkClient (cli , zkHost )) {
215203 zkClient .setData (
216204 "/security.json" , securityJson .getBytes (StandardCharsets .UTF_8 ), true );
217205 } catch (Exception ex ) {
@@ -322,11 +310,7 @@ private int handleBasicAuth(CommandLine cli) throws Exception {
322310 }
323311
324312 // check if security is already enabled or not
325- try (SolrZkClient zkClient =
326- new SolrZkClient .Builder ()
327- .withUrl (zkHost )
328- .withTimeout (SolrZkClientTimeout .DEFAULT_ZK_CLIENT_TIMEOUT , TimeUnit .MILLISECONDS )
329- .build ()) {
313+ try (SolrZkClient zkClient = SolrCLI .getSolrZkClient (cli , zkHost )) {
330314 checkSecurityJsonExists (zkClient );
331315 }
332316 }
@@ -374,11 +358,7 @@ private int handleBasicAuth(CommandLine cli) throws Exception {
374358
375359 if (!updateIncludeFileOnly ) {
376360 echoIfVerbose ("Uploading following security.json: " + securityJson , cli );
377- try (SolrZkClient zkClient =
378- new SolrZkClient .Builder ()
379- .withUrl (zkHost )
380- .withTimeout (SolrZkClientTimeout .DEFAULT_ZK_CLIENT_TIMEOUT , TimeUnit .MILLISECONDS )
381- .build ()) {
361+ try (SolrZkClient zkClient = SolrCLI .getSolrZkClient (cli , zkHost )) {
382362 zkClient .setData ("/security.json" , securityJson .getBytes (StandardCharsets .UTF_8 ), true );
383363 }
384364 }
@@ -469,11 +449,7 @@ private void clearSecurityJson(CommandLine cli, boolean updateIncludeFileOnly) t
469449
470450 echoIfVerbose ("Uploading following security.json: {}" , cli );
471451
472- try (SolrZkClient zkClient =
473- new SolrZkClient .Builder ()
474- .withUrl (zkHost )
475- .withTimeout (SolrZkClientTimeout .DEFAULT_ZK_CLIENT_TIMEOUT , TimeUnit .MILLISECONDS )
476- .build ()) {
452+ try (SolrZkClient zkClient = SolrCLI .getSolrZkClient (cli , zkHost )) {
477453 zkClient .setData ("/security.json" , "{}" .getBytes (StandardCharsets .UTF_8 ), true );
478454 }
479455 }
0 commit comments