You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Poornima BS <po...@gmail.com> on 2016/12/19 06:56:26 UTC

stopInstancesInRegion of EC2API

Hi,

I am using stopInstancesInRegion method of EC2API .

It stops the node without any issue.

The only issue i am worried about is it sends me the response when the node
is still
 in stopping state not stopped state.

By then if i raise a request for startInstancesInRegion method of EC2PI.

I throws me below stack,

instance 'i-011fd9b0646e59df9' is not in a state from which it can be
started

```

 ERROR [deploy-rest-service,194a1a8d137497c6,9ea7d8da6058b460,true] 5074
--- [nio-8090-exec-7] c.m.e.s.impl.ComputeServiceAdaptor : error: request
POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1 failed with code 400,
error: AWSError{requestId='499752fc-806d-46ed-91e9-47f8ceef2277',
requestToken='null', code='IncorrectInstanceState', message='The instance
'i-011fd9b0646e59df9' is not in a state from which it can be started.',
context='{Response=, Errors=}'}
```

How can i handle such situation in my application where i,

1. raise a request for stopping node and get back success response saying
current state is stopping.
2. raise a request for starting node i get node not in a state from which
it can be started

Please do suggest me if there is any workaround.

Thanks & Regards,
Poornima.BS

Re: stopInstancesInRegion of EC2API

Posted by Poornima BS <po...@gmail.com>.
Hi Ignasi Barrera,

That's nice let me check and get back.

Thanks for your suggestion.

Thanks & Regards,
Poornima.BS

On Wed, Dec 21, 2016 at 2:55 PM, Ignasi Barrera <na...@apache.org> wrote:

> You can also use the jclouds methods in the ComputeService to stop the
> nodes:
>
> ComputeService.suspendNode(id)
> ComputeService.suspendNodesMatching(predicate)
>
> That has the benefit that jclouds does the polling for you and waits
> until the nodes are actually stopped.
>
> On 20 December 2016 at 21:01, Andrew Phillips <ap...@qrmedia.com>
> wrote:
> >> But its tough to decide on to estimate how long a machine might take to
> >> reach STOPPED state.
> >>
> >> Anyway other option would be check the node state again and send the
> >> confirmation.
> >
> >
> > Yes, sorry, this is what I meant. I agree that inserting a "hopeful
> pause"
> > is probably too brittle; what is probably needed here is something like:
> >
> > for (i = 0 to max_attempts) {
> >   if stopped(instance) break
> >   sleep(pause_time)
> > }
> >
> > The AWS API more or less "recommends" this as an approach by providing an
> > explicit command for this:
> >
> > http://docs.aws.amazon.com/cli/latest/reference/ec2/wait/
> instance-stopped.html
> >
> > Regards
> >
> > ap
>

Re: stopInstancesInRegion of EC2API

Posted by Ignasi Barrera <na...@apache.org>.
You can also use the jclouds methods in the ComputeService to stop the nodes:

ComputeService.suspendNode(id)
ComputeService.suspendNodesMatching(predicate)

That has the benefit that jclouds does the polling for you and waits
until the nodes are actually stopped.

On 20 December 2016 at 21:01, Andrew Phillips <ap...@qrmedia.com> wrote:
>> But its tough to decide on to estimate how long a machine might take to
>> reach STOPPED state.
>>
>> Anyway other option would be check the node state again and send the
>> confirmation.
>
>
> Yes, sorry, this is what I meant. I agree that inserting a "hopeful pause"
> is probably too brittle; what is probably needed here is something like:
>
> for (i = 0 to max_attempts) {
>   if stopped(instance) break
>   sleep(pause_time)
> }
>
> The AWS API more or less "recommends" this as an approach by providing an
> explicit command for this:
>
> http://docs.aws.amazon.com/cli/latest/reference/ec2/wait/instance-stopped.html
>
> Regards
>
> ap

Re: stopInstancesInRegion of EC2API

Posted by Andrew Phillips <ap...@qrmedia.com>.
> But its tough to decide on to estimate how long a machine might take to
> reach STOPPED state.
> 
> Anyway other option would be check the node state again and send the
> confirmation.

Yes, sorry, this is what I meant. I agree that inserting a "hopeful 
pause" is probably too brittle; what is probably needed here is 
something like:

for (i = 0 to max_attempts) {
   if stopped(instance) break
   sleep(pause_time)
}

The AWS API more or less "recommends" this as an approach by providing 
an explicit command for this:

http://docs.aws.amazon.com/cli/latest/reference/ec2/wait/instance-stopped.html

Regards

ap

Re: stopInstancesInRegion of EC2API

Posted by Poornima BS <po...@gmail.com>.
Hi Andrew,

Thanks for the reply

I agree the way API is designed, its asynchronous system.

But its tough to decide on to estimate how long a machine might take to
reach STOPPED state.

Anyway other option would be check the node state again and send the
confirmation.

Please share your thoughts on this.

Thanks & regards,
Poornima.BS


On Mon, Dec 19, 2016 at 8:06 PM, Andrew Phillips <ap...@qrmedia.com>
wrote:

> How can i handle such situation in my application where i,
>>
>> 1. raise a request for stopping node and get back success response saying
>> current state is stopping.
>> 2. raise a request for starting node i get node not in a state from which
>> it can be started
>>
>
> In between 1 and 2, would it be possible for you to wait until the machine
> is actually in state STOPPED (rather than STOPPING)? The success response
> for 1 is intended, by the way: it indicates that your request to stop the
> machine was successful.
>
> Like many asynchronous systems where operations may take a long time, that
> does not mean that the request has actually *completed* - just that it has
> been *received*/is being acted upon.
>
> Regards
>
> ap
>

Re: stopInstancesInRegion of EC2API

Posted by Andrew Phillips <ap...@qrmedia.com>.
> How can i handle such situation in my application where i,
> 
> 1. raise a request for stopping node and get back success response 
> saying
> current state is stopping.
> 2. raise a request for starting node i get node not in a state from 
> which
> it can be started

In between 1 and 2, would it be possible for you to wait until the 
machine is actually in state STOPPED (rather than STOPPING)? The success 
response for 1 is intended, by the way: it indicates that your request 
to stop the machine was successful.

Like many asynchronous systems where operations may take a long time, 
that does not mean that the request has actually *completed* - just that 
it has been *received*/is being acted upon.

Regards

ap