mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
enable deletion of external stale ICs #84
This commit is contained in:
parent
f77b88e7e1
commit
b513b72f87
2 changed files with 20 additions and 10 deletions
|
@ -86,6 +86,7 @@ func InitConfig() error {
|
|||
apiUpdateInterval = flag.String("api-update-interval", "10s" /* 10 sec */, "Interval in which API URL is queried for status updates of ICs")
|
||||
k8sRancherURL = flag.String("k8s-rancher-url", "https://rancher.k8s.eonerc.rwth-aachen.de", "URL of Rancher instance that is used to deploy the backend")
|
||||
k8sClusterName = flag.String("k8s-cluster-name", "local", "Name of the Kubernetes cluster where the backend is deployed")
|
||||
staleICTime = flag.String("stale-ic-time", "1h" /* 1 hour */, "Time after which an IC is considered stale")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
|
@ -121,6 +122,7 @@ func InitConfig() error {
|
|||
"apiupdateinterval": *apiUpdateInterval,
|
||||
"k8s.rancher-url": *k8sRancherURL,
|
||||
"k8s.cluster-name": *k8sClusterName,
|
||||
"staleictime": *staleICTime,
|
||||
}
|
||||
|
||||
if *dbClear {
|
||||
|
|
|
@ -24,7 +24,9 @@ package infrastructure_component
|
|||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -232,21 +234,27 @@ func deleteIC(c *gin.Context) {
|
|||
|
||||
// Check if IC is managed externally
|
||||
if s.ManagedExternally {
|
||||
// if so: refuse deletion
|
||||
helper.BadRequestError(c, "delete for externally managed IC not possible with this endpoint - use /ic/{ICID}/action endpoint instead to request deletion of the component")
|
||||
return
|
||||
|
||||
staleICTime, _ := configuration.GlobalConfig.String("staleictime")
|
||||
staleDuration, err := time.ParseDuration(staleICTime)
|
||||
if err != nil {
|
||||
helper.InternalServerError(c, "deleting externally managed IC not possible, no or erroneous stale IC time parameter provided in API config")
|
||||
return
|
||||
}
|
||||
|
||||
// check if external IC is stale
|
||||
if time.Now().Sub(s.UpdatedAt).Seconds() < staleDuration.Seconds() {
|
||||
// IC is NOT stale, refuse deletion
|
||||
helper.BadRequestError(c, "delete for externally managed non-stale IC not possible with this endpoint - use /ic/{ICID}/action endpoint instead to request deletion of the component")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the IC
|
||||
err := s.delete()
|
||||
if helper.DBError(c, err) {
|
||||
return
|
||||
} else if err != nil {
|
||||
helper.InternalServerError(c, "Unable to send delete action: "+err.Error())
|
||||
return
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"ic": s.InfrastructureComponent})
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"ic": s.InfrastructureComponent})
|
||||
}
|
||||
|
||||
// getConfigsOfIC godoc
|
||||
|
|
Loading…
Add table
Reference in a new issue