}
private void startProvisioningProcess(String spotBid) throws Exception {
waitForProcessDeployment(AmazonProvisionr.MANAGEMENT_PROCESS_KEY);
final Provisionr provisionr = getOsgiService(Provisionr.class, 5000);
Provider provider = collectProviderCredentialsFromSystemProperties()
.option(ProviderOptions.REGION, getProviderProperty(
ProviderOptions.REGION, ProviderOptions.DEFAULT_REGION))
.createProvider();
if (spotBid != null) {
provider = provider.toBuilder()
.option(ProviderOptions.SPOT_BID, spotBid)
.createProvider();
}
final Network network = Network.builder().addRules(
Rule.builder().anySource().icmp().createRule(),
Rule.builder().anySource().port(22).protocol(Protocol.TCP).createRule()
).createNetwork();
final Hardware hardware = Hardware.builder().type(TEST_INSTANCE_TYPE).createHardware();
final AdminAccess adminAccess = AdminAccess.builder().asCurrentUser().createAdminAccess();
final String destinationPath = "/home/" + adminAccess.getUsername() + "/provisionr.html";
final Software software = Software.builder()
.imageId("default")
.file("http://provisionr.incubator.apache.org", destinationPath)
.createSoftware();
PoolTemplate template = getPoolTemplateWithId(TEST_POOL_TEMPLATE, 5000);
final Pool pool = template.apply(Pool.builder()
.provider(provider)
.network(network)
.adminAccess(adminAccess)
.software(software)
.hardware(hardware)
.minSize(TEST_POOL_SIZE)
.expectedSize(TEST_POOL_SIZE)
.createPool());
final String businessKey = "j-" + UUID.randomUUID().toString();
String processInstanceId = provisionr.startPoolManagementProcess(businessKey, pool);
try {
waitForPoolStatus(provisionr, businessKey, PoolStatus.READY);
List<Machine> machines = provisionr.getMachines(businessKey);
assertTrue(machines.size() >= TEST_POOL_SIZE && machines.size() <= TEST_POOL_SIZE);
for (Machine machine : machines) {
assertSshCommand(machine, adminAccess, "test -f " + destinationPath);
/* These are added through the Jenkins Debian template */
assertSshCommand(machine, adminAccess, "hash git >/dev/null 2>&1");
assertSshCommand(machine, adminAccess, "hash java >/dev/null 2>&1");
assertSshCommand(machine, adminAccess, "test -f /etc/apt/sources.list.d/jenkins.list");
}
} finally {
provisionr.destroyPool(businessKey);
waitForPoolStatus(provisionr, businessKey, PoolStatus.TERMINATED);
waitForProcessEnd(processInstanceId);
}
}