feat: implement resource:*-clear commands

This commit is contained in:
Jose Diaz-Gonzalez
2019-03-14 12:38:59 -04:00
parent ab9f516c08
commit 9acb9e527d

View File

@@ -18,7 +18,12 @@ func CommandLimit(args []string, processType string, r Resource, global bool) (e
// CommandLimitClear implements resource:limit-clear
func CommandLimitClear(args []string, processType string, global bool) (err error) {
return nil
appName, err = getAppName(args, global)
if err != nil {
return err
}
return clearByRequestType(appName, processType, "limit")
}
// CommandReserve implements resource:reserve
@@ -32,7 +37,47 @@ func CommandReserve(args []string, processType string, r Resource, global bool)
}
// CommandReserveClear implements resource:reserve-clear
func CommandReserveClear(args []string, processType string, global bool) (err error) {
func CommandReserveClear(args []string, processType string, global bool) error {
appName, err = getAppName(args, global)
if err != nil {
return err
}
return clearByRequestType(appName, processType, "reserve")
}
func clearByRequestType(appName, processType, requestType) error {
noun := "limits"
if requestType == "reserve" {
noun = "reservation"
}
humanAppName := appName
if appName == "_all_" {
humanAppName = "default"
}
message := fmt.Sprintf("clearing %v %v", humanAppName, noun)
if processType != "_all_" {
message = fmt.Sprintf("%v (%v)", message, processType)
}
common.LogInfo2Quiet(message)
resources := []string{
"cpu",
"memory",
"memory-swap",
"network",
"network-ingress",
"network-egress",
}
for _, key := range resources {
property := propertyKey(processType, requestType, key)
err = common.PropertyDelete("resource", appName, property)
if err != nil {
return err
}
}
return nil
}