MCPcopy
hub / github.com/CodisLabs/codis / CreateProxy

Method CreateProxy

pkg/topom/topom_proxy.go:14–43  ·  view source on GitHub ↗
(addr string)

Source from the content-addressed store, hash-verified

12)
13
14func (s *Topom) CreateProxy(addr string) error {
15 s.mu.Lock()
16 defer s.mu.Unlock()
17 ctx, err := s.newContext()
18 if err != nil {
19 return err
20 }
21
22 p, err := proxy.NewApiClient(addr).Model()
23 if err != nil {
24 return errors.Errorf("proxy@%s fetch model failed, %s", addr, err)
25 }
26 c := s.newProxyClient(p)
27
28 if err := c.XPing(); err != nil {
29 return errors.Errorf("proxy@%s check xauth failed, %s", addr, err)
30 }
31 if ctx.proxy[p.Token] != nil {
32 return errors.Errorf("proxy-[%s] already exists", p.Token)
33 } else {
34 p.Id = ctx.maxProxyId() + 1
35 }
36 defer s.dirtyProxyCache(p.Token)
37
38 if err := s.storeCreateProxy(p); err != nil {
39 return err
40 } else {
41 return s.reinitProxy(ctx, p, c)
42 }
43}
44
45func (s *Topom) OnlineProxy(addr string) error {
46 s.mu.Lock()

Callers 4

TestCreateProxyFunction · 0.45
TestRemoveProxyFunction · 0.45
TestApiProxyFunction · 0.45
handleProxyCommandMethod · 0.45

Calls 9

newContextMethod · 0.95
newProxyClientMethod · 0.95
dirtyProxyCacheMethod · 0.95
storeCreateProxyMethod · 0.95
reinitProxyMethod · 0.95
ErrorfMethod · 0.80
maxProxyIdMethod · 0.80
ModelMethod · 0.45
XPingMethod · 0.45

Tested by 3

TestCreateProxyFunction · 0.36
TestRemoveProxyFunction · 0.36
TestApiProxyFunction · 0.36