Automate router provisioning status flow

This commit is contained in:
litoral05
2026-05-05 10:59:07 +01:00
parent c952eb2eaa
commit b71030dba8
2 changed files with 30 additions and 4 deletions
@@ -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);
}
}
}
@@ -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);
}
}