bug4811: added optional userData parameter to launchHosts

This commit is contained in:
Axel Uhl
2020-09-25 15:56:17 +02:00
parent e593949fb0
commit 4128794af6
3 changed files with 16 additions and 5 deletions
@@ -42,6 +42,10 @@ public interface AwsInstance<ShardingKey, MetricsT extends ApplicationProcessMet
ChannelSftp createRootSftpChannel() throws JSchException, IOException;
/**
* Obtains an object through which, if present, an Apache reverse proxy running on this AWS host can be
* configured.
*/
ReverseProxy<ShardingKey, MetricsT> getReverseProxy();
String getInstanceId();
@@ -55,13 +55,18 @@ public interface AwsLandscape<ShardingKey, MetricsT extends ApplicationProcessMe
/**
* Launches a new {@link Host} from a given image into the availability zone specified and controls network access
* to that instance by setting the security groups specified for the resulting host.
*
* @param keyName
* the SSH key pair name to use when launching; this will grant root access with the corresponding
* private key; see also {@link #getKeyPairInfo(Region, String)}
* @param userData
* zero or more strings representing the user data to be passed to the instance; multiple strings will be
* concatenated, using the line separator to join them. The instance is able to read the user data throuh
* the AWS SDK installed on the instance.
*/
default AwsInstance<ShardingKey, MetricsT> launchHost(MachineImage<AwsInstance<ShardingKey, MetricsT>> fromImage, InstanceType instanceType,
AwsAvailabilityZone az, String keyName, Iterable<SecurityGroup> securityGroups) {
return launchHosts(1, fromImage, instanceType, az, keyName, securityGroups).iterator().next();
AwsAvailabilityZone az, String keyName, Iterable<SecurityGroup> securityGroups, String... userData) {
return launchHosts(1, fromImage, instanceType, az, keyName, securityGroups, userData).iterator().next();
}
/**
@@ -70,9 +75,10 @@ public interface AwsLandscape<ShardingKey, MetricsT extends ApplicationProcessMe
* @param keyName
* the SSH key pair name to use when launching; this will grant root access with the corresponding
* private key; see also {@link #getKeyPairInfo(Region, String)}
* @param userData TODO
*/
Iterable<AwsInstance<ShardingKey, MetricsT>> launchHosts(int numberOfHostsToLaunch, MachineImage<AwsInstance<ShardingKey, MetricsT>> fromImage, InstanceType instanceType,
AwsAvailabilityZone az, String keyName, Iterable<SecurityGroup> securityGroups);
AwsAvailabilityZone az, String keyName, Iterable<SecurityGroup> securityGroups, String... userData);
AmazonMachineImage<ShardingKey, MetricsT> getImage(Region region, String imageId);
@@ -335,7 +335,7 @@ public class AwsLandscapeImpl<ShardingKey, MetricsT extends ApplicationProcessMe
@Override
public Iterable<AwsInstance<ShardingKey, MetricsT>> launchHosts(int numberOfHostsToLaunch, MachineImage<AwsInstance<ShardingKey, MetricsT>> fromImage,
InstanceType instanceType, AwsAvailabilityZone az, String keyName, Iterable<SecurityGroup> securityGroups) {
InstanceType instanceType, AwsAvailabilityZone az, String keyName, Iterable<SecurityGroup> securityGroups, String... userData) {
if (!fromImage.getRegion().equals(az.getRegion())) {
throw new IllegalArgumentException("Trying to launch an instance in region "+az.getRegion()+
" with image "+fromImage+" that lives in region "+fromImage.getRegion()+" which is different."+
@@ -348,7 +348,8 @@ public class AwsLandscapeImpl<ShardingKey, MetricsT extends ApplicationProcessMe
.maxCount(numberOfHostsToLaunch)
.instanceType(instanceType).keyName(keyName)
.placement(Placement.builder().availabilityZone(az.getName()).build())
.securityGroupIds(Util.mapToArrayList(securityGroups, sg->sg.getId())).build();
.securityGroupIds(Util.mapToArrayList(securityGroups, sg->sg.getId()))
.userData(String.join("\n", userData)).build();
logger.info("Launching instance(s): "+launchRequest);
final RunInstancesResponse response = getEc2Client(getRegion(az.getRegion())).runInstances(launchRequest);
final List<AwsInstance<ShardingKey, MetricsT>> result = new ArrayList<>();