atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [3/7] atlas git commit: ATLAS-2132: incorrect error for invalid file path/unreadable file provided during import
Date Fri, 22 Sep 2017 02:10:31 GMT
ATLAS-2132: incorrect error for invalid file path/unreadable file provided during import

Signed-off-by: Madhan Neethiraj <madhan@apache.org>
(cherry picked from commit 67c04c63e1126791ab8537e2a8e8411f0b9e6897)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/ceb5c0cd
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/ceb5c0cd
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/ceb5c0cd

Branch: refs/heads/branch-0.8
Commit: ceb5c0cd90aa94d6836bb5f14154e5c5934e7ed2
Parents: 2e138da
Author: Ashutosh Mestry <amestry@apache.org>
Authored: Mon Sep 18 22:22:15 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Thu Sep 21 19:10:04 2017 -0700

----------------------------------------------------------------------
 .../atlas/repository/impexp/ImportService.java  |  8 ++-
 .../repository/impexp/ImportServiceTest.java    | 55 +++++++++++++++++---
 2 files changed, 53 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/ceb5c0cd/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
b/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
index 650741e..c976c59 100644
--- a/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
+++ b/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
@@ -36,6 +36,7 @@ import javax.inject.Inject;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 
 @Component
 public class ImportService {
@@ -108,7 +109,7 @@ public class ImportService {
 
     public AtlasImportResult run(AtlasImportRequest request, String userName, String hostName,
String requestingIP)
             throws AtlasBaseException {
-        String fileName = (String) request.getFileName();
+        String fileName = request.getFileName();
 
         if (StringUtils.isBlank(fileName)) {
             throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "FILENAME parameter
not found");
@@ -122,7 +123,6 @@ public class ImportService {
             String transforms = MapUtils.isNotEmpty(request.getOptions()) ? request.getOptions().get(AtlasImportRequest.TRANSFORMS_KEY)
: null;
             File file = new File(fileName);
             ZipSource source = new ZipSource(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)),
ImportTransforms.fromJson(transforms));
-
             result = run(source, request, userName, hostName, requestingIP);
         } catch (AtlasBaseException excp) {
             LOG.error("import(user={}, from={}, fileName={}): failed", userName, requestingIP,
excp);
@@ -132,6 +132,10 @@ public class ImportService {
             LOG.error("import(user={}, from={}, fileName={}): file not found", userName,
requestingIP, excp);
 
             throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, fileName + ":
file not found");
+        } catch (IOException excp) {
+            LOG.error("import(user={}, from={}, fileName={}): cannot read file", userName,
requestingIP, excp);
+
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, fileName + ":
cannot read file");
         } catch (Exception excp) {
             LOG.error("import(user={}, from={}, fileName={}): failed", userName, requestingIP,
excp);
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/ceb5c0cd/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
index 923b681..035ddac 100644
--- a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
@@ -27,6 +27,8 @@ import org.apache.atlas.model.impexp.AtlasImportRequest;
 import org.apache.atlas.store.AtlasTypeDefStore;
 import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasTypeRegistry;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.ITestContext;
@@ -40,6 +42,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
@@ -72,7 +76,7 @@ public class ImportServiceTest {
 
     @Test(dataProvider = "sales")
     public void importDB1(ZipSource zipSource) throws AtlasBaseException, IOException {
-        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
+        loadBaseModel();
         runAndVerifyQuickStart_v1_Import(importService, zipSource);
     }
 
@@ -83,7 +87,7 @@ public class ImportServiceTest {
 
     @Test(dataProvider = "reporting")
     public void importDB2(ZipSource zipSource) throws AtlasBaseException, IOException {
-        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
+        loadBaseModel();
         runAndVerifyQuickStart_v1_Import(importService, zipSource);
     }
 
@@ -94,7 +98,7 @@ public class ImportServiceTest {
 
     @Test(dataProvider = "logging")
     public void importDB3(ZipSource zipSource) throws AtlasBaseException, IOException {
-        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
+        loadBaseModel();
         runAndVerifyQuickStart_v1_Import(importService, zipSource);
     }
 
@@ -105,7 +109,7 @@ public class ImportServiceTest {
 
     @Test(dataProvider = "salesNewTypeAttrs", dependsOnMethods = "importDB1")
     public void importDB4(ZipSource zipSource) throws AtlasBaseException, IOException {
-        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
+        loadBaseModel();
         runImportWithParameters(importService, getDefaultImportRequest(), zipSource);
     }
 
@@ -154,8 +158,8 @@ public class ImportServiceTest {
 
     @Test(dataProvider = "ctas")
     public void importCTAS(ZipSource zipSource) throws IOException, AtlasBaseException {
-        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
-        loadModelFromJson("0030-hive_model.json", typeDefStore, typeRegistry);
+        loadBaseModel();
+        loadHiveModel();
 
         runImportWithNoParameters(importService, zipSource);
     }
@@ -168,8 +172,8 @@ public class ImportServiceTest {
 
     @Test(dataProvider = "hdfs_path1", expectedExceptions = AtlasBaseException.class)
     public void importHdfs_path1(ZipSource zipSource) throws IOException, AtlasBaseException
{
-        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
-        loadModelFromJson("0020-fs_model.json", typeDefStore, typeRegistry);
+        loadBaseModel();
+        loadFsModel();
         loadModelFromResourcesJson("tag1.json", typeDefStore, typeRegistry);
 
         try {
@@ -182,4 +186,39 @@ public class ImportServiceTest {
             throw e;
         }
     }
+
+    @Test
+    public void importServiceProcessesIOException() {
+        ImportService importService = new ImportService(typeDefStore, typeRegistry, null);
+        AtlasImportRequest req = mock(AtlasImportRequest.class);
+
+        Answer<Map> answer = new Answer<Map>() {
+            @Override
+            public Map answer(InvocationOnMock invocationOnMock) throws Throwable {
+                throw new IOException("file is read only");
+            }
+        };
+
+        when(req.getFileName()).thenReturn("some-file.zip");
+        when(req.getOptions()).thenAnswer(answer);
+
+        try {
+            importService.run(req, "a", "b", "c");
+        }
+        catch (AtlasBaseException ex) {
+            assertEquals(ex.getAtlasErrorCode().getErrorCode(), AtlasErrorCode.INVALID_PARAMETERS.getErrorCode());
+        }
+    }
+
+    private void loadBaseModel() throws IOException, AtlasBaseException {
+        loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
+    }
+
+    private void loadFsModel() throws IOException, AtlasBaseException {
+        loadModelFromJson("0020-fs_model.json", typeDefStore, typeRegistry);
+    }
+
+    private void loadHiveModel() throws IOException, AtlasBaseException {
+        loadModelFromJson("0030-hive_model.json", typeDefStore, typeRegistry);
+    }
 }


Mime
View raw message