HandleTask is an implementation of the cbgt.TaskRequestHandler interface
(in []byte)
| 444 | |
| 445 | // HandleTask is an implementation of the cbgt.TaskRequestHandler interface |
| 446 | func (r *IndexClient) HandleTask(in []byte) (*cbgt.TaskRequestStatus, error) { |
| 447 | var treq cbgt.TaskRequest |
| 448 | err := json.Unmarshal(in, &treq) |
| 449 | if err != nil { |
| 450 | return nil, err |
| 451 | } |
| 452 | // populate the target partitions |
| 453 | treq.PartitionNames = r.PIndexNames |
| 454 | buf, err := MarshalJSON(&treq) |
| 455 | if err != nil { |
| 456 | return nil, err |
| 457 | } |
| 458 | |
| 459 | u, err := UrlWithAuth(r.AuthType(), r.TaskRequestURL) |
| 460 | if err != nil { |
| 461 | return nil, fmt.Errorf("remote: auth for HandleTask,"+ |
| 462 | " TaskRequestURL: %s, authType: %s, err: %v", |
| 463 | r.TaskRequestURL, r.AuthType(), err) |
| 464 | } |
| 465 | |
| 466 | req, err := http.NewRequest("POST", u, bytes.NewReader(buf)) |
| 467 | if err != nil { |
| 468 | return nil, err |
| 469 | } |
| 470 | req.Header.Add("Content-Type", "application/json") |
| 471 | |
| 472 | resp, err := r.httpClient.Do(req) |
| 473 | if err != nil { |
| 474 | return nil, err |
| 475 | } |
| 476 | defer resp.Body.Close() |
| 477 | |
| 478 | respBuf, err := ioutil.ReadAll(resp.Body) |
| 479 | if err != nil { |
| 480 | return nil, fmt.Errorf("remote: HandleTask error reading resp.Body,"+ |
| 481 | " TaskRequestURL: %s, resp: %#v, err: %v", r.TaskRequestURL, |
| 482 | resp, err) |
| 483 | } |
| 484 | |
| 485 | r.lastMutex.Lock() |
| 486 | defer r.lastMutex.Unlock() |
| 487 | |
| 488 | rv := &cbgt.TaskRequestStatus{Errors: make(map[string]error)} |
| 489 | err = json.Unmarshal(respBuf, rv) |
| 490 | if err != nil { |
| 491 | return completeTaskStatus(&treq, err, r.PIndexNames), nil |
| 492 | } |
| 493 | if resp.StatusCode != http.StatusOK { |
| 494 | return completeTaskStatus(&treq, |
| 495 | fmt.Errorf("remote: HandleTask got status code: %d,"+ |
| 496 | " TaskRequestURL: %s, buf: %s, resp: %#v, err: %v", |
| 497 | resp.StatusCode, r.TaskRequestURL, buf, resp, err), |
| 498 | r.PIndexNames), nil |
| 499 | } |
| 500 | |
| 501 | return rv, nil |
| 502 | } |
| 503 |
nothing calls this directly
no test coverage detected