public void waitForOperation ( String operationName , int maxSeconds ) throws InterruptedException { long endTimeMillis = TimeUnit . SECONDS . toMillis ( maxSeconds ) + System . currentTimeMillis ( ) ; GetOperationRequest request = GetOperationRequest . newBuilder ( ) . setName ( operationName ) . build ( ) ; do { Thread . sleep ( 500 ) ; Operation response = client . getOperation ( request ) ; if ( response . getDone ( ) ) { switch ( response . getResultCase ( ) ) { case RESPONSE : return ; case ERROR : throw new RuntimeException ( "Cluster could not be resized: " + response . getError ( ) ) ; case RESULT_NOT_SET : throw new IllegalStateException ( "System returned invalid response for Operation check: " + response ) ; } } } while ( System . currentTimeMillis ( ) < endTimeMillis ) ; throw new IllegalStateException ( String . format ( "Waited %d seconds and cluster was not resized yet." , maxSeconds ) ) ; }
Waits for an operation like cluster resizing to complete .