private static String [ ] getCLDBLocations ( String authority ) throws IOException { // Determine the MapR home String maprHome = System . getenv ( MAPR_HOME_ENV ) ; if ( maprHome == null ) { maprHome = DEFAULT_MAPR_HOME ; } final File maprClusterConf = new File ( maprHome , MAPR_CLUSTER_CONF_FILE ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( String . format ( "Trying to retrieve MapR cluster configuration from %s" , maprClusterConf ) ) ; } if ( ! maprClusterConf . exists ( ) ) { throw new IOException ( "Could not find CLDB configuration '" + maprClusterConf . getAbsolutePath ( ) + "', assuming MapR home is '" + maprHome + "'." ) ; } // Read the cluster configuration file, format is specified at // http://doc.mapr.com/display/MapR/mapr-clusters.conf try ( BufferedReader br = new BufferedReader ( new FileReader ( maprClusterConf ) ) ) { String line ; while ( ( line = br . readLine ( ) ) != null ) { // Normalize the string line = line . trim ( ) ; line = line . replace ( ' ' , ' ' ) ; final String [ ] fields = line . split ( " " ) ; if ( fields . length < 1 ) { continue ; } final String clusterName = fields [ 0 ] ; if ( ! clusterName . equals ( authority ) ) { continue ; } final List < String > cldbLocations = new ArrayList <> ( ) ; for ( int i = 1 ; i < fields . length ; ++ i ) { // Make sure this is not a key-value pair MapR recently // introduced in the file format along with their security // features. if ( ! fields [ i ] . isEmpty ( ) && ! fields [ i ] . contains ( "=" ) ) { cldbLocations . add ( fields [ i ] ) ; } } if ( cldbLocations . isEmpty ( ) ) { throw new IOException ( String . format ( "%s contains entry for cluster %s but no CLDB locations." , maprClusterConf , authority ) ) ; } return cldbLocations . toArray ( new String [ cldbLocations . size ( ) ] ) ; } } throw new IOException ( String . format ( "Unable to find CLDB locations for cluster %s" , authority ) ) ; }
Retrieves the CLDB locations for the given MapR cluster name .