Commit f5db98b3 by Deep Singh Committed by Ashutosh Mestry

ATLAS-3987: Atlas client export API, must pass server error code in the exception

parent 4ab49623
...@@ -477,16 +477,16 @@ public abstract class AtlasBaseClient { ...@@ -477,16 +477,16 @@ public abstract class AtlasBaseClient {
public InputStream exportData(AtlasExportRequest request) throws AtlasServiceException { public InputStream exportData(AtlasExportRequest request) throws AtlasServiceException {
try { try {
return (InputStream) callAPI(EXPORT, Object.class, request); return (InputStream) callAPI(EXPORT, Object.class, request);
} catch (Exception e) { } catch (AtlasServiceException e) {
LOG.error("error writing to file", e); LOG.error("error in export API call", e);
throw new AtlasServiceException(e); throw new AtlasServiceException(e);
} }
} }
public void exportData(AtlasExportRequest request, String absolutePath) throws AtlasServiceException { public void exportData(AtlasExportRequest request, String absolutePath) throws AtlasServiceException {
OutputStream fileOutputStream = null; OutputStream fileOutputStream = null;
InputStream inputStream = exportData(request);
try { try {
InputStream inputStream = exportData(request);
fileOutputStream = new FileOutputStream(new File(absolutePath)); fileOutputStream = new FileOutputStream(new File(absolutePath));
byte[] buffer = new byte[8 * 1024]; byte[] buffer = new byte[8 * 1024];
int bytesRead; int bytesRead;
......
...@@ -41,6 +41,11 @@ public class AtlasServiceException extends Exception { ...@@ -41,6 +41,11 @@ public class AtlasServiceException extends Exception {
super(e); super(e);
} }
public AtlasServiceException(AtlasServiceException e) {
super(e);
this.status = e.status;
}
public ClientResponse.Status getStatus() { public ClientResponse.Status getStatus() {
return status; return status;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.impexp.AtlasExportResult; import org.apache.atlas.model.impexp.AtlasExportResult;
...@@ -84,6 +85,17 @@ public class AdminExportImportTestIT extends BaseResourceIT { ...@@ -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()); 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 { private void performImport(String fileToImport, int expectedProcessedEntitiesCount) throws AtlasServiceException {
AtlasImportRequest request = new AtlasImportRequest(); AtlasImportRequest request = new AtlasImportRequest();
request.getOptions().put(AtlasImportRequest.OPTION_KEY_REPLICATED_FROM, SOURCE_SERVER_NAME); request.getOptions().put(AtlasImportRequest.OPTION_KEY_REPLICATED_FROM, SOURCE_SERVER_NAME);
......
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