当前位置: 首页>>代码示例>>Java>>正文


Java Instance类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.Instance的典型用法代码示例。如果您正苦于以下问题:Java Instance类的具体用法?Java Instance怎么用?Java Instance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Instance类属于com.amazonaws.services.ec2.model包,在下文中一共展示了Instance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInstanceState

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
public String getInstanceState(String instanceId) {
    LOGGER.debug("getInstanceState('{}') entered", instanceId);
    DescribeInstancesResult result = getEC2().describeInstances(
            new DescribeInstancesRequest().withInstanceIds(instanceId));
    List<Reservation> reservations = result.getReservations();
    Set<Instance> instances = new HashSet<Instance>();

    for (Reservation reservation : reservations) {
        instances.addAll(reservation.getInstances());
        if (instances.size() > 0) {
            String state = instances.iterator().next().getState().getName();
            LOGGER.debug("  InstanceState: {}", state);
            return state;
        }
    }
    LOGGER.debug("getInstanceState('{}') left", instanceId);
    return null;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:EC2Communication.java

示例2: convertInstanceToServer

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
private List<Server> convertInstanceToServer(List<Instance> instances) {
    List<Server> servers = new ArrayList<>();
    for (Instance instance : instances) {
        Server server = new Server(instance.getInstanceId());
        for (Tag tag : instance.getTags()) {
            if (tag != null && tag.getKey() != null
                    && tag.getKey().equals("Name")) {
                server.setName(tag.getValue());
            }
        }
        server.setStatus(instance.getState().getName());
        server.setType(instance.getInstanceType());
        server.setPublicIP(Arrays.asList(instance.getPublicIpAddress()));
        server.setPrivateIP(Arrays.asList(instance.getPrivateIpAddress()));
        servers.add(server);
    }
    return servers;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:EC2Processor.java

示例3: getInstancesMapForZone

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
@Override
public Map<AvailabilityZone, List<Instance>> getInstancesMapForZone(
    AvailabilityZone zone, AmazonEC2Client client) throws Exception {

  OperationStats op = new OperationStats("ec2InstanceStore", "getInstancesMapForZone");

  try {
    Map<AvailabilityZone, List<Instance>> ret = new HashMap<>();
    ret.put(zone, getInstancesForZone(zone, client));

    op.succeed();
    return ret;

  } catch (Exception e) {

    op.failed();
    logger.error(ExceptionUtils.getRootCauseMessage(e));
    throw e;
  }
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:21,代码来源:Ec2InstanceStore.java

示例4: getAwsInstanceProperties

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
protected HashMap getAwsInstanceProperties(Instance awsInstance) throws Exception {
  HashMap map = mapper.readValue(mapper.writeValueAsString(awsInstance), HashMap.class);

  if (awsInstance.getMonitoring() != null && awsInstance.getMonitoring().getState() != null) {
    //Have to comply with the current AWS_V1 schema
    map.put("monitoring", awsInstance.getMonitoring().getState().toString());
  }

  if (awsInstance.getPlacement() != null
      && awsInstance.getPlacement().getAvailabilityZone() != null) {
    //Be backward compatible for tools
    Map placement = (Map) map.get("placement");
    if (placement != null) {
      placement.put("availability_zone", awsInstance.getPlacement().getAvailabilityZone());
    }
  }
  return map;
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:19,代码来源:AbstractEsInstanceFactory.java

示例5: calculateDailyInstanceCounts

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
private Boolean calculateDailyInstanceCounts() {

    try {

      DateTime utcNow = DateTime.now(DateTimeZone.UTC);

      List<Instance> instances = cloudInstanceStore.getInstances(region);
      List<ReservedInstances> reservedInstances = cloudInstanceStore.getReservedInstances(region);

      // Generate instance counts per type per Availability zone
      List<EsInstanceCountRecord> instanceCountRecords =
          getInstanceCountRecords(instances, reservedInstances, utcNow);
      logger.info("Number of instance count records {}", instanceCountRecords.size());

      // Insert records into soundwave store.
      instanceCounterStore.bulkInsert(instanceCountRecords);
      logger.info("Bulk insert succeeded for instance count records");

      return true;

    } catch (Exception e) {

      logger.error(ExceptionUtils.getRootCauseMessage(e));
      return false;
    }
  }
 
开发者ID:pinterest,项目名称:soundwave,代码行数:27,代码来源:DailyInstanceCountPerTypeJob.java

示例6: logReconcileStats

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
private void logReconcileStats(Collection<Instance> ec2Instances,
                               Collection<EsInstance> cmdbInstances) {

  int ec2RunningCount = 0;
  for (Instance inst : ec2Instances) {
    if (inst.getState().getCode() == 16) {
      //EC2 API may return some terminated instances. Only get the running count
      ec2RunningCount++;
    }
  }
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "ec2TotalRunningCount"), ec2RunningCount);
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "cmdbTotalRunningCount"),
      cmdbInstances.size());
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "diffcount"),
      Math.abs(ec2RunningCount - cmdbInstances.size()));

  int serviceMappingMissingCount = 0;
  for (EsInstance instance : cmdbInstances) {
    /*if (instance.getServiceMappings() == null || instance.getServiceMappings().length == 0) {
      serviceMappingMissingCount++;
    }*/
  }
  Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "servicemappingmissingcount"),
      serviceMappingMissingCount);

}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:27,代码来源:ReconcileWithAwsJob.java

