This commit is contained in:
12
main.go
12
main.go
@@ -86,12 +86,14 @@ func (a *App) HandleSave(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PoolServer struct {
|
type PoolServer struct {
|
||||||
pool GrainPool
|
pod_name string
|
||||||
|
pool GrainPool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoolServer(pool GrainPool) *PoolServer {
|
func NewPoolServer(pool GrainPool, pod_name string) *PoolServer {
|
||||||
return &PoolServer{
|
return &PoolServer{
|
||||||
pool: pool,
|
pod_name: pod_name,
|
||||||
|
pool: pool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +106,7 @@ func (s *PoolServer) HandleGet(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("X-Pod-Name", s.pod_name)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
@@ -121,6 +124,7 @@ func (s *PoolServer) HandleAddSku(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("X-Pod-Name", s.pod_name)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
@@ -186,7 +190,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
syncedServer := NewPoolServer(syncedPool)
|
syncedServer := NewPoolServer(syncedPool, name)
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/api/", http.StripPrefix("/api", syncedServer.Serve()))
|
mux.Handle("/api/", http.StripPrefix("/api", syncedServer.Serve()))
|
||||||
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -302,11 +302,9 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
|
|||||||
case RemoteGrainChanged:
|
case RemoteGrainChanged:
|
||||||
// remote grain changed
|
// remote grain changed
|
||||||
grainSyncCount.Inc()
|
grainSyncCount.Inc()
|
||||||
log.Printf("Remote grain changed\n")
|
|
||||||
|
|
||||||
idAndHost := make([]byte, packet.DataLength)
|
idAndHost := make([]byte, packet.DataLength)
|
||||||
_, err = conn.Read(idAndHost)
|
_, err = conn.Read(idAndHost)
|
||||||
log.Printf("Remote grain %s changed\n", idAndHost)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -328,7 +326,6 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
|
|||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
log.Printf("Remote host %s not found\n", idAndHostParts[1])
|
log.Printf("Remote host %s not found\n", idAndHostParts[1])
|
||||||
log.Printf("Remotes %v\n", p.remotes)
|
|
||||||
} else {
|
} else {
|
||||||
SendPacket(conn, AckChange, func(w io.Writer) error {
|
SendPacket(conn, AckChange, func(w io.Writer) error {
|
||||||
_, err := w.Write([]byte("ok"))
|
_, err := w.Write([]byte("ok"))
|
||||||
|
|||||||
Reference in New Issue
Block a user