usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject incubator-usergrid git commit: Created new exceptions to tell us what error is occurring in the backend should this error occur. Added ability to get access keys and secret keys from property files for the awsS3 binary store. Gave the credentials provide
Date Thu, 23 Jul 2015 22:25:55 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-869 050aa0a03 -> 2159ab1c1


Created new exceptions to tell us what error is occurring in the backend should this error
occur.
Added ability to get access keys and secret keys from property files for the awsS3 binary
store.
Gave the credentials provider the ability to look up the bucket name.
Gave the NoAwsRule a catch all as a stopgap for the time being. Can't seem to make service
tier errors bubble up properly ( not that we would want to ) in order for this hack of a rule
to work.
Returns a 500 because thats this is an internal server error.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2159ab1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2159ab1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2159ab1c

Branch: refs/heads/USERGRID-869
Commit: 2159ab1c1c98c88a26bbfd62e4d951e17b2d8661
Parents: 050aa0a
Author: GERey <greyes@apigee.com>
Authored: Thu Jul 23 15:25:52 2015 -0700
Committer: GERey <greyes@apigee.com>
Committed: Thu Jul 23 15:25:52 2015 -0700

----------------------------------------------------------------------
 .../queue/impl/UsergridAwsCredentials.java      |  7 ++++
 .../impl/UsergridAwsCredentialsProvider.java    |  5 +++
 .../AwsPRopertiesNotFoundExceptionMapper.java   | 37 ++++++++++++++++++
 .../applications/assets/aws/NoAWSCredsRule.java | 11 ++++++
 .../assets/data/AwsSdkS3BinaryStore.java        | 30 +++++++++++++--
 .../AwsPropertiesNotFoundException.java         | 40 ++++++++++++++++++++
 6 files changed, 127 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2159ab1c/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentials.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentials.java
b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentials.java
index b078291..fdbe625 100644
--- a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentials.java
+++ b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentials.java
@@ -48,6 +48,13 @@ public class UsergridAwsCredentials implements AWSCredentials {
 
         return StringUtils.trim(secret);
     }