示例7: getUpdateTags

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
/**
 * Return a list of tags that need to be updated to the Ec2Instance.
 * The tags are either not in Ec2Instance tags or having different
 * values
 * @param ec2Instance
 * @param esInstance
 * @return A list of tags
 */
public List<Tag> getUpdateTags(Instance ec2Instance, EsInstance esInstance) {
  Preconditions.checkNotNull(ec2Instance);
  Preconditions.checkNotNull(esInstance);
  List<Tag> updateTags = new ArrayList<>();

  List<Tag> currentEc2Tag = ec2Instance.getTags();
  List<Tag> esUploadTags = getUpdateTags(esInstance);

  for (Tag tag : esUploadTags) {
    boolean shouldUpdate = true;
    for (Tag ec2Tag : currentEc2Tag) {
      if (ec2Tag.getKey().equals(tag.getKey()) && ec2Tag.getValue().equals(tag.getValue())) {
        shouldUpdate = false;
        break;
      }
    }

    if (shouldUpdate) {
      updateTags.add(tag);
    }
  }

  return updateTags;

}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:34,代码来源:UploadTagsGenerator.java

示例8: getInstanceStateName

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
public String getInstanceStateName(InstanceRequest instanceRequest, Context context) {

		AmazonEC2Async client = createEC2Client();
		try {
			DescribeInstancesResult result = client
					.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceRequest.getInstanceId()));
			List<Instance> instances = result.getReservations().get(0).getInstances();
			if (instances.size() != 1) {
				throw new RuntimeException("instance can not be found.");
			}
			return instances.get(0).getState().getName();

		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:17,代码来源:InstanceOperation.java

