|
@@ -5256,12 +5256,12 @@ func encodeVarintControl(data []byte, offset int, v uint64) int {
|
|
|
}
|
|
|
|
|
|
type raftProxyControlServer struct {
|
|
|
- local ControlServer
|
|
|
- connSelector raftselector.ConnProvider
|
|
|
- ctxMods []func(context.Context) (context.Context, error)
|
|
|
+ local ControlServer
|
|
|
+ connSelector raftselector.ConnProvider
|
|
|
+ localCtxMods, remoteCtxMods []func(context.Context) (context.Context, error)
|
|
|
}
|
|
|
|
|
|
-func NewRaftProxyControlServer(local ControlServer, connSelector raftselector.ConnProvider, ctxMod func(context.Context) (context.Context, error)) ControlServer {
|
|
|
+func NewRaftProxyControlServer(local ControlServer, connSelector raftselector.ConnProvider, localCtxMod, remoteCtxMod func(context.Context) (context.Context, error)) ControlServer {
|
|
|
redirectChecker := func(ctx context.Context) (context.Context, error) {
|
|
|
s, ok := transport.StreamFromContext(ctx)
|
|
|
if !ok {
|
|
@@ -5278,18 +5278,24 @@ func NewRaftProxyControlServer(local ControlServer, connSelector raftselector.Co
|
|
|
md["redirect"] = append(md["redirect"], addr)
|
|
|
return metadata.NewContext(ctx, md), nil
|
|
|
}
|
|
|
- mods := []func(context.Context) (context.Context, error){redirectChecker}
|
|
|
- mods = append(mods, ctxMod)
|
|
|
+ remoteMods := []func(context.Context) (context.Context, error){redirectChecker}
|
|
|
+ remoteMods = append(remoteMods, remoteCtxMod)
|
|
|
+
|
|
|
+ var localMods []func(context.Context) (context.Context, error)
|
|
|
+ if localCtxMod != nil {
|
|
|
+ localMods = []func(context.Context) (context.Context, error){localCtxMod}
|
|
|
+ }
|
|
|
|
|
|
return &raftProxyControlServer{
|
|
|
- local: local,
|
|
|
- connSelector: connSelector,
|
|
|
- ctxMods: mods,
|
|
|
+ local: local,
|
|
|
+ connSelector: connSelector,
|
|
|
+ localCtxMods: localMods,
|
|
|
+ remoteCtxMods: remoteMods,
|
|
|
}
|
|
|
}
|
|
|
-func (p *raftProxyControlServer) runCtxMods(ctx context.Context) (context.Context, error) {
|
|
|
+func (p *raftProxyControlServer) runCtxMods(ctx context.Context, ctxMods []func(context.Context) (context.Context, error)) (context.Context, error) {
|
|
|
var err error
|
|
|
- for _, mod := range p.ctxMods {
|
|
|
+ for _, mod := range ctxMods {
|
|
|
ctx, err = mod(ctx)
|
|
|
if err != nil {
|
|
|
return ctx, err
|
|
@@ -5326,11 +5332,15 @@ func (p *raftProxyControlServer) GetNode(ctx context.Context, r *GetNodeRequest)
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.GetNode(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5357,11 +5367,15 @@ func (p *raftProxyControlServer) ListNodes(ctx context.Context, r *ListNodesRequ
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.ListNodes(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5388,11 +5402,15 @@ func (p *raftProxyControlServer) UpdateNode(ctx context.Context, r *UpdateNodeRe
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.UpdateNode(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5419,11 +5437,15 @@ func (p *raftProxyControlServer) RemoveNode(ctx context.Context, r *RemoveNodeRe
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.RemoveNode(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5450,11 +5472,15 @@ func (p *raftProxyControlServer) GetTask(ctx context.Context, r *GetTaskRequest)
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.GetTask(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5481,11 +5507,15 @@ func (p *raftProxyControlServer) ListTasks(ctx context.Context, r *ListTasksRequ
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.ListTasks(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5512,11 +5542,15 @@ func (p *raftProxyControlServer) RemoveTask(ctx context.Context, r *RemoveTaskRe
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.RemoveTask(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5543,11 +5577,15 @@ func (p *raftProxyControlServer) GetService(ctx context.Context, r *GetServiceRe
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.GetService(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5574,11 +5612,15 @@ func (p *raftProxyControlServer) ListServices(ctx context.Context, r *ListServic
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.ListServices(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5605,11 +5647,15 @@ func (p *raftProxyControlServer) CreateService(ctx context.Context, r *CreateSer
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.CreateService(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5636,11 +5682,15 @@ func (p *raftProxyControlServer) UpdateService(ctx context.Context, r *UpdateSer
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.UpdateService(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5667,11 +5717,15 @@ func (p *raftProxyControlServer) RemoveService(ctx context.Context, r *RemoveSer
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.RemoveService(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5698,11 +5752,15 @@ func (p *raftProxyControlServer) GetNetwork(ctx context.Context, r *GetNetworkRe
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.GetNetwork(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5729,11 +5787,15 @@ func (p *raftProxyControlServer) ListNetworks(ctx context.Context, r *ListNetwor
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.ListNetworks(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5760,11 +5822,15 @@ func (p *raftProxyControlServer) CreateNetwork(ctx context.Context, r *CreateNet
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.CreateNetwork(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5791,11 +5857,15 @@ func (p *raftProxyControlServer) RemoveNetwork(ctx context.Context, r *RemoveNet
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.RemoveNetwork(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5822,11 +5892,15 @@ func (p *raftProxyControlServer) GetCluster(ctx context.Context, r *GetClusterRe
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.GetCluster(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5853,11 +5927,15 @@ func (p *raftProxyControlServer) ListClusters(ctx context.Context, r *ListCluste
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.ListClusters(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5884,11 +5962,15 @@ func (p *raftProxyControlServer) UpdateCluster(ctx context.Context, r *UpdateClu
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.UpdateCluster(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5915,11 +5997,15 @@ func (p *raftProxyControlServer) GetSecret(ctx context.Context, r *GetSecretRequ
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.GetSecret(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5946,11 +6032,15 @@ func (p *raftProxyControlServer) UpdateSecret(ctx context.Context, r *UpdateSecr
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.UpdateSecret(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -5977,11 +6067,15 @@ func (p *raftProxyControlServer) ListSecrets(ctx context.Context, r *ListSecrets
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.ListSecrets(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -6008,11 +6102,15 @@ func (p *raftProxyControlServer) CreateSecret(ctx context.Context, r *CreateSecr
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.CreateSecret(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -6039,11 +6137,15 @@ func (p *raftProxyControlServer) RemoveSecret(ctx context.Context, r *RemoveSecr
|
|
|
conn, err := p.connSelector.LeaderConn(ctx)
|
|
|
if err != nil {
|
|
|
if err == raftselector.ErrIsLeader {
|
|
|
+ ctx, err = p.runCtxMods(ctx, p.localCtxMods)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
return p.local.RemoveSecret(ctx, r)
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
- modCtx, err := p.runCtxMods(ctx)
|
|
|
+ modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|