• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang http.NewWSMessage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/skydive-project/skydive/http.NewWSMessage函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWSMessage函数的具体用法?Golang NewWSMessage怎么用?Golang NewWSMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewWSMessage函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: injectPacket

func (pc *PacketInjectorClient) injectPacket(host string, pp *PacketParams, status chan *string) {
	msg := shttp.NewWSMessage(Namespace, "InjectPacket", pp)

	ch := make(chan *json.RawMessage)
	defer close(ch)

	pc.replyChanMutex.Lock()
	pc.replyChan[msg.UUID] = ch
	pc.replyChanMutex.Unlock()

	defer func() {
		pc.replyChanMutex.Lock()
		delete(pc.replyChan, msg.UUID)
		pc.replyChanMutex.Unlock()
	}()

	if !pc.WSServer.SendWSMessageTo(msg, host) {
		e := fmt.Sprintf("Unable to send message to agent: %s", host)
		logging.GetLogger().Errorf(e)
		status <- &e
		return
	}

	data := <-ch
	var reply string
	if err := json.Unmarshal([]byte(*data), &reply); err != nil {
		e := fmt.Sprintf("Error while reading reply from: %s", host)
		logging.GetLogger().Errorf(e)
		status <- &e
		return
	}

	status <- &reply
}
开发者ID:skydive-project,项目名称:skydive,代码行数:34,代码来源:client.go


示例2: lookupFlows

func (f *TableClient) lookupFlows(flowset chan *FlowSet, host string, flowSearchQuery *FlowSearchQuery) {
	obj, _ := proto.Marshal(flowSearchQuery)
	tq := TableQuery{
		Type: "FlowSearchQuery",
		Obj:  obj,
	}
	msg := shttp.NewWSMessage(Namespace, "TableQuery", tq)

	ch := make(chan *json.RawMessage)
	defer close(ch)

	f.replyChanMutex.Lock()
	f.replyChan[msg.UUID] = ch
	f.replyChanMutex.Unlock()

	defer func() {
		f.replyChanMutex.Lock()
		delete(f.replyChan, msg.UUID)
		f.replyChanMutex.Unlock()
	}()

	if !f.WSServer.SendWSMessageTo(msg, host) {
		logging.GetLogger().Errorf("Unable to send message to agent: %s", host)
		flowset <- NewFlowSet()
		return
	}

	select {
	case raw := <-ch:
		var reply TableReply
		if err := json.Unmarshal([]byte(*raw), &reply); err != nil {
			logging.GetLogger().Errorf("Error returned while reading TableReply from: %s", host)
			break
		}

		if reply.Status != http.StatusOK {
			logging.GetLogger().Errorf("Error %d TableReply from: %s", reply.Status, host)
			break
		}

		fs := NewFlowSet()

		context := MergeContext{Sorted: flowSearchQuery.Sort, Dedup: flowSearchQuery.Dedup}
		for _, b := range reply.Obj {
			var fsr FlowSearchReply
			if err := proto.Unmarshal(b, &fsr); err != nil {
				logging.GetLogger().Errorf("Unable to decode flow search reply from: %s", host)
				continue
			}
			fs.Merge(fsr.FlowSet, context)
		}
		flowset <- fs

		return
	case <-time.After(time.Second * 10):
		logging.GetLogger().Errorf("Timeout while reading TableReply from: %s", host)
	}

	flowset <- NewFlowSet()
}
开发者ID:nplanel,项目名称:skydive,代码行数:60,代码来源:client.go


示例3: unregisterProbe

func (o *OnDemandProbeClient) unregisterProbe(node *graph.Node) bool {
	msg := shttp.NewWSMessage(ondemand.Namespace, "CaptureStop", ondemand.CaptureQuery{NodeID: string(node.ID)})

	if !o.wsServer.SendWSMessageTo(msg, node.Host()) {
		logging.GetLogger().Errorf("Unable to send message to agent: %s", node.Host())
		return false
	}

	return true
}
开发者ID:skydive-project,项目名称:skydive,代码行数:10,代码来源:client.go


示例4: OnMessage

func (s *GraphServer) OnMessage(c *shttp.WSClient, msg shttp.WSMessage) {
	if msg.Namespace != Namespace {
		return
	}

	s.Graph.Lock()
	defer s.Graph.Unlock()

	msgType, obj, err := UnmarshalWSMessage(msg)
	if err != nil {
		logging.GetLogger().Errorf("Graph: Unable to parse the event %v: %s", msg, err.Error())
		return
	}

	switch msgType {
	case "SyncRequest":
		reply := shttp.NewWSMessage(Namespace, "SyncReply", s.Graph.WithContext(obj.(GraphContext)))
		c.SendWSMessage(reply)
	case "SubGraphDeleted":
		n := obj.(*Node)

		logging.GetLogger().Debugf("Got SubGraphDeleted event from the node %s", n.ID)

		node := s.Graph.GetNode(n.ID)
		if node != nil {
			s.Graph.DelSubGraph(node)
		}
	case "NodeUpdated":
		n := obj.(*Node)
		node := s.Graph.GetNode(n.ID)
		if node != nil {
			s.Graph.SetMetadata(node, n.metadata)
		}
	case "NodeDeleted":
		s.Graph.DelNode(obj.(*Node))
	case "NodeAdded":
		n := obj.(*Node)
		if s.Graph.GetNode(n.ID) == nil {
			s.Graph.AddNode(n)
		}
	case "EdgeUpdated":
		e := obj.(*Edge)
		edge := s.Graph.GetEdge(e.ID)
		if edge != nil {
			s.Graph.SetMetadata(edge, e.metadata)
		}
	case "EdgeDeleted":
		s.Graph.DelEdge(obj.(*Edge))
	case "EdgeAdded":
		e := obj.(*Edge)
		if s.Graph.GetEdge(e.ID) == nil {
			s.Graph.AddEdge(e)
		}
	}
}
开发者ID:nplanel,项目名称:skydive,代码行数:55,代码来源:server.go