示例9: runSearch

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
private void runSearch(T type) {
    AmazonWebServiceRequest descRequest = buildRequest(type);
    AsyncHandler describeHandler = buildHandler(type);
    if (type instanceof Instance) {
        this.amazonEC2Client.describeInstancesAsync(
                (DescribeInstancesRequest) descRequest, describeHandler);
    } else if (type instanceof NatGateway) {
        this.amazonEC2Client.describeNatGatewaysAsync(
                (DescribeNatGatewaysRequest) descRequest, describeHandler);
    } else if (type instanceof Volume) {
        this.amazonEC2Client.describeVolumesAsync(
                (DescribeVolumesRequest) descRequest, describeHandler);
    } else {
        AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(
                new IllegalArgumentException("Invalid type " + type));
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:18,代码来源:AWSTaskStatusChecker.java

示例10: onSuccess

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
@Override
public void onSuccess(DescribeInstancesRequest request,
        DescribeInstancesResult result) {
    OperationContext.restoreOperationContext(this.opContext);
    int totalNumberOfInstances = 0;
    // Print the details of the instances discovered on the AWS endpoint
    for (Reservation r : result.getReservations()) {
        for (Instance i : r.getInstances()) {
            ++totalNumberOfInstances;
            final int finalTotal1 = totalNumberOfInstances;
            this.service.logFine(() -> String.format("%d=====Instance details %s =====",
                    finalTotal1, i.getInstanceId()));
            this.aws.remoteInstanceIds.add(i.getInstanceId());
        }
    }
    final int finalTotal2 = totalNumberOfInstances;
    this.service.logFine(() -> String.format("Successfully enumerated %d instances on the"
                    + " AWS host.", finalTotal2));
    this.aws.subStage = this.next;
    ((AWSEnumerationAndDeletionAdapterService) this.service)
            .deleteResourcesInLocalSystem(this.aws);
    return;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:24,代码来源:AWSEnumerationAndDeletionAdapterService.java

示例11: getAwsInstancesByIds

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
/**
 * Method to get Instance details directly from Amazon
 *
 * @throws Throwable
 */
public static List<Instance> getAwsInstancesByIds(AmazonEC2AsyncClient client,
        VerificationHost host, List<String> instanceIds)
        throws Throwable {
    host.log("Getting instances with ids " + instanceIds
            + " from the AWS endpoint using the EC2 client.");

    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
            .withInstanceIds(instanceIds);

    DescribeInstancesResult describeInstancesResult = client
            .describeInstances(describeInstancesRequest);

    return describeInstancesResult.getReservations().stream()
            .flatMap(r -> r.getInstances().stream()).collect(Collectors.toList());
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:TestAWSSetupUtils.java

示例12: registerAWSInstancesToLoadBalancer

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
private static void registerAWSInstancesToLoadBalancer(VerificationHost host,
        AmazonElasticLoadBalancingAsyncClient client, String name, List<String> instanceIds) {
    RegisterInstancesWithLoadBalancerRequest registerRequest = new RegisterInstancesWithLoadBalancerRequest()
            .withLoadBalancerName(name)
            .withInstances(instanceIds.stream()
                    .map(com.amazonaws.services.elasticloadbalancing.model.Instance::new)
                    .collect(Collectors.toList())
            );

    RegisterInstancesWithLoadBalancerResult result = null;
    try {
        result = client.registerInstancesWithLoadBalancer(registerRequest);
    } catch (Exception e) {
        host.log(Level.SEVERE, "Error registering instances with load balancer %s",
                Utils.toString(e));
    }

    assertNotNull(result);
    assertFalse(result.getInstances().isEmpty());
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:TestAWSSetupUtils.java

示例13: testGetComputeDescriptionKeyFromAWSInstance

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
@Test
public void testGetComputeDescriptionKeyFromAWSInstance() throws Throwable {
    Map<String, ZoneData> zones = new HashMap<>();
    zones.put(AWS_ZONE_ID, ZoneData.build(AWS_REGION_ID, AWS_ZONE_ID, ""));

    Instance awsInstance = new Instance();
    awsInstance.setInstanceId(AWS_INSTANCE_ID);
    Placement placement = new Placement();
    placement.setAvailabilityZone(AWS_ZONE_ID);
    awsInstance.setPlacement(placement);
    String regionId = getRegionId(awsInstance);
    awsInstance.setInstanceType(AWS_INSTANCE_TYPE);
    awsInstance.setVpcId(AWS_VPC_ID);
    assertEquals(AWS_REGION_ID, regionId);
    InstanceDescKey computeDescriptionKey = getKeyForComputeDescriptionFromInstance(awsInstance,
            zones);
    assertEquals(AWS_COMPUTE_DESCRIPTION_KEY, computeDescriptionKey);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:19,代码来源:TestAWSEnumerationUtils.java

示例14: assertBootDiskConfiguration

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
protected void assertBootDiskConfiguration(AmazonEC2AsyncClient client, Instance awsInstance,
        String diskLink) {
    DiskState diskState = getDiskState(diskLink);

    Volume bootVolume = getVolume(client, awsInstance, awsInstance.getRootDeviceName());

    assertEquals("Boot Disk capacity in diskstate is not matching the boot disk size of the "
            + "vm launched in aws", diskState.capacityMBytes, bootVolume.getSize() * 1024);

    assertEquals(
            "Boot disk type in diskstate is not same as the type of the volume attached to the VM",
            diskState.customProperties.get("volumeType"), bootVolume.getVolumeType());

    assertEquals(
            "Boot disk iops in diskstate is the same as the iops of the volume attached to the VM",
            Integer.parseInt(diskState.customProperties.get("iops")),
            bootVolume.getIops().intValue());

    assertEquals("Boot disk attach status is not matching", DiskService.DiskStatus.ATTACHED, diskState.status);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:TestAWSProvisionTask.java

示例15: getVolume

import com.amazonaws.services.ec2.model.Instance; //导入依赖的package包/类
protected Volume getVolume(AmazonEC2AsyncClient client, Instance awsInstance, String deviceName) {
    InstanceBlockDeviceMapping bootDiskMapping = awsInstance.getBlockDeviceMappings().stream()
            .filter(blockDeviceMapping -> blockDeviceMapping.getDeviceName().equals(deviceName))
            .findAny()
            .orElse(null);

    //The ami used in this test is an ebs-backed AMI
    assertNotNull("Device type should be ebs type", bootDiskMapping.getEbs());

    String bootVolumeId = bootDiskMapping.getEbs().getVolumeId();
    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest()
            .withVolumeIds(bootVolumeId);
    DescribeVolumesResult describeVolumesResult = client
            .describeVolumes(describeVolumesRequest);

    return describeVolumesResult.getVolumes().get(0);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:18,代码来源:TestAWSProvisionTask.java


注:本文中的com.amazonaws.services.ec2.model.Instance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。