assert first.getCredentials() != null : first;
assert first.getCredentials().identity != null : first;
startedId = first.getProviderId();
AWSRunningInstance instance = AWSRunningInstance.class.cast(getOnlyElement(getOnlyElement(instanceClient
.describeInstancesInRegion(region, startedId))));
assertEquals(instance.getKeyName(), group);
assert instance.getSpotInstanceRequestId() != null;
assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED);
// generate some load
ListenableFuture<ExecResponse> future = client.submitScriptOnNode(first.getId(), Statements
.exec("while true; do true; done"), runAsRoot(false).nameTask("cpuSpinner"));
// monitoring granularity for free tier is 5 minutes, so lets make sure we have data.
Thread.sleep(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));
// stop the spinner
future.cancel(true);
CloudWatchApi monitoringApi = ContextBuilder.newBuilder(new AWSCloudWatchProviderMetadata())
.credentials(identity, credential)
.modules(setupModules())
.buildApi(CloudWatchApi.class);
try {
GetMetricStatisticsResponse datapoints = monitoringApi.getMetricApiForRegion(instance.getRegion())
.getMetricStatistics(GetMetricStatistics.builder()
.dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, instance.getId()))
.unit(Unit.PERCENT)
.namespace("AWS/EC2")
.metricName("CPUUtilization")
.startTime(before)
.endTime(new Date())
.period(60)
.statistic(Statistics.AVERAGE)
.build());
assert (datapoints.size() > 0) : instance;
} finally {
monitoringApi.close();
}
// make sure we made our dummy group and also let in the user's group
assertEquals(newTreeSet(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group, group));
// make sure our dummy group has no rules
SecurityGroup secgroup = getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(instance
.getRegion(), "jclouds#" + group));
assert secgroup.size() == 0 : secgroup;
// try to run a script with the original keyPair