Search in sources :

Example 6 with AtlasImportRequest

use of org.apache.atlas.model.impexp.AtlasImportRequest in project incubator-atlas by apache.

the class AdminResource method importFile.

@POST
@Path("/importfile")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasImportResult importFile(String jsonData) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AdminResource.importFile()");
    }
    acquireExportImportLock("importFile");
    AtlasImportResult result;
    try {
        AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class);
        ImportService importService = new ImportService(this.typesDefStore, this.entityStore, this.typeRegistry);
        result = importService.run(request, Servlets.getUserName(httpServletRequest), Servlets.getHostName(httpServletRequest), AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
    } catch (Exception excp) {
        LOG.error("importFile() failed", excp);
        throw new AtlasBaseException(excp);
    } finally {
        releaseExportImportLock();
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== AdminResource.importFile()");
        }
    }
    return result;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ImportService(org.apache.atlas.repository.impexp.ImportService) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 7 with AtlasImportRequest

use of org.apache.atlas.model.impexp.AtlasImportRequest in project incubator-atlas by apache.

the class AdminResource method importData.

@POST
@Path("/import")
@Produces(Servlets.JSON_MEDIA_TYPE)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public AtlasImportResult importData(@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 {
        AtlasImportRequest request = AtlasType.fromJson(jsonData, AtlasImportRequest.class);
        ImportService importService = new ImportService(this.typesDefStore, this.entityStore, this.typeRegistry);
        ZipSource zipSource = new ZipSource(inputStream);
        result = importService.run(zipSource, request, Servlets.getUserName(httpServletRequest), Servlets.getHostName(httpServletRequest), AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
    } catch (Exception excp) {
        LOG.error("importData(binary) failed", excp);
        throw new AtlasBaseException(excp);
    } finally {
        releaseExportImportLock();
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== AdminResource.importData(binary)");
        }
    }
    return result;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ImportService(org.apache.atlas.repository.impexp.ImportService) ZipSource(org.apache.atlas.repository.impexp.ZipSource) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

AtlasImportRequest (org.apache.atlas.model.impexp.AtlasImportRequest)7 Test (org.testng.annotations.Test)4 AtlasImportResult (org.apache.atlas.model.impexp.AtlasImportResult)3 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 ImportService (org.apache.atlas.repository.impexp.ImportService)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 JSONException (org.codehaus.jettison.json.JSONException)2 Consumes (javax.ws.rs.Consumes)1 AtlasExportResult (org.apache.atlas.model.impexp.AtlasExportResult)1 ZipSource (org.apache.atlas.repository.impexp.ZipSource)1