private void ensure_dashboards ( ) { HttpURLConnection urlConnection = null ; OutputStreamWriter wr = null ; URL myurl = null ; try { myurl = new URL ( url_str + "/dashboards.json" ) ; urlConnection = ( HttpURLConnection ) myurl . openConnection ( ) ; urlConnection . setRequestMethod ( "GET" ) ; urlConnection . setDoInput ( true ) ; urlConnection . setDoOutput ( true ) ; urlConnection . setReadTimeout ( coppereggApiTimeoutInMillis ) ; urlConnection . setRequestProperty ( "content-type" , "application/json; charset=utf-8" ) ; urlConnection . setRequestProperty ( "Authorization" , "Basic " + basicAuthentication ) ; int responseCode = urlConnection . getResponseCode ( ) ; if ( responseCode != 200 ) { logger . warn ( "Bad responsecode " + String . valueOf ( responseCode ) + " from Dahsboards Index: " + myurl ) ; } } catch ( Exception e ) { exceptionCounter . incrementAndGet ( ) ; logger . warn ( "Exception on dashboards index request " + myurl + " " + e ) ; } finally { if ( urlConnection != null ) { try { InputStream in = urlConnection . getInputStream ( ) ; String theString = convertStreamToString ( in ) ; for ( Map . Entry < String , String > entry : dashMap . entrySet ( ) ) { String checkName = entry . getKey ( ) ; try { String Rslt = groupFind ( checkName , theString , 1 ) ; if ( Rslt != null ) { // Update it Rslt = Send_Commmand ( "/dashboards/" + Rslt + ".json" , "PUT" , entry . getValue ( ) , 1 ) ; } else { // create it Rslt = Send_Commmand ( "/dashboards.json" , "POST" , entry . getValue ( ) , 1 ) ; } } catch ( Exception e ) { exceptionCounter . incrementAndGet ( ) ; logger . warn ( "Exception in dashboard update or create: " + myurl + " " + e ) ; } } } catch ( IOException e ) { exceptionCounter . incrementAndGet ( ) ; logger . warn ( "Exception flushing http connection" + e ) ; } } } }
If dashboard doesn t exist create it If it does exist update it .