create an explicit interface for a service #34

Merged
merged 5 commits into from Aug 6, 2012

Projects

None yet

3 participants

@kesselborn

currently, bazooka-pm and bazooka-proxy services register themselves in the coordinator via the generic file interface. We need to have an extra function for it that we can use for other services like bazooka-repomgr and eventually for something like mysql as well.
Those services need to have the possibility to store env vars on them as well -- just as apps.
Values that are currently saved in /bazooka/meta can all be saved in services:

  • irc
  • storage
  • yammer

...

@kesselborn kesselborn was assigned May 29, 2012
@xla

Needs further discussion.

@xla

Assumption is that every service returns one or more addresses. $ADDR consists of ip and port.

visor service get $SERVICE_NAME $PATH
visor service set $SERVICE_NAME $PATH $ADDR
visor service del $SERVICE_NAME $PATH $ADDR
@xla xla was assigned Jun 18, 2012
@xla
xla commented Aug 2, 2012

This is the first step to have discovery via dns based on coordinator information. We start with a simple representation of a service. A service consists of a name and a list of addresses. Through exposing this interface via the cli it should give enough flexibility to interact with it from non-bazooka controlled systems and use it programmatically from other components.

The underlying tree structure looks like this:

/$root
  /services
    /$service_name
      /addrs
        1.2.3.4 = $utc_timestamp
        5.6.7.8 = $utc_timestamp

This structure should give enough flexibility to add more important information like port.

TODO

  • Build service interface
  • Expose a cli
  • Apps should be represented by service entries
  • Implement service events
  • Add more attributes to service endpoints(port, priority, weight)
@cloudhead cloudhead commented on an outdated diff Aug 2, 2012
+ rev, err := s.Set(path.Join(ADDRS_PATH, addr), time.Now().UTC().String())
+ if err != nil {
+ return
+ }
+
+ srv = s.FastForward(rev)
+
+ return
+}
+
+// RemoveAddr removes the given address string from the Service.
+func (s *Service) RemoveAddr(addr string) (srv *Service, err error) {
+ _, ok := s.Addrs[addr]
+ if ok {
+ delete(s.Addrs, addr)
+ }
@cloudhead
cloudhead Aug 2, 2012

I'd move this to after the s.Del(), to avoid inconsistencies.

@cloudhead cloudhead and 1 other commented on an outdated diff Aug 2, 2012
+ return
+ }
+
+ srv = s.FastForward(rev)
+
+ return
+}
+
+// Unregister removes the Service form the global process state.
+func (s *Service) Unregister() error {
+ return s.Del("/")
+}
+
+// AddAddr adds the given address string to the Service.
+func (s *Service) AddAddr(addr string) (srv *Service, err error) {
+ s.Addrs[addr] = true
@cloudhead
cloudhead Aug 2, 2012

I'd move this to after the s.Set(), to avoid inconsistencies.

@cloudhead cloudhead and 1 other commented on an outdated diff Aug 2, 2012
+ return
+}
+
+func (s *Service) String() string {
+ return fmt.Sprintf("Service<%s>", s.Name)
+}
+
+func (s *Service) Inspect() string {
+ return fmt.Sprintf("%#v", s)
+}
+
+func (s *Service) getAddrs() (addrs []string, err error) {
+ addrs, err = s.Getdir(s.Path.Prefix(ADDRS_PATH))
+ if err != nil && err.Error() == "NOENT" {
+ return addrs, nil
+ }
@cloudhead cloudhead and 1 other commented on an outdated diff Aug 2, 2012
service_test.go
+ addrs := []string{"1.2.3.4", "4.3.2.1"}
+ srv := serviceSetup(name)
+
+ srv, err := srv.Register()
+ if err != nil {
+ t.Error(t)
+ }
+
+ for _, addr := range addrs {
+ srv, err = srv.AddAddr(addr)
+ if err != nil {
+ t.Error(t)
+ }
+ }
+
+ srv2, err := GetService(srv.FastForward(srv.Snapshot.Rev).Snapshot, name)
@cloudhead
cloudhead Aug 2, 2012

same as:

GetService(srv.Snapshot, name)

@cloudhead cloudhead commented on an outdated diff Aug 2, 2012
service_test.go
+ t.Error(err)
+ }
+
+ for _, addr := range addrs {
+ srv, err = srv.AddAddr(addr)
+ if err != nil {
+ t.Error(t)
+ }
+ }
+
+ srv, err = srv.RemoveAddr("5.6.7.8")
+ if err != nil {
+ t.Error(err)
+ }
+
+ srv2, err := GetService(srv.FastForward(srv.Snapshot.Rev).Snapshot, name)
@cloudhead
cloudhead Aug 2, 2012

see above comment 🐹

@cloudhead

🚀

@cloudhead cloudhead merged commit 4c75ed0 into master Aug 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment