-
Notifications
You must be signed in to change notification settings - Fork 294
Fixes #1113 & #1131 and Resolves #1126; improves task creation process in snapctl
#1127
Fixes #1113 & #1131 and Resolves #1126; improves task creation process in snapctl
#1127
Conversation
// an error (at least some of the defined window should be in the future) | ||
if time.Now().Add(createTaskNowPad).After(stop) { | ||
return fmt.Errorf("Usage error (poorly defined time window); when constructing a new 'windowed' schedule, part of that window must be in the future") | ||
} else if start.After(stop) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the else if
and just use if
as each statement will return from the function with an error if the if
statement is true.
8baf9fd
to
c604a50
Compare
if t.MaxFailures == 0 { | ||
fmt.Println("If the number of maximum failures is not specified, use default value of", DefaultMaxFailures) | ||
t.MaxFailures = DefaultMaxFailures | ||
// merge any CLI optiones specified by the user (if any) into the current task; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optiones -> options
snapctl
snapctl
@@ -100,14 +100,225 @@ func createTask(ctx *cli.Context) error { | |||
return err | |||
} | |||
|
|||
func stringValToInt(val string) (int, error) { | |||
// parse the input (string) value as an integer (log a Fatal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just word this comment as return an error instead of logging a fatal error message since we don't actually log a message in snapctl, but just return an error to the user.
d4b8d54
to
ce8cb50
Compare
ce8cb50
to
7e2913e
Compare
} | ||
|
||
// Parses the command-line parameters (if any) and uses them to override the underlying | ||
// sehedule for this task or to set a schedule for that task (if one is not already defined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
schedule*
edit:
Also looks like there are 2 spaces between for and this in for this
.
51a03eb
to
24749fd
Compare
LGTM. @geauxvirtual do you have any outstanding concerns? |
24749fd
to
667009f
Compare
} | ||
// if only the start date/time was specified, we will use it to replace | ||
// the current schedule's start date/time | ||
if start != nil && stop == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a condition if both start and stop are not nil to set StartTime and StopTime to those values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geauxvirtual; I just pushed up a change that I think addresses both this line comment and your next one (by ensuring that either value will be set if the corresponding input is non-nil)
667009f
to
6461ec4
Compare
} | ||
// if a start, stop, or duration value was provided, then it's a 'windowed' schedule | ||
isWindowed := (start != nil || stop != nil || duration != nil) | ||
// if there was an interval was passed in, then attempt to parse it (first as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there was an interval passed in
or if an interval was passed in
6461ec4
to
86f287e
Compare
// if start and stop were both defined, then return an error (since all three parameters cannot be used | ||
// to define the 'windowed' schedule) | ||
if start != nil && stop != nil { | ||
return fmt.Errorf("Usage error (too many parameters); only two of the parameters that define the window (start time, stop time and duration) can be specified for a 'windowed' schedule") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message needs to be reworded. There are technically 5 parameters that can be specified for a windowed schedule: start-time, start-date, stop-time, stop-date, and duration.
86f287e
to
11fd0da
Compare
// if start is set and stop is not then use duration to create stop | ||
if start != nil && stop == nil { | ||
newStop := start.Add(*duration) | ||
t.Schedule.StopTime = &newStop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this needs t.Schedule.StartTime = start
11fd0da
to
e8a77d3
Compare
… when creating a task using snapctl
LGTM |
Fixes #1113
Fixes #1131
Fixes #285
Resolves #1126
Summary of changes
There are two sets of changes in this pull request. The first, which fix Issue #1113 are fairly simple and don't change the behavior of the system at all. They can be summarized as follows:
core/task.go
file that used to set themax-failure
value to10
for all tasks, replacing it with a conditional that set the underlying option only in those cases where aMaxFailures
value was included as part of the task creation request.scheduler/task.go
file so that the value of theDefaultStopOnFailure
constant defined in that file is set to10
(making it consistent with the behavior that used to be defined elsewhere but was inconsistently set to a value of3
in this file)DefaultMaxFailures
constant) from thecmd/snapctl/flags.go
andmgmt/rest/flags.go
filesmax-failures
parameter so that it is a string flag rather than an integer flag and added code to parse this string value as an integer (and throw an error if the value passed in through this command-line flag cannot be parsed as an integer). This removes the string(default: 0)
from the help output for thesnapctl task create ...
command.The second set of changes were made to resolve Issue #1126. This set of changes does modify the behavior of the system, changing the
snapctl
command so that it honors any command-line flags that the user might have set, regardless of whether the user is creating a task using a task manifest or a workflow manifest. In the case where the user is creating a task using a task manifest and has included (new) definitions for parameters in appear that task manifest as command-line arguments, those command-line argument values will take precedence over the values defined in the task manifest. The changes in this second commit can best be summarized as follows:task
interface that can be used to parse any command-line parameters that might have been set by the user so that those command-line parameter values can be used when creating a new task. In the case where a workflow manifest is being used, those values will be used to set the necessary values for the underlying task. When a task manifest is being used those values will override the corresponding values from the task manifest file.windowed
task schedule (if one is defined in the task manifest and/or on the command-line) to ensure that the time window defined is valid.Note; this pull request is a replacement for PR #1120, which fixed and resolved the same issues but in a single commit. This PR breaks out the fix into two separate commits, making it much clearer what is being changed and how.
Testing done
Tested the first set of changes manually by running two tests using two different task manifests:
max-failures
parameter, then unloading the collector plugin(s) that the task depended on and ensuring that the task was disabled after10
failures (the default)max-failures
parameter (the value we chose was3
, but any value greater than zero would do for this test), then unloading the collector plugin(s) that the task depended on and ensuring that the task was disabled after the chosen number of failures (in our case,3
).The second set of changes were also tested manually by running a single test:
3
to themax-failures
parameter and a value of1s
for theinterval
), but passing in different values on the command-line for these two parameters (we chose values of5
and750ms
, respectively, for our test).750ms
value passed in on the command line; four times every three seconds or 80 times a minute).5
failures rather than3
.Finally, the current set of legacy tests was run to ensure that we hadn't changed the behavior of the system from the previous behavior, we'd only added the ability to override some of the parameters defined in the task manifest using values defined on the command-line.
@intelsdi-x/snap-maintainers