[ 
https://issues.apache.org/jira/browse/HIVE-23351?focusedWorklogId=432205&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-432205
 ]

ASF GitHub Bot logged work on HIVE-23351:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/May/20 17:55
            Start Date: 08/May/20 17:55
    Worklog Time Spent: 10m 
      Work Description: aasha commented on a change in pull request #1004:
URL: https://github.com/apache/hive/pull/1004#discussion_r422283834



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ranger/RangerRestClientImpl.java
##########
@@ -0,0 +1,356 @@
+/*
+ * 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.hadoop.hive.ql.exec.repl.ranger;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.multipart.FormDataMultiPart;
+import com.sun.jersey.multipart.MultiPart;
+import com.sun.jersey.multipart.file.StreamDataBodyPart;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.eclipse.jetty.util.MultiPartWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.MediaType;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.File;
+import java.io.Reader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+
+/**
+ * RangerRestClientImpl to connect to Ranger and export policies.
+ */
+public class RangerRestClientImpl implements RangerRestClient {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RangerRestClientImpl.class);
+  private static final String RANGER_REST_URL_EXPORTJSONFILE = 
"/service/plugins/policies/exportJson";
+  private static final String RANGER_REST_URL_IMPORTJSONFILE =
+      "/service/plugins/policies/importPoliciesFromFile?updateIfExists=true";
+
+  public RangerExportPolicyList exportRangerPolicies(String 
sourceRangerEndpoint,
+                                                     String dbName, String 
rangerHiveServiceName) throws Exception {
+    LOG.info("Ranger endpoint for cluster " + sourceRangerEndpoint);
+    ClientResponse clientResp = null;
+    String uri = null;
+    if (!StringUtils.isEmpty(rangerHiveServiceName)) {
+      uri = RANGER_REST_URL_EXPORTJSONFILE + "?serviceName=" + 
rangerHiveServiceName + "&polResource="
+          + dbName + "&resource:database=" + dbName
+          + 
"&serviceType=hive&resourceMatchScope=self_or_ancestor&resourceMatch=full";
+    }
+    if (sourceRangerEndpoint.endsWith("/")) {
+      sourceRangerEndpoint = StringUtils.removePattern(sourceRangerEndpoint, 
"/+$");
+    }
+    String url = sourceRangerEndpoint + (uri != null ? (uri.startsWith("/") ? 
uri : ("/" + uri)) : "");
+    LOG.debug("URL to export policies from source Ranger: {}", url);
+    RangerExportPolicyList rangerExportPolicyList = new 
RangerExportPolicyList();
+    WebResource.Builder builder = getRangerResourceBuilder(url);
+    clientResp = builder.get(ClientResponse.class);
+
+    String response = null;
+    if (clientResp != null) {
+      if (clientResp.getStatus() == HttpServletResponse.SC_OK) {
+        Gson gson = new GsonBuilder().create();
+        response = clientResp.getEntity(String.class);
+        LOG.debug("Response received for ranger export {} ", response);
+        if (StringUtils.isNotEmpty(response)) {
+          rangerExportPolicyList = gson.fromJson(response, 
RangerExportPolicyList.class);
+          return rangerExportPolicyList;
+        }
+      } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) {
+        LOG.debug("Ranger policy export request returned empty list");
+        return rangerExportPolicyList;
+      } else if (clientResp.getStatus() == 
HttpServletResponse.SC_UNAUTHORIZED) {

Review comment:
       Using SemanticException




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 432205)
    Time Spent: 2.5h  (was: 2h 20m)

> Ranger Replication Scheduling
> -----------------------------
>
>                 Key: HIVE-23351
>                 URL: https://issues.apache.org/jira/browse/HIVE-23351
>             Project: Hive
>          Issue Type: Task
>            Reporter: Aasha Medhi
>            Assignee: Aasha Medhi
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-23351.01.patch, HIVE-23351.02.patch, 
> HIVE-23351.03.patch, HIVE-23351.04.patch, HIVE-23351.05.patch, 
> HIVE-23351.06.patch
>
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to