You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/12/19 18:27:12 UTC

Adding an error state to the instance state machine

basically $SUBJECT... openstack instances (and likely other clouds too)
can enter a 'error' state. This adds the new state and a 'from' keyword
to the state machine dsl... comments on syntax etc welcome (e.g. making this an
'auto' transition, makes sense?)

thanks, marios

[PATCH] Adds error state to state machine model (+openstack)

Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>


Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/deltacloud/drivers/base_driver.rb                | 2 +-
 server/lib/deltacloud/drivers/openstack/openstack_driver.rb | 3 ++-
 server/lib/deltacloud/models/state_machine.rb               | 8 ++++++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index c63f94f..96a1b6c 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -26,7 +26,7 @@ module Deltacloud
     include Exceptions
 
     STATE_MACHINE_OPTS = {
-      :all_states => [:start, :pending, :running, :stopping, :stopped, :finish],
+      :all_states => [:start, :pending, :running, :stopping, :stopped, :finish, :error],
       :all_actions => [:create, :reboot, :stop, :start, :destroy]
     } unless defined?(STATE_MACHINE_OPTS)
 
diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
index ee9957a..6d0ae9c 100644
--- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
+++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
@@ -40,6 +40,7 @@ module Deltacloud
           running.to( :stopping )       .on( :stop )
           stopping.to( :stopped )       .automatically
           stopped.to( :finish )         .automatically
+          error.from(:running, :pending, :stopping)
         end
 
         define_hardware_profile('default')
@@ -541,7 +542,7 @@ private
             when /build.*$/
               "PENDING"
             when /error.*/
-              "STOPPED"
+              "ERROR"
             when /active/
               "RUNNING"
             else
diff --git a/server/lib/deltacloud/models/state_machine.rb b/server/lib/deltacloud/models/state_machine.rb
index cbdaf4a..c03b6a4 100644
--- a/server/lib/deltacloud/models/state_machine.rb
+++ b/server/lib/deltacloud/models/state_machine.rb
@@ -81,6 +81,14 @@ module Deltacloud
         transition
       end
 
+      def from(*states)
+        states.each do |s|
+          initial = @machine.state(s)
+          trans = initial.to self.name
+          trans.automatically
+        end
+      end
+
     end
 
     class Transition
-- 
1.7.11.7


Re: Adding an error state to the instance state machine

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2013-01-24 at 11:40 +1100, Koper, Dies wrote:
> Hi Marios,
> 
> For completion's sake, let me describe what I eventually pushed last night.
> 
> > This patch is about the instance entering an error state - not sure if
> > 'STOP_ERROR' for example is the same; do you mean it returns an error
> > code for instance, or the actual instance goes into the 'stop_error'
> > state... in which case you could use the deltacloud error state.
> 
> The actual instance goes into the 'stop_error' state.
> Fgcp has three 'error' states, ERROR, STOP_ERROR and START_ERROR.
> However, the allowable actions on instances in these states differ.
> With ERROR, it seems most operations are not allowed, while STOP_ERROR is basically equivalent to RUNNING and START_ERROR is equivalent to STOPPED in respect to what operations you can do on them.
> So that is how I have mapped them.

For the sake of completeness, you could have mapped all three to error;
describe in the state machine all the actions that are possible from the
error state, and list in the actions section of an individual machine
only the ones that are possible based on the finer-grained FGCP error
states.

Though whether what you have vs what I describe is better largely
depends on whether the user needs to know that an error happened in
START_ERROR or STOP_ERROR.

David



RE: Adding an error state to the instance state machine

Posted by "Koper, Dies" <di...@fast.au.fujitsu.com>.
Hi Marios,

For completion's sake, let me describe what I eventually pushed last night.

> This patch is about the instance entering an error state - not sure if
> 'STOP_ERROR' for example is the same; do you mean it returns an error
> code for instance, or the actual instance goes into the 'stop_error'
> state... in which case you could use the deltacloud error state.

