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
aad34ae0
Commit
aad34ae0
authored
Jun 15, 2016
by
Shwetha GS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-888 NPE in NotificationHookConsumer (sumasai via shwethags)
parent
8fefd165
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
17 deletions
+60
-17
release-log.txt
release-log.txt
+1
-0
pom.xml
webapp/pom.xml
+5
-0
EntityResource.java
...n/java/org/apache/atlas/web/resources/EntityResource.java
+28
-7
LocalAtlasClientTest.java
.../src/test/java/org/apache/atlas/LocalAtlasClientTest.java
+26
-10
No files found.
release-log.txt
View file @
aad34ae0
...
...
@@ -23,6 +23,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset
ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags)
ALL CHANGES:
ATLAS-888 NPE in NotificationHookConsumer (sumasai via shwethags)
ATLAS-884 Process registration should call Entity update instead of create (sumasai)
ATLAS-515 Ability to initialize Kafka topics with more than 1 replica (yhemanth)
ATLAS-891 UI changes to implement Update term (Kalyanikashikar via yhemanth)
...
...
webapp/pom.xml
View file @
aad34ae0
...
...
@@ -242,6 +242,11 @@
</dependency>
<dependency>
<groupId>
com.google.inject
</groupId>
<artifactId>
guice
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-core
</artifactId>
<version>
${spring.version}
</version>
...
...
webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
View file @
aad34ae0
...
...
@@ -18,8 +18,10 @@
package
org
.
apache
.
atlas
.
web
.
resources
;
import
com.google.common.annotations.VisibleForTesting
;
import
com.google.common.base.Preconditions
;
import
org.apache.atlas.AtlasClient
;
import
org.apache.atlas.AtlasConstants
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.EntityAuditEvent
;
import
org.apache.atlas.services.MetadataService
;
...
...
@@ -33,6 +35,7 @@ import org.apache.atlas.typesystem.types.ValueConversionException;
import
org.apache.atlas.utils.ParamChecker
;
import
org.apache.atlas.web.util.Servlets
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.protocol.HTTP
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.codehaus.jettison.json.JSONException
;
import
org.codehaus.jettison.json.JSONObject
;
...
...
@@ -59,6 +62,7 @@ import javax.ws.rs.core.Response;
import
javax.ws.rs.core.UriBuilder
;
import
javax.ws.rs.core.UriInfo
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -119,8 +123,7 @@ public class EntityResource {
final
List
<
String
>
guids
=
metadataService
.
createEntities
(
entities
);
JSONObject
response
=
getResponse
(
new
AtlasClient
.
EntityResult
(
guids
,
null
,
null
));
UriBuilder
ub
=
uriInfo
.
getAbsolutePathBuilder
();
URI
locationURI
=
guids
.
isEmpty
()
?
null
:
ub
.
path
(
guids
.
get
(
0
)).
build
();
URI
locationURI
=
getLocationURI
(
guids
);
return
Response
.
created
(
locationURI
).
entity
(
response
).
build
();
...
...
@@ -128,7 +131,7 @@ public class EntityResource {
LOG
.
error
(
"Unique constraint violation"
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
CONFLICT
));
}
catch
(
ValueConversionException
ve
)
{
LOG
.
error
(
"Unable to persist entity instance due to a desrialization error "
,
ve
);
LOG
.
error
(
"Unable to persist entity instance due to a des
e
rialization error "
,
ve
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ve
.
getCause
(),
Response
.
Status
.
BAD_REQUEST
));
}
catch
(
AtlasException
|
IllegalArgumentException
e
)
{
LOG
.
error
(
"Unable to persist entity instance"
,
e
);
...
...
@@ -139,6 +142,23 @@ public class EntityResource {
}
}
@VisibleForTesting
public
URI
getLocationURI
(
List
<
String
>
guids
)
{
URI
locationURI
=
null
;
if
(
uriInfo
!=
null
)
{
UriBuilder
ub
=
uriInfo
.
getAbsolutePathBuilder
();
locationURI
=
guids
.
isEmpty
()
?
null
:
ub
.
path
(
guids
.
get
(
0
)).
build
();
}
else
{
String
uriPath
=
AtlasClient
.
API
.
GET_ENTITY
.
getPath
();
locationURI
=
guids
.
isEmpty
()
?
null
:
UriBuilder
.
fromPath
(
AtlasConstants
.
DEFAULT_ATLAS_REST_ADDRESS
)
.
path
(
uriPath
).
path
(
guids
.
get
(
0
)).
build
();
}
return
locationURI
;
}
private
JSONObject
getResponse
(
AtlasClient
.
EntityResult
entityResult
)
throws
AtlasException
,
JSONException
{
JSONObject
response
=
new
JSONObject
();
response
.
put
(
AtlasClient
.
REQUEST_ID
,
Servlets
.
getRequestId
());
...
...
@@ -171,7 +191,7 @@ public class EntityResource {
LOG
.
error
(
"Unique constraint violation"
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
CONFLICT
));
}
catch
(
ValueConversionException
ve
)
{
LOG
.
error
(
"Unable to persist entity instance due to a desrialization error "
,
ve
);
LOG
.
error
(
"Unable to persist entity instance due to a des
e
rialization error "
,
ve
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ve
.
getCause
(),
Response
.
Status
.
BAD_REQUEST
));
}
catch
(
AtlasException
|
IllegalArgumentException
e
)
{
LOG
.
error
(
"Unable to persist entity instance"
,
e
);
...
...
@@ -234,7 +254,7 @@ public class EntityResource {
JSONObject
response
=
getResponse
(
entityResult
);
return
Response
.
ok
(
response
).
build
();
}
catch
(
ValueConversionException
ve
)
{
LOG
.
error
(
"Unable to persist entity instance due to a desrialization error "
,
ve
);
LOG
.
error
(
"Unable to persist entity instance due to a des
e
rialization error "
,
ve
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ve
.
getCause
(),
Response
.
Status
.
BAD_REQUEST
));
}
catch
(
EntityExistsException
e
)
{
LOG
.
error
(
"Unique constraint violation"
,
e
);
...
...
@@ -549,8 +569,9 @@ public class EntityResource {
LOG
.
debug
(
"Adding trait={} for entity={} "
,
traitDefinition
,
guid
);
metadataService
.
addTrait
(
guid
,
traitDefinition
);
UriBuilder
ub
=
uriInfo
.
getAbsolutePathBuilder
();
URI
locationURI
=
ub
.
path
(
guid
).
build
();
URI
locationURI
=
getLocationURI
(
new
ArrayList
<
String
>()
{{
add
(
guid
);
}});
JSONObject
response
=
new
JSONObject
();
response
.
put
(
AtlasClient
.
REQUEST_ID
,
Servlets
.
getRequestId
());
...
...
webapp/src/test/java/org/apache/atlas/LocalAtlasClientTest.java
View file @
aad34ae0
...
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
;
import
com.google.inject.Inject
;
import
com.sun.jersey.api.client.ClientResponse
;
import
org.apache.atlas.typesystem.Referenceable
;
import
org.apache.atlas.web.resources.EntityResource
;
...
...
@@ -27,11 +28,14 @@ import org.codehaus.jettison.json.JSONObject;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Guice
;
import
org.testng.annotations.Test
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.core.Response
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
...
...
@@ -46,8 +50,12 @@ import static org.testng.Assert.assertFalse;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
fail
;
@Guice
(
modules
=
RepositoryMetadataModule
.
class
)
public
class
LocalAtlasClientTest
{
@Mock
private
EntityResource
mockEntityResource
;
@Inject
private
EntityResource
entityResource
;
@Mock
...
...
@@ -61,14 +69,14 @@ public class LocalAtlasClientTest {
@Test
public
void
testCreateEntity
()
throws
Exception
{
Response
response
=
mock
(
Response
.
class
);
when
(
e
ntityResource
.
submit
(
any
(
HttpServletRequest
.
class
))).
thenReturn
(
response
);
when
(
mockE
ntityResource
.
submit
(
any
(
HttpServletRequest
.
class
))).
thenReturn
(
response
);
final
String
guid
=
random
();
when
(
response
.
getEntity
()).
thenReturn
(
new
JSONObject
()
{{
put
(
ENTITIES
,
new
JSONObject
(
new
AtlasClient
.
EntityResult
(
Arrays
.
asList
(
guid
),
null
,
null
).
toString
()).
get
(
ENTITIES
));
}});
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
e
ntityResource
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
mockE
ntityResource
);
List
<
String
>
results
=
atlasClient
.
createEntity
(
new
Referenceable
(
random
()));
assertEquals
(
results
.
size
(),
1
);
assertEquals
(
results
.
get
(
0
),
guid
);
...
...
@@ -76,10 +84,10 @@ public class LocalAtlasClientTest {
@Test
public
void
testException
()
throws
Exception
{
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
e
ntityResource
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
mockE
ntityResource
);
Response
response
=
mock
(
Response
.
class
);
when
(
e
ntityResource
.
submit
(
any
(
HttpServletRequest
.
class
))).
thenThrow
(
new
WebApplicationException
(
response
));
when
(
mockE
ntityResource
.
submit
(
any
(
HttpServletRequest
.
class
))).
thenThrow
(
new
WebApplicationException
(
response
));
when
(
response
.
getEntity
()).
thenReturn
(
new
JSONObject
()
{{
put
(
"stackTrace"
,
"stackTrace"
);
}});
...
...
@@ -91,7 +99,7 @@ public class LocalAtlasClientTest {
assertEquals
(
e
.
getStatus
(),
ClientResponse
.
Status
.
BAD_REQUEST
);
}
when
(
e
ntityResource
.
updateByUniqueAttribute
(
anyString
(),
anyString
(),
anyString
(),
when
(
mockE
ntityResource
.
updateByUniqueAttribute
(
anyString
(),
anyString
(),
anyString
(),
any
(
HttpServletRequest
.
class
))).
thenThrow
(
new
WebApplicationException
(
response
));
when
(
response
.
getStatus
()).
thenReturn
(
Response
.
Status
.
NOT_FOUND
.
getStatusCode
());
try
{
...
...
@@ -106,7 +114,7 @@ public class LocalAtlasClientTest {
@Test
public
void
testIsServerReady
()
throws
Exception
{
when
(
serviceState
.
getState
()).
thenReturn
(
ServiceState
.
ServiceStateValue
.
ACTIVE
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
e
ntityResource
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
mockE
ntityResource
);
assertTrue
(
atlasClient
.
isServerReady
());
when
(
serviceState
.
getState
()).
thenReturn
(
ServiceState
.
ServiceStateValue
.
BECOMING_ACTIVE
);
...
...
@@ -117,14 +125,14 @@ public class LocalAtlasClientTest {
public
void
testUpdateEntity
()
throws
Exception
{
final
String
guid
=
random
();
Response
response
=
mock
(
Response
.
class
);
when
(
e
ntityResource
.
updateByUniqueAttribute
(
anyString
(),
anyString
(),
anyString
(),
when
(
mockE
ntityResource
.
updateByUniqueAttribute
(
anyString
(),
anyString
(),
anyString
(),
any
(
HttpServletRequest
.
class
))).
thenReturn
(
response
);
when
(
response
.
getEntity
()).
thenReturn
(
new
JSONObject
()
{{
put
(
ENTITIES
,
new
JSONObject
(
new
AtlasClient
.
EntityResult
(
null
,
Arrays
.
asList
(
guid
),
null
).
toString
()).
get
(
ENTITIES
));
}});
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
e
ntityResource
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
mockE
ntityResource
);
AtlasClient
.
EntityResult
entityResult
=
atlasClient
.
updateEntity
(
random
(),
random
(),
random
(),
new
Referenceable
(
random
()));
assertEquals
(
entityResult
.
getUpdateEntities
(),
Arrays
.
asList
(
guid
));
...
...
@@ -139,8 +147,8 @@ public class LocalAtlasClientTest {
new
AtlasClient
.
EntityResult
(
null
,
null
,
Arrays
.
asList
(
guid
)).
toString
()).
get
(
ENTITIES
));
}});
when
(
e
ntityResource
.
deleteEntities
(
anyListOf
(
String
.
class
),
anyString
(),
anyString
(),
anyString
())).
thenReturn
(
response
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
e
ntityResource
);
when
(
mockE
ntityResource
.
deleteEntities
(
anyListOf
(
String
.
class
),
anyString
(),
anyString
(),
anyString
())).
thenReturn
(
response
);
LocalAtlasClient
atlasClient
=
new
LocalAtlasClient
(
serviceState
,
mockE
ntityResource
);
AtlasClient
.
EntityResult
entityResult
=
atlasClient
.
deleteEntity
(
random
(),
random
(),
random
());
assertEquals
(
entityResult
.
getDeletedEntities
(),
Arrays
.
asList
(
guid
));
}
...
...
@@ -148,4 +156,12 @@ public class LocalAtlasClientTest {
private
String
random
()
{
return
RandomStringUtils
.
randomAlphanumeric
(
10
);
}
@Test
@Inject
public
void
testGetLocationURI
()
{
final
String
guid
=
"123"
;
URI
uri
=
entityResource
.
getLocationURI
(
new
ArrayList
<
String
>()
{{
add
(
guid
);
}});
uri
.
getRawPath
().
equals
(
AtlasConstants
.
DEFAULT_ATLAS_REST_ADDRESS
+
"/"
+
AtlasClient
.
API
.
GET_ENTITY
.
getPath
()
+
"/"
+
guid
);
}
}
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