public AddStepsResponse addSteps ( AddStepsRequest request ) { checkNotNull ( request , "request should not be null." ) ; checkNotNull ( request . getSteps ( ) , "The parameter steps should not be null." ) ; checkStringNotEmpty ( request . getClusterId ( ) , "The parameter clusterId should not be null or empty string." ) ; StringWriter writer = new StringWriter ( ) ; List < StepConfig > steps = request . getSteps ( ) ; try { JsonGenerator jsonGenerator = JsonUtils . jsonGeneratorOf ( writer ) ; jsonGenerator . writeStartObject ( ) ; jsonGenerator . writeArrayFieldStart ( "steps" ) ; for ( StepConfig step : steps ) { jsonGenerator . writeStartObject ( ) ; if ( step . getName ( ) != null ) { jsonGenerator . writeStringField ( "name" , step . getName ( ) ) ; } jsonGenerator . writeStringField ( "type" , step . getType ( ) ) ; jsonGenerator . writeStringField ( "actionOnFailure" , step . getActionOnFailure ( ) ) ; jsonGenerator . writeObjectFieldStart ( "properties" ) ; for ( String propertyKey : step . getProperties ( ) . keySet ( ) ) { jsonGenerator . writeObjectField ( propertyKey , step . getProperties ( ) . get ( propertyKey ) ) ; } jsonGenerator . writeEndObject ( ) ; jsonGenerator . writeArrayFieldStart ( "additionalFiles" ) ; for ( AdditionalFile additionalFile : step . getAdditionalFiles ( ) ) { jsonGenerator . writeStartObject ( ) ; jsonGenerator . writeStringField ( "remote" , additionalFile . getRemote ( ) ) ; jsonGenerator . writeStringField ( "local" , additionalFile . getLocal ( ) ) ; jsonGenerator . writeEndObject ( ) ; } jsonGenerator . writeEndArray ( ) ; jsonGenerator . writeEndObject ( ) ; } jsonGenerator . writeEndArray ( ) ; jsonGenerator . writeEndObject ( ) ; jsonGenerator . close ( ) ; } catch ( IOException e ) { throw new BceClientException ( "Fail to generate json" , e ) ; } byte [ ] json = null ; try { json = writer . toString ( ) . getBytes ( DEFAULT_ENCODING ) ; } catch ( UnsupportedEncodingException e ) { throw new BceClientException ( "Fail to get UTF-8 bytes" , e ) ; } InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . POST , CLUSTER , request . getClusterId ( ) , STEP ) ; internalRequest . addHeader ( Headers . CONTENT_LENGTH , String . valueOf ( json . length ) ) ; internalRequest . addHeader ( Headers . CONTENT_TYPE , "application/json" ) ; internalRequest . setContent ( RestartableInputStream . wrap ( json ) ) ; if ( request . getClientToken ( ) != null ) { internalRequest . addParameter ( "clientToken" , request . getClientToken ( ) ) ; } return this . invokeHttpClient ( internalRequest , AddStepsResponse . class ) ; }
Add steps to a BMR cluster .