@@ -38,8 +38,15 @@ impl Handler<RefreshTick> for UpdateAgent {
38
38
let update = release. clone ( ) ;
39
39
self . try_stage_update ( update)
40
40
}
41
- UpdateAgentState :: UpdateStaged ( _release) => self . todo ( ) ,
42
- UpdateAgentState :: _EndState => self . nop ( ) ,
41
+ UpdateAgentState :: UpdateStaged ( release) => {
42
+ let update = release. clone ( ) ;
43
+ self . try_finalize_update ( update)
44
+ }
45
+ UpdateAgentState :: UpdateFinalized ( release) => {
46
+ let update = release. clone ( ) ;
47
+ self . end ( update)
48
+ }
49
+ UpdateAgentState :: EndState => self . nop ( ) ,
43
50
} ;
44
51
45
52
let update_machine = state_action. then ( move |_r, actor, ctx| {
@@ -127,6 +134,26 @@ impl UpdateAgent {
127
134
Box :: new ( state_change)
128
135
}
129
136
137
+ /// Try to finalize an update.
138
+ fn try_finalize_update ( & mut self , release : Release ) -> ResponseActFuture < Self , ( ) , ( ) > {
139
+ trace ! ( "trying to finalize an update" ) ;
140
+
141
+ let can_finalize = self . strategy . can_finalize ( & self . identity ) ;
142
+ let state_change = actix:: fut:: wrap_future :: < _ , Self > ( can_finalize)
143
+ . and_then ( |can_finalize, actor, _ctx| actor. finalize_deployment ( can_finalize, release) )
144
+ . map ( |release, actor, _ctx| actor. state . update_finalized ( release) ) ;
145
+
146
+ Box :: new ( state_change)
147
+ }
148
+
149
+ /// Actor job is done.
150
+ fn end ( & mut self , release : Release ) -> ResponseActFuture < Self , ( ) , ( ) > {
151
+ log:: info!( "update applied, waiting for reboot: {}" , release. version) ;
152
+ let state_change = self . nop ( ) . map ( |_r, actor, _ctx| actor. state . end ( ) ) ;
153
+
154
+ Box :: new ( state_change)
155
+ }
156
+
130
157
/// Fetch and stage an update, in finalization-locked mode.
131
158
fn locked_upgrade (
132
159
& mut self ,
@@ -148,15 +175,30 @@ impl UpdateAgent {
148
175
Box :: new ( upgrade)
149
176
}
150
177
178
+ /// Finalize a deployment (unlock and reboot).
179
+ fn finalize_deployment (
180
+ & mut self ,
181
+ can_finalize : bool ,
182
+ release : Release ,
183
+ ) -> ResponseActFuture < Self , Release , ( ) > {
184
+ if !can_finalize {
185
+ return Box :: new ( actix:: fut:: err ( ( ) ) ) ;
186
+ }
187
+
188
+ let msg = rpm_ostree:: FinalizeDeployment { release } ;
189
+ let upgrade = self
190
+ . rpm_ostree_actor
191
+ . send ( msg)
192
+ . flatten ( )
193
+ . map_err ( |e| log:: error!( "failed to finalize update: {}" , e) )
194
+ . into_actor ( self ) ;
195
+
196
+ Box :: new ( upgrade)
197
+ }
198
+
151
199
/// Do nothing, without errors.
152
200
fn nop ( & mut self ) -> ResponseActFuture < Self , ( ) , ( ) > {
153
201
let nop = actix:: fut:: ok ( ( ) ) ;
154
202
Box :: new ( nop)
155
203
}
156
-
157
- /// Pending implementation.
158
- fn todo ( & mut self ) -> ResponseActFuture < Self , ( ) , ( ) > {
159
- log:: error!( "pending implementation" ) ;
160
- self . nop ( )
161
- }
162
204
}
0 commit comments