MCPcopy
hub / github.com/NVIDIA/aistore / proxyListSortHandler

Function proxyListSortHandler

dsort/handler.go:137–183  ·  view source on GitHub ↗

GET /v1/sort?regex=...

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

135
136// GET /v1/sort?regex=...
137func proxyListSortHandler(w http.ResponseWriter, r *http.Request) {
138 var (
139 query = r.URL.Query()
140 regexStr = query.Get(apc.QparamRegex)
141 )
142 if _, err := regexp.CompilePOSIX(regexStr); err != nil {
143 cmn.WriteErr(w, r, err)
144 return
145 }
146
147 path := apc.URLPathdSortList.S
148 responses := broadcastTargets(http.MethodGet, path, query, nil, ctx.smapOwner.Get())
149
150 resultList := make([]*JobInfo, 0)
151 for _, r := range responses {
152 if r.err != nil {
153 glog.Error(r.err)
154 continue
155 }
156 var newMetrics []*JobInfo
157 err := jsoniter.Unmarshal(r.res, &newMetrics)
158 cos.AssertNoErr(err)
159
160 for _, v := range newMetrics {
161 found := false
162 for _, oldMetric := range resultList {
163 if oldMetric.ID == v.ID {
164 oldMetric.Aggregate(v)
165 found = true
166 break
167 }
168 }
169
170 if !found {
171 resultList = append(resultList, v)
172 }
173 }
174 }
175
176 body := cos.MustMarshal(resultList)
177 if _, err := w.Write(body); err != nil {
178 glog.Error(err)
179 // When we fail write we cannot call InvalidHandler since it will be
180 // double header write.
181 return
182 }
183}
184
185// GET /v1/sort?id=...
186func proxyMetricsSortHandler(w http.ResponseWriter, r *http.Request) {

Callers 1

ProxyGetHandlerFunction · 0.85

Calls 8

WriteErrFunction · 0.92
ErrorFunction · 0.92
AssertNoErrFunction · 0.92
MustMarshalFunction · 0.92
broadcastTargetsFunction · 0.85
GetMethod · 0.65
AggregateMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected