Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
e8661ecb
Commit
e8661ecb
authored
Mar 02, 2020
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3641: Import Service: Support zipDirect format of import.
parent
30a09955
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
10 deletions
+141
-10
AtlasImportRequest.java
...ava/org/apache/atlas/model/impexp/AtlasImportRequest.java
+18
-2
AtlasJson.java
intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
+4
-0
ImportService.java
...ava/org/apache/atlas/repository/impexp/ImportService.java
+14
-3
ZipExportFileNames.java
...rg/apache/atlas/repository/impexp/ZipExportFileNames.java
+4
-0
ZipSourceDirect.java
...a/org/apache/atlas/repository/impexp/ZipSourceDirect.java
+0
-0
ZipFileMigrationImporter.java
.../atlas/repository/migration/ZipFileMigrationImporter.java
+3
-5
ImportServiceTest.java
...org/apache/atlas/repository/impexp/ImportServiceTest.java
+15
-0
ZipDirectTest.java
...ava/org/apache/atlas/repository/impexp/ZipDirectTest.java
+83
-0
No files found.
intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java
View file @
e8661ecb
...
...
@@ -44,10 +44,13 @@ public class AtlasImportRequest implements Serializable {
public
static
final
String
TRANSFORMS_KEY
=
"transforms"
;
public
static
final
String
TRANSFORMERS_KEY
=
"transformers"
;
public
static
final
String
OPTION_KEY_REPLICATED_FROM
=
"replicatedFrom"
;
public
static
final
String
OPTION_KEY_FORMAT
=
"format"
;
public
static
final
String
OPTION_KEY_FORMAT_ZIP_DIRECT
=
"zipDirect"
;
private
static
final
String
START_POSITION_KEY
=
"startPosition"
;
private
static
final
String
START_GUID_KEY
=
"startGuid"
;
private
static
final
String
FILE_NAME_KEY
=
"fileName"
;
private
static
final
String
UPDATE_TYPE_DEFINITION_KEY
=
"updateTypeDefinition"
;
private
static
final
String
OPTION_KEY_STREAM_SIZE
=
"size"
;
private
Map
<
String
,
String
>
options
;
...
...
@@ -108,7 +111,7 @@ public class AtlasImportRequest implements Serializable {
return
null
;
}
return
(
String
)
this
.
options
.
get
(
key
);
return
this
.
options
.
get
(
key
);
}
@JsonIgnore
...
...
@@ -127,4 +130,17 @@ public class AtlasImportRequest implements Serializable {
options
=
new
HashMap
<>();
}
options
.
put
(
key
,
value
);
}}
}
public
void
setSizeOption
(
int
size
)
{
setOption
(
OPTION_KEY_STREAM_SIZE
,
Integer
.
toString
(
size
));
}
public
int
getSizeOption
()
{
if
(!
this
.
options
.
containsKey
(
OPTION_KEY_STREAM_SIZE
))
{
return
1
;
}
return
Integer
.
valueOf
(
this
.
options
.
get
(
OPTION_KEY_STREAM_SIZE
));
}
}
intg/src/main/java/org/apache/atlas/utils/AtlasJson.java
View file @
e8661ecb
...
...
@@ -251,6 +251,10 @@ public class AtlasJson {
return
ret
;
}
public
static
ObjectCodec
getMapper
()
{
return
mapper
;
}
static
class
DateSerializer
extends
JsonSerializer
<
Date
>
{
@Override
public
void
serialize
(
Date
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
{
...
...
repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
View file @
e8661ecb
...
...
@@ -92,7 +92,7 @@ public class ImportService {
request
=
new
AtlasImportRequest
();
}
EntityImportStream
source
=
createZipSource
(
inputStream
,
AtlasConfiguration
.
IMPORT_TEMP_DIRECTORY
.
getString
());
EntityImportStream
source
=
createZipSource
(
request
,
inputStream
,
AtlasConfiguration
.
IMPORT_TEMP_DIRECTORY
.
getString
());
return
run
(
source
,
request
,
userName
,
hostName
,
requestingIP
);
}
...
...
@@ -248,8 +248,13 @@ public class ImportService {
return
(
int
)
(
endTime
-
startTime
);
}
private
EntityImportStream
createZipSource
(
InputStream
inputStream
,
String
configuredTemporaryDirectory
)
throws
AtlasBaseException
{
private
EntityImportStream
createZipSource
(
AtlasImportRequest
request
,
InputStream
inputStream
,
String
configuredTemporaryDirectory
)
throws
AtlasBaseException
{
try
{
if
(
request
.
getOptions
().
containsKey
(
AtlasImportRequest
.
OPTION_KEY_FORMAT
)
&&
request
.
getOptions
().
get
(
AtlasImportRequest
.
OPTION_KEY_FORMAT
).
equals
(
AtlasImportRequest
.
OPTION_KEY_FORMAT_ZIP_DIRECT
)
)
{
return
getZipDirectEntityImportStream
(
request
,
inputStream
);
}
if
(
StringUtils
.
isEmpty
(
configuredTemporaryDirectory
))
{
return
new
ZipSource
(
inputStream
);
}
...
...
@@ -260,9 +265,15 @@ public class ImportService {
}
}
private
EntityImportStream
getZipDirectEntityImportStream
(
AtlasImportRequest
request
,
InputStream
inputStream
)
throws
IOException
,
AtlasBaseException
{
ZipSourceDirect
zipSourceDirect
=
new
ZipSourceDirect
(
inputStream
,
request
.
getSizeOption
());
LOG
.
info
(
"Using ZipSourceDirect: Size: {} entities"
,
zipSourceDirect
.
size
());
return
zipSourceDirect
;
}
@VisibleForTesting
boolean
checkHiveTableIncrementalSkipLineage
(
AtlasImportRequest
importRequest
,
AtlasExportRequest
exportRequest
)
{
if
(
CollectionUtils
.
isEmpty
(
exportRequest
.
getItemsToExport
()))
{
if
(
exportRequest
==
null
||
CollectionUtils
.
isEmpty
(
exportRequest
.
getItemsToExport
()))
{
return
false
;
}
...
...
repository/src/main/java/org/apache/atlas/repository/impexp/ZipExportFileNames.java
View file @
e8661ecb
...
...
@@ -31,4 +31,8 @@ public enum ZipExportFileNames {
public
String
toString
()
{
return
this
.
name
;
}
public
String
toEntryFileName
()
{
return
this
.
name
+
".json"
;
}
}
repository/src/main/java/org/apache/atlas/repository/impexp/ZipSourceDirect.java
0 → 100644
View file @
e8661ecb
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/migration/ZipFileMigrationImporter.java
View file @
e8661ecb
...
...
@@ -84,10 +84,8 @@ public class ZipFileMigrationImporter implements Runnable {
}
private
AtlasImportRequest
getImportRequest
()
throws
AtlasException
{
return
new
AtlasImportRequest
();
}
private
String
getPropertyValue
(
String
property
,
String
defaultValue
)
throws
AtlasException
{
return
ApplicationProperties
.
get
().
getString
(
property
,
defaultValue
);
AtlasImportRequest
request
=
new
AtlasImportRequest
();
request
.
setOption
(
AtlasImportRequest
.
OPTION_KEY_FORMAT
,
AtlasImportRequest
.
OPTION_KEY_FORMAT_ZIP_DIRECT
);
return
request
;
}
}
repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
View file @
e8661ecb
...
...
@@ -186,6 +186,11 @@ public class ImportServiceTest extends ExportImportTestBase {
return
getZipSource
(
"salesNewTypeAttrs-next.zip"
);
}
@DataProvider
(
name
=
"zip-direct-3"
)
public
static
Object
[][]
getZipDirect3
(
ITestContext
context
)
throws
IOException
,
AtlasBaseException
{
return
getZipSource
(
"zip-direct-3.zip"
);
}
@Test
(
dataProvider
=
"salesNewTypeAttrs-next"
,
dependsOnMethods
=
"importDB4"
)
public
void
importDB5
(
InputStream
inputStream
)
throws
AtlasBaseException
,
IOException
{
final
String
newEnumDefName
=
"database_action"
;
...
...
@@ -346,6 +351,16 @@ public class ImportServiceTest extends ExportImportTestBase {
}
}
@Test
(
dataProvider
=
"zip-direct-3"
,
expectedExceptions
=
AtlasBaseException
.
class
)
public
void
zipDirectSample
(
InputStream
inputStream
)
throws
IOException
,
AtlasBaseException
{
loadBaseModel
();
loadFsModel
();
AtlasImportRequest
request
=
new
AtlasImportRequest
();
request
.
setOption
(
AtlasImportRequest
.
OPTION_KEY_FORMAT
,
AtlasImportRequest
.
OPTION_KEY_FORMAT_ZIP_DIRECT
);
runImportWithParameters
(
importService
,
request
,
inputStream
);
}
@DataProvider
(
name
=
"relationshipLineage"
)
public
static
Object
[][]
getImportWithRelationships
(
ITestContext
context
)
throws
IOException
,
AtlasBaseException
{
return
getZipSource
(
"rel-lineage.zip"
);
...
...
repository/src/test/java/org/apache/atlas/repository/impexp/ZipDirectTest.java
0 → 100644
View file @
e8661ecb
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
impexp
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.impexp.AtlasExportResult
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.testng.annotations.Test
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertNull
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
public
class
ZipDirectTest
{
@Test
(
expectedExceptions
=
AtlasBaseException
.
class
)
public
void
loadFileEmpty
()
throws
IOException
,
AtlasBaseException
{
InputStream
inputStream
=
ZipFileResourceTestUtils
.
getFileInputStream
(
"zip-direct-1.zip"
);
new
ZipSourceDirect
(
inputStream
,
1
);
}
@Test
public
void
loadFile
()
throws
IOException
,
AtlasBaseException
{
final
int
EXPECTED_ENTITY_COUNT
=
3
;
InputStream
inputStream
=
ZipFileResourceTestUtils
.
getFileInputStream
(
"zip-direct-2.zip"
);
ZipSourceDirect
zipSourceDirect
=
new
ZipSourceDirect
(
inputStream
,
EXPECTED_ENTITY_COUNT
);
assertNotNull
(
zipSourceDirect
);
assertNotNull
(
zipSourceDirect
.
getTypesDef
());
assertTrue
(
zipSourceDirect
.
getTypesDef
().
getEntityDefs
().
size
()
>
0
);
assertNotNull
(
zipSourceDirect
.
getExportResult
());
int
count
=
0
;
AtlasEntity
.
AtlasEntityWithExtInfo
entityWithExtInfo
;
while
((
entityWithExtInfo
=
zipSourceDirect
.
getNextEntityWithExtInfo
())
!=
null
)
{
assertNotNull
(
entityWithExtInfo
);
count
++;
}
assertEquals
(
count
,
EXPECTED_ENTITY_COUNT
);
}
@Test
public
void
entitiesParserTest
()
throws
IOException
{
String
object1
=
"{\"type\":\"hdfs_path\"}"
;
String
object2
=
"{\"type\":\"hive_db\"}"
;
String
entities
=
"["
+
object1
+
","
+
object2
+
",{}]"
;
InputStream
inputStream
=
new
ByteArrayInputStream
(
entities
.
getBytes
());
ZipSourceDirect
.
EntitiesArrayParser
entitiesArrayParser
=
new
ZipSourceDirect
.
EntitiesArrayParser
(
inputStream
);
Object
o
=
entitiesArrayParser
.
next
();
assertNotNull
(
o
);
assertEquals
(
o
,
object1
);
o
=
entitiesArrayParser
.
next
();
assertEquals
(
o
,
object2
);
o
=
entitiesArrayParser
.
next
();
assertNull
(
o
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment