This is an automated email from the ASF dual-hosted git repository.
suvasude pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-gobblin.git
The following commit(s) were added to refs/heads/master by this push:
new 753f880 [GOBBLIN-1137] Add API for getting list of proxy users from
an azkaban project
753f880 is described below
commit 753f880c79155568139ab7836d49be952a346028
Author: Jack Moseley <[email protected]>
AuthorDate: Fri May 1 15:08:08 2020 -0700
[GOBBLIN-1137] Add API for getting list of proxy users from an azkaban
project
Closes #2976 from jack-moseley/get-proxy-users
---
.../modules/orchestration/AzkabanClient.java | 17 ++++++++++
.../orchestration/AzkabanGetProxyUsersStatus.java | 39 ++++++++++++++++++++++
.../orchestration/AzkabanMultiCallables.java | 38 +++++++++++++++++++++
3 files changed, 94 insertions(+)
diff --git
a/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanClient.java
b/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanClient.java
index 0e8ee48..5f88fa9 100644
---
a/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanClient.java
+++
b/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanClient.java
@@ -440,6 +440,23 @@ public class AzkabanClient implements Closeable {
return runWithRetry(callable, AzkabanClientStatus.class);
}
+ /**
+ * Get the list of proxy users for a given project.
+ *
+ * @param projectName project name
+ *
+ * @return {@link AzkabanGetProxyUsersStatus} containing the response map.
The response should have a key "proxyUsers"
+ * which will be in the format "[user1, user2, user3]"
+ */
+ public AzkabanGetProxyUsersStatus getProxyUsers(String projectName) throws
AzkabanClientException {
+ AzkabanMultiCallables.GetProxyUserCallable callable =
AzkabanMultiCallables.GetProxyUserCallable.builder()
+ .client(this)
+ .projectName(projectName)
+ .build();
+
+ return runWithRetry(callable, AzkabanGetProxyUsersStatus.class);
+ }
+
private <T> T runWithRetry(Callable callable, Class<T> cls) throws
AzkabanClientException {
try {
AzkabanClientStatus status = this.retryer.call(callable);
diff --git
a/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanGetProxyUsersStatus.java
b/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanGetProxyUsersStatus.java
new file mode 100644
index 0000000..adcf022
--- /dev/null
+++
b/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanGetProxyUsersStatus.java
@@ -0,0 +1,39 @@
+/*
+ * 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.gobblin.service.modules.orchestration;
+
+import java.util.Map;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+
+/**
+ * Status to return response from {@link AzkabanClient#getProxyUsers(String)}
+ */
+public class AzkabanGetProxyUsersStatus extends
AzkabanClientStatus<AzkabanGetProxyUsersStatus.ProxyUsers> {
+ public AzkabanGetProxyUsersStatus(AzkabanGetProxyUsersStatus.ProxyUsers
proxyUsers) {
+ super(proxyUsers);
+ }
+
+ @Getter
+ @AllArgsConstructor
+ public static class ProxyUsers {
+ Map<String, String> map;
+ }
+}
diff --git
a/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanMultiCallables.java
b/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanMultiCallables.java
index 601b4cb..30981aa 100644
---
a/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanMultiCallables.java
+++
b/gobblin-modules/gobblin-azkaban/src/main/java/org/apache/gobblin/service/modules/orchestration/AzkabanMultiCallables.java
@@ -415,4 +415,42 @@ class AzkabanMultiCallables {
}
}
}
+
+ /**
+ * A callable that will get the list of proxy users from a project on
Azkaban.
+ */
+ @Builder
+ static class GetProxyUserCallable implements Callable<AzkabanClientStatus> {
+ private AzkabanClient client;
+ private String projectName;
+ private boolean invalidSession = false;
+
+ @Override
+ public AzkabanClientStatus call()
+ throws AzkabanClientException {
+ try (Closer closer = Closer.create()) {
+ client.refreshSession(this.invalidSession);
+ List<NameValuePair> nvps = new ArrayList<>();
+ nvps.add(new BasicNameValuePair(AzkabanClientParams.AJAX,
"getProxyUsers"));
+ nvps.add(new BasicNameValuePair(AzkabanClientParams.SESSION_ID,
client.sessionId));
+ nvps.add(new BasicNameValuePair(AzkabanClientParams.PROJECT,
projectName));
+
+ Header contentType = new BasicHeader(HttpHeaders.CONTENT_TYPE,
"application/x-www-form-urlencoded");
+ Header requestType = new BasicHeader("X-Requested-With",
"XMLHttpRequest");
+
+ HttpGet httpGet = new HttpGet(client.url + "/manager?" +
URLEncodedUtils.format(nvps, "UTF-8"));
+ httpGet.setHeaders(new Header[]{contentType, requestType});
+
+ CloseableHttpResponse response = client.httpClient.execute(httpGet);
+ closer.register(response);
+ Map<String, String> map = AzkabanClient.handleResponse(response);
+ return new AzkabanGetProxyUsersStatus(new
AzkabanGetProxyUsersStatus.ProxyUsers(map));
+ } catch (InvalidSessionException e) {
+ this.invalidSession = true;
+ throw e;
+ } catch (Exception e) {
+ throw new AzkabanClientException("Azkaban client failed to get proxy
users", e);
+ }
+ }
+ }
}