本文整理汇总了Java中com.amazonaws.services.autoscaling.model.Instance类的典型用法代码示例。如果您正苦于以下问题:Java Instance类的具体用法?Java Instance怎么用?Java Instance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instance类属于com.amazonaws.services.autoscaling.model包,在下文中一共展示了Instance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testIncrementMinInstancesForAsgHappy
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
@Test
public void testIncrementMinInstancesForAsgHappy() {
String logicalId = "asg id";
String instanceId = "instance id";
int minSize = 2;
when(autoScalingClient.describeAutoScalingGroups(
new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(logicalId))
).thenReturn(
new DescribeAutoScalingGroupsResult()
.withAutoScalingGroups(
new AutoScalingGroup().withInstances(
new Instance().withInstanceId(instanceId))
.withMinSize(minSize)
)
);
autoScalingService.updateMinInstancesForAutoScalingGroup(logicalId, minSize - 1);
verify(autoScalingClient).updateAutoScalingGroup(new UpdateAutoScalingGroupRequest()
.withAutoScalingGroupName(logicalId)
.withMinSize(minSize - 1));
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:25,代码来源:AutoScalingServiceTest.java
示例2: execute
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
@Override
public void execute(Context context) throws Exception {
String key = "autoScaling/" + resource.id;
context.output(key, String.format("status=%s, ami=%s", resource.status, resource.launchConfig.ami.id()));
com.amazonaws.services.autoscaling.model.AutoScalingGroup remoteASGroup = resource.remoteASGroup;
if (remoteASGroup != null) {
context.output(key, String.format("name=%s, min=%s, desired=%s, max=%s, imageId=%s",
remoteASGroup.getAutoScalingGroupName(),
remoteASGroup.getMinSize(),
remoteASGroup.getDesiredCapacity(),
remoteASGroup.getMaxSize(),
resource.launchConfig.remoteLaunchConfig.getImageId()));
List<String> instanceIds = remoteASGroup.getInstances().stream().map(Instance::getInstanceId).collect(Collectors.toList());
if (!instanceIds.isEmpty()) {
for (com.amazonaws.services.ec2.model.Instance remoteInstance : AWS.ec2.describeInstances(instanceIds)) {
context.output(key, String.format("instanceId=%s, state=%s, privateDNS=%s, privateIP=%s",
remoteInstance.getInstanceId(),
remoteInstance.getState().getName(),
remoteInstance.getPrivateDnsName(),
remoteInstance.getPrivateIpAddress()));
}
}
}
}
开发者ID:neowu,项目名称:cmn-project,代码行数:27,代码来源:DescribeASGroupTask.java
示例3: checkInstanceInServiceOnAllElb
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public boolean checkInstanceInServiceOnAllElb(Instance newInstance, List<String> loadBalancerNames) {
if (newInstance == null) {
throw new IllegalStateException("Unable to check null instance");
}
for (String elb : loadBalancerNames) {
DescribeInstanceHealthResult result = awsElbClient.describeInstanceHealth(new DescribeInstanceHealthRequest(elb));
Optional<InstanceState> state = result.getInstanceStates().stream().filter(s -> s.getInstanceId().equals(newInstance.getInstanceId())).findFirst();
if (!state.isPresent()) {
log.info("instance state for instance " + newInstance.getInstanceId() + " on elb " + elb + " is unknown");
return false;
}
log.info("instance state for instance " + newInstance.getInstanceId() + " on elb " + elb + " is " + state.get().getState());
if (!"InService".equals(state.get().getState())) {
return false;
}
}
return true;
}
开发者ID:msoute,项目名称:vertx-deploy-tools,代码行数:19,代码来源:AwsAutoScalingDeployUtils.java
示例4: getInstancesForAutoScalingGroup
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
/**
* Gets a list of EC2 Instance objects for a given auto scaling group name
* @param groupName auto scaling group name
* @return List of Instances containing instance IDs and availability zones
*/
public List<EC2Instance> getInstancesForAutoScalingGroup(String groupName) {
List<Instance> instanceList = getAutoScalingGroup(groupName).getInstances();
return instanceList.stream().map(i -> new EC2Instance().withInstanceId(i.getInstanceId())
.withAvailabilityZone(i.getAvailabilityZone()) ).collect(Collectors.toList());
}
开发者ID:shinesolutions,项目名称:aem-orchestrator,代码行数:12,代码来源:AwsHelperService.java
示例5: listOldInstances
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
private List<String> listOldInstances() {
asGroupName = resource.remoteASGroup.getAutoScalingGroupName();
List<Instance> oldInstances = resource.remoteASGroup.getInstances();
List<String> oldInstanceIds = oldInstances.stream().map(Instance::getInstanceId).collect(Collectors.toList());
logger.info("old instances => {}", oldInstanceIds);
return oldInstanceIds;
}
开发者ID:neowu,项目名称:cmn-project,代码行数:8,代码来源:DeployASGroupTask.java
示例6: waitUntilInstanceAttachedToASG
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
private List<String> waitUntilInstanceAttachedToASG() throws InterruptedException {
List<String> newInstanceIds;
while (true) {
Threads.sleepRoughly(Duration.ofSeconds(30));
com.amazonaws.services.autoscaling.model.AutoScalingGroup remoteASGroup = AWS.as.describeASGroup(asGroupName);
for (Instance instance : remoteASGroup.getInstances()) {
logger.info("instance status, instanceId={}, lifecycle={}, health={}, new={}",
instance.getInstanceId(),
instance.getLifecycleState(),
instance.getHealthStatus(),
!oldInstanceIds.contains(instance.getInstanceId()));
}
long inServiceCount = remoteASGroup.getInstances().stream().filter(instance -> "InService".equals(instance.getLifecycleState())).count();
if (inServiceCount < remoteASGroup.getDesiredCapacity()) {
logger.info("continue to wait, not all instances are ready, inService={}, desired={}", inServiceCount, remoteASGroup.getDesiredCapacity());
} else {
logger.info("all instances of auto scaling group are in service");
newInstanceIds = remoteASGroup.getInstances().stream()
.filter(instance -> !oldInstanceIds.contains(instance.getInstanceId()))
.map(Instance::getInstanceId)
.collect(Collectors.toList());
break;
}
}
return newInstanceIds;
}
开发者ID:neowu,项目名称:cmn-project,代码行数:30,代码来源:DeployASGroupTask.java
示例7: execute
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
@Override
public void execute(Context context) throws Exception {
logger.info("upload package dir, asGroupId={}", resource.id);
List<String> instanceIds = resource.remoteASGroup.getInstances().stream()
.map(Instance::getInstanceId)
.collect(Collectors.toList());
List<com.amazonaws.services.ec2.model.Instance> remoteInstances = AWS.ec2.describeInstances(instanceIds);
LinuxUploader uploader = new LinuxUploader(context.env, remoteInstances, context);
uploader.upload();
}
开发者ID:neowu,项目名称:cmn-project,代码行数:14,代码来源:UploadTask.java
示例8: execute
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
@Override
public void execute(Context context) throws Exception {
logger.info("execute command, asGroupId={}", resource.id);
List<String> instanceIds = resource.remoteASGroup.getInstances().stream().map(Instance::getInstanceId).collect(Collectors.toList());
List<com.amazonaws.services.ec2.model.Instance> remoteInstances = AWS.ec2.describeInstances(instanceIds);
LinuxCommandRunner runner = new LinuxCommandRunner(context.env, remoteInstances, context);
runner.run();
}
开发者ID:neowu,项目名称:cmn-project,代码行数:11,代码来源:RunCommandTask.java
示例9: getRacMembership
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
@Override
public Map<String, List<String>> getRacMembership(Collection<String> autoScalingGroupNames) {
if (CollectionUtils.isEmpty(autoScalingGroupNames)) {
return Collections.emptyMap();
}
AmazonAutoScaling client = null;
try {
client = getAutoScalingClient();
DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest =
new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupNames);
DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = client.describeAutoScalingGroups(describeAutoScalingGroupsRequest);
Map<String, List<String>> asgs = new HashMap<>();
for (AutoScalingGroup autoScalingGroup : describeAutoScalingGroupsResult.getAutoScalingGroups()) {
List<String> asgInstanceIds = Lists.newArrayList();
for (Instance asgInstance : autoScalingGroup.getInstances()) {
if (!(asgInstance.getLifecycleState().equalsIgnoreCase("terminating") ||
asgInstance.getLifecycleState().equalsIgnoreCase("shutting-down") ||
asgInstance.getLifecycleState().equalsIgnoreCase("terminated"))) {
asgInstanceIds.add(asgInstance.getInstanceId());
}
}
asgs.put(autoScalingGroup.getAutoScalingGroupName(), asgInstanceIds);
logger.info("AWS returned the following instance ID's for {} ASG: {}",
autoScalingGroup.getAutoScalingGroupName(),
StringUtils.join(asgInstanceIds, ","));
}
return asgs;
} finally {
if (client != null) {
client.shutdown();
}
}
}
开发者ID:Netflix,项目名称:Raigad,代码行数:38,代码来源:AWSMembership.java
示例10: group
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public static AutoScalingGroup group(String name, LaunchConfiguration launchConfig, int desiredCapacity,
Collection<com.amazonaws.services.ec2.model.Instance> ec2Instances) {
AutoScalingGroup autoScalingGroup = new AutoScalingGroup().withAutoScalingGroupName(name)
.withLaunchConfigurationName(launchConfig.getLaunchConfigurationName())
.withDesiredCapacity(desiredCapacity).withInstances(toAsInstances(ec2Instances));
return autoScalingGroup;
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:8,代码来源:TestUtils.java
示例11: toAsInstances
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public static Collection<Instance> toAsInstances(
Collection<com.amazonaws.services.ec2.model.Instance> ec2Instances) {
List<Instance> asInstances = new ArrayList<>();
for (com.amazonaws.services.ec2.model.Instance ec2Instance : ec2Instances) {
Instance asInstance = new Instance().withInstanceId(ec2Instance.getInstanceId())
.withLifecycleState(ec2StateToLifecycleState(ec2Instance.getState()));
asInstances.add(asInstance);
}
return asInstances;
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:11,代码来源:TestUtils.java
示例12: getInstanceIds
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public List<String> getInstanceIds(AmazonAutoScalingClient amazonASClient, String asGroupName) {
DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = amazonASClient
.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asGroupName));
List<String> instanceIds = new ArrayList<>();
if (describeAutoScalingGroupsResult.getAutoScalingGroups().get(0).getInstances() != null) {
for (Instance instance : describeAutoScalingGroupsResult.getAutoScalingGroups().get(0).getInstances()) {
if ("InService".equals(instance.getLifecycleState())) {
instanceIds.add(instance.getInstanceId());
}
}
}
return instanceIds;
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:14,代码来源:CloudFormationStackUtil.java
示例13: getInstancesForAutoScalingGroup
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public List<Ec2Instance> getInstancesForAutoScalingGroup(Log log, AutoScalingGroup autoScalingGroup) throws MojoFailureException {
log.info("retrieving list of instanceId's for auto scaling group with id : " + activeConfiguration.getAutoScalingGroupId());
activeConfiguration.getHosts().clear();
log.debug("describing instances in auto scaling group");
if (autoScalingGroup.getInstances().isEmpty()) {
return new ArrayList<>();
}
Map<String, Instance> instanceMap = autoScalingGroup.getInstances().stream().collect(Collectors.toMap(Instance::getInstanceId, Function.identity()));
try {
DescribeInstancesResult instancesResult = awsEc2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(autoScalingGroup.getInstances().stream().map(Instance::getInstanceId).collect(Collectors.toList())));
List<Ec2Instance> ec2Instances = instancesResult.getReservations().stream().flatMap(r -> r.getInstances().stream()).map(this::toEc2Instance).collect(Collectors.toList());
log.debug("describing elb status");
autoScalingGroup.getLoadBalancerNames().forEach(elb -> this.updateInstancesStateOnLoadBalancer(elb, ec2Instances));
ec2Instances.forEach(i -> i.updateAsState(AwsState.map(instanceMap.get(i.getInstanceId()).getLifecycleState())));
ec2Instances.sort((o1, o2) -> {
int sComp = o1.getAsState().compareTo(o2.getAsState());
if (sComp != 0) {
return sComp;
} else {
return o1.getElbState().compareTo(o2.getElbState());
}
});
if (activeConfiguration.isIgnoreInStandby()) {
return ec2Instances.stream().filter(i -> i.getAsState() != AwsState.STANDBY).collect(Collectors.toList());
}
return ec2Instances;
} catch (AmazonClientException e) {
log.error(e.getMessage(), e);
throw new MojoFailureException(e.getMessage());
}
}
开发者ID:msoute,项目名称:vertx-deploy-tools,代码行数:40,代码来源:AwsAutoScalingDeployUtils.java
示例14: checkEc2Instance
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public boolean checkEc2Instance(String instanceId) {
boolean instanceTerminated = false;
try {
DescribeInstancesResult result = awsEc2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId));
List<com.amazonaws.services.ec2.model.Instance> instances = result.getReservations().stream()
.flatMap(r -> r.getInstances().stream())
.filter(i -> i.getInstanceId().equals(instanceId))
.collect(Collectors.toList());
instanceTerminated = instances.isEmpty() || instances.stream()
.map(com.amazonaws.services.ec2.model.Instance::getState)
.anyMatch(s -> s.getCode().equals(48));
} catch (AmazonServiceException e) {
log.info(e.toString(), e);
if (e.getStatusCode() == 400) {
instanceTerminated = true;
}
}
if (instanceTerminated) {
log.warn("Invalid instance " + instanceId + " in group " + activeConfiguration.getAutoScalingGroupId() + ". Detaching instance.");
awsAsClient.detachInstances(new DetachInstancesRequest()
.withAutoScalingGroupName(activeConfiguration.getAutoScalingGroupId())
.withInstanceIds(instanceId)
.withShouldDecrementDesiredCapacity(false));
}
return instanceTerminated;
}
开发者ID:msoute,项目名称:vertx-deploy-tools,代码行数:28,代码来源:AwsAutoScalingDeployUtils.java
示例15: checkInstances
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
private List<Ec2Instance> checkInstances(AwsAutoScalingDeployUtils awsDeployUtils, AutoScalingGroup asGroup, List<Ec2Instance> instances) {
List<String> removedInstances = asGroup.getInstances().stream()
.filter(i -> i.getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name()))
.map(Instance::getInstanceId)
.filter(awsDeployUtils::checkEc2Instance)
.collect(Collectors.toList());
if (removedInstances != null && removedInstances.isEmpty()) {
return instances.stream()
.filter(i -> !removedInstances.contains(i.getInstanceId()))
.collect(Collectors.toList());
}
return instances;
}
开发者ID:msoute,项目名称:vertx-deploy-tools,代码行数:15,代码来源:AutoScalingDeployService.java
示例16: testGetPublicDnsForAutoScalingGroup
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
@Test
public void testGetPublicDnsForAutoScalingGroup() {
String logicalId = "fake-logical-id";
String instanceId = "fake-instance-id";
String dnsName = "dns.name";
when(autoScalingClient.describeAutoScalingGroups(
new DescribeAutoScalingGroupsRequest()
.withAutoScalingGroupNames(logicalId)
)
).thenReturn(
new DescribeAutoScalingGroupsResult()
.withAutoScalingGroups(
new AutoScalingGroup()
.withInstances(
new Instance()
.withInstanceId(instanceId)
)
)
);
when(ec2Client.describeInstances(
new DescribeInstancesRequest()
.withInstanceIds(instanceId)
)
).thenReturn(
new DescribeInstancesResult()
.withReservations(
new Reservation()
.withInstances(
new com.amazonaws.services.ec2.model.Instance()
.withPublicDnsName(dnsName)
)
)
);
// invoke method under test
List<String> results = autoScalingService.getPublicDnsForAutoScalingGroup(logicalId);
assertEquals(1, results.size());
assertEquals(dnsName, results.get(0));
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:44,代码来源:AutoScalingServiceTest.java
示例17: asInstances
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public static Collection<Instance> asInstances(Instance... instances) {
return new ArrayList<>(Arrays.asList(instances));
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:4,代码来源:TestUtils.java
示例18: ec2Instances
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public static List<com.amazonaws.services.ec2.model.Instance> ec2Instances(
com.amazonaws.services.ec2.model.Instance... instances) {
return new ArrayList<>(Arrays.asList(instances));
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:5,代码来源:TestUtils.java
示例19: ec2Instance
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public static com.amazonaws.services.ec2.model.Instance ec2Instance(String id, String state) {
return new com.amazonaws.services.ec2.model.Instance().withInstanceId(id)
.withInstanceType(InstanceType.M1Medium).withState(new InstanceState().withName(state));
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:5,代码来源:TestUtils.java
示例20: spotInstance
import com.amazonaws.services.autoscaling.model.Instance; //导入依赖的package包/类
public static com.amazonaws.services.ec2.model.Instance spotInstance(String spotId, String instanceId,
String state) {
return new com.amazonaws.services.ec2.model.Instance().withInstanceId(instanceId)
.withInstanceType(InstanceType.M1Medium).withState(new InstanceState().withName(state))
.withSpotInstanceRequestId(spotId);
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:7,代码来源:TestUtils.java
注:本文中的com.amazonaws.services.autoscaling.model.Instance类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论