Skip to content

Commit ac42477

Browse files
committed
Supports backwards compatibility for new limit config
1 parent eba9904 commit ac42477

File tree

9 files changed

+79
-32
lines changed

9 files changed

+79
-32
lines changed

common/scala/src/main/resources/application.conf

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -511,32 +511,33 @@ whisk {
511511
default-list-limit = 30 # default limit on number of entities returned from a collection on a list operation
512512
}
513513

514-
# default namespace limit that users can set themselves
515-
namespace-default-limit {
516-
memory {
517-
min = 128 m
518-
max = 512 m
519-
}
520-
time-limit {
521-
min = 100 ms
522-
max = 5 m
523-
}
524-
log-limit {
525-
min = 0 m
526-
max = 10 m
527-
}
528-
concurrency-limit {
529-
min = 1
530-
max = 1
531-
}
532-
parameter-size-limit = 1 m
533-
activation {
534-
payload {
535-
max = 1 m
536-
truncation = 1 m
537-
}
538-
}
539-
}
514+
# default namespace limit settings
515+
# Disabled for backwards compatibility. If you want to use it, either uncomment it or add the setting at deployment time.
516+
# namespace-default-limit {
517+
# memory {
518+
# min = 128 m
519+
# max = 512 m
520+
# }
521+
# time-limit {
522+
# min = 100 ms
523+
# max = 5 m
524+
# }
525+
# log-limit {
526+
# min = 0 m
527+
# max = 10 m
528+
# }
529+
# concurrency-limit {
530+
# min = 1
531+
# max = 1
532+
# }
533+
# parameter-size-limit = 1 m
534+
# activation {
535+
# payload {
536+
# max = 1 m
537+
# truncation = 1 m
538+
# }
539+
# }
540+
# }
540541

