atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject atlas git commit: ATLAS-2017: updated import API to make request parameter optional
Date Thu, 03 Aug 2017 03:00:12 GMT
Repository: atlas
Updated Branches:
  refs/heads/master 38297a844 -> dd00c8596


ATLAS-2017: updated import API to make request parameter optional

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


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

Branch: refs/heads/master
Commit: dd00c8596625703dd3c18474fb9700a07d08f9d8
Parents: 38297a8
Author: ashutoshm <amestry@hortonworks.com>
Authored: Wed Aug 2 15:21:00 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Wed Aug 2 19:51:13 2017 -0700

----------------------------------------------------------------------
 docs/src/site/twiki/Import-API.twiki                 |  9 +++++++++
 .../atlas/repository/impexp/ImportService.java       | 15 +++++++++++----
 .../atlas/repository/impexp/ImportServiceTest.java   |  3 +--
 .../repository/impexp/ZipFileResourceTestUtils.java  | 10 ++++++++++
 .../apache/atlas/web/resources/AdminResource.java    |  8 ++------
 5 files changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/dd00c859/docs/src/site/twiki/Import-API.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/Import-API.twiki b/docs/src/site/twiki/Import-API.twiki
index 00ac9c4..6deda27 100644
--- a/docs/src/site/twiki/Import-API.twiki
+++ b/docs/src/site/twiki/Import-API.twiki
@@ -66,6 +66,15 @@ curl -g -X POST -u adminuser:password -H "Content-Type: multipart/form-data"
             "http://localhost:21000/api/atlas/admin/import"
 </verbatim>
 
+The _request_ parameter is optional. If import has to be run without any options use:
+<verbatim>
+curl -g -X POST -u adminuser:password -H "Content-Type: multipart/form-data"
+            -H "Cache-Control: no-cache"
+            -F data=@quickStartDB.zip
+            "http://localhost:21000/api/atlas/admin/import"
+</verbatim>
+
+
 The call below performs Import of _!QuickStart_ database using a ZIP file available on server.
 <verbatim>
 curl -X POST -u adminuser:password -H "Cache-Control: no-cache" -d ./importOptions.json

http://git-wip-us.apache.org/repos/asf/atlas/blob/dd00c859/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 bdeed7d..efe7687 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
@@ -55,13 +55,20 @@ public class ImportService {
         this.typeRegistry = typeRegistry;
     }
 
+    public AtlasImportResult run(ZipSource source, String userName,
+                                 String hostName, String requestingIP) throws AtlasBaseException
{
+        return run(source, null, userName, hostName, requestingIP);
+    }
+
     public AtlasImportResult run(ZipSource source, AtlasImportRequest request, String userName,
                                  String hostName, String requestingIP) throws AtlasBaseException
{
         AtlasImportResult result = new AtlasImportResult(request, userName, requestingIP,
hostName, System.currentTimeMillis());
 
         try {
-
             LOG.info("==> import(user={}, from={})", userName, requestingIP);
+            if (request == null) {
+                request = new AtlasImportRequest();
+            }
 
             String transforms = MapUtils.isNotEmpty(request.getOptions()) ? request.getOptions().get(AtlasImportRequest.TRANSFORMS_KEY)
: null;
 
@@ -90,9 +97,9 @@ public class ImportService {
     }
 
     private void setStartPosition(AtlasImportRequest request, ZipSource source) throws AtlasBaseException
{
-        if(request.getStartGuid() != null) {
+        if (request.getStartGuid() != null) {
             source.setPositionUsingEntityGuid(request.getStartGuid());
-        } else if(request.getStartPosition() != null) {
+        } else if (request.getStartPosition() != null) {
             source.setPosition(Integer.parseInt(request.getStartPosition()));
         }
     }
@@ -136,7 +143,7 @@ public class ImportService {
     }
 
     private void processTypes(AtlasTypesDef typeDefinitionMap, AtlasImportResult result)
throws AtlasBaseException {
-        if(result.getRequest().getUpdateTypeDefs() != null && !result.getRequest().getUpdateTypeDefs().equals("true"))
{
+        if (result.getRequest().getUpdateTypeDefs() != null && !result.getRequest().getUpdateTypeDefs().equals("true"))
{
             return;
         }
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/dd00c859/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 b96197b..42f7011 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
@@ -153,8 +153,7 @@ public class ImportServiceTest {
         loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
         loadModelFromJson("0030-hive_model.json", typeDefStore, typeRegistry);
 
-        AtlasImportRequest request = getDefaultImportRequest();
-        runImportWithParameters(getImportService(), getDefaultImportRequest(), zipSource);
+        runImportWithNoParameters(getImportService(), zipSource);
     }
 
     private ImportService getImportService() {

http://git-wip-us.apache.org/repos/asf/atlas/blob/dd00c859/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 3ccbd8e..d80fab0 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
@@ -147,6 +147,16 @@ public class ZipFileResourceTestUtils {
         return result;
     }
 
+    public static AtlasImportResult runImportWithNoParameters(ImportService importService,
ZipSource source) throws AtlasBaseException, IOException {
+        final String requestingIP = "1.0.0.0";
+        final String hostName = "localhost";
+        final String userName = "admin";
+
+        AtlasImportResult result = importService.run(source, userName, hostName, requestingIP);
+        assertEquals(result.getOperationStatus(), AtlasImportResult.OperationStatus.SUCCESS);
+        return result;
+    }
+
     public static void runAndVerifyQuickStart_v1_Import(ImportService importService, ZipSource
zipSource) throws AtlasBaseException, IOException {
         AtlasExportResult exportResult = zipSource.getExportResult();
         List<String> creationOrder = zipSource.getCreationOrder();

http://git-wip-us.apache.org/repos/asf/atlas/blob/dd00c859/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 fe9111b..82a4d4e 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
@@ -61,6 +61,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -359,21 +360,16 @@ public class AdminResource {
     @Path("/import")
     @Produces(Servlets.JSON_MEDIA_TYPE)
     @Consumes(MediaType.MULTIPART_FORM_DATA)
-    public AtlasImportResult importData(@FormDataParam("request") String jsonData,
+    public AtlasImportResult importData(@DefaultValue("{}") @FormDataParam("request") String
jsonData,
                                         @FormDataParam("data") InputStream inputStream) throws
AtlasBaseException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> AdminResource.importData(jsonData={}, inputStream={})", jsonData,
(inputStream != null));
         }
 
         acquireExportImportLock("import");
-
         AtlasImportResult result;
 
         try {
-            if (StringUtils.isEmpty(jsonData)) {
-                jsonData = "{}";
-            }
-
             AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class);
             ZipSource zipSource = new ZipSource(inputStream);
 


Mime
View raw message