-
Notifications
You must be signed in to change notification settings - Fork 912
Have the zookeeper backend use the host port for the service paths, allow publishing services if the base service path already exists, and allow publishing into the root of zookeeper. #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,30 +49,33 @@ type ZnodeBody struct { | |
|
||
func (r *ZkAdapter) Register(service *bridge.Service) error { | ||
privatePort, _ := strconv.Atoi(service.Origin.ExposedPort) | ||
publicPortString := strconv.Itoa(service.Port) | ||
acl := zk.WorldACL(zk.PermAll) | ||
|
||
exists, _, err := r.client.Exists(r.path + "/" + service.Name) | ||
basePath := r.path + "/" + service.Name | ||
if (r.path == "/") { | ||
basePath = r.path + service.Name | ||
} | ||
exists, _, err := r.client.Exists(basePath) | ||
if err != nil { | ||
log.Println("zookeeper: error checking if exists: ", err) | ||
} else { | ||
if !exists { | ||
_, err := r.client.Create(r.path+"/"+service.Name, []byte{}, 0, acl) | ||
_, err := r.client.Create(basePath, []byte{}, 0, acl) | ||
if err != nil { | ||
log.Println("zookeeper: failed to create base service node: ", err) | ||
} else { | ||
zbody := &ZnodeBody{Name: service.Name, IP: service.IP, PublicPort: service.Port, PrivatePort: privatePort, Tags: service.Tags, Attrs: service.Attrs, ContainerID: service.Origin.ContainerHostname} | ||
body, err := json.Marshal(zbody) | ||
if err != nil { | ||
log.Println("zookeeper: failed to json encode service body: ", err) | ||
} else { | ||
path := r.path + "/" + service.Name + "/" + service.Origin.ExposedPort | ||
_, err = r.client.Create(path, body, 1, acl) | ||
if err != nil { | ||
log.Println("zookeeper: failed to register service: ", err) | ||
} | ||
} // json encode error check | ||
log.Println("zookeeper: failed to create base service node at path '" + basePath + "': ", err) | ||
} | ||
} // create base path for the service name if it missing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses problem 3 (as part of the removal of the nesting) |
||
zbody := &ZnodeBody{Name: service.Name, IP: service.IP, PublicPort: service.Port, PrivatePort: privatePort, Tags: service.Tags, Attrs: service.Attrs, ContainerID: service.Origin.ContainerHostname} | ||
body, err := json.Marshal(zbody) | ||
if err != nil { | ||
log.Println("zookeeper: failed to json encode service body: ", err) | ||
} else { | ||
path := basePath + "/" + service.IP + ":" + publicPortString | ||
_, err = r.client.Create(path, body, 1, acl) | ||
if err != nil { | ||
log.Println("zookeeper: failed to register service at path '" + path + "': ", err) | ||
} // create service path error check | ||
} // service path exists | ||
} // json znode body creation check | ||
} // service path exists error check | ||
return err | ||
} | ||
|
@@ -88,8 +91,12 @@ func (r *ZkAdapter) Ping() error { | |
|
||
func (r *ZkAdapter) Deregister(service *bridge.Service) error { | ||
basePath := r.path + "/" + service.Name | ||
if (r.path == "/") { | ||
basePath = r.path + service.Name | ||
} | ||
publicPortString := strconv.Itoa(service.Port) | ||
servicePortPath := basePath + "/" + service.IP + ":" + publicPortString | ||
// Delete the service-port znode | ||
servicePortPath := basePath + "/" + service.Origin.ExposedPort | ||
err := r.client.Delete(servicePortPath, -1) // -1 means latest version number | ||
if err != nil { | ||
log.Println("zookeeper: failed to deregister service port entry: ", err) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addresses problem 2