@ Given ( "^I save the IP of an unused node in hosts '(.+?)' in the in environment variable '(.+?)'?$" ) public void getUnusedNode ( String hosts , String envVar ) throws Exception { Set < String > hostList = new HashSet ( Arrays . asList ( hosts . split ( "," ) ) ) ; //Get the list of currently used hosts commonspec . executeCommand ( "dcos task | awk '{print $2}'" , 0 , null ) ; String results = commonspec . getRemoteSSHConnection ( ) . getResult ( ) ; Set < String > usedHosts = new HashSet ( Arrays . asList ( results . replaceAll ( "\r" , "" ) . split ( "\n" ) ) ) ; //We get the nodes not being used hostList . removeAll ( usedHosts ) ; if ( hostList . size ( ) == 0 ) { throw new IllegalStateException ( "No unused nodes in the cluster." ) ; } else { //Pick the first available node ThreadProperty . set ( envVar , hostList . iterator ( ) . next ( ) ) ; } }
Checks if there are any unused nodes in the cluster and returns the IP of one of them . REQUIRES A PREVIOUSLY - ESTABLISHED SSH CONNECTION TO DCOS - CLI TO WORK