@ Given ( "^I obtain elasticsearch cluster name in '([^:]+?)(:.+?)?' and save it in variable '(.+?)'?$" ) public void saveElasticCluster ( String host , String port , String envVar ) throws Exception { commonspec . setRestProtocol ( "http://" ) ; commonspec . setRestHost ( host ) ; commonspec . setRestPort ( port ) ; Future < Response > response ; response = commonspec . generateRequest ( "GET" , false , null , null , "/" , "" , "json" , "" ) ; commonspec . setResponse ( "GET" , response . get ( ) ) ; String json ; String parsedElement ; json = commonspec . getResponse ( ) . getResponse ( ) ; parsedElement = "$..cluster_name" ; String json2 = "[" + json + "]" ; String value = commonspec . getJSONPathString ( json2 , parsedElement , "0" ) ; if ( value == null ) { throw new Exception ( "No cluster name is found" ) ; } else { ThreadProperty . set ( envVar , value ) ; } }
Save clustername of elasticsearch in an environment varible for future use .