-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first initial tests passing working moving average udf examples working snapshot/restore
- Loading branch information
1 parent
00c6e95
commit bb816f6
Showing
50 changed files
with
10,552 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ kapacitor*.rpm | |
kapacitor*.deb | ||
kapacitor*.tar | ||
kapacitor*.zip | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package command | ||
|
||
import ( | ||
"io" | ||
"os/exec" | ||
) | ||
|
||
type Command interface { | ||
Start() error | ||
Wait() error | ||
|
||
StdinPipe() (io.WriteCloser, error) | ||
StdoutPipe() (io.ReadCloser, error) | ||
StderrPipe() (io.ReadCloser, error) | ||
} | ||
|
||
type Commander interface { | ||
NewCommand() Command | ||
} | ||
|
||
// Necessary information to create a new command | ||
type CommandInfo struct { | ||
Prog string | ||
Args []string | ||
} | ||
|
||
// Create a new Command using golang exec package and the information. | ||
func (ci CommandInfo) NewCommand() Command { | ||
return exec.Command(ci.Prog, ci.Args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package test | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
|
||
"github.com/influxdata/kapacitor/command" | ||
"github.com/influxdata/kapacitor/udf" | ||
) | ||
|
||
type CommandHelper struct { | ||
inr *io.PipeReader | ||
inw *io.PipeWriter | ||
|
||
outr *io.PipeReader | ||
outw *io.PipeWriter | ||
|
||
errr *io.PipeReader | ||
errw *io.PipeWriter | ||
|
||
Requests chan *udf.Request | ||
Responses chan *udf.Response | ||
ErrC chan error | ||
} | ||
|
||
func NewCommandHelper() *CommandHelper { | ||
cmd := &CommandHelper{ | ||
Requests: make(chan *udf.Request), | ||
Responses: make(chan *udf.Response), | ||
ErrC: make(chan error, 1), | ||
} | ||
return cmd | ||
} | ||
|
||
func (c *CommandHelper) NewCommand() command.Command { | ||
return c | ||
} | ||
|
||
func (c *CommandHelper) readRequests() error { | ||
defer c.inr.Close() | ||
defer close(c.Requests) | ||
buf := bufio.NewReader(c.inr) | ||
var b []byte | ||
for { | ||
req := &udf.Request{} | ||
err := udf.ReadMessage(&b, buf, req) | ||
if err == io.EOF { | ||
return nil | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
c.Requests <- req | ||
} | ||
} | ||
|
||
func (c *CommandHelper) writeResponses() error { | ||
defer c.outw.Close() | ||
for response := range c.Responses { | ||
udf.WriteMessage(response, c.outw) | ||
} | ||
return nil | ||
} | ||
|
||
func (c *CommandHelper) Start() error { | ||
go func() { | ||
readErrC := make(chan error, 1) | ||
writeErrC := make(chan error, 1) | ||
go func() { | ||
readErrC <- c.readRequests() | ||
}() | ||
go func() { | ||
writeErrC <- c.writeResponses() | ||
}() | ||
var readErr, writeErr error | ||
for readErrC != nil || writeErrC != nil { | ||
select { | ||
case readErr = <-readErrC: | ||
readErrC = nil | ||
case writeErr = <-writeErrC: | ||
writeErrC = nil | ||
} | ||
} | ||
|
||
if readErr != nil { | ||
c.ErrC <- readErr | ||
} else { | ||
c.ErrC <- writeErr | ||
} | ||
}() | ||
return nil | ||
} | ||
|
||
func (c *CommandHelper) Wait() error { | ||
return nil | ||
} | ||
|
||
// Wrapps the STDIN pipe and when it is closed | ||
// closes the STDOUT and STDERR pipes of the command. | ||
type cmdCloser struct { | ||
*io.PipeWriter | ||
cmd *CommandHelper | ||
} | ||
|
||
func (cc *cmdCloser) Close() error { | ||
cc.cmd.errw.Close() | ||
return cc.PipeWriter.Close() | ||
} | ||
|
||
func (c *CommandHelper) StdinPipe() (io.WriteCloser, error) { | ||
c.inr, c.inw = io.Pipe() | ||
closer := &cmdCloser{ | ||
PipeWriter: c.inw, | ||
cmd: c, | ||
} | ||
return closer, nil | ||
} | ||
|
||
func (c *CommandHelper) StdoutPipe() (io.ReadCloser, error) { | ||
c.outr, c.outw = io.Pipe() | ||
return c.outr, nil | ||
} | ||
|
||
func (c *CommandHelper) StderrPipe() (io.ReadCloser, error) { | ||
c.errr, c.errw = io.Pipe() | ||
return c.errr, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.