當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonEC2Client.describeInstances方法代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2Client.describeInstances方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2Client.describeInstances方法的具體用法?Java AmazonEC2Client.describeInstances怎麽用?Java AmazonEC2Client.describeInstances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.ec2.AmazonEC2Client的用法示例。


在下文中一共展示了AmazonEC2Client.describeInstances方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: describeInstances

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private void describeInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } 
    DescribeInstancesResult result;
    try {
        result = ec2Client.describeInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Describe Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    Message message = getMessageForResponse(exchange);
    message.setBody(result);        
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:EC2Producer.java

示例2: fetchReservations

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private List<Reservation> fetchReservations(final AmazonEC2Client amazonEC2Client, final CloudTrailEvent event, final List<String> instanceIds){
    final DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();


    DescribeInstancesResult describeInstancesResult = null;
    try {
        describeInstancesResult = amazonEC2Client
                .describeInstances(describeInstancesRequest.withInstanceIds(instanceIds));
    }
    catch (final AmazonServiceException e) {

        LOG.warn("Subnet plugin: {}", e.getErrorMessage());
        return null;
    }

    return describeInstancesResult.getReservations();

}
 
開發者ID:zalando-stups,項目名稱:fullstop,代碼行數:19,代碼來源:SubnetPlugin.java

示例3: processEvent

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
// @HystrixCommand(fallback = my coole exception)
// command for account id and client type -> generate new credentials
public void processEvent(final CloudTrailEvent event) {

    final String parameters = event.getEventData().getRequestParameters();
    final String instanceId = getFromParameters(parameters);

    final AmazonEC2Client client = getClientForAccount(
            event.getEventData().getUserIdentity().getAccountId(),
            Region.getRegion(Regions.fromName(event.getEventData().getAwsRegion())));

    final DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.setInstanceIds(Collections.singleton(instanceId));

    // try
    final DescribeInstancesResult result = client.describeInstances(request);
    // catch credentials are old
    // throw new my coole exception ( account id, CLIENTTYPE.EC2, exception) -> this will trigger hystrix

    LOG.info("SAVING RESULT INTO MAGIC DB", result);
}
 
開發者ID:zalando-stups,項目名稱:fullstop,代碼行數:23,代碼來源:ExamplePlugin.java

示例4: fetchEC2

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private void fetchEC2(final Region region) {
    Path ec2Path = Paths.get(currentDir, "ec2");
    ec2Path.toFile().mkdir();

    AmazonEC2Client amazonEC2Client = new AmazonEC2Client();
    amazonEC2Client.setRegion(region);

    DescribeInstancesResult describeInstancesResult = amazonEC2Client.describeInstances();
    List<Reservation> reservations = describeInstancesResult.getReservations();
    for (Reservation reservation : reservations) {
        List<Instance> instances = reservation.getInstances();
        for (Instance instance : instances) {
            System.out.println("instance id: " + instance.getInstanceId());
        }
    }

}
 
開發者ID:Gregsen,項目名稱:aws-queen,代碼行數:18,代碼來源:FetchCLI.java

示例5: getInstancesForZone

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
public List<Instance> getInstancesForZone(AvailabilityZone zone, AmazonEC2Client client)
    throws Exception {
  OperationStats op = new OperationStats("ec2InstanceStore", "getInstancesForZone");
  try {
    List<Instance> ret = new ArrayList<>();
    DescribeInstancesRequest request = new DescribeInstancesRequest()
        .withMaxResults(1000)
        .withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName())))
        .withSdkClientExecutionTimeout(
            600 * 1000) //10 minutes time out for total execution including retries
        .withSdkRequestTimeout(300 * 1000); //5 minutes time out for a single request

    List<Reservation> reservations = new ArrayList<>();
    DescribeInstancesResult result = client.describeInstances(request);
    while (result != null) {
      reservations.addAll(result.getReservations());
      if (result.getNextToken() != null) {
        request.setNextToken(result.getNextToken());
        result = client.describeInstances(request);
      } else {
        result = null;
      }
    }

    for (Reservation reservation : reservations) {
      //Reservation refers to one launch command in EC2. Most time it should
      //only contains one instance
      for (Instance inst : reservation.getInstances()) {
        ret.add(inst);
      }
    }
    op.succeed();
    return ret;
  } catch (Exception ex) {
    op.failed();
    throw ex;
  }
}
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:40,代碼來源:Ec2InstanceStore.java