The actual instance goes into the 'stop_error' state.
Fgcp has three 'error' states, ERROR, STOP_ERROR and START_ERROR.
However, the allowable actions on instances in these states differ.
With ERROR, it seems most operations are not allowed, while STOP_ERROR is basically equivalent to RUNNING and START_ERROR is equivalent to STOPPED in respect to what operations you can do on them.
So that is how I have mapped them.

Regards,
Dies Koper

> -----Original Message-----
> From: marios@redhat.com [mailto:mandreou@redhat.com]
> Sent: Thursday, 20 December 2012 7:12 PM
> To: dev@deltacloud.apache.org
> Cc: Koper, Dies
> Subject: Re: Adding an error state to the instance state machine
> 
> On 20/12/12 05:50, Koper, Dies wrote:
> > (How) do we advertise what operations are possible on a machine in the
> error state?
> 
> you can use the existing syntax - i've made 'error' a bona-fide state
> now, so you could do something like:
> 
> error.to(:finish) .on(:destroy)
> 
> for example.
> 
> > From the documentation, Fgcp API can return STOP_ERROR when it failed
> to stop, START_ERROR when it failed to start and ERROR in other error cases
> (error during fail-over, creating snapshots, etc.).
> 
> This patch is about the instance entering an error state - not sure if
> 'STOP_ERROR' for example is the same; do you mean it returns an error
> code for instance, or the actual instance goes into the 'stop_error'
> state... in which case you could use the deltacloud error state.
> 
> 
> marios
> 
> >
> > Regards,
> > Dies Koper
> >
> >
> >> -----Original Message-----
> >> From: Michal Fojtik [mailto:mi@mifo.sk]
> >> Sent: Thursday, 20 December 2012 8:04 AM
> >> To: dev@deltacloud.apache.org
> >> Subject: Re: Adding an error state to the instance state machine
> >>
> >> +1 oVirt and possibly VSphere does have 'UNKNOWN' or 'ERROR' state too.
> In
> >> that case only possible operation is 'destroy'.
> >>
> >>
> >> On Wed, Dec 19, 2012 at 11:57 PM, David Lutterkort
> >> <lu...@redhat.com>wrote:
> >>
> >>> On Wed, 2012-12-19 at 19:27 +0200, marios@redhat.com wrote:
> >>>> basically $SUBJECT... openstack instances (and likely other clouds too)
> >>>> can enter a 'error' state. This adds the new state and a 'from' keyword
> >>>> to the state machine dsl... comments on syntax etc welcome (e.g.
> making
> >>> this an
> >>>> 'auto' transition, makes sense?)
> >>>>
> >>>> thanks, marios
> >>>
> >>> ACK; makes sense to me.
> >>>
> >>> David
> >>>
> >>>
> >>>
> >>
> >>
> >> --
> >> -----------------------------------------------
> >> Michal Fojtik <mf...@mifo.sk>
> >> Enthusiastic Ruby programmer.
> 


Re: Adding an error state to the instance state machine

Posted by "marios@redhat.com" <ma...@redhat.com>.
On 20/12/12 05:50, Koper, Dies wrote:
> (How) do we advertise what operations are possible on a machine in the error state?

you can use the existing syntax - i've made 'error' a bona-fide state
now, so you could do something like:

error.to(:finish) .on(:destroy)

for example.

> From the documentation, Fgcp API can return STOP_ERROR when it failed to stop, START_ERROR when it failed to start and ERROR in other error cases (error during fail-over, creating snapshots, etc.).

This patch is about the instance entering an error state - not sure if
'STOP_ERROR' for example is the same; do you mean it returns an error
code for instance, or the actual instance goes into the 'stop_error'
state... in which case you could use the deltacloud error state.


marios

