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
67c04c63
Commit
67c04c63
authored
7 years ago
by
Ashutosh Mestry
Committed by
Madhan Neethiraj
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2132: incorrect error for invalid file path/unreadable file provided during import
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
1dee77af
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
10 deletions
+53
-10
ImportService.java
...ava/org/apache/atlas/repository/impexp/ImportService.java
+6
-2
ImportServiceTest.java
...org/apache/atlas/repository/impexp/ImportServiceTest.java
+47
-8
No files found.
repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
View file @
67c04c63
...
...
@@ -36,6 +36,7 @@ import javax.inject.Inject;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
@Component
public
class
ImportService
{
...
...
@@ -108,7 +109,7 @@ public class ImportService {
public
AtlasImportResult
run
(
AtlasImportRequest
request
,
String
userName
,
String
hostName
,
String
requestingIP
)
throws
AtlasBaseException
{
String
fileName
=
(
String
)
request
.
getFileName
();
String
fileName
=
request
.
getFileName
();
if
(
StringUtils
.
isBlank
(
fileName
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
"FILENAME parameter not found"
);
...
...
@@ -122,7 +123,6 @@ public class ImportService {
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
);
...
...
@@ -132,6 +132,10 @@ public class ImportService {
LOG
.
error
(
"import(user={}, from={}, fileName={}): file not found"
,
userName
,
requestingIP
,
excp
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
fileName
+
": file not found"
);
}
catch
(
IOException
excp
)
{
LOG
.
error
(
"import(user={}, from={}, fileName={}): cannot read file"
,
userName
,
requestingIP
,
excp
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
fileName
+
": cannot read file"
);
}
catch
(
Exception
excp
)
{
LOG
.
error
(
"import(user={}, from={}, fileName={}): failed"
,
userName
,
requestingIP
,
excp
);
...
...
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
View file @
67c04c63
...
...
@@ -27,6 +27,8 @@ import org.apache.atlas.model.impexp.AtlasImportRequest;
import
org.apache.atlas.store.AtlasTypeDefStore
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.testng.ITestContext
;
...
...
@@ -40,6 +42,8 @@ import java.util.HashMap;
import
java.util.Map
;
import
static
org
.
apache
.
atlas
.
repository
.
impexp
.
ZipFileResourceTestUtils
.*;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
...
...
@@ -72,7 +76,7 @@ public class ImportServiceTest {
@Test
(
dataProvider
=
"sales"
)
public
void
importDB1
(
ZipSource
zipSource
)
throws
AtlasBaseException
,
IOException
{
load
ModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
load
BaseModel
(
);
runAndVerifyQuickStart_v1_Import
(
importService
,
zipSource
);
}
...
...
@@ -83,10 +87,14 @@ public class ImportServiceTest {
@Test
(
dataProvider
=
"reporting"
)
public
void
importDB2
(
ZipSource
zipSource
)
throws
AtlasBaseException
,
IOException
{
load
ModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
load
BaseModel
(
);
runAndVerifyQuickStart_v1_Import
(
importService
,
zipSource
);
}
private
void
loadBaseModel
()
throws
IOException
,
AtlasBaseException
{
loadModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
}
@DataProvider
(
name
=
"logging"
)
public
static
Object
[][]
getDataFromLogging
(
ITestContext
context
)
throws
IOException
{
return
getZipSource
(
"logging-v1-full.zip"
);
...
...
@@ -94,7 +102,7 @@ public class ImportServiceTest {
@Test
(
dataProvider
=
"logging"
)
public
void
importDB3
(
ZipSource
zipSource
)
throws
AtlasBaseException
,
IOException
{
load
ModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
load
BaseModel
(
);
runAndVerifyQuickStart_v1_Import
(
importService
,
zipSource
);
}
...
...
@@ -105,7 +113,7 @@ public class ImportServiceTest {
@Test
(
dataProvider
=
"salesNewTypeAttrs"
,
dependsOnMethods
=
"importDB1"
)
public
void
importDB4
(
ZipSource
zipSource
)
throws
AtlasBaseException
,
IOException
{
load
ModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
load
BaseModel
(
);
runImportWithParameters
(
importService
,
getDefaultImportRequest
(),
zipSource
);
}
...
...
@@ -154,8 +162,8 @@ public class ImportServiceTest {
@Test
(
dataProvider
=
"ctas"
)
public
void
importCTAS
(
ZipSource
zipSource
)
throws
IOException
,
AtlasBaseException
{
load
ModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
load
ModelFromJson
(
"1000-Hadoop/1030-hive_model.json"
,
typeDefStore
,
typeRegistry
);
load
BaseModel
(
);
load
HiveModel
(
);
runImportWithNoParameters
(
importService
,
zipSource
);
}
...
...
@@ -168,8 +176,8 @@ public class ImportServiceTest {
@Test
(
dataProvider
=
"hdfs_path1"
,
expectedExceptions
=
AtlasBaseException
.
class
)
public
void
importHdfs_path1
(
ZipSource
zipSource
)
throws
IOException
,
AtlasBaseException
{
load
ModelFromJson
(
"0000-Area0/0010-base_model.json"
,
typeDefStore
,
typeRegistry
);
load
ModelFromJson
(
"1000-Hadoop/1020-fs_model.json"
,
typeDefStore
,
typeRegistry
);
load
BaseModel
(
);
load
FsModel
(
);
loadModelFromResourcesJson
(
"tag1.json"
,
typeDefStore
,
typeRegistry
);
try
{
...
...
@@ -182,4 +190,35 @@ public class ImportServiceTest {
throw
e
;
}
}
@Test
public
void
importServiceProcessesIOException
()
{
ImportService
importService
=
new
ImportService
(
typeDefStore
,
typeRegistry
,
null
);
AtlasImportRequest
req
=
mock
(
AtlasImportRequest
.
class
);
Answer
<
Map
>
answer
=
new
Answer
<
Map
>()
{
@Override
public
Map
answer
(
InvocationOnMock
invocationOnMock
)
throws
Throwable
{
throw
new
IOException
(
"file is read only"
);
}
};
when
(
req
.
getFileName
()).
thenReturn
(
"some-file.zip"
);
when
(
req
.
getOptions
()).
thenAnswer
(
answer
);
try
{
importService
.
run
(
req
,
"a"
,
"b"
,
"c"
);
}
catch
(
AtlasBaseException
ex
)
{
assertEquals
(
ex
.
getAtlasErrorCode
().
getErrorCode
(),
AtlasErrorCode
.
INVALID_PARAMETERS
.
getErrorCode
());
}
}
private
void
loadFsModel
()
throws
IOException
,
AtlasBaseException
{
loadModelFromJson
(
"1000-Hadoop/1020-fs_model.json"
,
typeDefStore
,
typeRegistry
);
}
private
void
loadHiveModel
()
throws
IOException
,
AtlasBaseException
{
loadModelFromJson
(
"1000-Hadoop/1030-hive_model.json"
,
typeDefStore
,
typeRegistry
);
}
}
This diff is collapsed.
Click to expand it.
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