Search in sources :

Example 1 with AtlasImportResult

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

the class ImportService method run.

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);
        String transforms = MapUtils.isNotEmpty(request.getOptions()) ? request.getOptions().get(AtlasImportRequest.TRANSFORMS_KEY) : null;
        source.setImportTransform(ImportTransforms.fromJson(transforms));
        startTimestamp = System.currentTimeMillis();
        processTypes(source.getTypesDef(), result);
        processEntities(source, result);
        result.setOperationStatus(AtlasImportResult.OperationStatus.SUCCESS);
    } catch (AtlasBaseException excp) {
        LOG.error("import(user={}, from={}): failed", userName, requestingIP, excp);
        throw excp;
    } catch (Exception excp) {
        LOG.error("import(user={}, from={}): failed", userName, requestingIP, excp);
        throw new AtlasBaseException(excp);
    } finally {
        source.close();
        LOG.info("<== import(user={}, from={}): status={}", userName, requestingIP, result.getOperationStatus());
    }
    return result;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) FileNotFoundException(java.io.FileNotFoundException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 2 with AtlasImportResult

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

the class ImportService method run.

public AtlasImportResult run(AtlasImportRequest request, String userName, String hostName, String requestingIP) throws AtlasBaseException {
    String fileName = (String) request.getOptions().get("FILENAME");
    if (StringUtils.isBlank(fileName)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "FILENAME parameter not found");
    }
    AtlasImportResult result = null;
    try {
        LOG.info("==> import(user={}, from={}, fileName={})", userName, requestingIP, fileName);
        String transforms = MapUtils.isNotEmpty(request.getOptions()) ? request.getOptions().get(AtlasImportRequest.TRANSFORMS_KEY) : null;
        File file = new File(fileName);
        ZipSource source = new ZipSource(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)), ImportTransforms.fromJson(transforms));
        result = run(source, request, userName, hostName, requestingIP);
    } catch (AtlasBaseException excp) {
        LOG.error("import(user={}, from={}, fileName={}): failed", userName, requestingIP, excp);
        throw excp;
    } catch (FileNotFoundException excp) {
        LOG.error("import(user={}, from={}, fileName={}): file not found", userName, requestingIP, excp);
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, fileName + ": file not found");
    } catch (Exception excp) {
        LOG.error("import(user={}, from={}, fileName={}): failed", userName, requestingIP, excp);
        throw new AtlasBaseException(excp);
    } finally {
        LOG.info("<== import(user={}, from={}, fileName={}): status={}", userName, requestingIP, fileName, (result == null ? AtlasImportResult.OperationStatus.FAIL : result.getOperationStatus()));
    }
    return result;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 3 with AtlasImportResult

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

the class ZipFileResourceTestUtils method runAndVerifyQuickStart_v1_Import.

public static void runAndVerifyQuickStart_v1_Import(ImportService importService, ZipSource zipSource) throws AtlasBaseException, IOException {
    AtlasExportResult exportResult = zipSource.getExportResult();
    List<String> creationOrder = zipSource.getCreationOrder();
    AtlasImportRequest request = getDefaultImportRequest();
    AtlasImportResult result = runImportWithParameters(importService, request, zipSource);
    Assert.assertNotNull(result);
    verifyImportedMetrics(exportResult, result);
    verifyImportedEntities(creationOrder, result.getProcessedEntities());
}
Also used : AtlasExportResult(org.apache.atlas.model.impexp.AtlasExportResult) AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest)

Example 4 with AtlasImportResult

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

the class ZipFileResourceTestUtils method runImportWithParameters.

public static AtlasImportResult runImportWithParameters(ImportService importService, AtlasImportRequest request, 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, request, userName, hostName, requestingIP);
    Assert.assertEquals(result.getOperationStatus(), AtlasImportResult.OperationStatus.SUCCESS);
    return result;
}
Also used : AtlasImportResult(org.apache.atlas.model.impexp.AtlasImportResult)

Example 5 with AtlasImportResult

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

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