Skip to content

Commit dfd4e81

Browse files
committed
Merge pull request #3348 from aledbf/services_directory_with_ttl
fix(publisher): use TTL in services application etcd directories
2 parents 652cb41 + 25ebb4d commit dfd4e81

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

publisher/server/publisher.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ func (s *Server) publishContainer(container *docker.APIContainers, ttl time.Dura
9898
appName := match[1]
9999
appPath := fmt.Sprintf("%s/%s", appName, containerName)
100100
keyPath := fmt.Sprintf("/deis/services/%s", appPath)
101+
dirPath := fmt.Sprintf("/deis/services/%s", appName)
101102
for _, p := range container.Ports {
102103
port := strconv.Itoa(int(p.PublicPort))
103104
hostAndPort := host + ":" + port
104105
if s.IsPublishableApp(containerName) && s.IsPortOpen(hostAndPort) {
105106
s.setEtcd(keyPath, hostAndPort, uint64(ttl.Seconds()))
107+
s.updateDir(dirPath, uint64(ttl.Seconds()))
106108
safeMap.Lock()
107109
safeMap.data[container.ID] = appPath
108110
safeMap.Unlock()
@@ -146,6 +148,7 @@ func (s *Server) IsPublishableApp(name string) bool {
146148
return false
147149
}
148150

151+
// IsPortOpen checks if the given port is accepting tcp connections
149152
func (s *Server) IsPortOpen(hostAndPort string) bool {
150153
portOpen := false
151154
conn, err := net.Dial("tcp", hostAndPort)
@@ -215,3 +218,12 @@ func (s *Server) removeEtcd(key string, recursive bool) {
215218
}
216219
log.Println("del", key)
217220
}
221+
222+
// updateDir updates the given directory for a given ttl. It succeeds
223+
// only if the given directory already exists.
224+
func (s *Server) updateDir(directory string, ttl uint64) {
225+
if _, err := s.EtcdClient.UpdateDir(directory, ttl); err != nil {
226+
log.Println(err)
227+
}
228+
log.Println("updateDir", directory)
229+
}

0 commit comments

Comments
 (0)