Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable use of concurrency action limits via cli #383

Merged
merged 10 commits into from
Nov 26, 2018
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
build(['name':'golang.org/x/sys/unix', 'version':'7f918dd405547ecb864d14a8ecbbfe205b5f930f', 'transitive':false])
build(['name':'gopkg.in/yaml.v2', 'version':'cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b', 'transitive':false])
build(['name':'github.com/ghodss/yaml', 'version':'0ca9ea5df5451ffdf184b4428c902747c2c11cd7', 'transitive':false])
build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'d7cee96e83a1f38413a1f5286bd524dac72686c9','transitive':false])
build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'deb000839d59a7ed4a7be3db8bdd51d41cb1f4d4','transitive':false])
// END - Imported from Godeps
test name:'github.com/stretchr/testify', version:'b91bfb9ebec76498946beb6af7c0230c7cc7ba6c', transitive:false //, tag: 'v1.2.0'
test name:'github.com/spf13/viper', version:'aafc9e6bc7b7bb53ddaa75a5ef49a17d6e654be5', transitive:false
Expand Down
15 changes: 12 additions & 3 deletions commands/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
MEMORY_LIMIT = 256
TIMEOUT_LIMIT = 60000
LOGSIZE_LIMIT = 10
CONCURRENCY_LIMIT = 1
ACTIVATION_ID = "activationId"
WEB_EXPORT_ANNOT = "web-export"
RAW_HTTP_ANNOT = "raw-http"
Expand Down Expand Up @@ -413,9 +414,11 @@ func parseAction(cmd *cobra.Command, args []string, update bool) (*whisk.Action,
cmd.LocalFlags().Changed(MEMORY_FLAG),
cmd.LocalFlags().Changed(LOG_SIZE_FLAG),
cmd.LocalFlags().Changed(TIMEOUT_FLAG),
cmd.LocalFlags().Changed(CONCURRENCY_FLAG),
Flags.action.memory,
Flags.action.logsize,
Flags.action.timeout)
Flags.action.timeout,
Flags.action.concurrency)

paramArgs = Flags.common.param
annotArgs = Flags.common.annotation
Expand Down Expand Up @@ -886,10 +889,10 @@ func webSecureSecret(webSecureMode string) interface{} {
}
}

