You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by am...@apache.org on 2020/10/09 16:55:39 UTC

[atlas] branch master updated: ATLAS-3987: Atlas client export API, must pass server error code in the exception

This is an automated email from the ASF dual-hosted git repository.

amestry pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new f5db98b  ATLAS-3987: Atlas client export API, must pass server error code in the exception
f5db98b is described below

commit f5db98b3ba5a6bdf851b1319abab5f953d6ff0f4
Author: Deep Singh <de...@gmail.com>
AuthorDate: Fri Oct 9 00:52:41 2020 -0700

    ATLAS-3987: Atlas client export API, must pass server error code in the exception
    
    Signed-off-by: Ashutosh Mestry <am...@cloudera.com>
---
 .../src/main/java/org/apache/atlas/AtlasBaseClient.java      |  6 +++---
 .../main/java/org/apache/atlas/AtlasServiceException.java    |  5 +++++
 .../apache/atlas/web/resources/AdminExportImportTestIT.java  | 12 ++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
index 6e03669..cb35c94 100644
--- a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
@@ -477,16 +477,16 @@ public abstract class AtlasBaseClient {
     public InputStream exportData(AtlasExportRequest request) throws AtlasServiceException {
         try {
             return (InputStream) callAPI(EXPORT, Object.class, request);
-        } catch (Exception e) {
-            LOG.error("error writing to file", e);
+        } catch (AtlasServiceException e) {
+            LOG.error("error in export API call", e);
             throw new AtlasServiceException(e);
         }
     }
 
     public void exportData(AtlasExportRequest request, String absolutePath) throws AtlasServiceException {
         OutputStream fileOutputStream = null;
+        InputStream inputStream = exportData(request);
         try {
-            InputStream inputStream = exportData(request);
             fileOutputStream = new FileOutputStream(new File(absolutePath));
             byte[] buffer = new byte[8 * 1024];
             int bytesRead;
diff --git a/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
index 6b4dd11..b9fe24a 100755
--- a/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
+++ b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
@@ -41,6 +41,11 @@ public class AtlasServiceException extends Exception {
         super(e);
     }
 
+    public AtlasServiceException(AtlasServiceException e) {
+        super(e);
+        this.status = e.status;
+    }
+
     public ClientResponse.Status getStatus() {
         return status;
     }
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java
index e53f9a8..51580af 100644
--- a/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/AdminExportImportTestIT.java
@@ -19,6 +19,7 @@
 package org.apache.atlas.web.resources;
 
 
+import org.apache.atlas.AtlasClientV2;
 import org.apache.atlas.AtlasServiceException;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.impexp.AtlasExportResult;
@@ -84,6 +85,17 @@ public class AdminExportImportTestIT extends BaseResourceIT {
         assertTrue(zs.getCreationOrder().size() >= EXPECTED_CREATION_ORDER_SIZE, "expected creationOrderSize > " + EXPECTED_CREATION_ORDER_SIZE + ", but found " + zs.getCreationOrder().size());
     }
 
+    @Test
+    public void unAuthExportData() throws IOException {
+        AtlasClientV2 unAuthClient = new AtlasClientV2(atlasUrls, new String[]{"admin", "wr0ng_pa55w0rd"});
+        AtlasExportRequest request = TestResourceFileUtils.readObjectFromJson(".", EXPORT_REQUEST_FILE, AtlasExportRequest.class);
+        try {
+            InputStream exportedStream = unAuthClient.exportData(request);
+        } catch(AtlasServiceException e) {
+            assertNotNull(e.getStatus(), "expected server error code in the status");
+        }
+    }
+
     private void performImport(String fileToImport, int expectedProcessedEntitiesCount) throws AtlasServiceException {
         AtlasImportRequest request = new AtlasImportRequest();
         request.getOptions().put(AtlasImportRequest.OPTION_KEY_REPLICATED_FROM, SOURCE_SERVER_NAME);