> 
> Regards,
> Dies Koper
> 
> 
>> -----Original Message-----
>> From: Michal Fojtik [mailto:mi@mifo.sk]
>> Sent: Thursday, 20 December 2012 8:04 AM
>> To: dev@deltacloud.apache.org
>> Subject: Re: Adding an error state to the instance state machine
>>
>> +1 oVirt and possibly VSphere does have 'UNKNOWN' or 'ERROR' state too. In
>> that case only possible operation is 'destroy'.
>>
>>
>> On Wed, Dec 19, 2012 at 11:57 PM, David Lutterkort
>> <lu...@redhat.com>wrote:
>>
>>> On Wed, 2012-12-19 at 19:27 +0200, marios@redhat.com wrote:
>>>> basically $SUBJECT... openstack instances (and likely other clouds too)
>>>> can enter a 'error' state. This adds the new state and a 'from' keyword
>>>> to the state machine dsl... comments on syntax etc welcome (e.g. making
>>> this an
>>>> 'auto' transition, makes sense?)
>>>>
>>>> thanks, marios
>>>
>>> ACK; makes sense to me.
>>>
>>> David
>>>
>>>
>>>
>>
>>
>> --
>> -----------------------------------------------
>> Michal Fojtik <mf...@mifo.sk>
>> Enthusiastic Ruby programmer.


RE: Adding an error state to the instance state machine

Posted by "Koper, Dies" <di...@fast.au.fujitsu.com>.
(How) do we advertise what operations are possible on a machine in the error state?
From the documentation, Fgcp API can return STOP_ERROR when it failed to stop, START_ERROR when it failed to start and ERROR in other error cases (error during fail-over, creating snapshots, etc.).

Regards,
Dies Koper


> -----Original Message-----
> From: Michal Fojtik [mailto:mi@mifo.sk]
> Sent: Thursday, 20 December 2012 8:04 AM
> To: dev@deltacloud.apache.org
> Subject: Re: Adding an error state to the instance state machine
> 
> +1 oVirt and possibly VSphere does have 'UNKNOWN' or 'ERROR' state too. In
> that case only possible operation is 'destroy'.
> 
> 
> On Wed, Dec 19, 2012 at 11:57 PM, David Lutterkort
> <lu...@redhat.com>wrote:
> 
> > On Wed, 2012-12-19 at 19:27 +0200, marios@redhat.com wrote:
> > > basically $SUBJECT... openstack instances (and likely other clouds too)
> > > can enter a 'error' state. This adds the new state and a 'from' keyword
> > > to the state machine dsl... comments on syntax etc welcome (e.g. making
> > this an
> > > 'auto' transition, makes sense?)
> > >
> > > thanks, marios
> >
> > ACK; makes sense to me.
> >
> > David
> >
> >
> >
> 
> 
> --
> -----------------------------------------------
> Michal Fojtik <mf...@mifo.sk>
> Enthusiastic Ruby programmer.

Re: Adding an error state to the instance state machine

Posted by Michal Fojtik <mi...@mifo.sk>.
+1 oVirt and possibly VSphere does have 'UNKNOWN' or 'ERROR' state too. In
that case only possible operation is 'destroy'.


On Wed, Dec 19, 2012 at 11:57 PM, David Lutterkort <lu...@redhat.com>wrote:

> On Wed, 2012-12-19 at 19:27 +0200, marios@redhat.com wrote:
> > basically $SUBJECT... openstack instances (and likely other clouds too)
> > can enter a 'error' state. This adds the new state and a 'from' keyword
> > to the state machine dsl... comments on syntax etc welcome (e.g. making
> this an
> > 'auto' transition, makes sense?)
> >
> > thanks, marios
>
> ACK; makes sense to me.
>
> David
>
>
>


-- 
-----------------------------------------------
Michal Fojtik <mf...@mifo.sk>
Enthusiastic Ruby programmer.

Re: Adding an error state to the instance state machine

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2012-12-19 at 19:27 +0200, marios@redhat.com wrote:
> basically $SUBJECT... openstack instances (and likely other clouds too)
> can enter a 'error' state. This adds the new state and a 'from' keyword
> to the state machine dsl... comments on syntax etc welcome (e.g. making this an
> 'auto' transition, makes sense?)
> 
> thanks, marios

ACK; makes sense to me.

David