18
18
package org .apache .openwhisk .core .database
19
19
20
20
import java .time .Instant
21
-
22
21
import akka .actor .ActorSystem
23
22
import akka .http .scaladsl .model .HttpRequest
24
23
import spray .json .JsObject
@@ -33,9 +32,13 @@ import scala.concurrent.Future
33
32
case class UserContext (user : Identity , request : HttpRequest = HttpRequest ())
34
33
35
34
trait ActivationStore {
36
-
35
+ /* DEPRECATED: disableStoreResult config is now deprecated replaced with blocking activation store level */
37
36
protected val disableStoreResultConfig = loadConfigOrThrow[Boolean ](ConfigKeys .disableStoreResult)
38
- protected val disableStoreNonBlockingResultConfig = loadConfigOrThrow[Boolean ](ConfigKeys .disableStoreNonBlockingResult)
37
+ protected val storeBlockingResultLevelConfig =
38
+ if (disableStoreResultConfig) ActivationStoreLevel .STORE_FAILURES
39
+ else ActivationStoreLevel .valueOf(loadConfigOrThrow[String ](ConfigKeys .storeBlockingResultLevel))
40
+ protected val storeNonBlockingResultLevelConfig =
41
+ ActivationStoreLevel .valueOf(loadConfigOrThrow[String ](ConfigKeys .storeNonBlockingResultLevel))
39
42
protected val unstoredLogsEnabledConfig = loadConfigOrThrow[Boolean ](ConfigKeys .unstoredLogsEnabled)
40
43
41
44
/**
@@ -44,26 +47,26 @@ trait ActivationStore {
44
47
* @param activation activation to store
45
48
* @param isBlockingActivation is activation blocking
46
49
* @param disableBlockingStore do not store activation if successful and blocking
47
- * @param disableNonBlockingStore do not store activation if successful and non-blocking
50
+ * @param nonBlockingStoreLevel do not store activation if successful and non-blocking
48
51
* @param context user and request context
49
52
* @param transid transaction ID for request
50
53
* @param notifier cache change notifier
51
54
* @return Future containing DocInfo related to stored activation
52
55
*/
53
56
def storeAfterCheck (activation : WhiskActivation ,
54
57
isBlockingActivation : Boolean ,
55
- disableBlockingStore : Option [Boolean ],
56
- disableNonBlockingStore : Option [Boolean ],
58
+ blockingStoreLevel : Option [ActivationStoreLevel . Value ],
59
+ nonBlockingStoreLevel : Option [ActivationStoreLevel . Value ],
57
60
context : UserContext )(implicit transid : TransactionId ,
58
61
notifier : Option [CacheChangeNotification ],
59
62
logging : Logging ): Future [DocInfo ] = {
60
63
if (context.user.limits.storeActivations.getOrElse(true ) &&
61
64
shouldStoreActivation(
62
- activation.response.isSuccess ,
65
+ activation,
63
66
isBlockingActivation,
64
67
transid.meta.extraLogging,
65
- disableBlockingStore .getOrElse(disableStoreResultConfig ),
66
- disableNonBlockingStore .getOrElse(disableStoreNonBlockingResultConfig ))) {
68
+ blockingStoreLevel .getOrElse(storeBlockingResultLevelConfig ),
69
+ nonBlockingStoreLevel .getOrElse(storeNonBlockingResultLevelConfig ))) {
67
70
68
71
store(activation, context)
69
72
} else {
@@ -188,18 +191,29 @@ trait ActivationStore {
188
191
* - an activation in debug mode
189
192
* - activation stores is not disabled via a configuration parameter
190
193
*
191
- * @param isSuccess is successful activation
194
+ * @param activation to check
192
195
* @param isBlocking is blocking activation
193
196
* @param debugMode is logging header set to "on" for the invocation
194
- * @param disableBlockingStore is disable store configured
197
+ * @param blockingStoreLevel level of activation status to store for blocking invocations
198
+ * @param nonBlockingStoreLevel level of activation status to store for blocking invocations
195
199
* @return Should the activation be stored to the database
196
200
*/
197
- private def shouldStoreActivation (isSuccess : Boolean ,
201
+ private def shouldStoreActivation (activation : WhiskActivation ,
198
202
isBlocking : Boolean ,
199
203
debugMode : Boolean ,
200
- disableBlockingStore : Boolean ,
201
- disableNonBlockingStore : Boolean ): Boolean = {
202
- ! isSuccess || debugMode || (! isBlocking && ! disableNonBlockingStore) || (isBlocking && ! disableBlockingStore)
204
+ blockingStoreLevel : ActivationStoreLevel .Value ,
205
+ nonBlockingStoreLevel : ActivationStoreLevel .Value ): Boolean = {
206
+ def shouldStoreOnLevel (storageLevel : ActivationStoreLevel .Value ): Boolean = {
207
+ storageLevel match {
208
+ case ActivationStoreLevel .STORE_ALWAYS => true
209
+ case ActivationStoreLevel .STORE_FAILURES => ! activation.response.isSuccess
210
+ case ActivationStoreLevel .STORE_FAILURES_NOT_APPLICATION_ERRORS =>
211
+ ! activation.response.isSuccess && ! activation.response.isApplicationError
212
+ }
213
+ }
214
+
215
+ debugMode || (isBlocking && shouldStoreOnLevel(blockingStoreLevel)) || (! isBlocking && shouldStoreOnLevel(
216
+ nonBlockingStoreLevel))
203
217
}
204
218
}
205
219
0 commit comments