| 288 | } |
| 289 | |
| 290 | async fn start_deployment( |
| 291 | &self, |
| 292 | request: Request<api::StartFuotaDeploymentRequest>, |
| 293 | ) -> Result<Response<()>, Status> { |
| 294 | let req = request.get_ref(); |
| 295 | let id = Uuid::from_str(&req.id).map_err(|e| e.status())?; |
| 296 | |
| 297 | self.validator |
| 298 | .validate( |
| 299 | request.extensions(), |
| 300 | validator::ValidateFuotaDeploymentAccess::new(validator::Flag::Update, id), |
| 301 | ) |
| 302 | .await?; |
| 303 | |
| 304 | let mut d = fuota::get_deployment(id).await.map_err(|e| e.status())?; |
| 305 | if d.started_at.is_some() { |
| 306 | return Err(Status::failed_precondition( |
| 307 | "FUOTA deployment has already started", |
| 308 | )); |
| 309 | } |
| 310 | |
| 311 | d.started_at = Some(Utc::now()); |
| 312 | let d = fuota::update_deployment(d).await.map_err(|e| e.status())?; |
| 313 | |
| 314 | fuota::create_job(fuota::FuotaDeploymentJob { |
| 315 | fuota_deployment_id: d.id, |
| 316 | job: fields::FuotaJob::CreateMcGroup, |
| 317 | ..Default::default() |
| 318 | }) |
| 319 | .await |
| 320 | .map_err(|e| e.status())?; |
| 321 | |
| 322 | let mut resp = Response::new(()); |
| 323 | resp.metadata_mut() |
| 324 | .insert("x-log-fuota_deployment_id", req.id.parse().unwrap()); |
| 325 | Ok(resp) |
| 326 | } |
| 327 | |
| 328 | async fn list_deployments( |
| 329 | &self, |