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/02/11 19:10:16 UTC

incubator-usergrid git commit: Fixed the importResourceIT tests. Current failures reflect changes in the code or other status. Also changed null pointer exceptions to NullArgumentExceptions.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-import db8184c84 -> 25b3645f2


Fixed the importResourceIT tests. Current failures reflect changes in the code or other status. Also changed null pointer exceptions to NullArgumentExceptions.


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

Branch: refs/heads/two-dot-o-import
Commit: 25b3645f2f6a81206b60c52b9a75909675c734cc
Parents: db8184c
Author: grey <gr...@apigee.com>
Authored: Wed Feb 11 10:10:14 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Wed Feb 11 10:10:14 2015 -0800

----------------------------------------------------------------------
 .../exceptions/NullArgumentExceptionMapper.java |  42 ++++++++
 .../applications/imports/ImportsResource.java   |  54 ++++++----
 .../rest/management/ImportResourceIT.java       | 104 ++++++++-----------
 3 files changed, 124 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25b3645f/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NullArgumentExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NullArgumentExceptionMapper.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NullArgumentExceptionMapper.java
new file mode 100644
index 0000000..be6296f
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NullArgumentExceptionMapper.java
@@ -0,0 +1,42 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang.NullArgumentException;
+
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+
+
+
+public class NullArgumentExceptionMapper extends  AbstractExceptionMapper<NullArgumentException> {
+    private static final Logger logger = LoggerFactory.getLogger( NullArgumentExceptionMapper.class );
+
+    @Override
+    public Response toResponse( NullArgumentException e ) {
+
+        logger.error( "Argument needed was null, returning bad request to user", e );
+
+        return toResponse( BAD_REQUEST, e );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25b3645f/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
index 86bf278..1169346 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
@@ -37,11 +37,16 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriInfo;
+import javax.xml.ws.Response;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.lang.NullArgumentException;
+import org.apache.commons.lang.ObjectUtils;
+
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.management.importer.ImportService;
@@ -53,7 +58,9 @@ import org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials;
 import org.apache.usergrid.rest.AbstractContextResource;
 import org.apache.usergrid.rest.ApiResponse;
 import org.apache.usergrid.rest.RootResource;
+import org.apache.usergrid.rest.applications.ServiceResource;
 import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
+import org.apache.usergrid.rest.utils.JSONPUtils;
 
 import com.sun.jersey.api.json.JSONWithPadding;
 
@@ -110,27 +117,38 @@ public class ImportsResource extends AbstractContextResource {
 
         //             try {
         //checkJsonExportProperties(json);
-        if ( ( properties = ( Map<String, Object> ) json.get( "properties" ) ) == null ) {
-            throw new NullPointerException( "Could not find 'properties'" );
-        }
-        storage_info = ( Map<String, Object> ) properties.get( "storage_info" );
-        String storage_provider = ( String ) properties.get( "storage_provider" );
-        if ( storage_provider == null ) {
-            throw new NullPointerException( "Could not find field 'storage_provider'" );
-        }
-        if ( storage_info == null ) {
-            throw new NullPointerException( "Could not find field 'storage_info'" );
-        }
 
-        String bucketName = ( String ) storage_info.get( "bucket_location" );
 
-        //check to make sure that access key and secret key are there.
-        //        uac.getAWSAccessKeyIdJson( storage_info );
-        //        uac.getAWSSecretKeyJson( storage_info );
+            if ( ( properties = ( Map<String, Object> ) json.get( "properties" ) ) == null ) {
+                throw new NullArgumentException( "Could not find 'properties'" );
+            }
+            storage_info = ( Map<String, Object> ) properties.get( "storage_info" );
+            String storage_provider = ( String ) properties.get( "storage_provider" );
+            if ( storage_provider == null ) {
+                throw new NullArgumentException( "Could not find field 'storage_provider'" );
+            }
+            if ( storage_info == null ) {
+                throw new NullArgumentException( "Could not find field 'storage_info'" );
+            }
+
+            String bucketName = ( String ) storage_info.get( "bucket_location" );
+
+
+            String accessId = ( String ) storage_info.get( "s3_access_id" );
+            String secretKey = ( String ) storage_info.get( "s3_key" );
+
+            if ( bucketName == null ) {
+                throw new NullArgumentException( "Could not find field 'bucketName'" );
+            }
+            if ( accessId == null ) {
+                throw new NullArgumentException( "Could not find field 's3_access_id'" );
+            }
+            if ( secretKey == null ) {
+
+                throw new NullArgumentException( "Could not find field 's3_key'" );
+            }
+
 
-        if ( bucketName == null ) {
-            throw new NullPointerException( "Could not find field 'bucketName'" );
-        }
 
         json.put( "organizationId", organization.getUuid() );
         json.put( "applicationId", application.getId() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25b3645f/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
index d5e3486..f23e488 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
@@ -98,8 +98,8 @@ public class ImportResourceIT extends AbstractRestIT {
     public void before() {
 
         configured =
-            !StringUtils.isEmpty(System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR))
-                && !StringUtils.isEmpty(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR))
+            !StringUtils.isEmpty(System.getProperty("s3_key"))
+                && !StringUtils.isEmpty(System.getProperty("s3_access_id"))
                 && !StringUtils.isEmpty(System.getProperty("bucketName"));
 
 
@@ -107,8 +107,8 @@ public class ImportResourceIT extends AbstractRestIT {
             logger.warn("Skipping test because {}, {} and bucketName not " +
                     "specified as system properties, e.g. in your Maven settings.xml file.",
                 new Object[]{
-                    SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
-                    SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR
+                    "s3_key",
+                    "s3_access_id"
                 });
         }
 
@@ -135,16 +135,13 @@ public class ImportResourceIT extends AbstractRestIT {
         ///management/orgs/orgname/apps/appname/import
         Entity entity = this.management()
             .orgs()
-            .organization(org)
+            .organization( org )
             .app()
-            .addToPath(app)
-            .addToPath("import")
-            .post(payload);
-
-        String importEntity = entity.getString("Import Entity");
+            .addToPath( app )
+            .addToPath( "import" )
+            .post( payload );
 
         assertNotNull(entity);
-        assertNotNull(importEntity);
 
         entity = this.management()
             .orgs()
@@ -152,7 +149,7 @@ public class ImportResourceIT extends AbstractRestIT {
             .app()
             .addToPath(app)
             .addToPath("import")
-            .addToPath(importEntity)
+            .addToPath(entity.getUuid().toString())
             .get();
 
         assertNotNull(entity.getString("state"));
@@ -180,16 +177,14 @@ public class ImportResourceIT extends AbstractRestIT {
             .app()
             .addToPath(app)
             .addToPath("import")
-            .post(payload);
+            .post( payload );
 
-        String importEntity = entity.getString("Import Entity");
 
         assertNotNull(entity);
-        assertNotNull(importEntity);
 
         // test that you can access the organization using the currently set token.
         this.management().orgs().organization(org).app().addToPath(app)
-            .addToPath("import").addToPath(importEntity).get();
+            .addToPath("import").addToPath(entity.getUuid().toString()).get();
 
         //create a new org/app
         String newOrgName = "org" + UUIDUtils.newTimeUUID();
@@ -214,7 +209,7 @@ public class ImportResourceIT extends AbstractRestIT {
         //try to read with the new token, which should fail as unauthorized
         try {
             this.management().orgs().organization(org).app().addToPath(app)
-                .addToPath("import").addToPath(importEntity).get();
+                .addToPath("import").addToPath(entity.getUuid().toString()).get();
             fail("Should not be able to read import job with unauthorized token");
         } catch (UniformInterfaceException ex) {
             errorParse(401, "unauthorized", ex);
@@ -291,7 +286,7 @@ public class ImportResourceIT extends AbstractRestIT {
         Entity properties = (Entity) payload.get("properties");
         Entity storage_info = (Entity) properties.get("storage_info");
         //remove storage_key field
-        storage_info.remove(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
+        storage_info.remove("s3_key");
 
         try {
             this.management().orgs().organization(org).app().addToPath(app).addToPath("import").post(payload);
@@ -304,7 +299,7 @@ public class ImportResourceIT extends AbstractRestIT {
         properties = (Entity) payload.get("properties");
         storage_info = (Entity) properties.get("storage_info");
         //remove storage_key field
-        storage_info.remove(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
+        storage_info.remove("s3_access_id");
 
         try {
             this.management().orgs().organization(org).app().addToPath(app).addToPath("import").post(payload);
@@ -429,16 +424,16 @@ public class ImportResourceIT extends AbstractRestIT {
         // create 10 applications each with collection of 10 things, export all to S3
         S3Upload s3Upload = new S3Upload();
         s3Upload.copyToS3(
-            System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
-            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR),
+            System.getProperty("s3_access_id"),
+            System.getProperty("s3_key"),
             bucketName, filenames);
 
         // import all those exports from S3 into the default test application
 
         Entity importEntity = importCollection();
 
-        Entity importGet = this.management().orgs().organization(org).app().addToPath(app)
-            .addToPath("import").addToPath((String) importEntity.get("Import Entity")).get();
+        Entity importGet = this.management().orgs().organization( org ).app().addToPath( app )
+            .addToPath( "import" ).addToPath( importEntity.getUuid().toString() ).get();
 
 
         assertNotNull(importGet);
@@ -477,8 +472,8 @@ public class ImportResourceIT extends AbstractRestIT {
         // create 10 applications each with collection of 10 things, export all to S3
         S3Upload s3Upload = new S3Upload();
         s3Upload.copyToS3(
-            System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
-            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR),
+            System.getProperty("s3_access_id"),
+            System.getProperty("s3_key"),
             bucketName, filenames);
 
         // import all those exports from S3 into the default test application
@@ -486,7 +481,7 @@ public class ImportResourceIT extends AbstractRestIT {
         Entity importEntity = importCollection();
 
         Entity importGet = this.management().orgs().organization(org).app().addToPath(app)
-            .addToPath("import").addToPath((String) importEntity.get("Import Entity")).get();
+            .addToPath( "import" ).addToPath(importEntity.getUuid().toString() ).get();
 
 
         assertNotNull(importGet);
@@ -522,8 +517,8 @@ public class ImportResourceIT extends AbstractRestIT {
         // create 10 applications each with collection of 10 things, export all to S3
         S3Upload s3Upload = new S3Upload();
         s3Upload.copyToS3(
-            System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
-            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR),
+            System.getProperty("s3_access_id"),
+            System.getProperty("s3_key"),
             bucketName, filenames);
 
         // import all those exports from S3 into the default test application
@@ -531,7 +526,7 @@ public class ImportResourceIT extends AbstractRestIT {
         Entity importEntity = importCollection();
 
         Entity importGet = this.management().orgs().organization(org).app().addToPath(app)
-            .addToPath("import").addToPath((String) importEntity.get("Import Entity")).get();
+            .addToPath("import" ).addToPath(importEntity.getUuid().toString() ).get();
 
 
         assertNotNull(importGet);
@@ -566,8 +561,8 @@ public class ImportResourceIT extends AbstractRestIT {
         filenames.add("testImportInvalidJson.testApplication.3.json");
         // create 10 applications each with collection of 10 things, export all to S3
         S3Upload s3Upload = new S3Upload();
-        s3Upload.copyToS3(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
-            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR),
+        s3Upload.copyToS3(System.getProperty("s3_access_id"),
+            System.getProperty("s3_key"),
             bucketName, filenames);
 
         // import all those exports from S3 into the default test application
@@ -576,12 +571,12 @@ public class ImportResourceIT extends AbstractRestIT {
 
         // we should now have 100 Entities in the default app
 
-        Entity importGet = this.management().orgs().organization(org).app().addToPath(app).addToPath("import")
-            .addToPath((String) importEntity.get("Import Entity")).get();
+        Entity importGet = this.management().orgs().organization( org ).app().addToPath( app ).addToPath("import")
+            .addToPath( importEntity.getUuid().toString() ).get();
 
         Entity importGetIncludes = this.management().orgs().organization(org).app().addToPath(app)
-            .addToPath("import").addToPath((String) importEntity.get("Import Entity"))
-            .addToPath("includes").get();
+            .addToPath("import" ).addToPath(importEntity.getUuid().toString() )
+            .addToPath("includes" ).get();
 
         assertNotNull(importGet);
         //TODO: needs better error checking
@@ -604,22 +599,17 @@ public class ImportResourceIT extends AbstractRestIT {
             put("properties", new HashMap<String, Object>() {{
                 put("storage_provider", "s3");
                 put("storage_info", new HashMap<String, Object>() {{
-                    put(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
-                        System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR));
-                    put(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR,
-                        System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR));
+                    put("s3_key",
+                        System.getProperty("s3_key"));
+                    put("s3_access_id",
+                        System.getProperty("s3_access_id"));
                     put("bucket_location", bucketName);
                 }});
             }});
         }});
 
-        Entity importEntity = this.management()
-            .orgs()
-            .organization(org)
-            .app()
-            .addToPath(app)
-            .addToPath("import")
-            .post(importPayload);
+        Entity importEntity = this.management().orgs().organization(org).app().addToPath(app).addToPath("import" )
+                                  .post(importPayload );
 
         int maxRetries = 120;
         int retries = 0;
@@ -687,21 +677,19 @@ public class ImportResourceIT extends AbstractRestIT {
 
         logger.debug("\n\nDelete bucket\n");
 
-        String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
-        String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
+        String accessId = System.getProperty("s3_access_id");
+        String secretKey = System.getProperty("s3_key");
 
         Properties overrides = new Properties();
         overrides.setProperty("s3" + ".identity", accessId);
         overrides.setProperty("s3" + ".credential", secretKey);
 
-        final Iterable<? extends Module> MODULES = ImmutableSet.of(
-            new JavaUrlHttpCommandExecutorServiceModule(),
-            new Log4JLoggingModule(),
-            new NettyPayloadModule());
+        final Iterable<? extends Module> MODULES = ImmutableSet.of( new JavaUrlHttpCommandExecutorServiceModule(),
+            new Log4JLoggingModule(), new NettyPayloadModule() );
 
         BlobStoreContext context =
             ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
-                .overrides(overrides).buildView(BlobStoreContext.class);
+                .overrides(overrides ).buildView(BlobStoreContext.class);
 
         BlobStore blobStore = context.getBlobStore();
         blobStore.deleteContainer(bucketName);
@@ -712,8 +700,8 @@ public class ImportResourceIT extends AbstractRestIT {
 
         logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix);
 
-        String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
-        String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
+        String accessId = System.getProperty("s3_access_id");
+        String secretKey = System.getProperty("s3_key");
 
         Properties overrides = new Properties();
         overrides.setProperty("s3" + ".identity", accessId);
@@ -726,7 +714,7 @@ public class ImportResourceIT extends AbstractRestIT {
 
         BlobStoreContext context =
             ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
-                .overrides(overrides).buildView(BlobStoreContext.class);
+                .overrides(overrides ).buildView(BlobStoreContext.class);
 
         BlobStore blobStore = context.getBlobStore();
         final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list();
@@ -753,8 +741,8 @@ public class ImportResourceIT extends AbstractRestIT {
         Entity storage_info = new Entity();
         //TODO: always put dummy values here and ignore this test.
         //TODO: add a ret for when s3 values are invalid.
-        storage_info.put(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "insert key here");
-        storage_info.put(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "insert access id here");
+        storage_info.put("s3_key", "insert key here");
+        storage_info.put("s3_access_id", "insert access id here");
         storage_info.put("bucket_location", "insert bucket name here");
         properties.put("storage_provider", "s3");
         properties.put("storage_info", storage_info);