Explorar el Código

Merge pull request #1708 from aboch/astw

Add AgentStopWait method
Santhosh Manohar hace 8 años
padre
commit
66b794c455
Se han modificado 2 ficheros con 22 adiciones y 0 borrados
  1. 1 0
      libnetwork/agent.go
  2. 21 0
      libnetwork/controller.go

+ 1 - 0
libnetwork/agent.go

@@ -218,6 +218,7 @@ func (c *controller) agentSetup() error {
 	if c.agent != nil && c.agentInitDone != nil {
 		close(c.agentInitDone)
 		c.agentInitDone = nil
+		c.agentStopDone = make(chan struct{})
 	}
 	c.Unlock()
 

+ 21 - 0
libnetwork/controller.go

@@ -127,6 +127,9 @@ type NetworkController interface {
 	// Wait for agent initialization complete in libnetwork controller
 	AgentInitWait()
 
+	// Wait for agent to stop if running
+	AgentStopWait()
+
 	// SetKeys configures the encryption key for gossip and overlay data path
 	SetKeys(keys []*types.EncryptionKey) error
 }
@@ -160,6 +163,7 @@ type controller struct {
 	agent                  *agent
 	networkLocker          *locker.Locker
 	agentInitDone          chan struct{}
+	agentStopDone          chan struct{}
 	keys                   []*types.EncryptionKey
 	clusterConfigAvailable bool
 	sync.Mutex
@@ -337,6 +341,14 @@ func (c *controller) clusterAgentInit() {
 			// service bindings
 			c.agentClose()
 			c.cleanupServiceBindings("")
+
+			c.Lock()
+			if c.agentStopDone != nil {
+				close(c.agentStopDone)
+				c.agentStopDone = nil
+			}
+			c.Unlock()
+
 			return
 		}
 	}
@@ -354,6 +366,15 @@ func (c *controller) AgentInitWait() {
 	}
 }
 
+func (c *controller) AgentStopWait() {
+	c.Lock()
+	agentStopDone := c.agentStopDone
+	c.Unlock()
+	if agentStopDone != nil {
+		<-agentStopDone
+	}
+}
+
 func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
 	if c.cfg == nil {
 		return nil