541542
yarn {
542543
master-url="http://localhost:8088" //YARN Resource Manager endpoint to be accessed from the invoker

common/scala/src/main/scala/org/apache/openwhisk/core/entity/ActivationEntityLimit.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ case class ActivationEntityLimitConf(serdesOverhead: ByteSize, payload: Activati
3232
*/
3333
protected[core] object ActivationEntityLimit {
3434
private val config = loadConfigOrThrow[ActivationEntityLimitConf](ConfigKeys.activation)
35-
private val namespacePayloadLimitConfig =
35+
private val namespacePayloadLimitConfig = try {
3636
loadConfigOrThrow[ActivationEntityPayload](ConfigKeys.namespaceActivationPayloadLimit)
37+
} catch {
38+
case _: Throwable =>
39+
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
40+
ActivationEntityPayload(config.payload.max, config.payload.truncation)
41+
}
3742

3843
// system limit
3944
protected[core] val MAX_ACTIVATION_ENTITY_LIMIT: ByteSize = config.payload.max

common/scala/src/main/scala/org/apache/openwhisk/core/entity/ConcurrencyLimit.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ protected[core] object ConcurrencyLimit extends ArgNormalizer[ConcurrencyLimit]
6565
val config = ConfigFactory.load().getConfig("test")
6666
private val concurrencyConfig =
6767
loadConfigWithFallbackOrThrow[ConcurrencyLimitConfig](config, ConfigKeys.concurrencyLimit)
68-
private val namespaceConcurrencyDefaultConfig =
68+
private val namespaceConcurrencyDefaultConfig = try {
6969
loadConfigWithFallbackOrThrow[NamespaceConcurrencyLimitConfig](config, ConfigKeys.namespaceConcurrencyLimit)
70+
} catch {
71+
case _: Throwable =>
72+
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
73+
NamespaceConcurrencyLimitConfig(concurrencyConfig.min, concurrencyConfig.max)
74+
}
7075

7176
/**
7277
* These system limits and namespace default limits are set once at the beginning.

common/scala/src/main/scala/org/apache/openwhisk/core/entity/LogLimit.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ protected[core] class LogLimit private (val megabytes: Int) extends AnyVal {
6868

6969
protected[core] object LogLimit extends ArgNormalizer[LogLimit] {
7070
val config = loadConfigOrThrow[MemoryLimitConfig](ConfigKeys.logLimit)
71-
val namespaceDefaultConfig = loadConfigOrThrow[NamespaceMemoryLimitConfig](ConfigKeys.namespaceLogLimit)
71+
val namespaceDefaultConfig = try {
72+
loadConfigOrThrow[NamespaceMemoryLimitConfig](ConfigKeys.namespaceLogLimit)
73+
} catch {
74+
case _: Throwable =>
75+
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
76+
NamespaceMemoryLimitConfig(config.min, config.max)
77+
}
7278
val logLimitFieldName = "log"
7379

7480
/**

common/scala/src/main/scala/org/apache/openwhisk/core/entity/MemoryLimit.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ protected[entity] class MemoryLimit private (val megabytes: Int) extends AnyVal
6565

6666
protected[core] object MemoryLimit extends ArgNormalizer[MemoryLimit] {
6767
val config = loadConfigOrThrow[MemoryLimitConfig](ConfigKeys.memory)
68-
val namespaceDefaultConfig = loadConfigOrThrow[NamespaceMemoryLimitConfig](ConfigKeys.namespaceMemoryLimit)
68+
val namespaceDefaultConfig = try {
69+
loadConfigOrThrow[NamespaceMemoryLimitConfig](ConfigKeys.namespaceMemoryLimit)
70+
} catch {
71+
case _: Throwable =>
72+
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
73+
NamespaceMemoryLimitConfig(config.min, config.max)
74+
}
6975
val memoryLimitFieldName = "memory"
7076

7177
/**

common/scala/src/main/scala/org/apache/openwhisk/core/entity/Parameter.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ protected[entity] case class ParameterValue protected[entity] (private val v: Js
217217
protected[core] object Parameters extends ArgNormalizer[Parameters] {
218218

219219
protected[core] val MAX_SIZE = loadConfigOrThrow[ByteSize](ConfigKeys.parameterSizeLimit) // system limit
220-
protected[core] val MAX_SIZE_DEFAULT = loadConfigOrThrow[ByteSize](ConfigKeys.namespaceParameterSizeLimit) // namespace default limit
220+
protected[core] val MAX_SIZE_DEFAULT = try {
221+
loadConfigOrThrow[ByteSize](ConfigKeys.namespaceParameterSizeLimit)
222+
} catch {
223+
case _: Throwable =>
224+
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
225+
MAX_SIZE
226+
}
221227

222228
require(MAX_SIZE >= MAX_SIZE_DEFAULT, "The system limit must be greater than the namespace limit.")
223229

common/scala/src/main/scala/org/apache/openwhisk/core/entity/TimeLimit.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ case class TimeLimitConfig(max: FiniteDuration, min: FiniteDuration, std: Finite
6868

6969
protected[core] object TimeLimit extends ArgNormalizer[TimeLimit] {
7070
val config = loadConfigOrThrow[TimeLimitConfig](ConfigKeys.timeLimit)
71-
val namespaceDefaultConfig = loadConfigOrThrow[NamespaceTimeLimitConfig](ConfigKeys.namespaceTimeLimit)
71+
val namespaceDefaultConfig = try {
72+
loadConfigOrThrow[NamespaceTimeLimitConfig](ConfigKeys.namespaceTimeLimit)
73+
} catch {
74+
case _: Throwable =>
75+
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
76+
NamespaceTimeLimitConfig(config.max, config.min)
77+
}
7278
val timeLimitFieldName = "duration"
7379

7480
/**

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ object Controller {
215215
"triggers_per_minute" -> config.triggerFirePerMinuteLimit.toInt.toJson,
216216
"concurrent_actions" -> config.actionInvokeConcurrentLimit.toInt.toJson,
217217
"sequence_length" -> config.actionSequenceLimit.toInt.toJson,
218+
"default_min_action_duration" -> TimeLimit.namespaceDefaultConfig.min.toMillis.toJson,
219+
"default_max_action_duration" -> TimeLimit.namespaceDefaultConfig.max.toMillis.toJson,
220+
"default_min_action_memory" -> MemoryLimit.namespaceDefaultConfig.min.toBytes.toJson,
221+
"default_max_action_memory" -> MemoryLimit.namespaceDefaultConfig.max.toBytes.toJson,
222+
"default_min_action_logs" -> LogLimit.namespaceDefaultConfig.min.toBytes.toJson,
223+
"default_max_action_logs" -> LogLimit.namespaceDefaultConfig.max.toBytes.toJson,
218224
"min_action_duration" -> timeLimit.min.toMillis.toJson,
219225
"max_action_duration" -> timeLimit.max.toMillis.toJson,
220226
"min_action_memory" -> memLimit.min.toBytes.toJson,

tests/src/test/scala/org/apache/openwhisk/core/controller/test/ControllerApiTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class ControllerApiTests extends FlatSpec with RestUtil with Matchers with Strea
5757
"triggers_per_minute" -> config.triggerFirePerMinuteLimit.toInt.toJson,
5858
"concurrent_actions" -> config.actionInvokeConcurrentLimit.toInt.toJson,
5959
"sequence_length" -> config.actionSequenceLimit.toInt.toJson,
60+
"default_min_action_duration" -> TimeLimit.namespaceDefaultConfig.min.toMillis.toJson,
61+
"default_max_action_duration" -> TimeLimit.namespaceDefaultConfig.max.toMillis.toJson,
62+
"default_min_action_memory" -> MemoryLimit.namespaceDefaultConfig.min.toBytes.toJson,
63+
"default_max_action_memory" -> MemoryLimit.namespaceDefaultConfig.max.toBytes.toJson,
64+
"default_min_action_logs" -> LogLimit.namespaceDefaultConfig.min.toBytes.toJson,
65+
"default_max_action_logs" -> LogLimit.namespaceDefaultConfig.max.toBytes.toJson,
6066
"min_action_duration" -> TimeLimit.config.min.toMillis.toJson,
6167
"max_action_duration" -> TimeLimit.config.max.toMillis.toJson,
6268
"min_action_memory" -> MemoryLimit.config.min.toBytes.toJson,

0 commit comments

Comments
 (0)