check gateway instance referenced before delete
This commit is contained in:
parent
a1c0d78d44
commit
cf085fbd1a
|
@ -14,6 +14,7 @@ import (
|
|||
elastic2 "infini.sh/framework/core/elastic"
|
||||
"infini.sh/framework/core/orm"
|
||||
"infini.sh/framework/core/proxy"
|
||||
"infini.sh/framework/core/task"
|
||||
"infini.sh/framework/core/util"
|
||||
"infini.sh/framework/modules/elastic"
|
||||
"net/http"
|
||||
|
@ -146,6 +147,53 @@ func (h *GatewayAPI) deleteInstance(w http.ResponseWriter, req *http.Request, ps
|
|||
return
|
||||
}
|
||||
|
||||
//check reference
|
||||
query := util.MapStr{
|
||||
"size": 1,
|
||||
"query": util.MapStr{
|
||||
"bool": util.MapStr{
|
||||
"must": []util.MapStr{
|
||||
{
|
||||
"term": util.MapStr{
|
||||
"metadata.labels.permit_nodes.id": util.MapStr{
|
||||
"value": id,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"terms": util.MapStr{
|
||||
"metadata.type": []string{"cluster_migration", "cluster_comparison"},
|
||||
},
|
||||
},
|
||||
},
|
||||
"must_not": []util.MapStr{
|
||||
{
|
||||
"terms": util.MapStr{
|
||||
"status": []string{task.StatusError, task.StatusComplete},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
q := &orm.Query{
|
||||
RawQuery: util.MustToJSONBytes(query),
|
||||
}
|
||||
err, result := orm.Search(task.Task{}, q)
|
||||
if err != nil {
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
if len(result.Result) > 0 {
|
||||
var taskId interface{}
|
||||
if m, ok := result.Result[0].(map[string]interface{}); ok {
|
||||
taskId = m["id"]
|
||||
}
|
||||
h.WriteError(w, fmt.Sprintf("failed to delete gateway instance [%s] since it is used by task [%v]", id, taskId), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = orm.Delete(nil, &obj)
|
||||
if err != nil {
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
|
|
|
@ -104,6 +104,7 @@ func buildTask(config *migration_model.ClusterComparisonTaskConfig, creator *rba
|
|||
"target_cluster_id": config.Cluster.Target.Id,
|
||||
"source_total_docs": sourceTotalDocs,
|
||||
"target_total_docs": targetTotalDocs,
|
||||
"permit_nodes": config.Settings.Execution.Nodes.Permit,
|
||||
},
|
||||
},
|
||||
Cancellable: true,
|
||||
|
|
|
@ -101,6 +101,7 @@ func buildTask(config *migration_model.ClusterMigrationTaskConfig, creator *rbac
|
|||
"source_cluster_id": config.Cluster.Source.Id,
|
||||
"target_cluster_id": config.Cluster.Target.Id,
|
||||
"source_total_docs": totalDocs,
|
||||
"permit_nodes": config.Settings.Execution.Nodes.Permit,
|
||||
},
|
||||
},
|
||||
Cancellable: true,
|
||||
|
|
Loading…
Reference in New Issue