Skip to content

Commit 1cd918e

Browse files
authored
Get job id using query params (#1480)
1 parent 2745cb2 commit 1cd918e

File tree

18 files changed

+126
-135
lines changed

18 files changed

+126
-135
lines changed

cli/cluster/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func StopJob(operatorConfig OperatorConfig, apiName string, jobID string) (schem
7979
"jobID": jobID,
8080
}
8181

82-
httpRes, err := HTTPDelete(operatorConfig, path.Join("/batch", apiName, jobID), params)
82+
httpRes, err := HTTPDelete(operatorConfig, path.Join("/batch", apiName), params)
8383
if err != nil {
8484
return schema.DeleteResponse{}, err
8585
}

cli/cluster/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func GetAPI(operatorConfig OperatorConfig, apiName string) ([]schema.APIResponse
5252
}
5353

5454
func GetJob(operatorConfig OperatorConfig, apiName string, jobID string) (schema.JobResponse, error) {
55-
endpoint := path.Join("/batch", apiName, jobID)
56-
httpRes, err := HTTPGet(operatorConfig, endpoint)
55+
endpoint := path.Join("/batch", apiName)
56+
httpRes, err := HTTPGet(operatorConfig, endpoint, map[string]string{"jobID": jobID})
5757
if err != nil {
5858
return schema.JobResponse{}, err
5959
}

cli/cluster/lib_http_client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (oc OperatorConfig) AuthHeader() string {
5252
}
5353

5454
func HTTPGet(operatorConfig OperatorConfig, endpoint string, qParams ...map[string]string) ([]byte, error) {
55-
req, err := operatorRequest(operatorConfig, "GET", endpoint, nil, qParams)
55+
req, err := operatorRequest(operatorConfig, "GET", endpoint, nil, qParams...)
5656
if err != nil {
5757
return nil, err
5858
}
@@ -69,7 +69,7 @@ func HTTPPostObjAsJSON(operatorConfig OperatorConfig, endpoint string, requestDa
6969

7070
func HTTPPostJSON(operatorConfig OperatorConfig, endpoint string, jsonRequestData []byte, qParams ...map[string]string) ([]byte, error) {
7171
payload := bytes.NewBuffer(jsonRequestData)
72-
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, payload, qParams)
72+
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, payload, qParams...)
7373
if err != nil {
7474
return nil, err
7575
}
@@ -78,15 +78,15 @@ func HTTPPostJSON(operatorConfig OperatorConfig, endpoint string, jsonRequestDat
7878
}
7979

8080
func HTTPPostNoBody(operatorConfig OperatorConfig, endpoint string, qParams ...map[string]string) ([]byte, error) {
81-
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, nil, qParams)
81+
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, nil, qParams...)
8282
if err != nil {
8383
return nil, err
8484
}
8585
return makeOperatorRequest(operatorConfig, req)
8686
}
8787

8888
func HTTPDelete(operatorConfig OperatorConfig, endpoint string, qParams ...map[string]string) ([]byte, error) {
89-
req, err := operatorRequest(operatorConfig, http.MethodDelete, endpoint, nil, qParams)
89+
req, err := operatorRequest(operatorConfig, http.MethodDelete, endpoint, nil, qParams...)
9090
if err != nil {
9191
return nil, err
9292
}
@@ -124,7 +124,7 @@ func HTTPUpload(operatorConfig OperatorConfig, endpoint string, input *HTTPUploa
124124
return nil, errors.Wrap(err, _errStrCantMakeRequest)
125125
}
126126

127-
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, body, qParams)
127+
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, body, qParams...)
128128
if err != nil {
129129
return nil, err
130130
}
@@ -159,7 +159,7 @@ func HTTPUploadZip(operatorConfig OperatorConfig, endpoint string, zipInput *arc
159159
return HTTPUpload(operatorConfig, endpoint, uploadInput, qParams...)
160160
}
161161

