func (s *TableServer) OnTableQuery(msg shttp.WSMessage) { var query TableQuery if err := json.Unmarshal([]byte(*msg.Obj), &query); err != nil { logging.GetLogger().Errorf("Unable to decode search flow message %v", msg) return } reply := msg.Reply(s.TableAllocator.QueryTable(&query)) s.WSAsyncClient.SendWSMessage(reply) }
func (o *OnDemandProbeServer) OnMessage(msg shttp.WSMessage) { if msg.Namespace != ondemand.Namespace { return } var query ondemand.CaptureQuery if err := json.Unmarshal([]byte(*msg.Obj), &query); err != nil { logging.GetLogger().Errorf("Unable to decode capture %v", msg) return } o.Graph.Lock() defer o.Graph.Unlock() status := http.StatusOK n := o.Graph.GetNode(graph.Identifier(query.NodeID)) if n == nil { logging.GetLogger().Errorf("Unknown node %s for new capture", query.NodeID) status = http.StatusNotFound } else { var ok bool switch msg.Type { case "CaptureStart": if ok = o.registerProbe(n, &query.Capture); ok { t := o.Graph.StartMetadataTransaction(n) t.AddMetadata("State/FlowCapture", "ON") t.AddMetadata("CaptureID", query.Capture.UUID) t.Commit() } case "CaptureStop": if ok = o.unregisterProbe(n); ok { metadata := n.Metadata() metadata["State/FlowCapture"] = "OFF" delete(metadata, "CaptureID") o.Graph.SetMetadata(n, metadata) } } if !ok { status = http.StatusBadRequest } } reply := msg.Reply(&ondemand.CaptureQuery{}, "CaptureStopReply", status) o.wsClient.SendWSMessage(reply) }