2012-01-12 9 views
6

मैं एडब्ल्यूएस पर कुछ सामान स्वचालित करने की कोशिश कर रहा हूं और मैं ऐसा करने के लिए जावा एपीआई का उपयोग कर रहा हूं। मैं उन उदाहरणों की संख्या लॉन्च करने में सक्षम हूं, लेकिन मैं सही वर्ग या विधि नहीं ढूंढ पा रहा हूं जो मुझे उदाहरण की वर्तमान स्थिति (जैसे चलना, बंद करना आदि) ला सकता है।ईसी 2 इंस्टेंस की स्थिति प्राप्त करना जावा एपीआई

मैं इस

DescribeInstanceStatusRequest describeInstance = new DescribeInstanceStatusRequest().withInstanceIds(instances.get(i).getInstanceId()); DescribeInstanceStatusResult attr = ec2.describeInstanceStatus(describeInstance); List<InstanceStatus> state = attr.getInstanceStatuses();

यकीन नहीं करने की कोशिश की उदाहरण स्थिति एक सूची

किसी कृपया मुझे सही API कॉल को इंगित कर सकते हैं यही कारण है कि।

अग्रिम धन्यवाद

उत्तर

6

मुझे इस मुद्दे का पता चला। , इस मुद्दे

प्रलेखन (http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstanceStatus.html) से कम से कोड

DescribeInstanceStatusRequest describeInstanceRequest = new DescribeInstanceStatusRequest().withInstanceIds(i-xxxxxxxx); 
DescribeInstanceStatusResult describeInstanceResult = ec2.describeInstanceStatus(describeInstanceRequest); 
List<InstanceStatus> state = describeInstanceResult.getInstanceStatuses(); 
while (state.size() < 1) { 
    // Do nothing, just wait, have thread sleep if needed 
    describeInstanceResult = ec2.describeInstanceStatus(describeInstanceRequest); 
    state = describeInstanceResult.getInstanceStatuses(); 
} 
String status = state.get(0).getInstanceState().getName(); 
+0

अब मैं उस ईसी 2 इंस्टेंस पर टॉमकैट शुरू होने तक कैसे प्रतीक्षा करूं? । –

+1

और तुम 'DescribeInstanceStatusRequest अनुरोध = नए DescribeInstanceStatusRequest (कर सकते हैं आप सभी उदाहरणों की स्थिति प्राप्त करना चाहते हैं) withIncludeAllInstances (सही) \t \t \t \t .withInstanceIds (instanceIds);' –

3

मैं सिर्फ देख रहा था काम कर

DescribeInstanceStatus केवल चल रहा है राज्य में उदाहरण के लिए जानकारी देता है।

तो यदि आप पुनरारंभ करने के बजाय मशीन को रोक दिया गया है तो आप हमेशा के लिए प्रतीक्षा कर सकते हैं।

DescribeInstances (http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html) सभी मशीनों की स्थिति देता है।

+0

इस एक विशिष्ट उपयोग के मामले में होता है और मैं जानता था कि यह पुनरारंभ या शुरू हो रहा है और बंद नहीं किया गया है। यह प्रश्न कुछ समय पहले पोस्ट किया गया था और मुझे यकीन नहीं है कि एडब्ल्यूएस एपीआई बदल गई है या नहीं। – tazo

संबंधित मुद्दे