示例5: triggerResync

func (c *Forwarder) triggerResync() {
	logging.GetLogger().Infof("Start a resync of the graph")

	c.Graph.RLock()
	defer c.Graph.RUnlock()

	// request for deletion of everything belonging to Root node
	c.Client.SendWSMessage(shttp.NewWSMessage(Namespace, "HostGraphDeleted", c.Host))

	// re-added all the nodes and edges
	nodes := c.Graph.GetNodes(Metadata{})
	for _, n := range nodes {
		c.Client.SendWSMessage(shttp.NewWSMessage(Namespace, "NodeAdded", n))
	}

	edges := c.Graph.GetEdges(Metadata{})
	for _, e := range edges {
		c.Client.SendWSMessage(shttp.NewWSMessage(Namespace, "EdgeAdded", e))
	}
}
开发者ID:skydive-project,项目名称:skydive,代码行数:20,代码来源:forwarder.go


示例6: updateNode

func (mapper *NeutronMapper) updateNode(node *graph.Node, attrs *Attributes) {
	mapper.graph.Lock()

	tr := mapper.graph.StartMetadataTransaction(node)
	tr.AddMetadata("Manager", "neutron")

	if attrs.PortID != "" {
		tr.AddMetadata("Neutron/PortID", attrs.PortID)
	}

	if attrs.TenantID != "" {
		tr.AddMetadata("Neutron/TenantID", attrs.TenantID)
	}

	if attrs.NetworkID != "" {
		tr.AddMetadata("Neutron/NetworkID", attrs.NetworkID)
	}

	if attrs.NetworkName != "" {
		tr.AddMetadata("Neutron/NetworkName", attrs.NetworkName)
	}

	if segID, err := strconv.Atoi(attrs.VNI); err != nil && segID > 0 {
		tr.AddMetadata("Neutron/VNI", uint64(segID))
	}

	var registerLink *FabricRegisterLinkWSMessage
	if vm, ok := node.Metadata()["ExtID/vm-uuid"]; ok {
		if mac, ok := node.Metadata()["ExtID/attached-mac"]; ok {
			if path := mapper.graph.LookupShortestPath(node, graph.Metadata{"Type": "tun"}, graph.Metadata{"RelationType": "layer2"}); len(path) > 0 {
				registerLink = &FabricRegisterLinkWSMessage{
					ParentNodeID:   path[len(path)-1].ID,
					ParentMetadata: graph.Metadata{"Type": "host", "InstanceID": vm},
					ChildMetadata:  graph.Metadata{"Type": "device", "MAC": mac},
				}
			}
		}
	}
	tr.Commit()
	mapper.graph.Unlock()

	if registerLink != nil {
		msg := shttp.NewWSMessage(FabricNamespace, "RegisterLink", registerLink)
		mapper.wsClient.SendWSMessage(msg)
	}
}
开发者ID:skydive-project,项目名称:skydive,代码行数:46,代码来源:neutron.go


示例7: OnAlert

/* Called by alert.EvalNodes() */
func (c *alertClient) OnAlert(amsg *AlertMessage) {
	msg := shttp.NewWSMessage(Namespace, "Alert", amsg)
	c.wsClient.SendWSMessage(msg)
}
开发者ID:nplanel,项目名称:skydive,代码行数:5,代码来源:server.go


示例8: OnEdgeDeleted

func (c *Forwarder) OnEdgeDeleted(e *Edge) {
	c.Client.SendWSMessage(shttp.NewWSMessage(Namespace, "EdgeDeleted", e))
}
开发者ID:skydive-project,项目名称:skydive,代码行数:3,代码来源:forwarder.go


示例9: OnNodeDeleted

func (c *Forwarder) OnNodeDeleted(n *Node) {
	c.Client.SendWSMessage(shttp.NewWSMessage(Namespace, "NodeDeleted", n))
}
开发者ID:skydive-project,项目名称:skydive,代码行数:3,代码来源:forwarder.go


示例10: OnEdgeDeleted

func (s *GraphServer) OnEdgeDeleted(e *Edge) {
	s.WSServer.BroadcastWSMessage(shttp.NewWSMessage(Namespace, "EdgeDeleted", e))
}
开发者ID:nplanel,项目名称:skydive,代码行数:3,代码来源:server.go


示例11: OnNodeDeleted

func (s *GraphServer) OnNodeDeleted(n *Node) {
	s.WSServer.BroadcastWSMessage(shttp.NewWSMessage(Namespace, "NodeDeleted", n))
}
开发者ID:nplanel,项目名称:skydive,代码行数:3,代码来源:server.go



注:本文中的github.com/skydive-project/skydive/http.NewWSMessage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang logging.GetLogger函数代码示例发布时间:2022-05-28
下一篇:
Golang flow.Flow类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap