You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/10/03 06:24:08 UTC
[GitHub] chetanmeh closed pull request #4035: Add support for allowedKinds
limits in wskadmin
chetanmeh closed pull request #4035: Add support for allowedKinds limits in wskadmin
URL: https://github.com/apache/incubator-openwhisk/pull/4035
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/tests/src/test/scala/whisk/core/admin/WskAdminTests.scala b/tests/src/test/scala/whisk/core/admin/WskAdminTests.scala
index 7342f3e202..353e19996b 100644
--- a/tests/src/test/scala/whisk/core/admin/WskAdminTests.scala
+++ b/tests/src/test/scala/whisk/core/admin/WskAdminTests.scala
@@ -229,4 +229,17 @@ class WskAdminTests extends TestHelpers with WskActorSystem with Matchers with B
wskadmin.cli(Seq("limits", "delete", subject)).stdout should include("Limits deleted")
}
}
+ it should "adjust whitelist for namespace" in {
+ val subject = Subject().asString
+ try {
+ // set some limits
+ wskadmin.cli(Seq("limits", "set", subject, "--allowedKinds", "nodejs:6", "blackbox"))
+ // check correctly set
+ val lines = wskadmin.cli(Seq("limits", "get", subject)).stdout.lines.toSeq
+ lines should have size 1
+ lines(0) shouldBe "allowedKinds = [u'nodejs:6', u'blackbox']"
+ } finally {
+ wskadmin.cli(Seq("limits", "delete", subject)).stdout should include("Limits deleted")
+ }
+ }
}
diff --git a/tests/src/test/scala/whisk/core/database/LimitsCommandTests.scala b/tests/src/test/scala/whisk/core/database/LimitsCommandTests.scala
index e1b1660d0a..69684dbea7 100644
--- a/tests/src/test/scala/whisk/core/database/LimitsCommandTests.scala
+++ b/tests/src/test/scala/whisk/core/database/LimitsCommandTests.scala
@@ -49,10 +49,13 @@ class LimitsCommandTests extends FlatSpec with WhiskAdminCliTestBase {
"7",
"--concurrentInvocations",
"11",
+ "--allowedKinds",
+ "nodejs:6",
+ "blackbox",
ns) shouldBe CommandMessages.limitsSuccessfullySet(ns)
val limits = limitsStore.get[LimitEntity](DocInfo(LimitsCommand.limitIdOf(EntityName(ns)))).futureValue
- limits.limits shouldBe UserLimits(Some(3), Some(7), Some(11))
+ limits.limits shouldBe UserLimits(Some(3), Some(7), Some(11), Some(Set("nodejs:6", "blackbox")))
resultOk("limits", "set", "--invocationsPerMinute", "13", ns) shouldBe CommandMessages.limitsSuccessfullyUpdated(ns)
@@ -85,6 +88,23 @@ class LimitsCommandTests extends FlatSpec with WhiskAdminCliTestBase {
resultNotOk("limits", "delete", ns) shouldBe CommandMessages.limitsNotFound(ns)
}
+ it should "update existing allowedKind limit" in {
+ val ns = newNamespace()
+ resultOk("limits", "set", "--allowedKinds", "nodejs:6", ns)
+ resultOk("limits", "get", ns) shouldBe "allowedKinds = nodejs:6"
+ resultOk("limits", "set", "--allowedKinds", "nodejs:6", "blackbox", "python", ns)
+ resultOk("limits", "get", ns) shouldBe "allowedKinds = nodejs:6, blackbox, python"
+
+ //Delete
+ resultOk("limits", "delete", ns) shouldBe CommandMessages.limitsDeleted
+
+ //Read after delete should result in default message
+ resultOk("limits", "get", ns) shouldBe CommandMessages.defaultLimits
+
+ //Delete of deleted namespace should result in error
+ resultNotOk("limits", "delete", ns) shouldBe CommandMessages.limitsNotFound(ns)
+ }
+
override def cleanup()(implicit timeout: Duration): Unit = {
implicit val tid = TransactionId.testing
limitsToDelete.map { u =>
diff --git a/tools/admin/README-NEXT.md b/tools/admin/README-NEXT.md
index 99be20a016..ac877d4034 100644
--- a/tools/admin/README-NEXT.md
+++ b/tools/admin/README-NEXT.md
@@ -121,9 +121,13 @@ The `wskadmin-next limits` commands allow you set action and trigger throttles p
$ wskadmin-next limits get space1
No limits found, default system limits apply
-# set limits
+# set limits on invocationsPerMinute
$ wskadmin-next limits set --invocationsPerMinute 1 space1
Limits successfully set for "space1"
+
+# set limits on allowedKinds
+$ wskadmin-next limits set --allowedKinds nodejs:6 python space1
+Limits successfully set for "space1"
```
Note that limits apply to a namespace and will survive even if all users that share a namespace are deleted. You must manually delete them.
diff --git a/tools/admin/README.md b/tools/admin/README.md
index 23c68e2f58..19d15c0028 100644
--- a/tools/admin/README.md
+++ b/tools/admin/README.md
@@ -75,9 +75,13 @@ The `wskadmin limits` commands allow you set action and trigger throttles per na
$ wskadmin limits get space1
No limits found, default system limits apply
-# set limits
+# set limits on invocationsPerMinute
$ wskadmin limits set space1 --invocationsPerMinute 1
Limits successfully set for "space1"
+
+# set limits on allowedKinds
+$ wskadmin limits set space1 --allowedKinds nodejs:6 python
+Limits successfully set for "space1"
```
Note that limits apply to a namespace and will survive even if all users that share a namespace are deleted. You must manually delete them.
diff --git a/tools/admin/src/main/scala/whisk/core/database/LimitsCommand.scala b/tools/admin/src/main/scala/whisk/core/database/LimitsCommand.scala
index 6de66e198c..4e0e6e0244 100644
--- a/tools/admin/src/main/scala/whisk/core/database/LimitsCommand.scala
+++ b/tools/admin/src/main/scala/whisk/core/database/LimitsCommand.scala
@@ -64,11 +64,22 @@ class LimitsCommand extends Subcommand("limits") with WhiskCommand {
validate = _ >= 0,
name = "concurrentInvocations",
noshort = true)
+ val allowedKinds =
+ opt[List[String]](
+ descr = "list of runtime kinds allowed in this namespace",
+ argName = "ALLOWEDKINDS",
+ name = "allowedKinds",
+ noshort = true,
+ default = None)
lazy val limits: LimitEntity =
new LimitEntity(
EntityName(namespace()),
- UserLimits(invocationsPerMinute.toOption, firesPerMinute.toOption, concurrentInvocations.toOption))
+ UserLimits(
+ invocationsPerMinute.toOption,
+ firesPerMinute.toOption,
+ concurrentInvocations.toOption,
+ allowedKinds.toOption.map(_.toSet)))
}
addSubcommand(set)
@@ -126,7 +137,8 @@ class LimitsCommand extends Subcommand("limits") with WhiskCommand {
val msg = Seq(
l.concurrentInvocations.map(ci => s"concurrentInvocations = $ci"),
l.invocationsPerMinute.map(i => s"invocationsPerMinute = $i"),
- l.firesPerMinute.map(i => s"firesPerMinute = $i")).flatten.mkString(Properties.lineSeparator)
+ l.firesPerMinute.map(i => s"firesPerMinute = $i"),
+ l.allowedKinds.map(k => s"allowedKinds = ${k.mkString(", ")}")).flatten.mkString(Properties.lineSeparator)
Right(msg)
}
.recover {
diff --git a/tools/admin/wskadmin b/tools/admin/wskadmin
index 74b8ebaad5..39342a77ab 100755
--- a/tools/admin/wskadmin
+++ b/tools/admin/wskadmin
@@ -131,6 +131,7 @@ def parseArgs():
subcmd.add_argument('--invocationsPerMinute', help='invocations per minute allowed', type=int)
subcmd.add_argument('--firesPerMinute', help='trigger fires per minute allowed', type=int)
subcmd.add_argument('--concurrentInvocations', help='concurrent invocations allowed for this namespace', type=int)
+ subcmd.add_argument('--allowedKinds', help='list of runtime kinds allowed in this namespace', nargs='+', type=str)
subcmd = subparser.add_parser('get', help='get limits for a given namespace (if none exist, system defaults apply)')
subcmd.add_argument('namespace', help='the namespace to get limits for')
@@ -516,7 +517,7 @@ def setLimitsCmd(args, props):
(dbDoc, res) = getDocumentFromDb(props, quote_plus(docId), args.verbose)
doc = dbDoc or {'_id': docId}
- limits = ['invocationsPerMinute', 'firesPerMinute', 'concurrentInvocations']
+ limits = ['invocationsPerMinute', 'firesPerMinute', 'concurrentInvocations', 'allowedKinds']
for limit in limits:
givenLimit = argsDict.get(limit)
toSet = givenLimit if givenLimit != None else doc.get(limit)
@@ -535,7 +536,7 @@ def getLimitsCmd(args, props):
(dbDoc, res) = getDocumentFromDb(props, quote_plus(docId), args.verbose)
if dbDoc is not None:
- limits = ['invocationsPerMinute', 'firesPerMinute', 'concurrentInvocations']
+ limits = ['invocationsPerMinute', 'firesPerMinute', 'concurrentInvocations', 'allowedKinds']
for limit in limits:
givenLimit = dbDoc.get(limit)
if givenLimit != None:
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services