From 9acb9e527d68bee5bac5d84f320b2e524d201163 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 14 Mar 2019 12:38:59 -0400 Subject: [PATCH] feat: implement resource:*-clear commands --- plugins/resource/subcommands.go | 49 +++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/plugins/resource/subcommands.go b/plugins/resource/subcommands.go index 80631225f..edf9b4038 100644 --- a/plugins/resource/subcommands.go +++ b/plugins/resource/subcommands.go @@ -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 }