This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-alarms.git
The following commit(s) were added to refs/heads/master by this push:
new 7693072 support trigger get and update for timezone parameter (#172)
7693072 is described below
commit 7693072f37d4ae215bf89bd721053b3cad341fec
Author: Jason Peterson <[email protected]>
AuthorDate: Wed Dec 12 18:56:35 2018 -0500
support trigger get and update for timezone parameter (#172)
---
action/alarmWebAction.js | 23 ++++++++++++-----
.../system/packages/AlarmsFeedNegativeTests.scala | 30 ++++++++++++++++++++++
.../scala/system/packages/AlarmsFeedTests.scala | 13 +++++++---
3 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/action/alarmWebAction.js b/action/alarmWebAction.js
index 5d6b8e4..b1586cb 100644
--- a/action/alarmWebAction.js
+++ b/action/alarmWebAction.js
@@ -38,8 +38,7 @@ function main(params) {
status: {
'active': true,
'dateChanged': Date.now()
- },
- timezone: params.timezone
+ }
};
if (params.fireOnce) {
@@ -89,6 +88,7 @@ function main(params) {
return common.sendError(400, 'cron pattern is limited
to 5 fields with 1 minute as the finest granularity');
}
newTrigger.cron = params.cron;
+ newTrigger.timezone = params.timezone;
} catch(ex) {
var message = ex.message !== 'Invalid timezone.' ? `cron
pattern '${params.cron}' is not valid` : ex.message;
return common.sendError(400, message);
@@ -188,6 +188,7 @@ function main(params) {
}
else {
body.config.cron = doc.cron;
+ body.config.timezone = doc.timezone;
}
}
resolve({
@@ -252,17 +253,25 @@ function main(params) {
}
}
else {
- if (params.cron) {
+ if (params.cron || params.timezone) {
+ var cron = params.cron || trigger.cron;
+ var timezone = params.timezone || trigger.timezone;
try {
- new CronJob(params.cron, function() {});
+ cronHandle = new CronJob(cron, function() {},
undefined, false, timezone);
//validate cron granularity if 5 fields are
allowed instead of 6
- if (params.limitCronFields &&
hasSecondsGranularity(params.cron)) {
+ if (params.cron && params.limitCronFields &&
hasSecondsGranularity(params.cron)) {
return reject(common.sendError(400, 'cron
pattern is limited to 5 fields with 1 minute as the finest granularity'));
}
} catch (ex) {
- return reject(common.sendError(400, `cron
pattern '${params.cron}' is not valid`));
+ var message = ex.message !== 'Invalid
timezone.' ? `cron pattern '${cron}' is not valid` : ex.message;
+ return reject(common.sendError(400, message));
+ }
+ if (params.cron) {
+ updatedParams.cron = params.cron;
+ }
+ if (params.timezone) {
+ updatedParams.timezone = params.timezone;
}
- updatedParams.cron = params.cron;
}
}
diff --git a/tests/src/test/scala/system/packages/AlarmsFeedNegativeTests.scala
b/tests/src/test/scala/system/packages/AlarmsFeedNegativeTests.scala
index 2d4e24e..242878b 100644
--- a/tests/src/test/scala/system/packages/AlarmsFeedNegativeTests.scala
+++ b/tests/src/test/scala/system/packages/AlarmsFeedNegativeTests.scala
@@ -126,6 +126,36 @@ class AlarmsFeedNegativeTests
}
+ it should "return error message when alarm action includes invalid
timezone parameter" in withAssetCleaner(wskprops) {
+ (wp, assetHelper) =>
+ implicit val wskprops = wp // shadow global props and make implicit
+ val triggerName = s"dummyAlarmsTrigger-${System.currentTimeMillis}"
+ val packageName = "dummyAlarmsPackage"
+ val feed = "alarm"
+
+ // the package alarms should be there
+ val packageGetResult = wsk.pkg.get("/whisk.system/alarms")
+ println("fetched package alarms")
+ packageGetResult.stdout should include("ok")
+
+ // create package binding
+ assetHelper.withCleaner(wsk.pkg, packageName) {
+ (pkg, name) => pkg.bind("/whisk.system/alarms", name)
+ }
+
+ // create trigger with feed
+ val feedCreationResult = assetHelper.withCleaner(wsk.trigger,
triggerName, confirmDelete = false) {
+ (trigger, name) =>
+ trigger.create(name, feed = Some(s"$packageName/$feed"),
parameters = Map(
+ "trigger_payload" -> "alarmTest".toJson,
+ "cron" -> "* * * * *".toJson,
+ "timezone" -> "America/RTP".toJson),
+ expectedExitCode = 246)
+ }
+ feedCreationResult.stderr should include("Invalid timezone.")
+
+ }
+
it should "return error message when alarms once action includes an
invalid date parameter" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
implicit val wskprops = wp // shadow global props and make implicit
diff --git a/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
b/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
index 05ee61b..5b3d83c 100644
--- a/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
+++ b/tests/src/test/scala/system/packages/AlarmsFeedTests.scala
@@ -83,7 +83,7 @@ class AlarmsFeedTests
activations should be(1)
}
- it should "update cron, startDate and stopDate parameters" in
withAssetCleaner(wskprops) {
+ it should "update cron, timezone, startDate and stopDate parameters" in
withAssetCleaner(wskprops) {
(wp, assetHelper) =>
implicit val wskProps = wp
val triggerName = s"dummyAlarmsTrigger-${System.currentTimeMillis}"
@@ -102,6 +102,7 @@ class AlarmsFeedTests
val cron = "* * * * *"
val startDate = System.currentTimeMillis + (1000 * 30)
val stopDate = startDate + (1000 * 100)
+ val timezone = "America/New_York"
// create trigger feed
println(s"Creating trigger: $triggerName")
@@ -110,10 +111,10 @@ class AlarmsFeedTests
trigger.create(name, feed = Some(s"$packageName/alarm"),
parameters = Map(
"cron" -> cron.toJson,
"startDate" -> startDate.toJson,
- "stopDate" -> stopDate.toJson))
+ "stopDate" -> stopDate.toJson,
+ "timezone" -> timezone.toJson))
}
-
val actionName = s"$packageName/alarm"
val readRunResult = wsk.action.invoke(actionName, parameters = Map(
"triggerName" -> triggerName.toJson,
@@ -132,6 +133,7 @@ class AlarmsFeedTests
config should contain("cron" -> cron.toJson)
config should contain("startDate" ->
startDate.toJson)
config should contain("stopDate" ->
stopDate.toJson)
+ config should contain("timezone" ->
timezone.toJson)
status should contain("active" -> true.toJson)
status should contain key "dateChanged"
@@ -143,6 +145,7 @@ class AlarmsFeedTests
val updatedCron = "*/2 * * * *"
val updatedStartDate = System.currentTimeMillis + (1000 * 30)
val updatedStopDate = updatedStartDate + (1000 * 100)
+ val updatedTimezone = "America/Los_Angeles"
val updateRunAction = wsk.action.invoke(actionName, parameters =
Map(
"triggerName" -> triggerName.toJson,
@@ -150,7 +153,8 @@ class AlarmsFeedTests
"authKey" -> wskProps.authKey.toJson,
"cron" -> updatedCron.toJson,
"startDate" -> updatedStartDate.toJson,
- "stopDate" -> updatedStopDate.toJson
+ "stopDate" -> updatedStopDate.toJson,
+ "timezone" -> updatedTimezone.toJson
))
withActivation(wsk.activation, updateRunAction) {
@@ -171,6 +175,7 @@ class AlarmsFeedTests
val config =
result.getFields("config").head.asInstanceOf[JsObject].fields
config should contain("cron" -> updatedCron.toJson)
+ config should contain("timezone" ->
updatedTimezone.toJson)
config should contain("startDate" ->
updatedStartDate.toJson)
config should contain("stopDate" ->
updatedStopDate.toJson)
}