func getLimits(memorySet bool, logSizeSet bool, timeoutSet bool, memory int, logSize int, timeout int) *whisk.Limits {
func getLimits(memorySet bool, logSizeSet bool, timeoutSet bool, concurrencySet bool, memory int, logSize int, timeout int, concurrency int) *whisk.Limits {
var limits *whisk.Limits

if memorySet || logSizeSet || timeoutSet {
if memorySet || logSizeSet || timeoutSet || concurrencySet {
limits = new(whisk.Limits)

if memorySet {
Expand All @@ -903,6 +906,10 @@ func getLimits(memorySet bool, logSizeSet bool, timeoutSet bool, memory int, log
if timeoutSet {
limits.Timeout = &timeout
}

if concurrencySet {
limits.Concurrency = &concurrency
}
}

return limits
Expand Down Expand Up @@ -1268,6 +1275,7 @@ func init() {
actionCreateCmd.Flags().IntVarP(&Flags.action.timeout, TIMEOUT_FLAG, "t", TIMEOUT_LIMIT, wski18n.T("the timeout `LIMIT` in milliseconds after which the action is terminated"))
actionCreateCmd.Flags().IntVarP(&Flags.action.memory, MEMORY_FLAG, "m", MEMORY_LIMIT, wski18n.T("the maximum memory `LIMIT` in MB for the action"))
actionCreateCmd.Flags().IntVarP(&Flags.action.logsize, LOG_SIZE_FLAG, "l", LOGSIZE_LIMIT, wski18n.T("the maximum log size `LIMIT` in MB for the action"))
actionCreateCmd.Flags().IntVarP(&Flags.action.concurrency, CONCURRENCY_FLAG, "c", CONCURRENCY_LIMIT, wski18n.T("the maximum intra-container concurrent activation `LIMIT` for the action"))
actionCreateCmd.Flags().StringSliceVarP(&Flags.common.annotation, "annotation", "a", nil, wski18n.T("annotation values in `KEY VALUE` format"))
actionCreateCmd.Flags().StringVarP(&Flags.common.annotFile, "annotation-file", "A", "", wski18n.T("`FILE` containing annotation values in JSON format"))
actionCreateCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", nil, wski18n.T("parameter values in `KEY VALUE` format"))
Expand All @@ -1284,6 +1292,7 @@ func init() {
actionUpdateCmd.Flags().IntVarP(&Flags.action.timeout, TIMEOUT_FLAG, "t", TIMEOUT_LIMIT, wski18n.T("the timeout `LIMIT` in milliseconds after which the action is terminated"))
actionUpdateCmd.Flags().IntVarP(&Flags.action.memory, MEMORY_FLAG, "m", MEMORY_LIMIT, wski18n.T("the maximum memory `LIMIT` in MB for the action"))
actionUpdateCmd.Flags().IntVarP(&Flags.action.logsize, LOG_SIZE_FLAG, "l", LOGSIZE_LIMIT, wski18n.T("the maximum log size `LIMIT` in MB for the action"))
actionUpdateCmd.Flags().IntVarP(&Flags.action.concurrency, CONCURRENCY_FLAG, "c", CONCURRENCY_LIMIT, wski18n.T("the maximum intra-container concurrent activation `LIMIT` for the action"))
actionUpdateCmd.Flags().StringSliceVarP(&Flags.common.annotation, "annotation", "a", []string{}, wski18n.T("annotation values in `KEY VALUE` format"))
actionUpdateCmd.Flags().StringVarP(&Flags.common.annotFile, "annotation-file", "A", "", wski18n.T("`FILE` containing annotation values in JSON format"))
actionUpdateCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", []string{}, wski18n.T("parameter values in `KEY VALUE` format"))
Expand Down
46 changes: 24 additions & 22 deletions commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import (
///////////

const (
MEMORY_FLAG = "memory"
LOG_SIZE_FLAG = "logsize"
TIMEOUT_FLAG = "timeout"
WEB_FLAG = "web"
WEB_SECURE_FLAG = "web-secure"
SAVE_FLAG = "save"
SAVE_AS_FLAG = "save-as"
MEMORY_FLAG = "memory"
LOG_SIZE_FLAG = "logsize"
CONCURRENCY_FLAG = "concurrency"
TIMEOUT_FLAG = "timeout"
WEB_FLAG = "web"
WEB_SECURE_FLAG = "web-secure"
SAVE_FLAG = "save"
SAVE_AS_FLAG = "save-as"
)

var cliDebug = os.Getenv("WSK_CLI_DEBUG") // Useful for tracing init() code
Expand Down Expand Up @@ -130,21 +131,22 @@ type FlagsStruct struct {
}

type ActionFlags struct {
docker string
native bool
copy bool
web string
websecure string
sequence bool
timeout int
memory int
logsize int
result bool
kind string
main string
url bool
save bool
saveAs string
docker string
native bool
copy bool
web string
websecure string
sequence bool
timeout int
memory int
logsize int
concurrency int
result bool
kind string
main string
url bool
save bool
saveAs string
}

func IsVerbose() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import common.WskTestHelpers
import spray.json.DefaultJsonProtocol._
import spray.json._
import org.apache.openwhisk.core.entity._
import org.apache.openwhisk.core.entity.ConcurrencyLimit._
import org.apache.openwhisk.core.entity.LogLimit._
import org.apache.openwhisk.core.entity.MemoryLimit._
import org.apache.openwhisk.core.entity.TimeLimit._
Expand Down Expand Up @@ -390,14 +391,16 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
val memoryLimit = 512 MB
val logLimit = 1 MB
val timeLimit = 60 seconds
val concurrencyLimit = 500

assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(
name,
Some(TestUtils.getTestActionFilename("helloAsync.js")),
memory = Some(memoryLimit),
timeout = Some(timeLimit),
logsize = Some(logLimit))
logsize = Some(logLimit),
concurrency = Some(concurrencyLimit))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! thanks

}

val run = wsk.action.invoke(name, Map("payload" -> "this is a test".toJson))
Expand Down Expand Up @@ -2041,12 +2044,14 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
def testLimit(timeout: Option[Duration] = None,
memory: Option[ByteSize] = None,
logs: Option[ByteSize] = None,
concurrency: Option[Int] = None,
ec: Int = SUCCESS_EXIT) = {
// Limits to assert, standard values if CLI omits certain values
val limits = JsObject(
"timeout" -> timeout.getOrElse(STD_DURATION).toMillis.toJson,
"memory" -> memory.getOrElse(stdMemory).toMB.toInt.toJson,
"logs" -> logs.getOrElse(stdLogSize).toMB.toInt.toJson)
"logs" -> logs.getOrElse(stdLogSize).toMB.toInt.toJson,
"concurrency" -> concurrency.getOrElse(stdConcurrent).toJson)

val name = "ActionLimitTests" + Instant.now.toEpochMilli
val createResult =
Expand All @@ -2057,8 +2062,10 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
logsize = logs,
memory = memory,
timeout = timeout,
concurrency = concurrency,
expectedExitCode = DONTCARE_EXIT)
withClue(s"create failed for parameters: timeout = $timeout, memory = $memory, logsize = $logs:") {
withClue(
s"create failed for parameters: timeout = $timeout, memory = $memory, logsize = $logs, concurrency = $concurrency:") {
result.exitCode should be(ec)
}
result
Expand All @@ -2084,13 +2091,15 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
time <- Seq(None, Some(MIN_DURATION), Some(MAX_DURATION))
mem <- Seq(None, Some(minMemory), Some(maxMemory))
log <- Seq(None, Some(minLogSize), Some(maxLogSize))
} testLimit(time, mem, log)
concurrency <- Seq(None, Some(minConcurrent), Some(maxConcurrent))
} testLimit(time, mem, log, concurrency)

// Assert that invalid permutation are rejected
testLimit(Some(0.milliseconds), None, None, BAD_REQUEST)
testLimit(Some(100.minutes), None, None, BAD_REQUEST)
testLimit(None, Some(0.MB), None, BAD_REQUEST)
testLimit(None, Some(32768.MB), None, BAD_REQUEST)
testLimit(None, None, Some(32768.MB), BAD_REQUEST)
testLimit(Some(0.milliseconds), None, None, None, BAD_REQUEST)
testLimit(Some(100.minutes), None, None, None, BAD_REQUEST)
testLimit(None, Some(0.MB), None, None, BAD_REQUEST)
testLimit(None, Some(32768.MB), None, None, BAD_REQUEST)
testLimit(None, None, Some(32768.MB), None, BAD_REQUEST)
testLimit(None, None, None, Some(5000), BAD_REQUEST)
}
}
4 changes: 4 additions & 0 deletions wski18n/resources/en_US.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,10 @@
"id": "the maximum memory `LIMIT` in MB for the action",
"translation": "the maximum memory `LIMIT` in MB for the action"
},
{
"id": "the maximum intra-container concurrent activation `LIMIT` for the action",
"translation": "the maximum intra-container concurrent activation `LIMIT` for the action"
},
{
"id": "the maximum log size `LIMIT` in MB for the action",
"translation": "the maximum log size `LIMIT` in MB for the action"
Expand Down