github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/transitions/api.go (about) 1 // Copyright (c) 2015-2021, NVIDIA CORPORATION. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package transitions 5 6 import ( 7 "github.com/swiftstack/ProxyFS/conf" 8 ) 9 10 // Callbacks is the interface implemented by each package desiring notification of 11 // configuration changes. Each such package should implement a struct with pointer 12 // receivers for each API listed below even when there is no interest in being 13 // notified of a particular condition. 14 // 15 // By calling transitions.Register() in the package's init() func, the proper order 16 // of registration will be ensured. In specific, the following callbacks will be 17 // issued in the same order as package init() func calls have registered: 18 // 19 // Up() 20 // VolumeGroupCreated() 21 // VolumeGroupMoved() 22 // VolumeCreated() 23 // VolumeMoved() 24 // ServeVolume() 25 // SignaledFinish() 26 // 27 // By contrast, the following callbacks will be issued in the reverse order as package 28 // init() func calls have registered: 29 // 30 // SignaledStart() 31 // UnserveVolume() 32 // VolumeDestroyed() 33 // VolumeGroupDestroyed() 34 // Down() 35 // 36 type Callbacks interface { 37 Up(confMap conf.ConfMap) (err error) 38 VolumeGroupCreated(confMap conf.ConfMap, volumeGroupName string, activePeer string, virtualIPAddr string) (err error) 39 VolumeGroupMoved(confMap conf.ConfMap, volumeGroupName string, activePeer string, virtualIPAddr string) (err error) 40 VolumeGroupDestroyed(confMap conf.ConfMap, volumeGroupName string) (err error) 41 VolumeCreated(confMap conf.ConfMap, volumeName string, volumeGroupName string) (err error) 42 VolumeMoved(confMap conf.ConfMap, volumeName string, volumeGroupName string) (err error) 43 VolumeDestroyed(confMap conf.ConfMap, volumeName string) (err error) 44 ServeVolume(confMap conf.ConfMap, volumeName string) (err error) 45 UnserveVolume(confMap conf.ConfMap, volumeName string) (err error) 46 VolumeToBeUnserved(confMap conf.ConfMap, volumeName string) (err error) 47 SignaledStart(confMap conf.ConfMap) (err error) 48 SignaledFinish(confMap conf.ConfMap) (err error) 49 Down(confMap conf.ConfMap) (err error) 50 } 51 52 // Register should be called from a package's init() func should the package be interested 53 // in one or more of the callbacks that they will receive. Each callback func should receive 54 // a struct implementing the Callbacks interface by reference. 55 // 56 // As an example, consider the following: 57 // 58 // package foo 59 // 60 // import "github.com/swiftstack/ProxyFS/conf" 61 // import "github.com/swiftstack/ProxyFS/transitions" 62 // 63 // type transitionsCallbackInterfaceStruct struct { 64 // } 65 // 66 // var transitionsCallbackInterface transitionsCallbackInterfaceStruct 67 // 68 // func init() { 69 // transitions.Register("foo", &transitionsCallbackInterface) 70 // } 71 // 72 // func (transitionsCallbackInterface *transitionsCallbackInterfaceStruct) Up(confMap conf.ConfMap) (err error) { 73 // // Perform start-up initialization derived from confMap 74 // // ...set err at some point 75 // return 76 // } 77 // 78 // ... 79 // 80 // Package foo would also have to provide callbacks for each of the other APIs in 81 // the transitions.Callbacks interface (returning nil if simply not interested). 82 // 83 // A special exception to the need for registration is the package logger. Package 84 // transitions makes an explicit reference to logging functions in package logger and, 85 // as such, will perform the registration for package logger itself. 86 // 87 func Register(packageName string, callbacks Callbacks) { 88 register(packageName, callbacks) 89 } 90 91 // Up should be called at startup by the main() (or setup func) of each program including 92 // any of the packages needing callback notifications. This will trigger Up() callbacks 93 // to each of the packages that have registered with package transitions starting with 94 // package logger (that was registered automatically by package transitions). 95 // 96 // Following the Up() callbacks, the following subset of the callbacks triggered 97 // by a call to Signaled() will be made as if the prior confMap were empty: 98 // 99 // VolumeGroupCreated() - registration order (for each such volume group) 100 // VolumeCreated() - registration order (for each such volume) 101 // ServeVolume() - registration order (for each such volume) 102 // SignaledFinish() - registration order 103 // 104 func Up(confMap conf.ConfMap) (err error) { 105 return up(confMap) 106 } 107 108 // Signaled should be called during execution of a signal handler for e.g. SIGHUP by the 109 // main() (or monitoring func) of each program including any of the packages needing 110 // callback notifications. This will potentially trigger multiple of the following 111 // callbacks to each of the packages that have registered with package transitions. 112 // 113 // As part of this call, a determination will be made as to which volumes have migrated 114 // as well as which volumes have either been created or destroyed. Upon determining 115 // these volume sets, the following callbacks will be issued to each of the packages 116 // that have registered with package transitions: 117 // 118 // VolumeToBeUnserved() - reverse registration order (for each such volume) 119 // SignaledStart() - reverse registration order 120 // VolumeGroupCreated() - registration order (for each such volume group) 121 // VolumeCreated() - registration order (for each such volume) 122 // UnserveVolume() - reverse registration order (for each such volume) 123 // VolumeGroupMoved() - registration order (for each such volume group) 124 // VolumeMoved() - registration order (for each such volume) 125 // ServeVolume() - registration order (for each such volume) 126 // VolumeDestroyed() - reverse registration order (for each such volume) 127 // VolumeGroupDestroyed() - reverse registration order (for each such volume group) 128 // SignaledFinish() - registration order 129 // 130 func Signaled(confMap conf.ConfMap) (err error) { 131 return signaled(confMap) 132 } 133 134 // Down should be called just before shutdown by the main() (or teardown func) of each 135 // program including any of the packages needing callback notifications. This will trigger 136 // Down() callbacks to each of the packages that have registered with package transitions 137 // ending with package logger (that was registered automatically by package transitions). 138 // 139 // Prior to the Down() callbacks, the following subset of the callbacks triggered 140 // by a call to Signaled() will be made as if the prior confMap were empty: 141 // 142 // VolumeToBeUnserved() - reverse registration order (for each such volume) 143 // SignaledStart() - reverse registration order 144 // UnserveVolume() - reverse registration order (for each such volume) 145 // VolumeDestroyed() - reverse registration order (for each such volume) 146 // VolumeGroupDestroyed() - reverse registration order (for each such volume group) 147 // 148 func Down(confMap conf.ConfMap) (err error) { 149 return down(confMap) 150 } 151 152 // UpgradeConfMapIfNeeded should be removed once backwards compatibility is no longer required... 153 // 154 func UpgradeConfMapIfNeeded(confMap conf.ConfMap) (err error) { 155 return upgradeConfMapIfNeeded(confMap) 156 }