ATLAS-2897: Elegant handling of empty zip files. Part 2.

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

Branch: refs/heads/branch-1.0
Commit: a9ffa992c1e89a381ce926d94626efe93f556086
Parents: 80dc1e5
Author: Ashutosh Mestry <ames...@hortonworks.com>
Authored: Wed Oct 3 09:01:07 2018 -0700
Committer: Ashutosh Mestry <ames...@hortonworks.com>
Committed: Thu Nov 1 15:42:57 2018 -0700

----------------------------------------------------------------------
 .../atlas/repository/impexp/ZipSource.java      | 19 +++++++++++--------
 .../repository/impexp/ExportServiceTest.java    |  1 -
 .../impexp/ZipFileResourceTestUtils.java        | 20 ++++++++------------
 .../atlas/web/resources/AdminResource.java      | 19 ++++++++++++++++++-
 4 files changed, 37 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/a9ffa992/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java
index bfa0441..be8c168 100644
--- a/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java
+++ b/repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java
@@ -64,13 +64,20 @@ public class ZipSource implements EntityImportStream {
         this.importTransform   = importTransform;
 
         updateGuidZipEntryMap();
-        if (MapUtils.isEmpty(guidEntityJsonMap)) {
+        if (isZipFileEmpty()) {
             throw new AtlasBaseException(IMPORT_ATTEMPTING_EMPTY_ZIP, 
"Attempting to import empty ZIP.");
         }
 
         setCreationOrder();
     }
 
+    private boolean isZipFileEmpty() {
+        return MapUtils.isEmpty(guidEntityJsonMap) ||
+                
(guidEntityJsonMap.containsKey(ZipExportFileNames.ATLAS_EXPORT_ORDER_NAME.toString())
 &&
+                        
(guidEntityJsonMap.get(ZipExportFileNames.ATLAS_EXPORT_ORDER_NAME.toString()) 
== null)
+                );
+    }
+
     public ImportTransforms getImportTransform() { return 
this.importTransform; }
 
     public void setImportTransform(ImportTransforms importTransform) {
@@ -136,7 +143,7 @@ public class ZipSource implements EntityImportStream {
         zipInputStream.close();
     }
 
-    public List<String> getCreationOrder() throws AtlasBaseException {
+    public List<String> getCreationOrder() {
         return this.creationOrder;
     }
 
@@ -234,12 +241,8 @@ public class ZipSource implements EntityImportStream {
 
     @Override
     public void reset() {
-        try {
-            getCreationOrder();
-            this.iterator = this.creationOrder.iterator();
-        } catch (AtlasBaseException e) {
-            LOG.error("reset", e);
-        }
+        getCreationOrder();
+        this.iterator = this.creationOrder.iterator();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/atlas/blob/a9ffa992/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
index 7aa0b57..7886a64 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
@@ -314,7 +314,6 @@ public class ExportServiceTest extends ExportImportTestBase 
{
 
         assertNotNull(zipSource.getCreationOrder());
         assertEquals(zipSource.getCreationOrder().size(), 0);
-        assertEquals(AtlasExportResult.OperationStatus.FAIL, 
zipSource.getExportResult().getOperationStatus());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/atlas/blob/a9ffa992/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
----------------------------------------------------------------------
diff --git 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
index fe473b8..5e287d8 100644
--- 
a/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
+++ 
b/repository/src/test/java/org/apache/atlas/repository/impexp/ZipFileResourceTestUtils.java
@@ -255,19 +255,15 @@ public class ZipFileResourceTestUtils {
 
     public static AtlasEntity.AtlasEntityWithExtInfo getEntities(ZipSource 
source, int expectedCount) {
         AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = new 
AtlasEntity.AtlasEntityWithExtInfo();
-        try {
-            int count = 0;
-            for (String s : source.getCreationOrder()) {
-                AtlasEntity entity = source.getByGuid(s);
-                entityWithExtInfo.addReferredEntity(s, entity);
-                count++;
-            }
-
-            assertEquals(count, expectedCount);
-            return entityWithExtInfo;
-        } catch (AtlasBaseException e) {
-            throw new SkipException("getEntities: failed!");
+        int count = 0;
+        for (String s : source.getCreationOrder()) {
+            AtlasEntity entity = source.getByGuid(s);
+            entityWithExtInfo.addReferredEntity(s, entity);
+            count++;
         }
+
+        assertEquals(count, expectedCount);
+        return entityWithExtInfo;
     }
 
     public static void loadModelFromJson(String fileName, AtlasTypeDefStore 
typeDefStore, AtlasTypeRegistry typeRegistry) throws IOException, 
AtlasBaseException {

http://git-wip-us.apache.org/repos/asf/atlas/blob/a9ffa992/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
----------------------------------------------------------------------
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java 
b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
index 55e8b9e..d9b1a41 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
@@ -391,7 +391,7 @@ public class AdminResource {
         AtlasAuthorizationUtils.verifyAccess(new 
AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_IMPORT), "importData");
 
         acquireExportImportLock("import");
-        AtlasImportResult result;
+        AtlasImportResult result = null;
 
         try {
             AtlasImportRequest request = AtlasType.fromJson(jsonData, 
AtlasImportRequest.class);
@@ -400,6 +400,15 @@ public class AdminResource {
             result = importService.run(zipSource, request, 
Servlets.getUserName(httpServletRequest),
                     Servlets.getHostName(httpServletRequest),
                     
AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
+        } catch (AtlasBaseException excp) {
+            if 
(excp.getAtlasErrorCode().equals(AtlasErrorCode.IMPORT_ATTEMPTING_EMPTY_ZIP)) {
+                LOG.info(excp.getMessage());
+            } else {
+                LOG.error("importData(binary) failed", excp);
+            }
+
+            throw excp;
+
         } catch (Exception excp) {
             LOG.error("importData(binary) failed", excp);
 
@@ -434,6 +443,14 @@ public class AdminResource {
             result = importService.run(request, 
Servlets.getUserName(httpServletRequest),
                                        
Servlets.getHostName(httpServletRequest),
                                        
AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
+        } catch (AtlasBaseException excp) {
+            if 
(excp.getAtlasErrorCode().getErrorCode().equals(AtlasErrorCode.IMPORT_ATTEMPTING_EMPTY_ZIP))
 {
+                LOG.info(excp.getMessage());
+            } else {
+                LOG.error("importData(binary) failed", excp);
+            }
+
+            throw excp;
         } catch (Exception excp) {
             LOG.error("importFile() failed", excp);
 

Reply via email to