You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/07/30 19:36:47 UTC
incubator-usergrid git commit: Updated amazon sdk dependency Added
notThreadSafe to Asset tests because I am changing test properties. Changed
BinaryStore to throw Exceptions when errors occur.
Repository: incubator-usergrid
Updated Branches:
refs/heads/USERGRID-898 [created] f02cf24f5
Updated amazon sdk dependency
Added notThreadSafe to Asset tests because I am changing test properties.
Changed BinaryStore to throw Exceptions when errors occur.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f02cf24f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f02cf24f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f02cf24f
Branch: refs/heads/USERGRID-898
Commit: f02cf24f54739d26c9f2b660062ae90ff7031edb
Parents: 5171dc4
Author: GERey <gr...@apigee.com>
Authored: Thu Jul 30 10:36:45 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Thu Jul 30 10:36:45 2015 -0700
----------------------------------------------------------------------
stack/pom.xml | 2 +-
.../rest/applications/ApplicationResource.java | 4 +-
.../rest/applications/ServiceResource.java | 90 ++++++++++++++------
.../rest/applications/users/UsersResource.java | 4 +-
.../applications/assets/AssetResourceIT.java | 19 ++++-
.../services/assets/data/BinaryStore.java | 8 +-
6 files changed, 92 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f02cf24f/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index aefe060..d680f53 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -283,7 +283,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
- <version>1.9.31</version>
+ <version>1.10.6</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f02cf24f/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index bf350bc..c49c543 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -445,7 +445,7 @@ public class ApplicationResource extends ServiceResource {
@FormParam("username") String username,
@FormParam("password") String password ) {
- LOG.debug( "ApplicationResource /authorize: {}/{}", username, password );
+ logger.debug( "ApplicationResource /authorize: {}/{}", username, password );
try {
responseType = response_type;
@@ -489,7 +489,7 @@ public class ApplicationResource extends ServiceResource {
throw e;
}
catch ( Exception e ) {
- LOG.debug("handleAuthorizeForm failed", e);
+ logger.debug("handleAuthorizeForm failed", e);
return Response.ok( handleViewable( "error", this ) ).build() ;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f02cf24f/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
index bd5d89f..36f9d5c 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
@@ -71,6 +71,7 @@ import org.apache.usergrid.services.assets.data.AssetUtils;
import org.apache.usergrid.services.assets.data.AwsSdkS3BinaryStore;
import org.apache.usergrid.services.assets.data.BinaryStore;
import org.apache.usergrid.services.assets.data.LocalFileBinaryStore;
+import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
import org.apache.usergrid.utils.InflectionUtils;
import org.apache.usergrid.utils.JsonUtils;
@@ -94,7 +95,7 @@ import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_USE
})
public class ServiceResource extends AbstractContextResource {
- protected static final Logger LOG = LoggerFactory.getLogger( ServiceResource.class );
+ protected static final Logger logger = LoggerFactory.getLogger( ServiceResource.class );
private static final String FILE_FIELD_NAME = "file";
@@ -207,7 +208,7 @@ public class ServiceResource extends AbstractContextResource {
@Path("file")
public AbstractContextResource getFileResource( @Context UriInfo ui ) throws Exception {
- LOG.debug( "in assets in ServiceResource" );
+ logger.debug( "in assets in ServiceResource" );
ServiceParameter.addParameter( getServiceParameters(), "assets" );
PathSegment ps = getFirstPathSegment( "assets" );
@@ -223,7 +224,7 @@ public class ServiceResource extends AbstractContextResource {
public AbstractContextResource addIdParameter( @Context UriInfo ui, @PathParam("entityId") PathSegment entityId )
throws Exception {
- LOG.debug( "ServiceResource.addIdParameter" );
+ logger.debug( "ServiceResource.addIdParameter" );
UUID itemId = UUID.fromString( entityId.getPath() );
@@ -239,9 +240,9 @@ public class ServiceResource extends AbstractContextResource {
public AbstractContextResource addNameParameter( @Context UriInfo ui, @PathParam("itemName") PathSegment itemName )
throws Exception {
- LOG.debug( "ServiceResource.addNameParameter" );
+ logger.debug( "ServiceResource.addNameParameter" );
- LOG.debug( "Current segment is {}", itemName.getPath() );
+ logger.debug( "Current segment is {}", itemName.getPath() );
if ( itemName.getPath().startsWith( "{" ) ) {
Query query = Query.fromJsonString( itemName.getPath() );
@@ -262,7 +263,7 @@ public class ServiceResource extends AbstractContextResource {
public ServiceResults executeServiceRequest( UriInfo ui, ApiResponse response, ServiceAction action,
ServicePayload payload ) throws Exception {
- LOG.debug( "ServiceResource.executeServiceRequest" );
+ logger.debug( "ServiceResource.executeServiceRequest" );
boolean tree = "true".equalsIgnoreCase( ui.getQueryParameters().getFirst( "tree" ) );
boolean collectionGet = false;
@@ -311,7 +312,7 @@ public class ServiceResource extends AbstractContextResource {
@QueryParam("callback") @DefaultValue("callback") String callback )
throws Exception {
- LOG.debug( "ServiceResource.executeGet" );
+ logger.debug( "ServiceResource.executeGet" );
ApiResponse response = createApiResponse();
@@ -360,7 +361,7 @@ public class ServiceResource extends AbstractContextResource {
public JSONWithPadding executePostWithObject( @Context UriInfo ui, Object json,
@QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception {
- LOG.debug( "ServiceResource.executePostWithMap" );
+ logger.debug( "ServiceResource.executePostWithMap" );
ApiResponse response = createApiResponse();
@@ -405,7 +406,7 @@ public class ServiceResource extends AbstractContextResource {
public JSONWithPadding executePost( @Context UriInfo ui, String body,
@QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception {
- LOG.debug( "ServiceResource.executePost: body = " + body );
+ logger.debug( "ServiceResource.executePost: body = " + body );
Object json;
if ( StringUtils.isEmpty( body ) ) {
@@ -437,7 +438,7 @@ public class ServiceResource extends AbstractContextResource {
@QueryParam("callback") @DefaultValue("callback") String callback )
throws Exception {
- LOG.debug( "ServiceResource.executePut" );
+ logger.debug( "ServiceResource.executePut" );
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> json = mapper.readValue( body, mapTypeReference );
@@ -454,7 +455,7 @@ public class ServiceResource extends AbstractContextResource {
@QueryParam("app_delete_confirm") String confirmAppDelete )
throws Exception {
- LOG.debug( "ServiceResource.executeDelete" );
+ logger.debug( "ServiceResource.executeDelete" );
ApiResponse response = createApiResponse();
response.setAction( "delete" );
@@ -471,7 +472,13 @@ public class ServiceResource extends AbstractContextResource {
for ( Entity entity : sr.getEntities() ) {
if ( entity.getProperty( AssetUtils.FILE_METADATA ) != null ) {
- binaryStore.delete( services.getApplicationId(), entity );
+ try {
+ binaryStore.delete( services.getApplicationId(), entity );
+ }catch(AwsPropertiesNotFoundException apnfe){
+ logger.error( "Amazon Property needed for this operation not found",apnfe );
+ response.setError( "500","Amazon Property needed for this operation not found",apnfe );
+ //return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
}
}
}
@@ -564,7 +571,7 @@ public class ServiceResource extends AbstractContextResource {
@QueryParam("callback") @DefaultValue("callback") String callback,
FormDataMultiPart multiPart ) throws Exception {
- LOG.debug( "ServiceResource.executeMultiPartPost" );
+ logger.debug( "ServiceResource.executeMultiPartPost" );
return executeMultiPart( ui, callback, multiPart, ServiceAction.POST );
}
@@ -576,7 +583,7 @@ public class ServiceResource extends AbstractContextResource {
@QueryParam("callback") @DefaultValue("callback") String callback,
FormDataMultiPart multiPart ) throws Exception {
- LOG.debug( "ServiceResource.executeMultiPartPut" );
+ logger.debug( "ServiceResource.executeMultiPartPut" );
return executeMultiPart( ui, callback, multiPart, ServiceAction.PUT );
}
@@ -601,7 +608,7 @@ public class ServiceResource extends AbstractContextResource {
data.put( bodyPart.getName(), bodyPart.getValue() );
}
else {
- LOG.info( "skipping bodyPart {} of media type {}", bodyPart.getName(), bodyPart.getMediaType() );
+ logger.info( "skipping bodyPart {} of media type {}", bodyPart.getName(), bodyPart.getMediaType() );
}
}
@@ -625,7 +632,17 @@ public class ServiceResource extends AbstractContextResource {
if ( fileInput != null ) {
Entity entity = serviceResults.getEntity();
EntityManager em = emf.getEntityManager( getApplicationId() );
- binaryStore.write( getApplicationId(), entity, fileInput );
+ try {
+ binaryStore.write( getApplicationId(), entity, fileInput );
+ }
+ catch ( AwsPropertiesNotFoundException apnfe){
+ logger.error( "Amazon Property needed for this operation not found",apnfe );
+ response.setError( "500","Amazon Property needed for this operation not found",apnfe );
+ }
+ catch ( RuntimeException re){
+ logger.error(re.getMessage());
+ response.setError( "500", re );
+ }
em.update( entity );
serviceResults.setEntity( entity );
}
@@ -663,7 +680,15 @@ public class ServiceResource extends AbstractContextResource {
ServiceResults serviceResults = executeServiceRequest( ui, response, ServiceAction.GET, null );
Entity entity = serviceResults.getEntity();
- binaryStore.write( getApplicationId(), entity, uploadedInputStream );
+ try {
+ binaryStore.write( getApplicationId(), entity, uploadedInputStream );
+ }catch(AwsPropertiesNotFoundException apnfe){
+ logger.error( "Amazon Property needed for this operation not found",apnfe );
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }catch ( RuntimeException re ){
+ logger.error(re.getMessage());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
EntityManager em = emf.getEntityManager( getApplicationId() );
em.update( entity );
@@ -678,7 +703,7 @@ public class ServiceResource extends AbstractContextResource {
@HeaderParam("range") String rangeHeader,
@HeaderParam("if-modified-since") String modifiedSince ) throws Exception {
- LOG.debug( "ServiceResource.executeStreamGet" );
+ logger.debug( "ServiceResource.executeStreamGet" );
//Needed for testing
if(properties.getProperty( PROPERTIES_USERGRID_BINARY_UPLOADER ).equals( "local" )){
@@ -695,8 +720,8 @@ public class ServiceResource extends AbstractContextResource {
ServiceResults serviceResults = executeServiceRequest( ui, response, ServiceAction.GET, null );
Entity entity = serviceResults.getEntity();
- LOG.info( "In ServiceResource.executeStreamGet with id: {}, range: {}, modifiedSince: {}",
- new Object[] { entityId, rangeHeader, modifiedSince } );
+ logger.info( "In ServiceResource.executeStreamGet with id: {}, range: {}, modifiedSince: {}",
+ new Object[] { entityId, rangeHeader, modifiedSince } );
Map<String, Object> fileMetadata = AssetUtils.getFileMetadata( entity );
@@ -711,7 +736,7 @@ public class ServiceResource extends AbstractContextResource {
boolean range = StringUtils.isNotBlank( rangeHeader );
long start = 0, end = 0, contentLength = 0;
- InputStream inputStream;
+ InputStream inputStream = null;
if ( range ) { // honor range request, calculate start & end
@@ -734,12 +759,27 @@ public class ServiceResource extends AbstractContextResource {
}
}
}
-
- inputStream = binaryStore.read( getApplicationId(), entity, start, end - start );
+ try {
+ inputStream = binaryStore.read( getApplicationId(), entity, start, end - start );
+ }catch(AwsPropertiesNotFoundException apnfe){
+ logger.error( "Amazon Property needed for this operation not found",apnfe );
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }catch(RuntimeException re){
+ logger.error(re.getMessage());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
}
else { // no range
-
- inputStream = binaryStore.read( getApplicationId(), entity );
+ try {
+ inputStream = binaryStore.read( getApplicationId(), entity );
+ }catch(AwsPropertiesNotFoundException apnfe){
+ logger.error( "Amazon Property needed for this operation not found",apnfe );
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+ catch(RuntimeException re){
+ logger.error(re.getMessage());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
}
// return 404 if not found
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f02cf24f/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
index 2993b8f..c3f0283 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
@@ -212,7 +212,7 @@ public class UsersResource extends ServiceResource {
@QueryParam("callback") @DefaultValue("callback") String callback )
throws Exception {
- LOG.debug( "UsersResource.executePost: body = " + body);
+ logger.debug( "UsersResource.executePost: body = " + body);
Object json = readJsonToObject( body );
@@ -224,7 +224,7 @@ public class UsersResource extends ServiceResource {
boolean activated = !( ( confRequred != null ) && confRequred );
- LOG.debug("Confirmation required: {} Activated: {}", confRequred, activated );
+ logger.debug("Confirmation required: {} Activated: {}", confRequred, activated );
if ( json instanceof Map ) {
@SuppressWarnings("unchecked") Map<String, Object> map = ( Map<String, Object> ) json;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f02cf24f/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
index f3bb1c4..79a6957 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
@@ -25,6 +25,8 @@ import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.services.assets.data.AssetUtils;
+
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -39,21 +41,36 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import net.jcip.annotations.NotThreadSafe;
+
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_USERGRID_BINARY_UPLOADER;
import static org.apache.usergrid.utils.MapUtils.hashMap;
import static org.junit.Assert.*;
-
+@NotThreadSafe
public class AssetResourceIT extends AbstractRestIT {
private String access_token;
private Logger LOG = LoggerFactory.getLogger( AssetResourceIT.class );
+ private Map<String, Object> originalProperties;
+
+
@Before
public void setup(){
+ originalProperties = getRemoteTestProperties();
+ setTestProperty(PROPERTIES_USERGRID_BINARY_UPLOADER, "local");
+
+
access_token = this.getAdminToken().getAccessToken();
}
+ @After
+ public void teardown(){
+ setTestProperties(originalProperties);
+ }
+
@Test
public void octetStreamOnDynamicEntity() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f02cf24f/stack/services/src/main/java/org/apache/usergrid/services/assets/data/BinaryStore.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/assets/data/BinaryStore.java b/stack/services/src/main/java/org/apache/usergrid/services/assets/data/BinaryStore.java
index 5ed2918..a3b02f8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/assets/data/BinaryStore.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/assets/data/BinaryStore.java
@@ -31,14 +31,14 @@ public interface BinaryStore {
* writes the inputStream to the store and updates the entity's file-metadata field. however, it doesn't persistent
* the entity.
*/
- void write( UUID appId, Entity entity, InputStream inputStream ) throws IOException, NoSuchAlgorithmException;
+ void write( UUID appId, Entity entity, InputStream inputStream ) throws Exception;
/** read the entity's file data from the store */
- InputStream read( UUID appId, Entity entity ) throws IOException;
+ InputStream read( UUID appId, Entity entity ) throws Exception;
/** read partial data from the store */
- InputStream read( UUID appId, Entity entity, long offset, long length ) throws IOException;
+ InputStream read( UUID appId, Entity entity, long offset, long length ) throws Exception;
/** delete the entity data from the store. */
- void delete( UUID appId, Entity entity );
+ void delete( UUID appId, Entity entity ) throws Exception;
}