private static void setRequiredProperties ( Properties zkProps ) { // Set default client port if ( zkProps . getProperty ( "clientPort" ) == null ) { zkProps . setProperty ( "clientPort" , String . valueOf ( DEFAULT_ZOOKEEPER_CLIENT_PORT ) ) ; LOG . warn ( "No 'clientPort' configured. Set to '{}'." , DEFAULT_ZOOKEEPER_CLIENT_PORT ) ; } // Set default init limit if ( zkProps . getProperty ( "initLimit" ) == null ) { zkProps . setProperty ( "initLimit" , String . valueOf ( DEFAULT_ZOOKEEPER_INIT_LIMIT ) ) ; LOG . warn ( "No 'initLimit' configured. Set to '{}'." , DEFAULT_ZOOKEEPER_INIT_LIMIT ) ; } // Set default sync limit if ( zkProps . getProperty ( "syncLimit" ) == null ) { zkProps . setProperty ( "syncLimit" , String . valueOf ( DEFAULT_ZOOKEEPER_SYNC_LIMIT ) ) ; LOG . warn ( "No 'syncLimit' configured. Set to '{}'." , DEFAULT_ZOOKEEPER_SYNC_LIMIT ) ; } // Set default data dir if ( zkProps . getProperty ( "dataDir" ) == null ) { String dataDir = String . format ( "%s/%s/zookeeper" , System . getProperty ( "java.io.tmpdir" ) , UUID . randomUUID ( ) . toString ( ) ) ; zkProps . setProperty ( "dataDir" , dataDir ) ; LOG . warn ( "No 'dataDir' configured. Set to '{}'." , dataDir ) ; } int peerPort = DEFAULT_ZOOKEEPER_PEER_PORT ; int leaderPort = DEFAULT_ZOOKEEPER_LEADER_PORT ; // Set peer and leader ports if none given, because ZooKeeper complains if multiple // servers are configured, but no ports are given. for ( Map . Entry < Object , Object > entry : zkProps . entrySet ( ) ) { String key = ( String ) entry . getKey ( ) ; if ( entry . getKey ( ) . toString ( ) . startsWith ( "server." ) ) { String value = ( String ) entry . getValue ( ) ; String [ ] parts = value . split ( ":" ) ; if ( parts . length == 1 ) { String address = String . format ( "%s:%d:%d" , parts [ 0 ] , peerPort , leaderPort ) ; zkProps . setProperty ( key , address ) ; LOG . info ( "Set peer and leader port of '{}': '{}' => '{}'." , key , value , address ) ; } else if ( parts . length == 2 ) { String address = String . format ( "%s:%d:%d" , parts [ 0 ] , Integer . valueOf ( parts [ 1 ] ) , leaderPort ) ; zkProps . setProperty ( key , address ) ; LOG . info ( "Set peer port of '{}': '{}' => '{}'." , key , value , address ) ; } } } }
Sets required properties to reasonable defaults and logs it .