// EnrollNode enroll node for the incoming connection
EnrollNode enroll node for the incoming connection
// EnrollNode enroll node for the incoming connection
func (mh *MessageHandle) EnrollNode(hi hubio.CloudHubIO, info *model.HubInfo) error {
	var err error
	for i := 0; i <= mh.KeepaliveInterval; i++ {
		if err = mh.MessageQueue.Connect(info); err == nil {
			break
		}
		time.Sleep(time.Duration(1) * time.Second)
	}
	if err != nil {
		klog.Errorf("fail to connect to event queue for node %s, reason %s", info.NodeID, err.Error())
		notifyEventQueueError(hi, messageQueueDisconnect, info.NodeID)
		err = hi.Close()
		if err != nil {
			klog.Errorf("fail to close connection, reason: %s", err.Error())
		}
		return err
	}
	err = mh.MessageQueue.Publish(constructConnectMessage(info, true))
	if err != nil {
		klog.Errorf("fail to publish node connect event for node %s, reason %s", info.NodeID, err.Error())
		notifyEventQueueError(hi, messageQueueDisconnect, info.NodeID)
		err = hi.Close()
		if err != nil {
			klog.Errorf("fail to close connection, reason: %s", err.Error())
		}
		mh.MessageQueue.Close(info)
		return err
	}
	mh.nodeConns.Store(info.NodeID, hi)
	mh.nodeLocks.Store(info.NodeID, &sync.Mutex{})
	mh.Nodes.Store(info.NodeID, true)
	return nil
}
func ( mh * MessageHandle ) EnrollNode ( hi hubio . CloudHubIO , info * model . HubInfo ) error { var err error for i := 0 ; i <= mh . KeepaliveInterval ; i ++ { if err = mh . MessageQueue . Connect ( info ) ; err == nil { break } time . Sleep ( time . Duration ( 1 ) * time . Second ) } if err != nil { klog . Errorf ( " " , info . NodeID , err . Error ( ) ) notifyEventQueueError ( hi , messageQueueDisconnect , info . NodeID ) err = hi . Close ( ) if err != nil { klog . Errorf ( " " , err . Error ( ) ) } return err } err = mh . MessageQueue . Publish ( constructConnectMessage ( info , true ) ) if err != nil { klog . Errorf ( " " , info . NodeID , err . Error ( ) ) notifyEventQueueError ( hi , messageQueueDisconnect , info . NodeID ) err = hi . Close ( ) if err != nil { klog . Errorf ( " " , err . Error ( ) ) } mh . MessageQueue . Close ( info ) return err } mh . nodeConns . Store ( info . NodeID , hi ) mh . nodeLocks . Store ( info . NodeID , & sync . Mutex { } ) mh . Nodes . Store ( info . NodeID , true ) return nil }
EnrollNode enroll node for the incoming connection
EnrollNode enroll node for the incoming connection
// Wait for the previous connection to be cleaned up