+
+
+    public String getBucketName(){
+        String bucketName = System.getProperty( "usergrid.binary.bucketname" );
+
+        return StringUtils.trim( bucketName );
+    }
     // do these methods in json.
     public String getAWSAccessKeyIdJson(Map<String,Object> jsonObject){
         String accessKey = (String) jsonObject.get( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR
);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2159ab1c/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentialsProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentialsProvider.java
b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentialsProvider.java
index 4e50104..7307f71 100644
--- a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentialsProvider.java
+++ b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/UsergridAwsCredentialsProvider.java
@@ -33,6 +33,7 @@ public class UsergridAwsCredentialsProvider implements AWSCredentialsProvider
{
 
     private AWSCredentials creds = new UsergridAwsCredentials();
 
+
     public  UsergridAwsCredentialsProvider(){
         init();
     }
@@ -51,6 +52,10 @@ public class UsergridAwsCredentialsProvider implements AWSCredentialsProvider
{
         return creds;
     }
 
+    public String getBucketName(){
+
+        return getBucketName();
+    }
 
     @Override
     public void refresh() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2159ab1c/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPRopertiesNotFoundExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPRopertiesNotFoundExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPRopertiesNotFoundExceptionMapper.java
new file mode 100644
index 0000000..f0f6e97
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPRopertiesNotFoundExceptionMapper.java
@@ -0,0 +1,37 @@
+/*
+ * 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.usergrid.rest.exceptions;
+
+
+import javax.ws.rs.core.Response;
+
+import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
+
+import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+
+
+/**
+ * Maps the AwsPropertiesNotFoundExceptionMapper to a 500 error due to having a legit response
+ * but there is an error in the properties file.
+ */
+public class AwsPropertiesNotFoundExceptionMapper extends AbstractExceptionMapper<AwsPropertiesNotFoundException>
{
+    @Override
+    public Response toResponse( AwsPropertiesNotFoundException e ) {
+        return toResponse( INTERNAL_SERVER_ERROR, e );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2159ab1c/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
index fe49d6c..c5f3278 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
@@ -26,7 +26,10 @@ import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
+import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
+
 import com.amazonaws.AmazonClientException;
+import com.sun.jersey.api.client.UniformInterfaceException;
 
 
 /**
@@ -74,6 +77,14 @@ public class NoAWSCredsRule implements TestRule {
             }
         }
 
+        if(t instanceof UniformInterfaceException){
+            return true;
+        }
+
+        if( t instanceof AwsPropertiesNotFoundException ){
+            return true;
+        }
+
         /**
          * Handle the multiple failure junit trace
          */

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2159ab1c/stack/services/src/main/java/org/apache/usergrid/services/assets/data/AwsSdkS3BinaryStore.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/assets/data/AwsSdkS3BinaryStore.java
b/stack/services/src/main/java/org/apache/usergrid/services/assets/data/AwsSdkS3BinaryStore.java
index e492f42..cf01bb1 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/assets/data/AwsSdkS3BinaryStore.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/assets/data/AwsSdkS3BinaryStore.java
@@ -34,12 +34,16 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+import org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentialsProvider;
+import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
 import org.apache.usergrid.utils.StringUtils;
 
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 
+import com.amazonaws.AmazonClientException;
 import com.amazonaws.ClientConfiguration;
 import com.amazonaws.Protocol;
 import com.amazonaws.auth.AWSCredentials;
@@ -97,13 +101,33 @@ public class AwsSdkS3BinaryStore implements BinaryStore {
     }
 
     public AwsSdkS3BinaryStore( String accessId, String secretKey, String bucketName ) {
-        this.accessId = accessId;
-        this.secretKey = secretKey;
-        this.bucketName = bucketName;
+//        this.accessId = accessId;
+//        this.secretKey = secretKey;
+//        this.bucketName = bucketName;
+    }
+
+    public AwsSdkS3BinaryStore( ) {
+
+        //need to add bucket name here
     }
 
     private AmazonS3 getS3Client() {
         if ( s3Client == null ) {
+            try {
+                final UsergridAwsCredentialsProvider ugProvider = new UsergridAwsCredentialsProvider();
+                this.accessId = ugProvider.getCredentials().getAWSAccessKeyId();
+                this.secretKey = ugProvider.getCredentials().getAWSSecretKey();
+                this.bucketName = ugProvider.getBucketName();
+            }
+            catch(Exception e){
+                if(e instanceof AmazonClientException){
+                    //TODO:GREY Move this exception into the service tier
+                    throw new AwsPropertiesNotFoundException( "Access Keys" );
+                }
+
+            }
+
+
             AWSCredentials credentials = new BasicAWSCredentials(accessId, secretKey);
             ClientConfiguration clientConfig = new ClientConfiguration();
             clientConfig.setProtocol(Protocol.HTTP);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2159ab1c/stack/services/src/main/java/org/apache/usergrid/services/exceptions/AwsPropertiesNotFoundException.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/exceptions/AwsPropertiesNotFoundException.java
b/stack/services/src/main/java/org/apache/usergrid/services/exceptions/AwsPropertiesNotFoundException.java
new file mode 100644
index 0000000..c2933b0
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/exceptions/AwsPropertiesNotFoundException.java
@@ -0,0 +1,40 @@
+/*
+ * 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.usergrid.services.exceptions;
+
+
+
+import static org.apache.usergrid.utils.JsonUtils.mapToJsonString;
+
+
+/**
+ * Created by ApigeeCorporation on 7/23/15.
+ */
+public class AwsPropertiesNotFoundException extends RuntimeException {
+    private static final long serialVersionUID = 1L;
+
+
+    public AwsPropertiesNotFoundException() {
+        super();
+    }
+
+
+    public AwsPropertiesNotFoundException( String propertyName ) {
+        super( "The following property was not found in the properties file: " + propertyName
);
+    }
+
+}


Mime
View raw message