Skip to content

Commit

Permalink
Merge pull request influxdata#1825 from influxdata/aa_1794_cmdbug
Browse files Browse the repository at this point in the history
define properly assigns task name
  • Loading branch information
aanthony1243 authored Mar 2, 2018
2 parents 2bbd687 + 74e24ca commit f7527cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [#1690](https://github.com/influxdata/kapacitor/issues/1690): Add https-private-key option to httpd config.

### Bugfixes
- [#1794](https://github.com/influxdata/kapacitor/issues/1794): Kapacitor ticks generating a hash instead of their actual given name.

- [#1827](https://github.com/influxdata/kapacitor/pull/1827): Fix deadlock in load service when task has an error.

Expand Down
20 changes: 17 additions & 3 deletions cmd/kapacitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ var (
dtype = defineFlags.String("type", "", "The task type (stream|batch)")
dtemplate = defineFlags.String("template", "", "Optional template ID")
dvars = defineFlags.String("vars", "", "Optional path to a JSON vars file")
dfile = defineFlags.String("file", "", "Optional path to a YAML or JSON template task file")
dfile = defineFlags.String("file", "", "Optional path to a YAML or JSON template task file. If id is given in the task file, it must match the Task id given on the command line.")
dnoReload = defineFlags.Bool("no-reload", false, "Do not reload the task even if it is enabled")
ddbrp = make(dbrps, 0)
)
Expand Down Expand Up @@ -661,11 +661,13 @@ Options:
}

func doDefine(args []string) error {
if len(args) < 1 {
// should be getting 1 task ID and 0 or more pairs of flags
if len(args)%2 == 0 {
fmt.Fprintln(os.Stderr, "Must provide a task ID.")
defineFlags.Usage()
os.Exit(2)
}

defineFlags.Parse(args[1:])
id := args[0]

Expand Down Expand Up @@ -695,7 +697,7 @@ func doDefine(args []string) error {
if *dvars != "" {
f, err := os.Open(*dvars)
if err != nil {
return errors.Wrapf(err, "faild to open file %s", *dvars)
return errors.Wrapf(err, "failed to open file %s", *dvars)
}
defer f.Close()
dec := json.NewDecoder(f)
Expand Down Expand Up @@ -736,6 +738,11 @@ func doDefine(args []string) error {
if task.ID == "" {
if *dfile != "" {
o, err := fileVars.CreateTaskOptions()
if o.ID == "" {
o.ID = id
} else if o.ID != id {
return errors.New("Task id given on command line does not match id in " + *dfile)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -764,6 +771,13 @@ func doDefine(args []string) error {
if err != nil {
return err
}

if o.ID == "" {
o.ID = id
} else if o.ID != id {
return errors.New("Task id given on command line does not match id in " + *dfile)
}

_, err = cli.UpdateTask(
l,
o,
Expand Down

0 comments on commit f7527cf

Please sign in to comment.