github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/sub/rpcd/api.go (about) 1 package rpcd 2 3 import ( 4 "io" 5 "sync" 6 7 "github.com/Cloud-Foundations/Dominator/lib/log" 8 "github.com/Cloud-Foundations/Dominator/lib/rateio" 9 "github.com/Cloud-Foundations/Dominator/lib/srpc" 10 "github.com/Cloud-Foundations/Dominator/lib/srpc/serverutil" 11 "github.com/Cloud-Foundations/Dominator/sub/scanner" 12 "github.com/Cloud-Foundations/tricorder/go/tricorder" 13 "github.com/Cloud-Foundations/tricorder/go/tricorder/units" 14 ) 15 16 type rpcType struct { 17 scannerConfiguration *scanner.Configuration 18 fileSystemHistory *scanner.FileSystemHistory 19 objectsDir string 20 rootDir string 21 networkReaderContext *rateio.ReaderContext 22 netbenchFilename string 23 oldTriggersFilename string 24 rescanObjectCacheFunction func() 25 disableScannerFunc func(disableScanner bool) 26 logger log.Logger 27 *serverutil.PerUserMethodLimiter 28 rwLock sync.RWMutex 29 getFilesLock sync.Mutex 30 fetchInProgress bool // Fetch() & Update() mutually exclusive. 31 updateInProgress bool 32 startTimeNanoSeconds int32 // For Fetch() or Update(). 33 startTimeSeconds int64 34 lastFetchError error 35 lastUpdateError error 36 lastUpdateHadTriggerFailures bool 37 lastSuccessfulImageName string 38 } 39 40 type addObjectsHandlerType struct { 41 objectsDir string 42 scannerConfiguration *scanner.Configuration 43 logger log.Logger 44 } 45 46 type HtmlWriter struct { 47 lastSuccessfulImageName *string 48 } 49 50 func Setup(configuration *scanner.Configuration, fsh *scanner.FileSystemHistory, 51 objectsDirname string, rootDirname string, 52 netReaderContext *rateio.ReaderContext, 53 netbenchFname string, oldTriggersFname string, 54 disableScannerFunction func(disableScanner bool), 55 rescanObjectCacheFunction func(), logger log.Logger) *HtmlWriter { 56 rpcObj := &rpcType{ 57 scannerConfiguration: configuration, 58 fileSystemHistory: fsh, 59 objectsDir: objectsDirname, 60 rootDir: rootDirname, 61 networkReaderContext: netReaderContext, 62 netbenchFilename: netbenchFname, 63 oldTriggersFilename: oldTriggersFname, 64 rescanObjectCacheFunction: rescanObjectCacheFunction, 65 disableScannerFunc: disableScannerFunction, 66 logger: logger, 67 PerUserMethodLimiter: serverutil.NewPerUserMethodLimiter( 68 map[string]uint{ 69 "Poll": 1, 70 }), 71 } 72 srpc.RegisterNameWithOptions("Subd", rpcObj, 73 srpc.ReceiverOptions{ 74 PublicMethods: []string{ 75 "Poll", 76 }}) 77 addObjectsHandler := &addObjectsHandlerType{ 78 objectsDir: objectsDirname, 79 scannerConfiguration: configuration, 80 logger: logger} 81 srpc.RegisterName("ObjectServer", addObjectsHandler) 82 tricorder.RegisterMetric("/image-name", &rpcObj.lastSuccessfulImageName, 83 units.None, "name of the image for the last successful update") 84 return &HtmlWriter{&rpcObj.lastSuccessfulImageName} 85 } 86 87 func (hw *HtmlWriter) WriteHtml(writer io.Writer) { 88 hw.writeHtml(writer) 89 }