mirror of
https://github.com/datarhei/core.git
synced 2025-11-03 10:30:53 +08:00
Add node resource error, replace ping with about
This commit is contained in:
@@ -37,10 +37,13 @@ type ProxyReader interface {
|
||||
FindNodeFromProcess(id app.ProcessID) (string, error)
|
||||
|
||||
Resources() map[string]NodeResources
|
||||
|
||||
ListProcesses(ProcessListOptions) []clientapi.Process
|
||||
ListProxyProcesses() []Process
|
||||
ProbeProcess(nodeid string, id app.ProcessID) (clientapi.Probe, error)
|
||||
|
||||
ListFiles(storage, patter string) []clientapi.FileInfo
|
||||
|
||||
GetURL(prefix, path string) (*url.URL, error)
|
||||
GetFile(prefix, path string, offset int64) (io.ReadCloser, error)
|
||||
GetFileInfo(prefix, path string) (int64, time.Time, error)
|
||||
@@ -343,6 +346,49 @@ func (p *proxy) getNodeForFile(prefix, path string) (Node, error) {
|
||||
return p.GetNode(id)
|
||||
}
|
||||
|
||||
func (p *proxy) ListFiles(storage, pattern string) []clientapi.FileInfo {
|
||||
filesChan := make(chan []clientapi.FileInfo, 64)
|
||||
filesList := []clientapi.FileInfo{}
|
||||
|
||||
wgList := sync.WaitGroup{}
|
||||
wgList.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wgList.Done()
|
||||
|
||||
for list := range filesChan {
|
||||
filesList = append(filesList, list...)
|
||||
}
|
||||
}()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
p.nodesLock.RLock()
|
||||
for _, node := range p.nodes {
|
||||
wg.Add(1)
|
||||
|
||||
go func(node Node, p chan<- []clientapi.FileInfo) {
|
||||
defer wg.Done()
|
||||
|
||||
files, err := node.FileList(storage, pattern)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
p <- files
|
||||
}(node, filesChan)
|
||||
}
|
||||
p.nodesLock.RUnlock()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
close(filesChan)
|
||||
|
||||
wgList.Wait()
|
||||
|
||||
return filesList
|
||||
}
|
||||
|
||||
type Process struct {
|
||||
NodeID string
|
||||
Order string
|
||||
|
||||
Reference in New Issue
Block a user