2012-10-10 78 views

回答

2

請求日誌快照是一個3步過程。首先,你需要做的的環境信息請求:

elasticBeanstalk.requestEnvironmentInfo(
    new RequestEnvironmentInfoRequest() 
     .withEnvironmentName(envionmentName) 
     .withInfoType("tail")); 

然後你中檢索環境信息:

final List<EnvironmentInfoDescription> envInfos = 
    elasticBeanstalk.retrieveEnvironmentInfo(
     new RetrieveEnvironmentInfoRequest() 
      .withEnvironmentName(environmentName) 
      .withInfoType("tail")).getEnvironmentInfo(); 

這將返回環境信息說明的列表,與EC2實例ID和URL到包含日誌快照的S3對象。然後您可以通過以下方式檢索日誌:

DefaultHttpClient client = new DefaultHttpClient(); 
    DefaultHttpRequestRetryHandler retryhandler = 
     new DefaultHttpRequestRetryHandler(3, true); 
    client.setHttpRequestRetryHandler(retryhandler); 

    for (EnvironmentInfoDescription environmentInfoDescription : envInfos) { 
     System.out.println(environmentInfoDescription.getEc2InstanceId()); 
     HttpGet rq = new HttpGet(environmentInfoDescription.getMessage()); 
     try {      
      HttpResponse response = client.execute(rq); 
      InputStream content = response.getEntity().getContent();      
      System.out.println(IOUtils.toString(content)); 
     } catch (Exception e) { 
      System.out.println("Exception fetching " + 
       environmentInfoDescription.getMessage()); 
     } 
    } 

我希望這有助於您!

+0

第三步我將用'new URL(desc.getMessage())。getContent()' – yegor256

+0

來替換注意環境信息不可立即使用,我們應該循環等待(〜10-15秒在我的情況下) – yegor256