usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [1/2] usergrid git commit: passing tests
Date Wed, 26 Aug 2015 23:50:28 GMT
Repository: usergrid
Updated Branches:
  refs/heads/entity-size e6b6c0789 -> a11aaa03d


passing tests


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

Branch: refs/heads/entity-size
Commit: bed924fcdff60732361db43b5f455cbe07ec4b17
Parents: e6b6c07
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Aug 26 16:51:17 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Aug 26 16:51:17 2015 -0600

----------------------------------------------------------------------
 .../apache/usergrid/persistence/EntityTest.java |  2 +-
 .../apache/usergrid/utils/IndexUtilsTest.java   |  2 +-
 .../applications/ApplicationResource.java       | 42 ++++++++++++++++++--
 .../usergrid/management/ManagementService.java  |  4 ++
 .../cassandra/ManagementServiceImpl.java        | 23 +++++++++++
 5 files changed, 68 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
index e9e6163..0e29a71 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
@@ -81,7 +81,7 @@ public class EntityTest {
         User user = new User();
         // user.setId(UUIDUtils.newTimeUUID());
         user.setProperty( "foo", "bar" );
-        assertEquals( "{\"type\":\"user\",\"foo\":\"bar\"}", JsonUtils.mapToJsonString( user
) );
+        assertEquals( "{\"type\":\"user\",\"size\":0,\"foo\":\"bar\"}", JsonUtils.mapToJsonString(
user ) );
 
         String json = "{\"username\":\"edanuff\", \"bar\" : \"baz\" }";
         Map<String, Object> p = ( Map<String, Object> ) JsonUtils.parse( json
);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java b/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
index c107f20..a727e3f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
@@ -66,6 +66,6 @@ public class IndexUtilsTest {
             LOG.info( e.getKey() + " = " + e.getValue() );
         }
 
-        assertEquals( 7, l.size() );
+        assertEquals( 8, l.size() );
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index bcec775..fcb01d7 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -134,13 +134,13 @@ public class ApplicationResource extends AbstractContextResource {
         throws Exception {
 
         ApiResponse response = createApiResponse();
-        response.setAction( "get application client credentials" );
+        response.setAction("get application client credentials");
 
         ClientCredentialsInfo credentials =
                 new ClientCredentialsInfo( management.getClientIdForApplication( applicationId
),
                         management.getClientSecretForApplication( applicationId ) );
 
-        response.setCredentials( credentials );
+        response.setCredentials(credentials);
         return new JSONWithPadding( response, callback );
     }
 
@@ -157,12 +157,48 @@ public class ApplicationResource extends AbstractContextResource {
 
         ClientCredentialsInfo credentials =
                 new ClientCredentialsInfo( management.getClientIdForApplication( applicationId
),
-                        management.newClientSecretForApplication( applicationId ) );
+                        management.newClientSecretForApplication(applicationId) );
 
         response.setCredentials( credentials );
         return new JSONWithPadding( response, callback );
     }
 
+    @RequireOrganizationAccess
+    @GET
+    @Path("size")
+    public JSONWithPadding getApplicationSize(
+        @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback
)
+        throws Exception {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "get application size for all entities" );
+        long size = management.getApplicationSize(this.applicationId);
+        Map<String,Object> map = new HashMap<>();
+        Map<String,Object> innerMap = new HashMap<>();
+        innerMap.put("application",size);
+        map.put("aggregation",innerMap);
+        response.setMetadata(map);
+        return new JSONWithPadding( response, callback );
+    }
+
+    @RequireOrganizationAccess
+    @GET
+    @Path("size/{collection_name}")
+    public JSONWithPadding getCollectionSize(
+        @Context UriInfo ui,
+        @PathParam( "collection_name" ) String collection_name,
+        @QueryParam("callback") @DefaultValue("callback") String callback )
+        throws Exception {
+        ApiResponse response = createApiResponse();
+        response.setAction("get collection size for all entities");
+        long size = management.getCollectionSize(this.applicationId ,collection_name);
+        Map<String,Object> map = new HashMap<>();
+        Map<String,Object> innerMap = new HashMap<>();
+        innerMap.put(collection_name,size);
+        map.put("aggregation",innerMap);
+        response.setMetadata(map);
+        return new JSONWithPadding( response, callback );
+    }
 
     @POST
     @Path("sia-provider")

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 9131e47..c822057 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -332,4 +332,8 @@ public interface ManagementService {
     public void deleteApplication(UUID applicationId) throws Exception;
 
     public ApplicationInfo restoreApplication(UUID applicationId) throws Exception;
+
+    long getApplicationSize(final UUID applicationId);
+
+    long getCollectionSize(final UUID applicationId, final String collectionName);
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 32e4393..e36e31c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -20,9 +20,12 @@ package org.apache.usergrid.management.cassandra;
 import com.google.common.base.Optional;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
+import com.google.inject.Injector;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang.text.StrSubstitutor;
 import org.apache.shiro.UnavailableSecurityManagerException;
+import org.apache.usergrid.corepersistence.service.AggregationService;
+import org.apache.usergrid.corepersistence.service.AggregationServiceFactory;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.exception.ConflictException;
 import org.apache.usergrid.locking.Lock;
@@ -31,6 +34,7 @@ import org.apache.usergrid.management.*;
 import org.apache.usergrid.management.exceptions.*;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.Query.Level;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Group;
 import org.apache.usergrid.persistence.entities.User;
@@ -138,6 +142,9 @@ public class ManagementServiceImpl implements ManagementService {
     @Autowired
     protected MailUtils mailUtils;
 
+    @Autowired
+    protected Injector injector;
+
     protected EncryptionService encryptionService;
 
 
@@ -1709,6 +1716,22 @@ public class ManagementServiceImpl implements ManagementService {
         return new ApplicationInfo( applicationId, appInfo.getName() );
     }
 
+    @Override
+    public long getApplicationSize(final UUID applicationId) {
+        AggregationServiceFactory aggregationServiceFactory = injector.getInstance(AggregationServiceFactory.class);
+        AggregationService aggregationService = aggregationServiceFactory.getAggregationService();
+        ApplicationScope applicationScope =CpNamingUtils.getApplicationScope(applicationId);
+        return aggregationService.sumAllCollections(applicationScope);
+    }
+
+    @Override
+    public long getCollectionSize(final UUID applicationId, final String collectionName)
{
+        AggregationServiceFactory aggregationServiceFactory = injector.getInstance(AggregationServiceFactory.class);
+        AggregationService aggregationService = aggregationServiceFactory.getAggregationService();
+        ApplicationScope applicationScope =CpNamingUtils.getApplicationScope(applicationId);
+        return aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),collectionName));
+    }
+
 
     @Override
     public OrganizationInfo getOrganizationForApplication( UUID applicationInfoId ) throws
Exception {


Mime
View raw message