github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/netmap/types.go (about) 1 package netmap 2 3 import ( 4 "github.com/TrueCloudLab/frostfs-api-go/v2/refs" 5 "github.com/TrueCloudLab/frostfs-api-go/v2/session" 6 ) 7 8 type LocalNodeInfoRequest struct { 9 body *LocalNodeInfoRequestBody 10 11 session.RequestHeaders 12 } 13 14 type LocalNodeInfoResponse struct { 15 body *LocalNodeInfoResponseBody 16 17 session.ResponseHeaders 18 } 19 20 // NetworkInfoRequest is a structure of NetworkInfo request. 21 type NetworkInfoRequest struct { 22 body *NetworkInfoRequestBody 23 24 session.RequestHeaders 25 } 26 27 // NetworkInfoResponse is a structure of NetworkInfo response. 28 type NetworkInfoResponse struct { 29 body *NetworkInfoResponseBody 30 31 session.ResponseHeaders 32 } 33 34 type Filter struct { 35 name string 36 key string 37 op Operation 38 value string 39 filters []Filter 40 } 41 42 type Selector struct { 43 name string 44 count uint32 45 clause Clause 46 attribute string 47 filter string 48 } 49 50 type Replica struct { 51 count uint32 52 selector string 53 } 54 55 type Operation uint32 56 57 type PlacementPolicy struct { 58 replicas []Replica 59 backupFactor uint32 60 selectors []Selector 61 filters []Filter 62 subnetID *refs.SubnetID 63 } 64 65 // Attribute of storage node. 66 type Attribute struct { 67 key string 68 value string 69 parents []string 70 } 71 72 // NodeInfo of storage node. 73 type NodeInfo struct { 74 publicKey []byte 75 addresses []string 76 attributes []Attribute 77 state NodeState 78 } 79 80 // NodeState of storage node. 81 type NodeState uint32 82 83 // Clause of placement selector. 84 type Clause uint32 85 86 type LocalNodeInfoRequestBody struct{} 87 88 type LocalNodeInfoResponseBody struct { 89 version *refs.Version 90 nodeInfo *NodeInfo 91 } 92 93 const ( 94 UnspecifiedState NodeState = iota 95 Online 96 Offline 97 Maintenance 98 ) 99 100 const ( 101 UnspecifiedOperation Operation = iota 102 EQ 103 NE 104 GT 105 GE 106 LT 107 LE 108 OR 109 AND 110 ) 111 112 const ( 113 UnspecifiedClause Clause = iota 114 Same 115 Distinct 116 ) 117 118 func (f *Filter) GetFilters() []Filter { 119 if f != nil { 120 return f.filters 121 } 122 123 return nil 124 } 125 126 func (f *Filter) SetFilters(filters []Filter) { 127 f.filters = filters 128 } 129 130 func (f *Filter) GetValue() string { 131 if f != nil { 132 return f.value 133 } 134 135 return "" 136 } 137 138 func (f *Filter) SetValue(value string) { 139 f.value = value 140 } 141 142 func (f *Filter) GetOp() Operation { 143 if f != nil { 144 return f.op 145 } 146 return UnspecifiedOperation 147 } 148 149 func (f *Filter) SetOp(op Operation) { 150 f.op = op 151 } 152 153 func (f *Filter) GetKey() string { 154 if f != nil { 155 return f.key 156 } 157 158 return "" 159 } 160 161 func (f *Filter) SetKey(key string) { 162 f.key = key 163 } 164 165 func (f *Filter) GetName() string { 166 if f != nil { 167 return f.name 168 } 169 170 return "" 171 } 172 173 func (f *Filter) SetName(name string) { 174 f.name = name 175 } 176 177 func (s *Selector) GetFilter() string { 178 if s != nil { 179 return s.filter 180 } 181 182 return "" 183 } 184 185 func (s *Selector) SetFilter(filter string) { 186 s.filter = filter 187 } 188 189 func (s *Selector) GetAttribute() string { 190 if s != nil { 191 return s.attribute 192 } 193 194 return "" 195 } 196 197 func (s *Selector) SetAttribute(attribute string) { 198 s.attribute = attribute 199 } 200 201 func (s *Selector) GetClause() Clause { 202 if s != nil { 203 return s.clause 204 } 205 206 return UnspecifiedClause 207 } 208 209 func (s *Selector) SetClause(clause Clause) { 210 s.clause = clause 211 } 212 213 func (s *Selector) GetCount() uint32 { 214 if s != nil { 215 return s.count 216 } 217 218 return 0 219 } 220 221 func (s *Selector) SetCount(count uint32) { 222 s.count = count 223 } 224 225 func (s *Selector) GetName() string { 226 if s != nil { 227 return s.name 228 } 229 230 return "" 231 } 232 233 func (s *Selector) SetName(name string) { 234 s.name = name 235 } 236 237 func (r *Replica) GetSelector() string { 238 if r != nil { 239 return r.selector 240 } 241 242 return "" 243 } 244 245 func (r *Replica) SetSelector(selector string) { 246 r.selector = selector 247 } 248 249 func (r *Replica) GetCount() uint32 { 250 if r != nil { 251 return r.count 252 } 253 254 return 0 255 } 256 257 func (r *Replica) SetCount(count uint32) { 258 r.count = count 259 } 260 261 func (p *PlacementPolicy) GetFilters() []Filter { 262 if p != nil { 263 return p.filters 264 } 265 266 return nil 267 } 268 269 func (p *PlacementPolicy) SetFilters(filters []Filter) { 270 p.filters = filters 271 } 272 273 func (p *PlacementPolicy) GetSelectors() []Selector { 274 if p != nil { 275 return p.selectors 276 } 277 278 return nil 279 } 280 281 func (p *PlacementPolicy) SetSelectors(selectors []Selector) { 282 p.selectors = selectors 283 } 284 285 func (p *PlacementPolicy) GetContainerBackupFactor() uint32 { 286 if p != nil { 287 return p.backupFactor 288 } 289 290 return 0 291 } 292 293 func (p *PlacementPolicy) SetContainerBackupFactor(backupFactor uint32) { 294 p.backupFactor = backupFactor 295 } 296 297 func (p *PlacementPolicy) GetReplicas() []Replica { 298 return p.replicas 299 } 300 301 func (p *PlacementPolicy) SetReplicas(replicas []Replica) { 302 p.replicas = replicas 303 } 304 305 func (p *PlacementPolicy) GetSubnetID() *refs.SubnetID { 306 return p.subnetID 307 } 308 309 func (p *PlacementPolicy) SetSubnetID(id *refs.SubnetID) { 310 p.subnetID = id 311 } 312 313 func (a *Attribute) GetKey() string { 314 if a != nil { 315 return a.key 316 } 317 318 return "" 319 } 320 321 func (a *Attribute) SetKey(v string) { 322 a.key = v 323 } 324 325 func (a *Attribute) GetValue() string { 326 if a != nil { 327 return a.value 328 } 329 330 return "" 331 } 332 333 func (a *Attribute) SetValue(v string) { 334 a.value = v 335 } 336 337 func (a *Attribute) GetParents() []string { 338 if a != nil { 339 return a.parents 340 } 341 342 return nil 343 } 344 345 func (a *Attribute) SetParents(parent []string) { 346 a.parents = parent 347 } 348 349 func (ni *NodeInfo) GetPublicKey() []byte { 350 if ni != nil { 351 return ni.publicKey 352 } 353 354 return nil 355 } 356 357 func (ni *NodeInfo) SetPublicKey(v []byte) { 358 ni.publicKey = v 359 } 360 361 // GetAddress returns node's network address. 362 // 363 // Deprecated: use IterateAddresses. 364 func (ni *NodeInfo) GetAddress() (addr string) { 365 ni.IterateAddresses(func(s string) bool { 366 addr = s 367 return true 368 }) 369 370 return 371 } 372 373 // SetAddress sets node's network address. 374 // 375 // Deprecated: use SetAddresses. 376 func (ni *NodeInfo) SetAddress(v string) { 377 ni.SetAddresses(v) 378 } 379 380 // SetAddresses sets list of network addresses of the node. 381 func (ni *NodeInfo) SetAddresses(v ...string) { 382 ni.addresses = v 383 } 384 385 // NumberOfAddresses returns number of network addresses of the node. 386 func (ni *NodeInfo) NumberOfAddresses() int { 387 if ni != nil { 388 return len(ni.addresses) 389 } 390 391 return 0 392 } 393 394 // IterateAddresses iterates over network addresses of the node. 395 // Breaks iteration on f's true return. 396 // 397 // Handler should not be nil. 398 func (ni *NodeInfo) IterateAddresses(f func(string) bool) { 399 if ni != nil { 400 for i := range ni.addresses { 401 if f(ni.addresses[i]) { 402 break 403 } 404 } 405 } 406 } 407 408 func (ni *NodeInfo) GetAttributes() []Attribute { 409 if ni != nil { 410 return ni.attributes 411 } 412 413 return nil 414 } 415 416 func (ni *NodeInfo) SetAttributes(v []Attribute) { 417 ni.attributes = v 418 } 419 420 func (ni *NodeInfo) GetState() NodeState { 421 if ni != nil { 422 return ni.state 423 } 424 425 return UnspecifiedState 426 } 427 428 func (ni *NodeInfo) SetState(state NodeState) { 429 ni.state = state 430 } 431 432 func (l *LocalNodeInfoResponseBody) GetVersion() *refs.Version { 433 if l != nil { 434 return l.version 435 } 436 437 return nil 438 } 439 440 func (l *LocalNodeInfoResponseBody) SetVersion(version *refs.Version) { 441 l.version = version 442 } 443 444 func (l *LocalNodeInfoResponseBody) GetNodeInfo() *NodeInfo { 445 if l != nil { 446 return l.nodeInfo 447 } 448 449 return nil 450 } 451 452 func (l *LocalNodeInfoResponseBody) SetNodeInfo(nodeInfo *NodeInfo) { 453 l.nodeInfo = nodeInfo 454 } 455 456 func (l *LocalNodeInfoRequest) GetBody() *LocalNodeInfoRequestBody { 457 if l != nil { 458 return l.body 459 } 460 return nil 461 } 462 463 func (l *LocalNodeInfoRequest) SetBody(body *LocalNodeInfoRequestBody) { 464 l.body = body 465 } 466 467 func (l *LocalNodeInfoResponse) GetBody() *LocalNodeInfoResponseBody { 468 if l != nil { 469 return l.body 470 } 471 return nil 472 } 473 474 func (l *LocalNodeInfoResponse) SetBody(body *LocalNodeInfoResponseBody) { 475 l.body = body 476 } 477 478 // NetworkParameter represents NeoFS network parameter. 479 type NetworkParameter struct { 480 k, v []byte 481 } 482 483 // GetKey returns parameter key. 484 func (x *NetworkParameter) GetKey() []byte { 485 if x != nil { 486 return x.k 487 } 488 489 return nil 490 } 491 492 // SetKey sets parameter key. 493 func (x *NetworkParameter) SetKey(k []byte) { 494 x.k = k 495 } 496 497 // GetValue returns parameter value. 498 func (x *NetworkParameter) GetValue() []byte { 499 if x != nil { 500 return x.v 501 } 502 503 return nil 504 } 505 506 // SetValue sets parameter value. 507 func (x *NetworkParameter) SetValue(v []byte) { 508 x.v = v 509 } 510 511 // NetworkConfig represents NeoFS network configuration. 512 type NetworkConfig struct { 513 ps []NetworkParameter 514 } 515 516 // NumberOfParameters returns number of network parameters. 517 func (x *NetworkConfig) NumberOfParameters() int { 518 if x != nil { 519 return len(x.ps) 520 } 521 522 return 0 523 } 524 525 // IterateParameters iterates over network parameters. 526 // Breaks iteration on f's true return. 527 // 528 // Handler must not be nil. 529 func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) { 530 if x != nil { 531 for i := range x.ps { 532 if f(&x.ps[i]) { 533 break 534 } 535 } 536 } 537 } 538 539 // SetParameters sets list of network parameters. 540 func (x *NetworkConfig) SetParameters(v ...NetworkParameter) { 541 x.ps = v 542 } 543 544 // NetworkInfo groups information about 545 // NeoFS network. 546 type NetworkInfo struct { 547 curEpoch, magicNum uint64 548 549 msPerBlock int64 550 551 netCfg *NetworkConfig 552 } 553 554 // GetCurrentEpoch returns number of the current epoch. 555 func (i *NetworkInfo) GetCurrentEpoch() uint64 { 556 if i != nil { 557 return i.curEpoch 558 } 559 560 return 0 561 } 562 563 // SetCurrentEpoch sets number of the current epoch. 564 func (i *NetworkInfo) SetCurrentEpoch(epoch uint64) { 565 i.curEpoch = epoch 566 } 567 568 // GetMagicNumber returns magic number of the sidechain. 569 func (i *NetworkInfo) GetMagicNumber() uint64 { 570 if i != nil { 571 return i.magicNum 572 } 573 574 return 0 575 } 576 577 // SetMagicNumber sets magic number of the sidechain. 578 func (i *NetworkInfo) SetMagicNumber(magic uint64) { 579 i.magicNum = magic 580 } 581 582 // GetMsPerBlock returns MillisecondsPerBlock network parameter. 583 func (i *NetworkInfo) GetMsPerBlock() int64 { 584 if i != nil { 585 return i.msPerBlock 586 } 587 588 return 0 589 } 590 591 // SetMsPerBlock sets MillisecondsPerBlock network parameter. 592 func (i *NetworkInfo) SetMsPerBlock(v int64) { 593 i.msPerBlock = v 594 } 595 596 // GetNetworkConfig returns NeoFS network configuration. 597 func (i *NetworkInfo) GetNetworkConfig() *NetworkConfig { 598 if i != nil { 599 return i.netCfg 600 } 601 602 return nil 603 } 604 605 // SetNetworkConfig sets NeoFS network configuration. 606 func (i *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { 607 i.netCfg = v 608 } 609 610 // NetworkInfoRequestBody is a structure of NetworkInfo request body. 611 type NetworkInfoRequestBody struct{} 612 613 // NetworkInfoResponseBody is a structure of NetworkInfo response body. 614 type NetworkInfoResponseBody struct { 615 netInfo *NetworkInfo 616 } 617 618 // GetNetworkInfo returns information about the NeoFS network. 619 func (i *NetworkInfoResponseBody) GetNetworkInfo() *NetworkInfo { 620 if i != nil { 621 return i.netInfo 622 } 623 624 return nil 625 } 626 627 // SetNetworkInfo sets information about the NeoFS network. 628 func (i *NetworkInfoResponseBody) SetNetworkInfo(netInfo *NetworkInfo) { 629 i.netInfo = netInfo 630 } 631 632 func (l *NetworkInfoRequest) GetBody() *NetworkInfoRequestBody { 633 if l != nil { 634 return l.body 635 } 636 return nil 637 } 638 639 func (l *NetworkInfoRequest) SetBody(body *NetworkInfoRequestBody) { 640 l.body = body 641 } 642 643 func (l *NetworkInfoResponse) GetBody() *NetworkInfoResponseBody { 644 if l != nil { 645 return l.body 646 } 647 return nil 648 } 649 650 func (l *NetworkInfoResponse) SetBody(body *NetworkInfoResponseBody) { 651 l.body = body 652 } 653 654 // NetMap represents structure of NeoFS network map. 655 type NetMap struct { 656 epoch uint64 657 658 nodes []NodeInfo 659 } 660 661 // Epoch returns revision number of the NetMap. 662 func (x *NetMap) Epoch() uint64 { 663 if x != nil { 664 return x.epoch 665 } 666 667 return 0 668 } 669 670 // SetEpoch sets revision number of the NetMap. 671 func (x *NetMap) SetEpoch(v uint64) { 672 x.epoch = v 673 } 674 675 // Nodes returns nodes presented in the NetMap. 676 func (x *NetMap) Nodes() []NodeInfo { 677 if x != nil { 678 return x.nodes 679 } 680 681 return nil 682 } 683 684 // SetNodes sets nodes presented in the NetMap. 685 func (x *NetMap) SetNodes(v []NodeInfo) { 686 x.nodes = v 687 } 688 689 // SnapshotRequestBody represents structure of Snapshot request body. 690 type SnapshotRequestBody struct{} 691 692 // SnapshotRequest represents structure of Snapshot request. 693 type SnapshotRequest struct { 694 body *SnapshotRequestBody 695 696 session.RequestHeaders 697 } 698 699 func (x *SnapshotRequest) GetBody() *SnapshotRequestBody { 700 if x != nil { 701 return x.body 702 } 703 704 return nil 705 } 706 707 func (x *SnapshotRequest) SetBody(body *SnapshotRequestBody) { 708 x.body = body 709 } 710 711 // SnapshotResponseBody represents structure of Snapshot response body. 712 type SnapshotResponseBody struct { 713 netMap *NetMap 714 } 715 716 // NetMap returns current NetMap. 717 func (x *SnapshotResponseBody) NetMap() *NetMap { 718 if x != nil { 719 return x.netMap 720 } 721 722 return nil 723 } 724 725 // SetNetMap sets current NetMap. 726 func (x *SnapshotResponseBody) SetNetMap(netMap *NetMap) { 727 x.netMap = netMap 728 } 729 730 // SnapshotResponse represents structure of Snapshot response. 731 type SnapshotResponse struct { 732 body *SnapshotResponseBody 733 734 session.ResponseHeaders 735 } 736 737 func (x *SnapshotResponse) GetBody() *SnapshotResponseBody { 738 if x != nil { 739 return x.body 740 } 741 742 return nil 743 } 744 745 func (x *SnapshotResponse) SetBody(body *SnapshotResponseBody) { 746 x.body = body 747 }