resource.pb.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. // Code generated by protoc-gen-gogo.
  2. // source: resource.proto
  3. // DO NOT EDIT!
  4. package api
  5. import proto "github.com/gogo/protobuf/proto"
  6. import fmt "fmt"
  7. import math "math"
  8. import _ "github.com/gogo/protobuf/gogoproto"
  9. import _ "github.com/docker/swarmkit/protobuf/plugin"
  10. import strings "strings"
  11. import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
  12. import sort "sort"
  13. import strconv "strconv"
  14. import reflect "reflect"
  15. import (
  16. context "golang.org/x/net/context"
  17. grpc "google.golang.org/grpc"
  18. )
  19. import raftselector "github.com/docker/swarmkit/manager/raftselector"
  20. import codes "google.golang.org/grpc/codes"
  21. import metadata "google.golang.org/grpc/metadata"
  22. import transport "google.golang.org/grpc/transport"
  23. import time "time"
  24. import io "io"
  25. // Reference imports to suppress errors if they are not otherwise used.
  26. var _ = proto.Marshal
  27. var _ = fmt.Errorf
  28. var _ = math.Inf
  29. type AttachNetworkRequest struct {
  30. Config *NetworkAttachmentConfig `protobuf:"bytes,1,opt,name=config" json:"config,omitempty"`
  31. ContainerID string `protobuf:"bytes,2,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"`
  32. }
  33. func (m *AttachNetworkRequest) Reset() { *m = AttachNetworkRequest{} }
  34. func (*AttachNetworkRequest) ProtoMessage() {}
  35. func (*AttachNetworkRequest) Descriptor() ([]byte, []int) { return fileDescriptorResource, []int{0} }
  36. type AttachNetworkResponse struct {
  37. AttachmentID string `protobuf:"bytes,1,opt,name=attachment_id,json=attachmentId,proto3" json:"attachment_id,omitempty"`
  38. }
  39. func (m *AttachNetworkResponse) Reset() { *m = AttachNetworkResponse{} }
  40. func (*AttachNetworkResponse) ProtoMessage() {}
  41. func (*AttachNetworkResponse) Descriptor() ([]byte, []int) { return fileDescriptorResource, []int{1} }
  42. type DetachNetworkRequest struct {
  43. AttachmentID string `protobuf:"bytes,1,opt,name=attachment_id,json=attachmentId,proto3" json:"attachment_id,omitempty"`
  44. }
  45. func (m *DetachNetworkRequest) Reset() { *m = DetachNetworkRequest{} }
  46. func (*DetachNetworkRequest) ProtoMessage() {}
  47. func (*DetachNetworkRequest) Descriptor() ([]byte, []int) { return fileDescriptorResource, []int{2} }
  48. type DetachNetworkResponse struct {
  49. }
  50. func (m *DetachNetworkResponse) Reset() { *m = DetachNetworkResponse{} }
  51. func (*DetachNetworkResponse) ProtoMessage() {}
  52. func (*DetachNetworkResponse) Descriptor() ([]byte, []int) { return fileDescriptorResource, []int{3} }
  53. func init() {
  54. proto.RegisterType((*AttachNetworkRequest)(nil), "docker.swarmkit.v1.AttachNetworkRequest")
  55. proto.RegisterType((*AttachNetworkResponse)(nil), "docker.swarmkit.v1.AttachNetworkResponse")
  56. proto.RegisterType((*DetachNetworkRequest)(nil), "docker.swarmkit.v1.DetachNetworkRequest")
  57. proto.RegisterType((*DetachNetworkResponse)(nil), "docker.swarmkit.v1.DetachNetworkResponse")
  58. }
  59. type authenticatedWrapperResourceAllocatorServer struct {
  60. local ResourceAllocatorServer
  61. authorize func(context.Context, []string) error
  62. }
  63. func NewAuthenticatedWrapperResourceAllocatorServer(local ResourceAllocatorServer, authorize func(context.Context, []string) error) ResourceAllocatorServer {
  64. return &authenticatedWrapperResourceAllocatorServer{
  65. local: local,
  66. authorize: authorize,
  67. }
  68. }
  69. func (p *authenticatedWrapperResourceAllocatorServer) AttachNetwork(ctx context.Context, r *AttachNetworkRequest) (*AttachNetworkResponse, error) {
  70. if err := p.authorize(ctx, []string{"swarm-worker", "swarm-manager"}); err != nil {
  71. return nil, err
  72. }
  73. return p.local.AttachNetwork(ctx, r)
  74. }
  75. func (p *authenticatedWrapperResourceAllocatorServer) DetachNetwork(ctx context.Context, r *DetachNetworkRequest) (*DetachNetworkResponse, error) {
  76. if err := p.authorize(ctx, []string{"swarm-worker", "swarm-manager"}); err != nil {
  77. return nil, err
  78. }
  79. return p.local.DetachNetwork(ctx, r)
  80. }
  81. func (m *AttachNetworkRequest) Copy() *AttachNetworkRequest {
  82. if m == nil {
  83. return nil
  84. }
  85. o := &AttachNetworkRequest{
  86. Config: m.Config.Copy(),
  87. ContainerID: m.ContainerID,
  88. }
  89. return o
  90. }
  91. func (m *AttachNetworkResponse) Copy() *AttachNetworkResponse {
  92. if m == nil {
  93. return nil
  94. }
  95. o := &AttachNetworkResponse{
  96. AttachmentID: m.AttachmentID,
  97. }
  98. return o
  99. }
  100. func (m *DetachNetworkRequest) Copy() *DetachNetworkRequest {
  101. if m == nil {
  102. return nil
  103. }
  104. o := &DetachNetworkRequest{
  105. AttachmentID: m.AttachmentID,
  106. }
  107. return o
  108. }
  109. func (m *DetachNetworkResponse) Copy() *DetachNetworkResponse {
  110. if m == nil {
  111. return nil
  112. }
  113. o := &DetachNetworkResponse{}
  114. return o
  115. }
  116. func (this *AttachNetworkRequest) GoString() string {
  117. if this == nil {
  118. return "nil"
  119. }
  120. s := make([]string, 0, 6)
  121. s = append(s, "&api.AttachNetworkRequest{")
  122. if this.Config != nil {
  123. s = append(s, "Config: "+fmt.Sprintf("%#v", this.Config)+",\n")
  124. }
  125. s = append(s, "ContainerID: "+fmt.Sprintf("%#v", this.ContainerID)+",\n")
  126. s = append(s, "}")
  127. return strings.Join(s, "")
  128. }
  129. func (this *AttachNetworkResponse) GoString() string {
  130. if this == nil {
  131. return "nil"
  132. }
  133. s := make([]string, 0, 5)
  134. s = append(s, "&api.AttachNetworkResponse{")
  135. s = append(s, "AttachmentID: "+fmt.Sprintf("%#v", this.AttachmentID)+",\n")
  136. s = append(s, "}")
  137. return strings.Join(s, "")
  138. }
  139. func (this *DetachNetworkRequest) GoString() string {
  140. if this == nil {
  141. return "nil"
  142. }
  143. s := make([]string, 0, 5)
  144. s = append(s, "&api.DetachNetworkRequest{")
  145. s = append(s, "AttachmentID: "+fmt.Sprintf("%#v", this.AttachmentID)+",\n")
  146. s = append(s, "}")
  147. return strings.Join(s, "")
  148. }
  149. func (this *DetachNetworkResponse) GoString() string {
  150. if this == nil {
  151. return "nil"
  152. }
  153. s := make([]string, 0, 4)
  154. s = append(s, "&api.DetachNetworkResponse{")
  155. s = append(s, "}")
  156. return strings.Join(s, "")
  157. }
  158. func valueToGoStringResource(v interface{}, typ string) string {
  159. rv := reflect.ValueOf(v)
  160. if rv.IsNil() {
  161. return "nil"
  162. }
  163. pv := reflect.Indirect(rv).Interface()
  164. return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
  165. }
  166. func extensionToGoStringResource(m github_com_gogo_protobuf_proto.Message) string {
  167. e := github_com_gogo_protobuf_proto.GetUnsafeExtensionsMap(m)
  168. if e == nil {
  169. return "nil"
  170. }
  171. s := "proto.NewUnsafeXXX_InternalExtensions(map[int32]proto.Extension{"
  172. keys := make([]int, 0, len(e))
  173. for k := range e {
  174. keys = append(keys, int(k))
  175. }
  176. sort.Ints(keys)
  177. ss := []string{}
  178. for _, k := range keys {
  179. ss = append(ss, strconv.Itoa(k)+": "+e[int32(k)].GoString())
  180. }
  181. s += strings.Join(ss, ",") + "})"
  182. return s
  183. }
  184. // Reference imports to suppress errors if they are not otherwise used.
  185. var _ context.Context
  186. var _ grpc.ClientConn
  187. // This is a compile-time assertion to ensure that this generated file
  188. // is compatible with the grpc package it is being compiled against.
  189. const _ = grpc.SupportPackageIsVersion3
  190. // Client API for ResourceAllocator service
  191. type ResourceAllocatorClient interface {
  192. AttachNetwork(ctx context.Context, in *AttachNetworkRequest, opts ...grpc.CallOption) (*AttachNetworkResponse, error)
  193. DetachNetwork(ctx context.Context, in *DetachNetworkRequest, opts ...grpc.CallOption) (*DetachNetworkResponse, error)
  194. }
  195. type resourceAllocatorClient struct {
  196. cc *grpc.ClientConn
  197. }
  198. func NewResourceAllocatorClient(cc *grpc.ClientConn) ResourceAllocatorClient {
  199. return &resourceAllocatorClient{cc}
  200. }
  201. func (c *resourceAllocatorClient) AttachNetwork(ctx context.Context, in *AttachNetworkRequest, opts ...grpc.CallOption) (*AttachNetworkResponse, error) {
  202. out := new(AttachNetworkResponse)
  203. err := grpc.Invoke(ctx, "/docker.swarmkit.v1.ResourceAllocator/AttachNetwork", in, out, c.cc, opts...)
  204. if err != nil {
  205. return nil, err
  206. }
  207. return out, nil
  208. }
  209. func (c *resourceAllocatorClient) DetachNetwork(ctx context.Context, in *DetachNetworkRequest, opts ...grpc.CallOption) (*DetachNetworkResponse, error) {
  210. out := new(DetachNetworkResponse)
  211. err := grpc.Invoke(ctx, "/docker.swarmkit.v1.ResourceAllocator/DetachNetwork", in, out, c.cc, opts...)
  212. if err != nil {
  213. return nil, err
  214. }
  215. return out, nil
  216. }
  217. // Server API for ResourceAllocator service
  218. type ResourceAllocatorServer interface {
  219. AttachNetwork(context.Context, *AttachNetworkRequest) (*AttachNetworkResponse, error)
  220. DetachNetwork(context.Context, *DetachNetworkRequest) (*DetachNetworkResponse, error)
  221. }
  222. func RegisterResourceAllocatorServer(s *grpc.Server, srv ResourceAllocatorServer) {
  223. s.RegisterService(&_ResourceAllocator_serviceDesc, srv)
  224. }
  225. func _ResourceAllocator_AttachNetwork_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
  226. in := new(AttachNetworkRequest)
  227. if err := dec(in); err != nil {
  228. return nil, err
  229. }
  230. if interceptor == nil {
  231. return srv.(ResourceAllocatorServer).AttachNetwork(ctx, in)
  232. }
  233. info := &grpc.UnaryServerInfo{
  234. Server: srv,
  235. FullMethod: "/docker.swarmkit.v1.ResourceAllocator/AttachNetwork",
  236. }
  237. handler := func(ctx context.Context, req interface{}) (interface{}, error) {
  238. return srv.(ResourceAllocatorServer).AttachNetwork(ctx, req.(*AttachNetworkRequest))
  239. }
  240. return interceptor(ctx, in, info, handler)
  241. }
  242. func _ResourceAllocator_DetachNetwork_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
  243. in := new(DetachNetworkRequest)
  244. if err := dec(in); err != nil {
  245. return nil, err
  246. }
  247. if interceptor == nil {
  248. return srv.(ResourceAllocatorServer).DetachNetwork(ctx, in)
  249. }
  250. info := &grpc.UnaryServerInfo{
  251. Server: srv,
  252. FullMethod: "/docker.swarmkit.v1.ResourceAllocator/DetachNetwork",
  253. }
  254. handler := func(ctx context.Context, req interface{}) (interface{}, error) {
  255. return srv.(ResourceAllocatorServer).DetachNetwork(ctx, req.(*DetachNetworkRequest))
  256. }
  257. return interceptor(ctx, in, info, handler)
  258. }
  259. var _ResourceAllocator_serviceDesc = grpc.ServiceDesc{
  260. ServiceName: "docker.swarmkit.v1.ResourceAllocator",
  261. HandlerType: (*ResourceAllocatorServer)(nil),
  262. Methods: []grpc.MethodDesc{
  263. {
  264. MethodName: "AttachNetwork",
  265. Handler: _ResourceAllocator_AttachNetwork_Handler,
  266. },
  267. {
  268. MethodName: "DetachNetwork",
  269. Handler: _ResourceAllocator_DetachNetwork_Handler,
  270. },
  271. },
  272. Streams: []grpc.StreamDesc{},
  273. Metadata: fileDescriptorResource,
  274. }
  275. func (m *AttachNetworkRequest) Marshal() (data []byte, err error) {
  276. size := m.Size()
  277. data = make([]byte, size)
  278. n, err := m.MarshalTo(data)
  279. if err != nil {
  280. return nil, err
  281. }
  282. return data[:n], nil
  283. }
  284. func (m *AttachNetworkRequest) MarshalTo(data []byte) (int, error) {
  285. var i int
  286. _ = i
  287. var l int
  288. _ = l
  289. if m.Config != nil {
  290. data[i] = 0xa
  291. i++
  292. i = encodeVarintResource(data, i, uint64(m.Config.Size()))
  293. n1, err := m.Config.MarshalTo(data[i:])
  294. if err != nil {
  295. return 0, err
  296. }
  297. i += n1
  298. }
  299. if len(m.ContainerID) > 0 {
  300. data[i] = 0x12
  301. i++
  302. i = encodeVarintResource(data, i, uint64(len(m.ContainerID)))
  303. i += copy(data[i:], m.ContainerID)
  304. }
  305. return i, nil
  306. }
  307. func (m *AttachNetworkResponse) Marshal() (data []byte, err error) {
  308. size := m.Size()
  309. data = make([]byte, size)
  310. n, err := m.MarshalTo(data)
  311. if err != nil {
  312. return nil, err
  313. }
  314. return data[:n], nil
  315. }
  316. func (m *AttachNetworkResponse) MarshalTo(data []byte) (int, error) {
  317. var i int
  318. _ = i
  319. var l int
  320. _ = l
  321. if len(m.AttachmentID) > 0 {
  322. data[i] = 0xa
  323. i++
  324. i = encodeVarintResource(data, i, uint64(len(m.AttachmentID)))
  325. i += copy(data[i:], m.AttachmentID)
  326. }
  327. return i, nil
  328. }
  329. func (m *DetachNetworkRequest) Marshal() (data []byte, err error) {
  330. size := m.Size()
  331. data = make([]byte, size)
  332. n, err := m.MarshalTo(data)
  333. if err != nil {
  334. return nil, err
  335. }
  336. return data[:n], nil
  337. }
  338. func (m *DetachNetworkRequest) MarshalTo(data []byte) (int, error) {
  339. var i int
  340. _ = i
  341. var l int
  342. _ = l
  343. if len(m.AttachmentID) > 0 {
  344. data[i] = 0xa
  345. i++
  346. i = encodeVarintResource(data, i, uint64(len(m.AttachmentID)))
  347. i += copy(data[i:], m.AttachmentID)
  348. }
  349. return i, nil
  350. }
  351. func (m *DetachNetworkResponse) Marshal() (data []byte, err error) {
  352. size := m.Size()
  353. data = make([]byte, size)
  354. n, err := m.MarshalTo(data)
  355. if err != nil {
  356. return nil, err
  357. }
  358. return data[:n], nil
  359. }
  360. func (m *DetachNetworkResponse) MarshalTo(data []byte) (int, error) {
  361. var i int
  362. _ = i
  363. var l int
  364. _ = l
  365. return i, nil
  366. }
  367. func encodeFixed64Resource(data []byte, offset int, v uint64) int {
  368. data[offset] = uint8(v)
  369. data[offset+1] = uint8(v >> 8)
  370. data[offset+2] = uint8(v >> 16)
  371. data[offset+3] = uint8(v >> 24)
  372. data[offset+4] = uint8(v >> 32)
  373. data[offset+5] = uint8(v >> 40)
  374. data[offset+6] = uint8(v >> 48)
  375. data[offset+7] = uint8(v >> 56)
  376. return offset + 8
  377. }
  378. func encodeFixed32Resource(data []byte, offset int, v uint32) int {
  379. data[offset] = uint8(v)
  380. data[offset+1] = uint8(v >> 8)
  381. data[offset+2] = uint8(v >> 16)
  382. data[offset+3] = uint8(v >> 24)
  383. return offset + 4
  384. }
  385. func encodeVarintResource(data []byte, offset int, v uint64) int {
  386. for v >= 1<<7 {
  387. data[offset] = uint8(v&0x7f | 0x80)
  388. v >>= 7
  389. offset++
  390. }
  391. data[offset] = uint8(v)
  392. return offset + 1
  393. }
  394. type raftProxyResourceAllocatorServer struct {
  395. local ResourceAllocatorServer
  396. connSelector raftselector.ConnProvider
  397. localCtxMods, remoteCtxMods []func(context.Context) (context.Context, error)
  398. }
  399. func NewRaftProxyResourceAllocatorServer(local ResourceAllocatorServer, connSelector raftselector.ConnProvider, localCtxMod, remoteCtxMod func(context.Context) (context.Context, error)) ResourceAllocatorServer {
  400. redirectChecker := func(ctx context.Context) (context.Context, error) {
  401. s, ok := transport.StreamFromContext(ctx)
  402. if !ok {
  403. return ctx, grpc.Errorf(codes.InvalidArgument, "remote addr is not found in context")
  404. }
  405. addr := s.ServerTransport().RemoteAddr().String()
  406. md, ok := metadata.FromContext(ctx)
  407. if ok && len(md["redirect"]) != 0 {
  408. return ctx, grpc.Errorf(codes.ResourceExhausted, "more than one redirect to leader from: %s", md["redirect"])
  409. }
  410. if !ok {
  411. md = metadata.New(map[string]string{})
  412. }
  413. md["redirect"] = append(md["redirect"], addr)
  414. return metadata.NewContext(ctx, md), nil
  415. }
  416. remoteMods := []func(context.Context) (context.Context, error){redirectChecker}
  417. remoteMods = append(remoteMods, remoteCtxMod)
  418. var localMods []func(context.Context) (context.Context, error)
  419. if localCtxMod != nil {
  420. localMods = []func(context.Context) (context.Context, error){localCtxMod}
  421. }
  422. return &raftProxyResourceAllocatorServer{
  423. local: local,
  424. connSelector: connSelector,
  425. localCtxMods: localMods,
  426. remoteCtxMods: remoteMods,
  427. }
  428. }
  429. func (p *raftProxyResourceAllocatorServer) runCtxMods(ctx context.Context, ctxMods []func(context.Context) (context.Context, error)) (context.Context, error) {
  430. var err error
  431. for _, mod := range ctxMods {
  432. ctx, err = mod(ctx)
  433. if err != nil {
  434. return ctx, err
  435. }
  436. }
  437. return ctx, nil
  438. }
  439. func (p *raftProxyResourceAllocatorServer) pollNewLeaderConn(ctx context.Context) (*grpc.ClientConn, error) {
  440. ticker := time.NewTicker(500 * time.Millisecond)
  441. defer ticker.Stop()
  442. for {
  443. select {
  444. case <-ticker.C:
  445. conn, err := p.connSelector.LeaderConn(ctx)
  446. if err != nil {
  447. return nil, err
  448. }
  449. client := NewHealthClient(conn)
  450. resp, err := client.Check(ctx, &HealthCheckRequest{Service: "Raft"})
  451. if err != nil || resp.Status != HealthCheckResponse_SERVING {
  452. continue
  453. }
  454. return conn, nil
  455. case <-ctx.Done():
  456. return nil, ctx.Err()
  457. }
  458. }
  459. }
  460. func (p *raftProxyResourceAllocatorServer) AttachNetwork(ctx context.Context, r *AttachNetworkRequest) (*AttachNetworkResponse, error) {
  461. conn, err := p.connSelector.LeaderConn(ctx)
  462. if err != nil {
  463. if err == raftselector.ErrIsLeader {
  464. ctx, err = p.runCtxMods(ctx, p.localCtxMods)
  465. if err != nil {
  466. return nil, err
  467. }
  468. return p.local.AttachNetwork(ctx, r)
  469. }
  470. return nil, err
  471. }
  472. modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
  473. if err != nil {
  474. return nil, err
  475. }
  476. resp, err := NewResourceAllocatorClient(conn).AttachNetwork(modCtx, r)
  477. if err != nil {
  478. if !strings.Contains(err.Error(), "is closing") && !strings.Contains(err.Error(), "the connection is unavailable") && !strings.Contains(err.Error(), "connection error") {
  479. return resp, err
  480. }
  481. conn, err := p.pollNewLeaderConn(ctx)
  482. if err != nil {
  483. if err == raftselector.ErrIsLeader {
  484. return p.local.AttachNetwork(ctx, r)
  485. }
  486. return nil, err
  487. }
  488. return NewResourceAllocatorClient(conn).AttachNetwork(modCtx, r)
  489. }
  490. return resp, err
  491. }
  492. func (p *raftProxyResourceAllocatorServer) DetachNetwork(ctx context.Context, r *DetachNetworkRequest) (*DetachNetworkResponse, error) {
  493. conn, err := p.connSelector.LeaderConn(ctx)
  494. if err != nil {
  495. if err == raftselector.ErrIsLeader {
  496. ctx, err = p.runCtxMods(ctx, p.localCtxMods)
  497. if err != nil {
  498. return nil, err
  499. }
  500. return p.local.DetachNetwork(ctx, r)
  501. }
  502. return nil, err
  503. }
  504. modCtx, err := p.runCtxMods(ctx, p.remoteCtxMods)
  505. if err != nil {
  506. return nil, err
  507. }
  508. resp, err := NewResourceAllocatorClient(conn).DetachNetwork(modCtx, r)
  509. if err != nil {
  510. if !strings.Contains(err.Error(), "is closing") && !strings.Contains(err.Error(), "the connection is unavailable") && !strings.Contains(err.Error(), "connection error") {
  511. return resp, err
  512. }
  513. conn, err := p.pollNewLeaderConn(ctx)
  514. if err != nil {
  515. if err == raftselector.ErrIsLeader {
  516. return p.local.DetachNetwork(ctx, r)
  517. }
  518. return nil, err
  519. }
  520. return NewResourceAllocatorClient(conn).DetachNetwork(modCtx, r)
  521. }
  522. return resp, err
  523. }
  524. func (m *AttachNetworkRequest) Size() (n int) {
  525. var l int
  526. _ = l
  527. if m.Config != nil {
  528. l = m.Config.Size()
  529. n += 1 + l + sovResource(uint64(l))
  530. }
  531. l = len(m.ContainerID)
  532. if l > 0 {
  533. n += 1 + l + sovResource(uint64(l))
  534. }
  535. return n
  536. }
  537. func (m *AttachNetworkResponse) Size() (n int) {
  538. var l int
  539. _ = l
  540. l = len(m.AttachmentID)
  541. if l > 0 {
  542. n += 1 + l + sovResource(uint64(l))
  543. }
  544. return n
  545. }
  546. func (m *DetachNetworkRequest) Size() (n int) {
  547. var l int
  548. _ = l
  549. l = len(m.AttachmentID)
  550. if l > 0 {
  551. n += 1 + l + sovResource(uint64(l))
  552. }
  553. return n
  554. }
  555. func (m *DetachNetworkResponse) Size() (n int) {
  556. var l int
  557. _ = l
  558. return n
  559. }
  560. func sovResource(x uint64) (n int) {
  561. for {
  562. n++
  563. x >>= 7
  564. if x == 0 {
  565. break
  566. }
  567. }
  568. return n
  569. }
  570. func sozResource(x uint64) (n int) {
  571. return sovResource(uint64((x << 1) ^ uint64((int64(x) >> 63))))
  572. }
  573. func (this *AttachNetworkRequest) String() string {
  574. if this == nil {
  575. return "nil"
  576. }
  577. s := strings.Join([]string{`&AttachNetworkRequest{`,
  578. `Config:` + strings.Replace(fmt.Sprintf("%v", this.Config), "NetworkAttachmentConfig", "NetworkAttachmentConfig", 1) + `,`,
  579. `ContainerID:` + fmt.Sprintf("%v", this.ContainerID) + `,`,
  580. `}`,
  581. }, "")
  582. return s
  583. }
  584. func (this *AttachNetworkResponse) String() string {
  585. if this == nil {
  586. return "nil"
  587. }
  588. s := strings.Join([]string{`&AttachNetworkResponse{`,
  589. `AttachmentID:` + fmt.Sprintf("%v", this.AttachmentID) + `,`,
  590. `}`,
  591. }, "")
  592. return s
  593. }
  594. func (this *DetachNetworkRequest) String() string {
  595. if this == nil {
  596. return "nil"
  597. }
  598. s := strings.Join([]string{`&DetachNetworkRequest{`,
  599. `AttachmentID:` + fmt.Sprintf("%v", this.AttachmentID) + `,`,
  600. `}`,
  601. }, "")
  602. return s
  603. }
  604. func (this *DetachNetworkResponse) String() string {
  605. if this == nil {
  606. return "nil"
  607. }
  608. s := strings.Join([]string{`&DetachNetworkResponse{`,
  609. `}`,
  610. }, "")
  611. return s
  612. }
  613. func valueToStringResource(v interface{}) string {
  614. rv := reflect.ValueOf(v)
  615. if rv.IsNil() {
  616. return "nil"
  617. }
  618. pv := reflect.Indirect(rv).Interface()
  619. return fmt.Sprintf("*%v", pv)
  620. }
  621. func (m *AttachNetworkRequest) Unmarshal(data []byte) error {
  622. l := len(data)
  623. iNdEx := 0
  624. for iNdEx < l {
  625. preIndex := iNdEx
  626. var wire uint64
  627. for shift := uint(0); ; shift += 7 {
  628. if shift >= 64 {
  629. return ErrIntOverflowResource
  630. }
  631. if iNdEx >= l {
  632. return io.ErrUnexpectedEOF
  633. }
  634. b := data[iNdEx]
  635. iNdEx++
  636. wire |= (uint64(b) & 0x7F) << shift
  637. if b < 0x80 {
  638. break
  639. }
  640. }
  641. fieldNum := int32(wire >> 3)
  642. wireType := int(wire & 0x7)
  643. if wireType == 4 {
  644. return fmt.Errorf("proto: AttachNetworkRequest: wiretype end group for non-group")
  645. }
  646. if fieldNum <= 0 {
  647. return fmt.Errorf("proto: AttachNetworkRequest: illegal tag %d (wire type %d)", fieldNum, wire)
  648. }
  649. switch fieldNum {
  650. case 1:
  651. if wireType != 2 {
  652. return fmt.Errorf("proto: wrong wireType = %d for field Config", wireType)
  653. }
  654. var msglen int
  655. for shift := uint(0); ; shift += 7 {
  656. if shift >= 64 {
  657. return ErrIntOverflowResource
  658. }
  659. if iNdEx >= l {
  660. return io.ErrUnexpectedEOF
  661. }
  662. b := data[iNdEx]
  663. iNdEx++
  664. msglen |= (int(b) & 0x7F) << shift
  665. if b < 0x80 {
  666. break
  667. }
  668. }
  669. if msglen < 0 {
  670. return ErrInvalidLengthResource
  671. }
  672. postIndex := iNdEx + msglen
  673. if postIndex > l {
  674. return io.ErrUnexpectedEOF
  675. }
  676. if m.Config == nil {
  677. m.Config = &NetworkAttachmentConfig{}
  678. }
  679. if err := m.Config.Unmarshal(data[iNdEx:postIndex]); err != nil {
  680. return err
  681. }
  682. iNdEx = postIndex
  683. case 2:
  684. if wireType != 2 {
  685. return fmt.Errorf("proto: wrong wireType = %d for field ContainerID", wireType)
  686. }
  687. var stringLen uint64
  688. for shift := uint(0); ; shift += 7 {
  689. if shift >= 64 {
  690. return ErrIntOverflowResource
  691. }
  692. if iNdEx >= l {
  693. return io.ErrUnexpectedEOF
  694. }
  695. b := data[iNdEx]
  696. iNdEx++
  697. stringLen |= (uint64(b) & 0x7F) << shift
  698. if b < 0x80 {
  699. break
  700. }
  701. }
  702. intStringLen := int(stringLen)
  703. if intStringLen < 0 {
  704. return ErrInvalidLengthResource
  705. }
  706. postIndex := iNdEx + intStringLen
  707. if postIndex > l {
  708. return io.ErrUnexpectedEOF
  709. }
  710. m.ContainerID = string(data[iNdEx:postIndex])
  711. iNdEx = postIndex
  712. default:
  713. iNdEx = preIndex
  714. skippy, err := skipResource(data[iNdEx:])
  715. if err != nil {
  716. return err
  717. }
  718. if skippy < 0 {
  719. return ErrInvalidLengthResource
  720. }
  721. if (iNdEx + skippy) > l {
  722. return io.ErrUnexpectedEOF
  723. }
  724. iNdEx += skippy
  725. }
  726. }
  727. if iNdEx > l {
  728. return io.ErrUnexpectedEOF
  729. }
  730. return nil
  731. }
  732. func (m *AttachNetworkResponse) Unmarshal(data []byte) error {
  733. l := len(data)
  734. iNdEx := 0
  735. for iNdEx < l {
  736. preIndex := iNdEx
  737. var wire uint64
  738. for shift := uint(0); ; shift += 7 {
  739. if shift >= 64 {
  740. return ErrIntOverflowResource
  741. }
  742. if iNdEx >= l {
  743. return io.ErrUnexpectedEOF
  744. }
  745. b := data[iNdEx]
  746. iNdEx++
  747. wire |= (uint64(b) & 0x7F) << shift
  748. if b < 0x80 {
  749. break
  750. }
  751. }
  752. fieldNum := int32(wire >> 3)
  753. wireType := int(wire & 0x7)
  754. if wireType == 4 {
  755. return fmt.Errorf("proto: AttachNetworkResponse: wiretype end group for non-group")
  756. }
  757. if fieldNum <= 0 {
  758. return fmt.Errorf("proto: AttachNetworkResponse: illegal tag %d (wire type %d)", fieldNum, wire)
  759. }
  760. switch fieldNum {
  761. case 1:
  762. if wireType != 2 {
  763. return fmt.Errorf("proto: wrong wireType = %d for field AttachmentID", wireType)
  764. }
  765. var stringLen uint64
  766. for shift := uint(0); ; shift += 7 {
  767. if shift >= 64 {
  768. return ErrIntOverflowResource
  769. }
  770. if iNdEx >= l {
  771. return io.ErrUnexpectedEOF
  772. }
  773. b := data[iNdEx]
  774. iNdEx++
  775. stringLen |= (uint64(b) & 0x7F) << shift
  776. if b < 0x80 {
  777. break
  778. }
  779. }
  780. intStringLen := int(stringLen)
  781. if intStringLen < 0 {
  782. return ErrInvalidLengthResource
  783. }
  784. postIndex := iNdEx + intStringLen
  785. if postIndex > l {
  786. return io.ErrUnexpectedEOF
  787. }
  788. m.AttachmentID = string(data[iNdEx:postIndex])
  789. iNdEx = postIndex
  790. default:
  791. iNdEx = preIndex
  792. skippy, err := skipResource(data[iNdEx:])
  793. if err != nil {
  794. return err
  795. }
  796. if skippy < 0 {
  797. return ErrInvalidLengthResource
  798. }
  799. if (iNdEx + skippy) > l {
  800. return io.ErrUnexpectedEOF
  801. }
  802. iNdEx += skippy
  803. }
  804. }
  805. if iNdEx > l {
  806. return io.ErrUnexpectedEOF
  807. }
  808. return nil
  809. }
  810. func (m *DetachNetworkRequest) Unmarshal(data []byte) error {
  811. l := len(data)
  812. iNdEx := 0
  813. for iNdEx < l {
  814. preIndex := iNdEx
  815. var wire uint64
  816. for shift := uint(0); ; shift += 7 {
  817. if shift >= 64 {
  818. return ErrIntOverflowResource
  819. }
  820. if iNdEx >= l {
  821. return io.ErrUnexpectedEOF
  822. }
  823. b := data[iNdEx]
  824. iNdEx++
  825. wire |= (uint64(b) & 0x7F) << shift
  826. if b < 0x80 {
  827. break
  828. }
  829. }
  830. fieldNum := int32(wire >> 3)
  831. wireType := int(wire & 0x7)
  832. if wireType == 4 {
  833. return fmt.Errorf("proto: DetachNetworkRequest: wiretype end group for non-group")
  834. }
  835. if fieldNum <= 0 {
  836. return fmt.Errorf("proto: DetachNetworkRequest: illegal tag %d (wire type %d)", fieldNum, wire)
  837. }
  838. switch fieldNum {
  839. case 1:
  840. if wireType != 2 {
  841. return fmt.Errorf("proto: wrong wireType = %d for field AttachmentID", wireType)
  842. }
  843. var stringLen uint64
  844. for shift := uint(0); ; shift += 7 {
  845. if shift >= 64 {
  846. return ErrIntOverflowResource
  847. }
  848. if iNdEx >= l {
  849. return io.ErrUnexpectedEOF
  850. }
  851. b := data[iNdEx]
  852. iNdEx++
  853. stringLen |= (uint64(b) & 0x7F) << shift
  854. if b < 0x80 {
  855. break
  856. }
  857. }
  858. intStringLen := int(stringLen)
  859. if intStringLen < 0 {
  860. return ErrInvalidLengthResource
  861. }
  862. postIndex := iNdEx + intStringLen
  863. if postIndex > l {
  864. return io.ErrUnexpectedEOF
  865. }
  866. m.AttachmentID = string(data[iNdEx:postIndex])
  867. iNdEx = postIndex
  868. default:
  869. iNdEx = preIndex
  870. skippy, err := skipResource(data[iNdEx:])
  871. if err != nil {
  872. return err
  873. }
  874. if skippy < 0 {
  875. return ErrInvalidLengthResource
  876. }
  877. if (iNdEx + skippy) > l {
  878. return io.ErrUnexpectedEOF
  879. }
  880. iNdEx += skippy
  881. }
  882. }
  883. if iNdEx > l {
  884. return io.ErrUnexpectedEOF
  885. }
  886. return nil
  887. }
  888. func (m *DetachNetworkResponse) Unmarshal(data []byte) error {
  889. l := len(data)
  890. iNdEx := 0
  891. for iNdEx < l {
  892. preIndex := iNdEx
  893. var wire uint64
  894. for shift := uint(0); ; shift += 7 {
  895. if shift >= 64 {
  896. return ErrIntOverflowResource
  897. }
  898. if iNdEx >= l {
  899. return io.ErrUnexpectedEOF
  900. }
  901. b := data[iNdEx]
  902. iNdEx++
  903. wire |= (uint64(b) & 0x7F) << shift
  904. if b < 0x80 {
  905. break
  906. }
  907. }
  908. fieldNum := int32(wire >> 3)
  909. wireType := int(wire & 0x7)
  910. if wireType == 4 {
  911. return fmt.Errorf("proto: DetachNetworkResponse: wiretype end group for non-group")
  912. }
  913. if fieldNum <= 0 {
  914. return fmt.Errorf("proto: DetachNetworkResponse: illegal tag %d (wire type %d)", fieldNum, wire)
  915. }
  916. switch fieldNum {
  917. default:
  918. iNdEx = preIndex
  919. skippy, err := skipResource(data[iNdEx:])
  920. if err != nil {
  921. return err
  922. }
  923. if skippy < 0 {
  924. return ErrInvalidLengthResource
  925. }
  926. if (iNdEx + skippy) > l {
  927. return io.ErrUnexpectedEOF
  928. }
  929. iNdEx += skippy
  930. }
  931. }
  932. if iNdEx > l {
  933. return io.ErrUnexpectedEOF
  934. }
  935. return nil
  936. }
  937. func skipResource(data []byte) (n int, err error) {
  938. l := len(data)
  939. iNdEx := 0
  940. for iNdEx < l {
  941. var wire uint64
  942. for shift := uint(0); ; shift += 7 {
  943. if shift >= 64 {
  944. return 0, ErrIntOverflowResource
  945. }
  946. if iNdEx >= l {
  947. return 0, io.ErrUnexpectedEOF
  948. }
  949. b := data[iNdEx]
  950. iNdEx++
  951. wire |= (uint64(b) & 0x7F) << shift
  952. if b < 0x80 {
  953. break
  954. }
  955. }
  956. wireType := int(wire & 0x7)
  957. switch wireType {
  958. case 0:
  959. for shift := uint(0); ; shift += 7 {
  960. if shift >= 64 {
  961. return 0, ErrIntOverflowResource
  962. }
  963. if iNdEx >= l {
  964. return 0, io.ErrUnexpectedEOF
  965. }
  966. iNdEx++
  967. if data[iNdEx-1] < 0x80 {
  968. break
  969. }
  970. }
  971. return iNdEx, nil
  972. case 1:
  973. iNdEx += 8
  974. return iNdEx, nil
  975. case 2:
  976. var length int
  977. for shift := uint(0); ; shift += 7 {
  978. if shift >= 64 {
  979. return 0, ErrIntOverflowResource
  980. }
  981. if iNdEx >= l {
  982. return 0, io.ErrUnexpectedEOF
  983. }
  984. b := data[iNdEx]
  985. iNdEx++
  986. length |= (int(b) & 0x7F) << shift
  987. if b < 0x80 {
  988. break
  989. }
  990. }
  991. iNdEx += length
  992. if length < 0 {
  993. return 0, ErrInvalidLengthResource
  994. }
  995. return iNdEx, nil
  996. case 3:
  997. for {
  998. var innerWire uint64
  999. var start int = iNdEx
  1000. for shift := uint(0); ; shift += 7 {
  1001. if shift >= 64 {
  1002. return 0, ErrIntOverflowResource
  1003. }
  1004. if iNdEx >= l {
  1005. return 0, io.ErrUnexpectedEOF
  1006. }
  1007. b := data[iNdEx]
  1008. iNdEx++
  1009. innerWire |= (uint64(b) & 0x7F) << shift
  1010. if b < 0x80 {
  1011. break
  1012. }
  1013. }
  1014. innerWireType := int(innerWire & 0x7)
  1015. if innerWireType == 4 {
  1016. break
  1017. }
  1018. next, err := skipResource(data[start:])
  1019. if err != nil {
  1020. return 0, err
  1021. }
  1022. iNdEx = start + next
  1023. }
  1024. return iNdEx, nil
  1025. case 4:
  1026. return iNdEx, nil
  1027. case 5:
  1028. iNdEx += 4
  1029. return iNdEx, nil
  1030. default:
  1031. return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
  1032. }
  1033. }
  1034. panic("unreachable")
  1035. }
  1036. var (
  1037. ErrInvalidLengthResource = fmt.Errorf("proto: negative length found during unmarshaling")
  1038. ErrIntOverflowResource = fmt.Errorf("proto: integer overflow")
  1039. )
  1040. func init() { proto.RegisterFile("resource.proto", fileDescriptorResource) }
  1041. var fileDescriptorResource = []byte{
  1042. // 373 bytes of a gzipped FileDescriptorProto
  1043. 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0x4a, 0x2d, 0xce,
  1044. 0x2f, 0x2d, 0x4a, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4a, 0xc9, 0x4f, 0xce,
  1045. 0x4e, 0x2d, 0xd2, 0x2b, 0x2e, 0x4f, 0x2c, 0xca, 0xcd, 0xce, 0x2c, 0xd1, 0x2b, 0x33, 0x94, 0xe2,
  1046. 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x28, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x33, 0xf5,
  1047. 0x41, 0x2c, 0xa8, 0xa8, 0x70, 0x41, 0x4e, 0x69, 0x7a, 0x66, 0x9e, 0x3e, 0x84, 0x82, 0x08, 0x2a,
  1048. 0xf5, 0x33, 0x72, 0x89, 0x38, 0x96, 0x94, 0x24, 0x26, 0x67, 0xf8, 0xa5, 0x96, 0x94, 0xe7, 0x17,
  1049. 0x65, 0x07, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x39, 0x73, 0xb1, 0x25, 0xe7, 0xe7, 0xa5,
  1050. 0x65, 0xa6, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x69, 0xeb, 0x61, 0xda, 0xaa, 0x07, 0xd5,
  1051. 0x03, 0x31, 0x20, 0x37, 0x35, 0xaf, 0xc4, 0x19, 0xac, 0x25, 0x08, 0xaa, 0x55, 0xc8, 0x88, 0x8b,
  1052. 0x27, 0x39, 0x3f, 0xaf, 0x24, 0x31, 0x33, 0x2f, 0xb5, 0x28, 0x3e, 0x33, 0x45, 0x82, 0x49, 0x81,
  1053. 0x51, 0x83, 0xd3, 0x89, 0xff, 0xd1, 0x3d, 0x79, 0x6e, 0x67, 0x98, 0xb8, 0xa7, 0x4b, 0x10, 0x37,
  1054. 0x5c, 0x91, 0x67, 0x8a, 0x92, 0x1f, 0x97, 0x28, 0x9a, 0x83, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, 0x53,
  1055. 0x85, 0x4c, 0xb9, 0x78, 0x13, 0xe1, 0x16, 0x81, 0x4c, 0x63, 0x04, 0x9b, 0x26, 0xf0, 0xe8, 0x9e,
  1056. 0x3c, 0x0f, 0xc2, 0x05, 0x9e, 0x2e, 0x41, 0x3c, 0x08, 0x65, 0x9e, 0x29, 0x4a, 0xbe, 0x5c, 0x22,
  1057. 0x2e, 0xa9, 0x58, 0x3c, 0x48, 0xa6, 0x71, 0xe2, 0x5c, 0xa2, 0x68, 0xc6, 0x41, 0x9c, 0x67, 0xb4,
  1058. 0x9a, 0x89, 0x4b, 0x30, 0x08, 0x1a, 0x51, 0x8e, 0x39, 0x39, 0xf9, 0xc9, 0x89, 0x25, 0xf9, 0x45,
  1059. 0x42, 0x9d, 0x8c, 0x5c, 0xbc, 0x28, 0xde, 0x11, 0xd2, 0xc0, 0x16, 0x90, 0xd8, 0xa2, 0x40, 0x4a,
  1060. 0x93, 0x08, 0x95, 0x10, 0xcb, 0x95, 0x94, 0x4f, 0xad, 0x7b, 0x37, 0x83, 0x49, 0x96, 0x8b, 0x07,
  1061. 0xac, 0x54, 0x17, 0x24, 0x97, 0x5a, 0xc4, 0xc5, 0x0b, 0xe1, 0xe5, 0x26, 0xe6, 0x25, 0xa6, 0xa7,
  1062. 0x42, 0xdc, 0x82, 0xe2, 0x76, 0xec, 0x6e, 0xc1, 0x16, 0x5a, 0xd8, 0xdd, 0x82, 0x35, 0x20, 0x88,
  1063. 0x72, 0x8b, 0x93, 0xcc, 0x89, 0x87, 0x72, 0x0c, 0x37, 0x1e, 0xca, 0x31, 0x7c, 0x78, 0x28, 0xc7,
  1064. 0xd8, 0xf0, 0x48, 0x8e, 0xf1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92,
  1065. 0x63, 0x4c, 0x62, 0x03, 0x27, 0x4e, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xef, 0x94, 0x58,
  1066. 0xde, 0xfa, 0x02, 0x00, 0x00,
  1067. }