Commit 24a106b4 by ashutoshm Committed by Madhan Neethiraj

ATLAS-1948: export fix to correct the import order

parent cfb6b84f
......@@ -98,7 +98,6 @@ public class ExportService {
AtlasExportResult.OperationStatus[] statuses = processItems(request, context);
processTypesDef(context);
updateSinkWithOperationMetrics(context, statuses, getOperationDuration(startTime));
} catch(Exception ex) {
LOG.error("Operation failed: ", ex);
......@@ -113,6 +112,7 @@ public class ExportService {
}
private void updateSinkWithOperationMetrics(ExportContext context, AtlasExportResult.OperationStatus[] statuses, int duration) throws AtlasBaseException {
context.result.getData().getEntityCreationOrder().addAll(context.lineageProcessed);
context.sink.setExportOrder(context.result.getData().getEntityCreationOrder());
context.sink.setTypesDef(context.result.getData().getTypesDef());
clearContextData(context);
......@@ -201,9 +201,10 @@ public class ExportService {
processEntity(guid, context);
}
if (!context.guidsLineageToProcess.isEmpty()) {
context.guidsToProcess.addAll(context.guidsLineageToProcess);
context.guidsLineageToProcess.clear();
if (!context.lineageToProcess.isEmpty()) {
context.guidsToProcess.addAll(context.lineageToProcess);
context.lineageProcessed.addAll(context.lineageToProcess.getList());
context.lineageToProcess.clear();
}
}
} catch (AtlasBaseException excp) {
......@@ -295,7 +296,9 @@ public class ExportService {
TraversalDirection direction = context.guidDirection.get(guid);
AtlasEntityWithExtInfo entityWithExtInfo = entityGraphRetriever.toAtlasEntityWithExtInfo(guid);
context.result.getData().getEntityCreationOrder().add(entityWithExtInfo.getEntity().getGuid());
if(!context.lineageProcessed.contains(guid)) {
context.result.getData().getEntityCreationOrder().add(entityWithExtInfo.getEntity().getGuid());
}
addEntity(entityWithExtInfo, context);
addTypes(entityWithExtInfo.getEntity(), context);
......@@ -651,13 +654,18 @@ public class ExportService {
list.clear();
set.clear();
}
public List<T> getList() {
return list;
}
}
private class ExportContext {
final Set<String> guidsProcessed = new HashSet<>();
final UniqueList<String> guidsToProcess = new UniqueList<>();
final UniqueList<String> guidsLineageToProcess = new UniqueList<>();
final UniqueList<String> lineageToProcess = new UniqueList<>();
final Set<String> lineageProcessed = new HashSet<>();
final Map<String, TraversalDirection> guidDirection = new HashMap<>();
final Set<String> entityTypes = new HashSet<>();
final Set<String> classificationTypes = new HashSet<>();
......@@ -719,7 +727,7 @@ public class ExportService {
}
if(isSuperTypeProcess) {
guidsLineageToProcess.add(guid);
lineageToProcess.add(guid);
}
guidDirection.put(guid, direction);
......
......@@ -196,7 +196,7 @@ public class ZipSource implements EntityImportStream {
AtlasEntity entity = getEntity(guid);
return entity;
} catch (AtlasBaseException e) {
e.printStackTrace();
LOG.error("getByGuid: {} failed!", guid, e);
return null;
}
}
......
......@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -133,4 +133,22 @@ public class ImportServiceTest {
assertNotNull(typeDefStore.getEnumDefByName(newEnumDefName));
assertEquals(typeDefStore.getEnumDefByName(newEnumDefName).getElementDefs().size(), 8);
}
@DataProvider(name = "ctas")
public static Object[][] getDataFromCtas(ITestContext context) throws IOException {
return getZipSource("ctas.zip");
}
@Test(dataProvider = "ctas")
public void importCTAS(ZipSource zipSource) throws IOException, AtlasBaseException {
loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
loadModelFromJson("0030-hive_model.json", typeDefStore, typeRegistry);
AtlasImportRequest request = getDefaultImportRequest();
runImportWithParameters(getImportService(), getDefaultImportRequest(), zipSource);
}
private ImportService getImportService() {
return new ImportService(typeDefStore, entityStore, typeRegistry);
}
}
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