Automate router provisioning status flow
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.litoralregas.openvpn.router;
|
package com.litoralregas.openvpn.router;
|
||||||
|
|
||||||
import com.litoralregas.openvpn.deployment.DeploymentAction;
|
import com.litoralregas.openvpn.deployment.DeploymentAction;
|
||||||
|
import com.litoralregas.openvpn.deployment.DeploymentResponse;
|
||||||
import com.litoralregas.openvpn.deployment.DeploymentService;
|
import com.litoralregas.openvpn.deployment.DeploymentService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -49,14 +50,32 @@ public class RouterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/provision")
|
@PostMapping("/{id}/provision")
|
||||||
public String provision(@PathVariable UUID id) {
|
public DeploymentResponse provision(@PathVariable UUID id) {
|
||||||
Router router = service.findById(id);
|
Router router = service.findById(id);
|
||||||
|
|
||||||
var deployment = deploymentService.startDeployment(router, DeploymentAction.PROVISION);
|
var deployment = deploymentService.startDeployment(router, DeploymentAction.PROVISION);
|
||||||
|
|
||||||
// simulate success
|
try {
|
||||||
deploymentService.finishSuccess(deployment, "Provision completed");
|
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;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user