Repository: incubator-atlas Updated Branches: refs/heads/master 8fefd1655 -> aad34ae00
ATLAS-888 NPE in NotificationHookConsumer (sumasai via shwethags) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/aad34ae0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/aad34ae0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/aad34ae0 Branch: refs/heads/master Commit: aad34ae00fb0d39d292dff9743fce1ceb3eaa270 Parents: 8fefd16 Author: Shwetha GS <[email protected]> Authored: Wed Jun 15 11:53:03 2016 +0530 Committer: Shwetha GS <[email protected]> Committed: Wed Jun 15 11:53:03 2016 +0530 ---------------------------------------------------------------------- release-log.txt | 1 + webapp/pom.xml | 5 +++ .../atlas/web/resources/EntityResource.java | 35 +++++++++++++++---- .../org/apache/atlas/LocalAtlasClientTest.java | 36 ++++++++++++++------ 4 files changed, 60 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aad34ae0/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index f168af6..0f384d2 100644 --- a/release-log.txt +++ b/release-log.txt @@ -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) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aad34ae0/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/webapp/pom.xml b/webapp/pom.xml index cce6dd6..bc62f87 100755 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -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> http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aad34ae0/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java index ef6b810..364f17a 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java @@ -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 deserialization 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 deserialization 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 deserialization 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()); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aad34ae0/webapp/src/test/java/org/apache/atlas/LocalAtlasClientTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/LocalAtlasClientTest.java b/webapp/src/test/java/org/apache/atlas/LocalAtlasClientTest.java index e774399..c5616df 100644 --- a/webapp/src/test/java/org/apache/atlas/LocalAtlasClientTest.java +++ b/webapp/src/test/java/org/apache/atlas/LocalAtlasClientTest.java @@ -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(entityResource.submit(any(HttpServletRequest.class))).thenReturn(response); + when(mockEntityResource.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, entityResource); + LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, mockEntityResource); 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, entityResource); + LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, mockEntityResource); Response response = mock(Response.class); - when(entityResource.submit(any(HttpServletRequest.class))).thenThrow(new WebApplicationException(response)); + when(mockEntityResource.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(entityResource.updateByUniqueAttribute(anyString(), anyString(), anyString(), + when(mockEntityResource.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, entityResource); + LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, mockEntityResource); 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(entityResource.updateByUniqueAttribute(anyString(), anyString(), anyString(), + when(mockEntityResource.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, entityResource); + LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, mockEntityResource); 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(entityResource.deleteEntities(anyListOf(String.class), anyString(), anyString(), anyString())).thenReturn(response); - LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, entityResource); + when(mockEntityResource.deleteEntities(anyListOf(String.class), anyString(), anyString(), anyString())).thenReturn(response); + LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, mockEntityResource); 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); + } }
