From b71030dba81de0e19170dd54a63173974bf71c5f Mon Sep 17 00:00:00 2001 From: litoral05 Date: Tue, 5 May 2026 10:59:07 +0100 Subject: [PATCH] Automate router provisioning status flow --- .../openvpn/router/RouterController.java | 27 ++++++++++++++++--- .../openvpn/router/RouterService.java | 7 +++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/litoralregas/openvpn/router/RouterController.java b/src/main/java/com/litoralregas/openvpn/router/RouterController.java index 638f2ac..8c751c1 100644 --- a/src/main/java/com/litoralregas/openvpn/router/RouterController.java +++ b/src/main/java/com/litoralregas/openvpn/router/RouterController.java @@ -1,6 +1,7 @@ package com.litoralregas.openvpn.router; import com.litoralregas.openvpn.deployment.DeploymentAction; +import com.litoralregas.openvpn.deployment.DeploymentResponse; import com.litoralregas.openvpn.deployment.DeploymentService; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; @@ -49,14 +50,32 @@ public class RouterController { } @PostMapping("/{id}/provision") - public String provision(@PathVariable UUID id) { + public DeploymentResponse provision(@PathVariable UUID id) { Router router = service.findById(id); var deployment = deploymentService.startDeployment(router, DeploymentAction.PROVISION); - // simulate success - deploymentService.finishSuccess(deployment, "Provision completed"); + try { + service.forceStatus(id, RouterStatus.PROVISIONING); - return "Provision simulated"; + // Simulated provisioning for now. + var finishedDeployment = deploymentService.finishSuccess( + deployment, + "Provision completed successfully" + ); + + service.forceStatus(id, RouterStatus.PROVISIONED); + + return DeploymentResponse.from(finishedDeployment); + } catch (Exception exception) { + var failedDeployment = deploymentService.finishFailure( + deployment, + exception.getMessage() + ); + + service.forceStatus(id, RouterStatus.FAILED); + + return DeploymentResponse.from(failedDeployment); + } } } \ No newline at end of file diff --git a/src/main/java/com/litoralregas/openvpn/router/RouterService.java b/src/main/java/com/litoralregas/openvpn/router/RouterService.java index d14ad7e..36d349d 100644 --- a/src/main/java/com/litoralregas/openvpn/router/RouterService.java +++ b/src/main/java/com/litoralregas/openvpn/router/RouterService.java @@ -75,4 +75,11 @@ public class RouterService { case REMOVED -> false; }; } + + public Router forceStatus(UUID id, RouterStatus status) { + Router router = findById(id); + router.setStatus(status); + router.setUpdatedAt(LocalDateTime.now()); + return repository.save(router); + } } \ No newline at end of file