Commit dd00c859 by ashutoshm Committed by Madhan Neethiraj

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

parent 38297a84
......@@ -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
......
......@@ -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;
}
......
......@@ -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() {
......
......@@ -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();
......
......@@ -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);
......
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