/
BatchRestApi.java
95 lines (80 loc) · 3.31 KB
/
BatchRestApi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kyuubi.client;
import java.util.HashMap;
import java.util.Map;
import org.apache.kyuubi.client.api.v1.dto.Batch;
import org.apache.kyuubi.client.api.v1.dto.BatchRequest;
import org.apache.kyuubi.client.api.v1.dto.CloseBatchResponse;
import org.apache.kyuubi.client.api.v1.dto.GetBatchesResponse;
import org.apache.kyuubi.client.api.v1.dto.OperationLog;
import org.apache.kyuubi.client.util.JsonUtil;
public class BatchRestApi {
private KyuubiRestClient client;
private static final String API_BASE_PATH = "batches";
private BatchRestApi() {}
public BatchRestApi(KyuubiRestClient client) {
this.client = client;
}
public Batch createBatch(BatchRequest request) {
String requestBody = JsonUtil.toJson(request);
return this.getClient().post(API_BASE_PATH, requestBody, Batch.class, client.getAuthHeader());
}
public Batch getBatchById(String batchId) {
String path = String.format("%s/%s", API_BASE_PATH, batchId);
return this.getClient().get(path, null, Batch.class, client.getAuthHeader());
}
public GetBatchesResponse listBatches(
String batchType,
String batchUser,
String batchState,
Long createTime,
Long endTime,
int from,
int size) {
Map<String, Object> params = new HashMap<>();
params.put("batchType", batchType);
params.put("batchUser", batchUser);
params.put("batchState", batchState);
if (null != createTime && createTime >= 0) {
params.put("createTime", createTime);
}
if (null != endTime && endTime >= 0) {
params.put("endTime", endTime);
}
params.put("from", from);
params.put("size", size);
return this.getClient()
.get(API_BASE_PATH, params, GetBatchesResponse.class, client.getAuthHeader());
}
public OperationLog getBatchLocalLog(String batchId, int from, int size) {
Map<String, Object> params = new HashMap<>();
params.put("from", from);
params.put("size", size);
String path = String.format("%s/%s/localLog", API_BASE_PATH, batchId);
return this.getClient().get(path, params, OperationLog.class, client.getAuthHeader());
}
public CloseBatchResponse deleteBatch(String batchId, String hs2ProxyUser) {
Map<String, Object> params = new HashMap<>();
params.put("hive.server2.proxy.user", hs2ProxyUser);
String path = String.format("%s/%s", API_BASE_PATH, batchId);
return this.getClient().delete(path, params, CloseBatchResponse.class, client.getAuthHeader());
}
private RestClient getClient() {
return this.client.getHttpClient();
}
}