func (manager *Manager) registerManagerResource(grpcAddr string) error { node, err := scale.GetOwnNodeName() if err != nil { return err } ttl := 30 * time.Second resource := "swarm://" + node res, success, err := scale.RegisterResourceCustom( ManagerService, resource, grpcAddr, node, ttl) if err != nil { return err } if !success { // Leftover from a previous life. Clean up and try again. err := scale.ExistingResource(ManagerService, resource, "").Deregister() if err != nil { return err } return manager.registerManagerResource(grpcAddr) } manager.resource = res manager.sessionSKA = scale.NewSessionSelfKeepAlive( res.GetSessionID(), ttl/2) return nil }
// RegisterThisHost registers the current swarm node against the current // service. func RegisterThisHost( hostAddr string) ( serviceSka *scale.SelfKeepAlive, sessionSka *scale.SelfKeepAlive, err error) { service := leverutil.ServiceFlag.Get() instanceID := leverutil.InstanceIDFlag.Get() err = scale.RegisterServiceLocal( service, instanceID, hostAddr, 30*time.Second) if err != nil { return nil, nil, err } node, err := scale.GetOwnNodeName() if err != nil { return nil, nil, err } res, success, err := scale.RegisterResourceLocal( "swarm://"+node, 30*time.Second) if err != nil { return nil, nil, err } if !success { return nil, nil, fmt.Errorf("Duplicate Lever host on this node") } return scale.NewServiceSelfKeepAlive(instanceID, 15*time.Second), scale.NewSessionSelfKeepAlive(res.GetSessionID(), 15*time.Second), nil }