[ADD] add api for deleting label

This commit is contained in:
GLYASAI 2018-12-04 13:35:27 +08:00
parent 59742714d8
commit daa8503108
5 changed files with 30 additions and 3 deletions

View File

@ -206,6 +206,7 @@ func (v2 *V2) serviceRouter() chi.Router {
r.Delete("/node-label", controller.GetManager().NodeLabel)
// label
r.Post("/label", controller.GetManager().Label)
r.Delete("/label", controller.GetManager().Label)
//插件
r.Mount("/plugin", v2.serviceRelatePluginRouter())

View File

@ -929,7 +929,7 @@ func (t *TenantStruct) Label(w http.ResponseWriter, r *http.Request) {
}
func (t *TenantStruct) AddLabel(w http.ResponseWriter, r *http.Request) {
logrus.Debugf("add http rule.")
logrus.Debugf("add label")
var req api_model.LabelStruct
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil)
if !ok {
@ -947,7 +947,21 @@ func (t *TenantStruct) AddLabel(w http.ResponseWriter, r *http.Request) {
}
func (t *TenantStruct) DeleteLabel(w http.ResponseWriter, r *http.Request) {
logrus.Debugf("delete label")
var req api_model.LabelStruct
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil)
if !ok {
return
}
reqJSON, _ := json.Marshal(req)
logrus.Debugf("Request is : %s", string(reqJSON))
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
if err := handler.GetServiceManager().DeleteLabel(req.LabelKey, serviceID, req.LabelValues); err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("delete node label failure, %v", err))
return
}
httputil.ReturnSuccess(r, w, nil)
}
//DeleteNodeLabel DeleteLabel

View File

@ -280,8 +280,9 @@ func (s *ServiceAction) DeleteLabel(kind, serviceID string, amp []string) error
switch kind {
case "node":
return db.GetManager().TenantServiceLabelDao().DELTenantServiceLabelsByLabelvaluesAndServiceID(serviceID, amp)
default:
return db.GetManager().TenantServiceLabelDao().DelTenantServiceLabels(serviceID, kind, amp)
}
return nil
}
//UpdateServiceLabel UpdateLabel

View File

@ -244,6 +244,7 @@ type TenantServiceLabelDao interface {
GetTenantServiceAffinityLabel(serviceID string) ([]*model.TenantServiceLable, error)
GetTenantServiceTypeLabel(serviceID string) (*model.TenantServiceLable, error)
DELTenantServiceLabelsByLabelvaluesAndServiceID(serviceID string, labelValues []string) error
DelTenantServiceLabels(serviceID string, labelKey string, labelValues []string) error
}
//LocalSchedulerDao 本地调度信息

View File

@ -1263,3 +1263,13 @@ func (t *ServiceLabelDaoImpl) DELTenantServiceLabelsByLabelvaluesAndServiceID(se
}
return nil
}
//DelTenantServiceLabels deletes labels
func (t *ServiceLabelDaoImpl) DelTenantServiceLabels(serviceID string, labelKey string, labelValues []string) error {
var label model.TenantServiceLable
if err := t.DB.Where("service_id=? and label_key=? and label_value in (?)",
serviceID, labelKey, labelValues).Delete(&label).Error; err != nil {
return err
}
return nil
}