private RunInstancesRequest prepareEC2RequestNode ( Map < String , String > targetProperties , String userData ) throws UnsupportedEncodingException { RunInstancesRequest runInstancesRequest = new RunInstancesRequest ( ) ; String flavor = targetProperties . get ( Ec2Constants . VM_INSTANCE_TYPE ) ; if ( Utils . isEmptyOrWhitespaces ( flavor ) ) flavor = "t1.micro" ; runInstancesRequest . setInstanceType ( flavor ) ; runInstancesRequest . setImageId ( targetProperties . get ( Ec2Constants . AMI_VM_NODE ) ) ; runInstancesRequest . setMinCount ( 1 ) ; runInstancesRequest . setMaxCount ( 1 ) ; runInstancesRequest . setKeyName ( targetProperties . get ( Ec2Constants . SSH_KEY_NAME ) ) ; String secGroup = targetProperties . get ( Ec2Constants . SECURITY_GROUP_NAME ) ; if ( Utils . isEmptyOrWhitespaces ( secGroup ) ) secGroup = "default" ; runInstancesRequest . setSecurityGroups ( Collections . singletonList ( secGroup ) ) ; String availabilityZone = targetProperties . get ( Ec2Constants . AVAILABILITY_ZONE ) ; if ( ! Utils . isEmptyOrWhitespaces ( availabilityZone ) ) runInstancesRequest . setPlacement ( new Placement ( availabilityZone ) ) ; // The following part enables to transmit data to the VM. // When the VM is up, it will be able to read this data. String encodedUserData = new String ( Base64 . encodeBase64 ( userData . getBytes ( StandardCharsets . UTF_8 ) ) , "UTF-8" ) ; runInstancesRequest . setUserData ( encodedUserData ) ; return runInstancesRequest ; }
Prepares the request .