Commit 7763fd0d by Ashutosh Mestry

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

parent f6acb086
...@@ -64,13 +64,20 @@ public class ZipSource implements EntityImportStream { ...@@ -64,13 +64,20 @@ public class ZipSource implements EntityImportStream {
this.importTransform = importTransform; this.importTransform = importTransform;
updateGuidZipEntryMap(); updateGuidZipEntryMap();
if (MapUtils.isEmpty(guidEntityJsonMap)) { if (isZipFileEmpty()) {
throw new AtlasBaseException(IMPORT_ATTEMPTING_EMPTY_ZIP, "Attempting to import empty ZIP."); throw new AtlasBaseException(IMPORT_ATTEMPTING_EMPTY_ZIP, "Attempting to import empty ZIP.");
} }
setCreationOrder(); 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 ImportTransforms getImportTransform() { return this.importTransform; }
public void setImportTransform(ImportTransforms importTransform) { public void setImportTransform(ImportTransforms importTransform) {
...@@ -136,7 +143,7 @@ public class ZipSource implements EntityImportStream { ...@@ -136,7 +143,7 @@ public class ZipSource implements EntityImportStream {
zipInputStream.close(); zipInputStream.close();
} }
public List<String> getCreationOrder() throws AtlasBaseException { public List<String> getCreationOrder() {
return this.creationOrder; return this.creationOrder;
} }
...@@ -234,12 +241,8 @@ public class ZipSource implements EntityImportStream { ...@@ -234,12 +241,8 @@ public class ZipSource implements EntityImportStream {
@Override @Override
public void reset() { public void reset() {
try { getCreationOrder();
getCreationOrder(); this.iterator = this.creationOrder.iterator();
this.iterator = this.creationOrder.iterator();
} catch (AtlasBaseException e) {
LOG.error("reset", e);
}
} }
@Override @Override
......
...@@ -314,7 +314,6 @@ public class ExportServiceTest extends ExportImportTestBase { ...@@ -314,7 +314,6 @@ public class ExportServiceTest extends ExportImportTestBase {
assertNotNull(zipSource.getCreationOrder()); assertNotNull(zipSource.getCreationOrder());
assertEquals(zipSource.getCreationOrder().size(), 0); assertEquals(zipSource.getCreationOrder().size(), 0);
assertEquals(AtlasExportResult.OperationStatus.FAIL, zipSource.getExportResult().getOperationStatus());
} }
@Test @Test
......
...@@ -255,19 +255,15 @@ public class ZipFileResourceTestUtils { ...@@ -255,19 +255,15 @@ public class ZipFileResourceTestUtils {
public static AtlasEntity.AtlasEntityWithExtInfo getEntities(ZipSource source, int expectedCount) { public static AtlasEntity.AtlasEntityWithExtInfo getEntities(ZipSource source, int expectedCount) {
AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntity.AtlasEntityWithExtInfo(); AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntity.AtlasEntityWithExtInfo();
try { int count = 0;
int count = 0; for (String s : source.getCreationOrder()) {
for (String s : source.getCreationOrder()) { AtlasEntity entity = source.getByGuid(s);
AtlasEntity entity = source.getByGuid(s); entityWithExtInfo.addReferredEntity(s, entity);
entityWithExtInfo.addReferredEntity(s, entity); count++;
count++;
}
assertEquals(count, expectedCount);
return entityWithExtInfo;
} catch (AtlasBaseException e) {
throw new SkipException("getEntities: failed!");
} }
assertEquals(count, expectedCount);
return entityWithExtInfo;
} }
public static void loadModelFromJson(String fileName, AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry) throws IOException, AtlasBaseException { public static void loadModelFromJson(String fileName, AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry) throws IOException, AtlasBaseException {
......
...@@ -391,7 +391,7 @@ public class AdminResource { ...@@ -391,7 +391,7 @@ public class AdminResource {
AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_IMPORT), "importData"); AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_IMPORT), "importData");
acquireExportImportLock("import"); acquireExportImportLock("import");
AtlasImportResult result; AtlasImportResult result = null;
try { try {
AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class); AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class);
...@@ -400,6 +400,15 @@ public class AdminResource { ...@@ -400,6 +400,15 @@ public class AdminResource {
result = importService.run(zipSource, request, Servlets.getUserName(httpServletRequest), result = importService.run(zipSource, request, Servlets.getUserName(httpServletRequest),
Servlets.getHostName(httpServletRequest), Servlets.getHostName(httpServletRequest),
AtlasAuthorizationUtils.getRequestIpAddress(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) { } catch (Exception excp) {
LOG.error("importData(binary) failed", excp); LOG.error("importData(binary) failed", excp);
...@@ -434,6 +443,14 @@ public class AdminResource { ...@@ -434,6 +443,14 @@ public class AdminResource {
result = importService.run(request, Servlets.getUserName(httpServletRequest), result = importService.run(request, Servlets.getUserName(httpServletRequest),
Servlets.getHostName(httpServletRequest), Servlets.getHostName(httpServletRequest),
AtlasAuthorizationUtils.getRequestIpAddress(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) { } catch (Exception excp) {
LOG.error("importFile() failed", excp); LOG.error("importFile() failed", excp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment