unamount http api
This commit is contained in:
parent
bf96ba7891
commit
62ebf5f087
|
@ -48,6 +48,38 @@ func (wr wrr) MountHandler (w http.ResponseWriter, r *http.Request) {
|
|||
w.Write(state)
|
||||
}
|
||||
|
||||
//UmountHandler /umount location
|
||||
func (wr wrr) UmountHandler (w http.ResponseWriter, r *http.Request) {
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
var m RBDDevice
|
||||
err := decoder.Decode(&m)
|
||||
log.Print("[DEBUG] ", m)
|
||||
var msE []byte
|
||||
if err != nil {
|
||||
msE, _ = json.Marshal(MountState{"FAIL", "JSON parse failure"})
|
||||
w.Write(msE)
|
||||
return
|
||||
}
|
||||
|
||||
// var wCh chan MountState
|
||||
wCh := make(chan MountState, 1)
|
||||
go func() { wCh <- wr.z.WatchAnswer(m.Node, "umount") }()
|
||||
err = wr.z.UmountRequest(m)
|
||||
if err != nil {
|
||||
w.Write(msE)
|
||||
}
|
||||
|
||||
answerState := <-wCh
|
||||
log.Print(answerState)
|
||||
wr.z.RMR(strings.Join([]string{wr.z.Path, "cluster", wr.Fqdn, "answers", "umount"}, "/"))
|
||||
state, err := json.Marshal(answerState)
|
||||
if err != nil {
|
||||
log.Print("[ERROR] ", err)
|
||||
w.Write(msE)
|
||||
}
|
||||
w.Write(state)
|
||||
}
|
||||
|
||||
//wrr API
|
||||
type wrr struct {
|
||||
Fqdn string
|
||||
|
@ -86,9 +118,7 @@ func (s ServerConf) ServeHTTP(z ZooNode, fqdn string) {
|
|||
http.HandleFunc("/mount", wr.MountHandler)
|
||||
|
||||
// Umount volume. Accept JSON. Return JSON.
|
||||
http.HandleFunc("/umount", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Not implemented yet."))
|
||||
})
|
||||
http.HandleFunc("/umount", wr.UmountHandler)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: s.Addr,
|
||||
|
|
|
@ -57,7 +57,21 @@ func (z ZooNode) RequestWatch(fqdn string) {
|
|||
z.Answer(fqdn, child, std, "OK")
|
||||
// 1) Unmount FS 2) Unmap RBD
|
||||
} else if child == "umount" {
|
||||
log.Print("[DEBUG] Umount")
|
||||
err := r.UnmountFS()
|
||||
if err != nil {
|
||||
z.RMR(p)
|
||||
z.Answer(fqdn, child, []byte("Failed umount device"), "FAIL")
|
||||
log.Print("[ERROR] Umount error: ", err)
|
||||
break
|
||||
}
|
||||
std, err := r.UnmapDevice()
|
||||
if err != nil {
|
||||
z.RMR(p)
|
||||
z.Answer(fqdn, child, std, "FAIL")
|
||||
log.Print("[ERROR] Unmapping error: ", string(std), err)
|
||||
break
|
||||
}
|
||||
z.Answer(fqdn, child, std, "OK")
|
||||
} else {
|
||||
log.Print("[DEBUG] Unknown ", child)
|
||||
}
|
||||
|
@ -87,11 +101,6 @@ func (z ZooNode) Answer(fqdn string, req string, stderr []byte, t string) {
|
|||
}
|
||||
}
|
||||
|
||||
//MountRequest write mount request
|
||||
// func (z ZooNode) MountRequest(RBDDevice) {
|
||||
|
||||
// }
|
||||
|
||||
//MountRequest create node with mount requests from API
|
||||
func (z ZooNode) MountRequest(r RBDDevice) error {
|
||||
jsReq, err := json.Marshal(r)
|
||||
|
@ -111,6 +120,26 @@ func (z ZooNode) MountRequest(r RBDDevice) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
//UmountRequest create node with umount requests from API
|
||||
// OMFG: Needs merge with MountRequest
|
||||
func (z ZooNode) UmountRequest(r RBDDevice) error {
|
||||
jsReq, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestsPath := strings.Join([]string{z.Path, "cluster", r.Node, "requests", "umount"}, "/")
|
||||
_, err = z.Conn.Create(requestsPath, jsReq, 0, zk.WorldACL(zk.PermAll))
|
||||
if err != nil {
|
||||
_, err := z.Conn.Set(requestsPath, jsReq, -1)
|
||||
if err != nil {
|
||||
log.Print("[zk ERROR] ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//WatchAnswer watch for answer
|
||||
func (z ZooNode) WatchAnswer(fqdn string, t string) MountState {
|
||||
answersPath := strings.Join([]string{z.Path, "cluster", fqdn, "answers"}, "/")
|
||||
|
|
Loading…
Reference in New Issue
Block a user