示例6: collectGroupMetaData

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private List<CloudVmMetaDataStatus> collectGroupMetaData(AuthenticatedContext ac, AmazonAutoScalingClient amazonASClient,
        AmazonEC2Client amazonEC2Client, AmazonCloudFormationClient amazonCFClient, String groupName, List<CloudInstance> cloudInstances) {

    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();

    String asGroupName = cloudFormationStackUtil.getAutoscalingGroupName(ac, amazonCFClient, groupName);
    List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(amazonASClient, asGroupName);

    DescribeInstancesRequest instancesRequest = cloudFormationStackUtil.createDescribeInstancesRequest(instanceIds);
    DescribeInstancesResult instancesResult = amazonEC2Client.describeInstances(instancesRequest);

    //contains instances with instanceId
    Map<String, CloudInstance> mapByInstanceId = mapByInstanceId(cloudInstances);

    //contains instances with privateId (without instanceId)
    Queue<CloudInstance> untrackedInstances = untrackedInstances(cloudInstances);

    for (Reservation reservation : instancesResult.getReservations()) {
        LOGGER.info("Number of instances found in reservation: {}", reservation.getInstances().size());
        for (Instance instance : reservation.getInstances()) {

            String instanceId = instance.getInstanceId();
            CloudInstance cloudInstance = ensureInstanceTag(mapByInstanceId, instance, instanceId, untrackedInstances, amazonEC2Client);
            if (cloudInstance != null) {
                CloudInstanceMetaData md = new CloudInstanceMetaData(instance.getPrivateIpAddress(), instance.getPublicIpAddress());
                CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
                CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, md);
                cloudVmMetaDataStatuses.add(cloudVmMetaDataStatus);
            }
        }
    }

    return cloudVmMetaDataStatuses;
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:35,代碼來源:AwsMetadataCollector.java

示例7: removeInstanceIdsWhichAreNotInCorrectState

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private Collection<String> removeInstanceIdsWhichAreNotInCorrectState(Collection<String> instances, AmazonEC2Client amazonEC2Client, String state) {
    DescribeInstancesResult describeInstances = amazonEC2Client.describeInstances(
            new DescribeInstancesRequest().withInstanceIds(instances));
    for (Reservation reservation : describeInstances.getReservations()) {
        for (Instance instance : reservation.getInstances()) {
            if (state.equalsIgnoreCase(instance.getState().getName())) {
                instances.remove(instance.getInstanceId());
            }
        }
    }
    return instances;
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:13,代碼來源:AwsInstanceConnector.java

示例8: init

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private static void init() throws Exception
{
	//vamos buscar um historico de metricas guardados na memoria persistente do Load Balancer e guardamos na memoria interna para acesso mais rapido
	internalStorage = Request.getRanksFromPersistentMemory();
	if(internalStorage == null)
		internalStorage = new HashMap<String,BigInteger>();
	
	Connection.setupServer();
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException(
                "Cannot load the credentials from the credential profiles file. " +
                "Please make sure that your credentials file is at the correct " +
                "location (~/.aws/credentials), and is in valid format.",
                e);
    }
    ec2 = new AmazonEC2Client(credentials);
    cloudWatch= new AmazonCloudWatchClient(credentials);

    try {
        /* Using AWS Ireland. Pick the zone where you have AMI, key and secgroup */
        ec2.setEndpoint("ec2.eu-west-1.amazonaws.com");
        cloudWatch.setEndpoint("monitoring.eu-west-1.amazonaws.com");

        describeInstancesResult = ec2.describeInstances();
        reservations = describeInstancesResult.getReservations();
        listOfActiveInstances = new ArrayList<InstanceObject>();

		//funcionamento:vamos buscar todas as instancias e guardamos numa lista auxiliar, depois metemos na lista definitiva
		//apenas as instancias que estao a correr

		ArrayList<Instance> auxListOfInstances = new ArrayList<Instance>();
        for (Reservation reservation : reservations) {
        	auxListOfInstances.addAll(reservation.getInstances());
        }
		lockListOfActiveInstances.lock();
        for (Instance instance : auxListOfInstances) {
        	if(AutoScaling.checkInstanceState(instance)) //se a instancia estiver running, adicionamo-la
        	{
        		if(!instance.getInstanceId().equals(Connection.checkInstanceId())) //id do load balancer, nao adicionamos este as instancias
        		{
        			InstanceObject instanceObject = new InstanceObject(instance);
        			listOfActiveInstances.add(instanceObject);
        		}
        	}
        }
		lockListOfActiveInstances.unlock();

        instanceDimension = new Dimension();
        instanceDimension.setName("InstanceId");
        List<Dimension> dims = new ArrayList<Dimension>();
        dims.add(instanceDimension);

    } catch (AmazonServiceException ase) {    		
    		lockListOfActiveInstances.unlock();
            System.out.println("Caught Exception: " + ase.getMessage());
            System.out.println("Reponse Status Code: " + ase.getStatusCode());
            System.out.println("Error Code: " + ase.getErrorCode());
            System.out.println("Request ID: " + ase.getRequestId());
    }

    Thread thread = new ThreadScaling();
    thread.start(); //thread responsavel pela monitorizacao das instancias (Fara o papel de Auto Scaling)

    //vamos ter outra thread que e responsavel por fazer os health checks das instancias iniciais
    Thread threadHealth = new ThreadHealthChecks();
    threadHealth.start();
}
 
開發者ID:carlosfaria94,項目名稱:CloudPrime,代碼行數:70,代碼來源:LoadBalancer.java

示例9: describeInstances

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
public List<Reservation> describeInstances(AWSCredentials crendentials) {
	AmazonEC2Client client = amazonEC2ClientFactory.createAmazonEC2Client(crendentials);
	DescribeInstancesResult describeInstancesResult = client.describeInstances();
	return describeInstancesResult.getReservations();
}
 
開發者ID:sequenceiq,項目名稱:sequenceiq-samples,代碼行數:7,代碼來源:SimpleInstanceService.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2Client.describeInstances方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。