162-
func operatorRequest(operatorConfig OperatorConfig, method string, endpoint string, body io.Reader, qParams []map[string]string) (*http.Request, error) {
162+
func operatorRequest(operatorConfig OperatorConfig, method string, endpoint string, body io.Reader, qParams ...map[string]string) (*http.Request, error) {
163163
req, err := http.NewRequest(method, operatorConfig.OperatorEndpoint+endpoint, body)
164164
if err != nil {
165165
return nil, errors.Wrap(err, _errStrCantMakeRequest)

cli/cluster/logs.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ import (
3434
)
3535

3636
func StreamLogs(operatorConfig OperatorConfig, apiName string) error {
37+
return streamLogs(operatorConfig, "/logs/"+apiName)
38+
}
39+
40+
func StreamJobLogs(operatorConfig OperatorConfig, apiName string, jobID string) error {
41+
return streamLogs(operatorConfig, "/logs/"+apiName, map[string]string{"jobID": jobID})
42+
}
43+
44+
func streamLogs(operatorConfig OperatorConfig, path string, qParams ...map[string]string) error {
3745
interrupt := make(chan os.Signal, 1)
3846
signal.Notify(interrupt, os.Interrupt)
3947

40-
req, err := operatorRequest(operatorConfig, "GET", "/logs/"+apiName, nil, nil)
48+
req, err := operatorRequest(operatorConfig, "GET", path, nil, qParams...)
4149
if err != nil {
4250
return err
4351
}

cli/cmd/logs.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package cmd
1818

1919
import (
2020
"fmt"
21-
"path"
2221

2322
"github.com/cortexlabs/cortex/cli/cluster"
2423
"github.com/cortexlabs/cortex/cli/local"
@@ -54,10 +53,17 @@ var _logsCmd = &cobra.Command{
5453

5554
apiName := args[0]
5655
if env.Provider == types.AWSProviderType {
57-
logPath := path.Join(args...)
58-
err := cluster.StreamLogs(MustGetOperatorConfig(env.Name), logPath)
59-
if err != nil {
60-
exit.Error(err)
56+
if len(args) == 1 {
57+
err := cluster.StreamLogs(MustGetOperatorConfig(env.Name), apiName)
58+
if err != nil {
59+
exit.Error(err)
60+
}
61+
}
62+
if len(args) == 2 {
63+
err := cluster.StreamJobLogs(MustGetOperatorConfig(env.Name), apiName, args[1])
64+
if err != nil {
65+
exit.Error(err)
66+
}
6167
}
6268
} else {
6369
if len(args) == 2 {

docs/deployments/batch-api/endpoints.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Submitting data in the request can be useful in the following scenarios:
3333
* you want to avoid using S3 as an intermediate storage layer
3434

3535
```yaml
36-
POST <batch_api_endpoint>/:
36+
POST <batch_api_endpoint>:
3737
{
3838
"workers": <int>, # the number of workers to allocate for this job (required)
3939
"item_list": {
@@ -74,7 +74,7 @@ This submission pattern can be useful in the following scenarios:
7474
If a single S3 file contains a lot of samples/rows, try the next submission strategy.
7575

7676
```yaml
77-
POST <batch_api_endpoint>/:
77+
POST <batch_api_endpoint>:
7878
{
7979
"workers": <int>, # the number of workers to allocate for this job (required)
8080
"file_path_lister": {
@@ -113,7 +113,7 @@ This submission pattern is useful in the following scenarios:
113113
* one or more S3 files contains a large number of samples and must be broken down into batches
114114

115115
```yaml
116-
POST <batch_api_endpoint>/:
116+
POST <batch_api_endpoint>:
117117
{
118118
"workers": <int>, # the number of workers to allocate for this job (required)
119119
"delimited_files": {
@@ -146,7 +146,7 @@ You can get the status of a job by making a GET request to `<batch_api_endpoint>
146146
See [Job Status Codes](statuses.md) for a list of the possible job statuses and what they mean.
147147

148148
```yaml
149-
GET <batch_api_endpoint>/<job_id>:
149+
GET <batch_api_endpoint>?jobID=<jobID>:
150150

151151
RESPONSE:
152152
{
@@ -188,7 +188,7 @@ Stop a job in progress. You can also use the Cortex CLI command
188188
You stop a running job by making a DELETE request to `<batch_api_endpoint>/<job_id>` (note that you can also delete a job with the Cortex CLI command `cortex delete <api_name> <job_id>`).
189189

190190
```yaml
191-
DELETE <batch_api_endpoint>/<job_id>:
191+
DELETE <batch_api_endpoint>?jobID=<jobID>:
192192

193193
RESPONSE:
194194
{"message":"stopped job <job_id>"}

examples/batch/image-classifier/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ endpoint: https://abcdefg.execute-api.us-west-2.amazonaws.com/image-classifier
234234
You can make a GET request to your `<BATCH_API_ENDPOINT>/JOB_ID` to get the status of your job.
235235

236236
```bash
237-
$ curl https://abcdefg.execute-api.us-west-2.amazonaws.com/69d6faf82e4660d3
237+
$ curl https://abcdefg.execute-api.us-west-2.amazonaws.com?jobID=69d6faf82e4660d3
238238
239239
{
240240
"job_status":{
@@ -545,7 +545,7 @@ You can stop a running job by sending a DELETE request to `<BATCH_API_ENDPOINT>/
545545

546546
```bash
547547
$ export BATCH_API_ENDPOINT=<BATCH_API_ENDPOINT> # e.g. export BATCH_API_ENDPOINT=https://abcdefg.execute-api.us-west-2.amazonaws.com/image-classifier
548-
$ curl -X DELETE $BATCH_API_ENDPOINT/69d96a01ea55da8c
548+
$ curl -X DELETE $BATCH_API_ENDPOINT?jobID=69d96a01ea55da8c
549549
550550
stopped job 69d96a01ea55da8c
551551
```

pkg/operator/endpoints/get_job.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import (
3232
func GetJob(w http.ResponseWriter, r *http.Request) {
3333
vars := mux.Vars(r)
3434
apiName := vars["apiName"]
35-
jobID := vars["jobID"]
35+
jobID, err := getRequiredQueryParam("jobID", r)
36+
if err != nil {
37+
respondError(w, r, err)
38+
return
39+
}
3640

3741
deployedResource, err := resources.GetDeployedResourceByName(apiName)
3842
if err != nil {

pkg/operator/endpoints/logs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ import (
2828

2929
func ReadLogs(w http.ResponseWriter, r *http.Request) {
3030
apiName := mux.Vars(r)["apiName"]
31+
jobID := getOptionalQParam("jobID", r)
32+
33+
if jobID != "" {
34+
ReadJobLogs(w, r)
35+
return
36+
}
3137

3238
deployedResource, err := resources.GetDeployedResourceByName(apiName)
3339
if err != nil {

pkg/operator/endpoints/logs_job.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ import (
2929

3030
func ReadJobLogs(w http.ResponseWriter, r *http.Request) {
3131
apiName := mux.Vars(r)["apiName"]
32-
jobID := mux.Vars(r)["jobID"]
32+
jobID, err := getRequiredQueryParam("jobID", r)
33+
if err != nil {
34+
respondError(w, r, err)
35+
return
36+
}
3337

3438
deployedResource, err := resources.GetDeployedResourceByName(apiName)
3539
if err != nil {

0 commit comments

Comments
 (0)