@Test public void testApplyWithIAMInstanceProfileName() { LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123") .iamInstanceProfileName("Webserver").build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.IamInstanceProfile.Name", "Webserver")); }
@Override public Map<String, String> apply(LaunchSpecification launchSpec) { Builder<String, String> builder = ImmutableMap.builder(); builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId")); if (launchSpec.getAvailabilityZone() != null) builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone()); AWSRunInstancesOptions options = new AWSRunInstancesOptions(); if (!launchSpec.getBlockDeviceMappings().isEmpty()) options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings()); if (!launchSpec.getSecurityGroupNames().isEmpty()) options.withSecurityGroups(launchSpec.getSecurityGroupNames()); if (!launchSpec.getSecurityGroupIds().isEmpty()) options.withSecurityGroupIds(launchSpec.getSecurityGroupIds()); options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType")); if (launchSpec.getSubnetId() != null) options.withSubnetId(launchSpec.getSubnetId()); if (launchSpec.getKernelId() != null) options.withKernelId(launchSpec.getKernelId()); if (launchSpec.getKeyName() != null) options.withKeyName(launchSpec.getKeyName()); if (launchSpec.getRamdiskId() != null) options.withRamdisk(launchSpec.getRamdiskId()); if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled())) options.enableMonitoring(); if (launchSpec.getUserData() != null) options.withUserData(launchSpec.getUserData()); if (launchSpec.getIAMInstanceProfile().isPresent()) { IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get(); if (profile.getArn().isPresent()) options.withIAMInstanceProfileArn(profile.getArn().get()); if (profile.getName().isPresent()) options.withIAMInstanceProfileName(profile.getName().get()); } for (Entry<String, String> entry : options.buildFormParameters().entries()) { builder.put("LaunchSpecification." + entry.getKey(), entry.getValue()); } return builder.build(); }
BindLaunchSpecificationToFormParams implements Binder, Function<LaunchSpecification, Map<String, String>> { @Override public Map<String, String> apply(LaunchSpecification launchSpec) { Builder<String, String> builder = ImmutableMap.builder(); builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId")); if (launchSpec.getAvailabilityZone() != null) builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone()); AWSRunInstancesOptions options = new AWSRunInstancesOptions(); if (!launchSpec.getBlockDeviceMappings().isEmpty()) options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings()); if (!launchSpec.getSecurityGroupNames().isEmpty()) options.withSecurityGroups(launchSpec.getSecurityGroupNames()); if (!launchSpec.getSecurityGroupIds().isEmpty()) options.withSecurityGroupIds(launchSpec.getSecurityGroupIds()); options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType")); if (launchSpec.getSubnetId() != null) options.withSubnetId(launchSpec.getSubnetId()); if (launchSpec.getKernelId() != null) options.withKernelId(launchSpec.getKernelId()); if (launchSpec.getKeyName() != null) options.withKeyName(launchSpec.getKeyName()); if (launchSpec.getRamdiskId() != null) options.withRamdisk(launchSpec.getRamdiskId()); if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled())) options.enableMonitoring(); if (launchSpec.getUserData() != null) options.withUserData(launchSpec.getUserData()); if (launchSpec.getIAMInstanceProfile().isPresent()) { IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get(); if (profile.getArn().isPresent()) options.withIAMInstanceProfileArn(profile.getArn().get()); if (profile.getName().isPresent()) options.withIAMInstanceProfileName(profile.getName().get()); } for (Entry<String, String> entry : options.buildFormParameters().entries()) { builder.put("LaunchSpecification." + entry.getKey(), entry.getValue()); } return builder.build(); } }
BindLaunchSpecificationToFormParams implements Binder, Function<LaunchSpecification, Map<String, String>> { @Override public Map<String, String> apply(LaunchSpecification launchSpec) { Builder<String, String> builder = ImmutableMap.builder(); builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId")); if (launchSpec.getAvailabilityZone() != null) builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone()); AWSRunInstancesOptions options = new AWSRunInstancesOptions(); if (!launchSpec.getBlockDeviceMappings().isEmpty()) options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings()); if (!launchSpec.getSecurityGroupNames().isEmpty()) options.withSecurityGroups(launchSpec.getSecurityGroupNames()); if (!launchSpec.getSecurityGroupIds().isEmpty()) options.withSecurityGroupIds(launchSpec.getSecurityGroupIds()); options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType")); if (launchSpec.getSubnetId() != null) options.withSubnetId(launchSpec.getSubnetId()); if (launchSpec.getKernelId() != null) options.withKernelId(launchSpec.getKernelId()); if (launchSpec.getKeyName() != null) options.withKeyName(launchSpec.getKeyName()); if (launchSpec.getRamdiskId() != null) options.withRamdisk(launchSpec.getRamdiskId()); if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled())) options.enableMonitoring(); if (launchSpec.getUserData() != null) options.withUserData(launchSpec.getUserData()); if (launchSpec.getIAMInstanceProfile().isPresent()) { IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get(); if (profile.getArn().isPresent()) options.withIAMInstanceProfileArn(profile.getArn().get()); if (profile.getName().isPresent()) options.withIAMInstanceProfileName(profile.getName().get()); } for (Entry<String, String> entry : options.buildFormParameters().entries()) { builder.put("LaunchSpecification." + entry.getKey(), entry.getValue()); } return builder.build(); }  }
BindLaunchSpecificationToFormParams implements Binder, Function<LaunchSpecification, Map<String, String>> { @Override public Map<String, String> apply(LaunchSpecification launchSpec) { Builder<String, String> builder = ImmutableMap.builder(); builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId")); if (launchSpec.getAvailabilityZone() != null) builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone()); AWSRunInstancesOptions options = new AWSRunInstancesOptions(); if (!launchSpec.getBlockDeviceMappings().isEmpty()) options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings()); if (!launchSpec.getSecurityGroupNames().isEmpty()) options.withSecurityGroups(launchSpec.getSecurityGroupNames()); if (!launchSpec.getSecurityGroupIds().isEmpty()) options.withSecurityGroupIds(launchSpec.getSecurityGroupIds()); options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType")); if (launchSpec.getSubnetId() != null) options.withSubnetId(launchSpec.getSubnetId()); if (launchSpec.getKernelId() != null) options.withKernelId(launchSpec.getKernelId()); if (launchSpec.getKeyName() != null) options.withKeyName(launchSpec.getKeyName()); if (launchSpec.getRamdiskId() != null) options.withRamdisk(launchSpec.getRamdiskId()); if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled())) options.enableMonitoring(); if (launchSpec.getUserData() != null) options.withUserData(launchSpec.getUserData()); if (launchSpec.getIAMInstanceProfile().isPresent()) { IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get(); if (profile.getArn().isPresent()) options.withIAMInstanceProfileArn(profile.getArn().get()); if (profile.getName().isPresent()) options.withIAMInstanceProfileName(profile.getName().get()); } for (Entry<String, String> entry : options.buildFormParameters().entries()) { builder.put("LaunchSpecification." + entry.getKey(), entry.getValue()); } return builder.build(); }  @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input); @Override Map<String, String> apply(LaunchSpecification launchSpec); }
BindLaunchSpecificationToFormParams implements Binder, Function<LaunchSpecification, Map<String, String>> { @Override public Map<String, String> apply(LaunchSpecification launchSpec) { Builder<String, String> builder = ImmutableMap.builder(); builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId")); if (launchSpec.getAvailabilityZone() != null) builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone()); AWSRunInstancesOptions options = new AWSRunInstancesOptions(); if (!launchSpec.getBlockDeviceMappings().isEmpty()) options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings()); if (!launchSpec.getSecurityGroupNames().isEmpty()) options.withSecurityGroups(launchSpec.getSecurityGroupNames()); if (!launchSpec.getSecurityGroupIds().isEmpty()) options.withSecurityGroupIds(launchSpec.getSecurityGroupIds()); options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType")); if (launchSpec.getSubnetId() != null) options.withSubnetId(launchSpec.getSubnetId()); if (launchSpec.getKernelId() != null) options.withKernelId(launchSpec.getKernelId()); if (launchSpec.getKeyName() != null) options.withKeyName(launchSpec.getKeyName()); if (launchSpec.getRamdiskId() != null) options.withRamdisk(launchSpec.getRamdiskId()); if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled())) options.enableMonitoring(); if (launchSpec.getUserData() != null) options.withUserData(launchSpec.getUserData()); if (launchSpec.getIAMInstanceProfile().isPresent()) { IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get(); if (profile.getArn().isPresent()) options.withIAMInstanceProfileArn(profile.getArn().get()); if (profile.getName().isPresent()) options.withIAMInstanceProfileName(profile.getName().get()); } for (Entry<String, String> entry : options.buildFormParameters().entries()) { builder.put("LaunchSpecification." + entry.getKey(), entry.getValue()); } return builder.build(); }  @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input); @Override Map<String, String> apply(LaunchSpecification launchSpec);  }