returning binary contents of binary logs
This commit is contained in:
Родитель
a78cdbae59
Коммит
d377fdae7d
|
@ -474,7 +474,7 @@ func (this *HttpAPI) RelayLogEndCoordinates(params martini.Params, r render.Rend
|
|||
r.JSON(200, coordinates)
|
||||
}
|
||||
|
||||
// BinlogContents returns contents of binary log entries
|
||||
// RelaylogContentsTail returns contents of relay logs, from given position to the very last entry
|
||||
func (this *HttpAPI) RelaylogContentsTail(params martini.Params, r render.Render, req *http.Request) {
|
||||
if err := this.validateToken(r, req); err != nil {
|
||||
return
|
||||
|
@ -501,7 +501,7 @@ func (this *HttpAPI) RelaylogContentsTail(params martini.Params, r render.Render
|
|||
}
|
||||
}
|
||||
|
||||
output, err := osagent.MySQLBinlogContents(parseRelaylogs, startPosition, 0)
|
||||
output, err := osagent.MySQLBinlogBinaryContents(parseRelaylogs, startPosition, 0)
|
||||
if err != nil {
|
||||
r.JSON(500, &APIResponse{Code: ERROR, Message: err.Error()})
|
||||
return
|
||||
|
@ -509,8 +509,10 @@ func (this *HttpAPI) RelaylogContentsTail(params martini.Params, r render.Render
|
|||
r.JSON(200, output)
|
||||
}
|
||||
|
||||
// BinlogContents returns contents of binary log entries
|
||||
func (this *HttpAPI) BinlogContents(params martini.Params, r render.Render, req *http.Request) {
|
||||
// binlogContents returns contents of binary log entries
|
||||
func (this *HttpAPI) binlogContents(params martini.Params, r render.Render, req *http.Request,
|
||||
contentsFunc func(binlogFiles []string, startPosition int64, stopPosition int64) (string, error),
|
||||
) {
|
||||
if err := this.validateToken(r, req); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -538,6 +540,16 @@ func (this *HttpAPI) BinlogContents(params martini.Params, r render.Render, req
|
|||
r.JSON(200, output)
|
||||
}
|
||||
|
||||
// BinlogContents returns contents of binary log entries
|
||||
func (this *HttpAPI) BinlogContents(params martini.Params, r render.Render, req *http.Request) {
|
||||
this.binlogContents(params, r, req, osagent.MySQLBinlogContents)
|
||||
}
|
||||
|
||||
// BinlogBinaryContents returns contents of binary log entries
|
||||
func (this *HttpAPI) BinlogBinaryContents(params martini.Params, r render.Render, req *http.Request) {
|
||||
this.binlogContents(params, r, req, osagent.MySQLBinlogBinaryContents)
|
||||
}
|
||||
|
||||
func (this *HttpAPI) RunCommand(params martini.Params, r render.Render, req *http.Request) {
|
||||
if err := this.validateToken(r, req); err != nil {
|
||||
return
|
||||
|
@ -593,6 +605,7 @@ func (this *HttpAPI) RegisterRequests(m *martini.ClassicMartini) {
|
|||
m.Get("/api/mysql-relay-log-files", this.RelayLogFiles)
|
||||
m.Get("/api/mysql-relay-log-end-coordinates", this.RelayLogEndCoordinates)
|
||||
m.Get("/api/mysql-binlog-contents", this.BinlogContents)
|
||||
m.Get("/api/mysql-binlog-binary-contents", this.BinlogBinaryContents)
|
||||
m.Get("/api/mysql-relaylog-contents-tail/:relaylog/:start", this.RelaylogContentsTail)
|
||||
m.Get("/api/custom-commands/:cmd", this.RunCommand)
|
||||
m.Get(config.Config.StatusEndpoint, this.Status)
|
||||
|
|
|
@ -142,6 +142,35 @@ func MySQLBinlogContents(binlogFiles []string, startPosition int64, stopPosition
|
|||
return string(output), err
|
||||
}
|
||||
|
||||
func MySQLBinlogBinaryContents(binlogFiles []string, startPosition int64, stopPosition int64) (string, error) {
|
||||
if len(binlogFiles) == 0 {
|
||||
return "", log.Errorf("No binlog files provided in MySQLBinlogContents")
|
||||
}
|
||||
tmpFile, err := ioutil.TempFile("", "orchestrator-agent-binlog-contents-")
|
||||
if err != nil {
|
||||
return "", log.Errore(err)
|
||||
}
|
||||
for i, binlogFile := range binlogFiles {
|
||||
cmd := fmt.Sprintf("cat %s", binlogFile)
|
||||
|
||||
if i == len(binlogFiles)-1 && stopPosition != 0 {
|
||||
cmd = fmt.Sprintf("%s | head -c%d", cmd, stopPosition)
|
||||
}
|
||||
if i == 0 && startPosition != 0 {
|
||||
cmd = fmt.Sprintf("%s | tail -c+%d", cmd, startPosition)
|
||||
}
|
||||
cmd = fmt.Sprintf("%s >> %s", cmd, tmpFile)
|
||||
_, err = commandOutput(sudoCmd(cmd))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf("cat %s | gzip | base64", tmpFile)
|
||||
output, err := commandOutput(cmd)
|
||||
return string(output), err
|
||||
}
|
||||
|
||||
// Equals tests equality of this corrdinate and another one.
|
||||
func (this *LogicalVolume) IsSnapshotValid() bool {
|
||||
if !this.IsSnapshot {
|
||||
|
|
Загрузка…
Ссылка в новой задаче