Search in sources :

Example 6 with AtlasImportResult

use of org.apache.atlas.model.impexp.AtlasImportResult 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

AtlasImportResult (org.apache.atlas.model.impexp.AtlasImportResult)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)4 AtlasImportRequest (org.apache.atlas.model.impexp.AtlasImportRequest)3 FileNotFoundException (java.io.FileNotFoundException)2 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 ImportService (org.apache.atlas.repository.impexp.ImportService)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 JSONException (org.codehaus.jettison.json.JSONException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Consumes (javax.ws.rs.Consumes)1 AtlasExportResult (org.apache.atlas.model.impexp.AtlasExportResult)1 ZipSource (org.apache.atlas.repository.impexp.ZipSource)1