usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [17/21] usergrid git commit: add queue depth, reorg rest into system folder
Date Sun, 20 Sep 2015 22:12:51 GMT
add queue depth, reorg rest into system folder


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

Branch: refs/heads/two-dot-o-dev
Commit: f04f50c1b755dab02e11a82adb10820efb4c2078
Parents: 73dd687
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Fri Sep 18 12:08:37 2015 -0400
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Fri Sep 18 12:08:37 2015 -0400

----------------------------------------------------------------------
 .../usergrid/rest/ApplicationsResource.java     | 168 -------------------
 .../apache/usergrid/rest/DatabaseResource.java  |  98 -----------
 .../apache/usergrid/rest/SystemResource.java    |  14 +-
 .../rest/system/ApplicationsResource.java       | 168 +++++++++++++++++++
 .../usergrid/rest/system/DatabaseResource.java  | 100 +++++++++++
 .../rest/system/QueueSystemResource.java        |  78 +++++++++
 .../apache/usergrid/rest/SystemResourceIT.java  |  23 ++-
 .../test/resource/endpoints/NamedResource.java  |  34 +++-
 .../test/resource/endpoints/RootResource.java   |   5 +
 .../test/resource/endpoints/SubResource.java    |  37 ++++
 .../test/resource/endpoints/UrlResource.java    |   6 +
 11 files changed, 449 insertions(+), 282 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java
deleted file mode 100644
index 6127efc..0000000
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- *
- *  * Licensed to the Apache Software Foundation (ASF) under one or more
- *  *  contributor license agreements.  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.  For additional information regarding
- *  * copyright in this work, please see the NOTICE file in the top level
- *  * directory of this distribution.
- *
- */
-package org.apache.usergrid.rest;
-
-import com.sun.jersey.api.json.JSONWithPadding;
-import org.apache.usergrid.corepersistence.service.StatusService;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.core.util.StringUtils;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Classy class class.
- */
-@Component
-@Scope( "singleton" )
-@Produces( {
-    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
-    "application/ecmascript", "text/jscript"
-} )
-public class ApplicationsResource extends AbstractContextResource {
-
-    private static final Logger logger = LoggerFactory.getLogger(ApplicationsResource.class);
-
-
-    public ApplicationsResource() {
-
-        logger.info( "ApplicationsResource initialized" );
-    } {
-
-    }
-
-    @RequireSystemAccess
-    @DELETE
-    @Path( "{applicationId}" )
-    public JSONWithPadding clearApplication( @Context UriInfo ui,
-                                             @PathParam("applicationId") UUID applicationId,
-                                             @QueryParam( "confirmApplicationName" ) String
confirmApplicationName,
-                                             @QueryParam( "limit" ) int limit,
-                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-        throws Exception {
-
-        if(confirmApplicationName == null){
-            throw new IllegalArgumentException("please make add a QueryString for confirmApplicationName");
-        }
-
-        final UUID jobId = UUIDGenerator.newTimeUUID();
-
-        final EntityManager em =  emf.getEntityManager(applicationId);
-        final String name =  em.getApplication().getApplicationName();
-        if(!name.toLowerCase().equals(confirmApplicationName.toLowerCase())){
-            throw new IllegalArgumentException("confirmApplicationName: " + confirmApplicationName
+ " does not equal " + name);
-        }
-        final StatusService statusService = injector.getInstance(StatusService.class);
-
-        final ApiResponse response = createApiResponse();
-
-        response.setAction( "clear application" );
-
-        logger.info("clearing up application");
-
-
-        final Thread delete = new Thread() {
-
-            @Override
-            public void run() {
-                final AtomicInteger itemsDeleted = new AtomicInteger(0);
-                try {
-                    management.deleteAllEntities(applicationId, limit)
-                        .map(id -> itemsDeleted.incrementAndGet())
-                        .doOnNext(count -> {
-                            if( count % 100 == 0 ){
-                                Map<String,Object> map = new LinkedHashMap<>();
-                                map.put("count",itemsDeleted.intValue());
-                                final StatusService statusService = injector.getInstance(StatusService.class);
-                                statusService.setStatus(applicationId, jobId, StatusService.Status.INPROGRESS,map).subscribe();
-                            }
-                        })
-                        .doOnCompleted(() ->{
-                            Map<String,Object> map = new LinkedHashMap<>();
-                            map.put("count",itemsDeleted.intValue());
-                            final StatusService statusService = injector.getInstance(StatusService.class);
-                            statusService.setStatus(applicationId,jobId, StatusService.Status.COMPLETE,map).subscribe();
-                        })
-                        .subscribe();
-
-                } catch ( Exception e ) {
-                    Map<String,Object> map = new LinkedHashMap<>();
-                    map.put("exception",e);
-                    statusService.setStatus(applicationId,jobId, StatusService.Status.FAILED,map).subscribe();
-                    logger.error( "Failed to delete appid:"+applicationId + " jobid:"+jobId+"
count:"+itemsDeleted, e );
-                }
-            }
-        };
-
-        delete.setName("Delete for app : " + applicationId + " job: " + jobId);
-        delete.setDaemon(true);
-        delete.start();
-
-        statusService.setStatus(applicationId,jobId, StatusService.Status.STARTED,new LinkedHashMap<>()).subscribe();
-
-        Map<String,Object> data = new HashMap<>();
-        data.put("jobId",jobId);
-        data.put("status",StatusService.Status.STARTED);
-        response.setData(data);
-        response.setSuccess();
-        return new JSONWithPadding( response, callback );
-    }
-
-    @RequireSystemAccess
-    @GET
-    @Path( "{applicationId}/job/{jobId}" )
-    public JSONWithPadding getStatus( @Context UriInfo ui,
-                                             @PathParam("applicationId") UUID applicationId,
-                                            @PathParam("jobId") UUID jobId,
-                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback ) throws Exception{
-        final StatusService statusService = injector.getInstance(StatusService.class);
-
-        final ApiResponse response = createApiResponse();
-
-        response.setAction( "clear application" );
-
-        StatusService.JobStatus jobStatus = statusService.getStatus(applicationId, jobId).toBlocking().lastOrDefault(null);
-
-        Map<String,Object> data = new HashMap<>();
-        data.put("jobId",jobId);
-        data.put( "status", jobStatus.getStatus().toString() );
-        data.put( "metadata", jobStatus.getData() );
-        response.setData(data);
-        response.setSuccess();
-
-        return new JSONWithPadding( response, callback );
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/main/java/org/apache/usergrid/rest/DatabaseResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/DatabaseResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/DatabaseResource.java
deleted file mode 100644
index a8c5fee..0000000
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/DatabaseResource.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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;
-
-
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
-
-import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
-
-import com.sun.jersey.api.json.JSONWithPadding;
-
-
-@Component
-@Scope( "singleton" )
-@Produces( {
-    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
-    "application/ecmascript", "text/jscript"
-} )
-public class DatabaseResource extends AbstractContextResource {
-
-    private static final Logger logger = LoggerFactory.getLogger( DatabaseResource.class
);
-
-
-    public DatabaseResource() {
-        logger.info( "DatabaseResource initialized" );
-    }
-
-
-    @RequireSystemAccess
-    @PUT
-    @Path( "setup" )
-    public JSONWithPadding runDatabaseSetup( @Context UriInfo ui,
-                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-        throws Exception {
-
-        ApiResponse response = createApiResponse();
-        response.setAction( "cassandra setup" );
-
-        logger.info( "Setting up Cassandra" );
-
-
-        emf.setup();
-
-
-        response.setSuccess();
-
-        return new JSONWithPadding( response, callback );
-    }
-
-
-    @RequireSystemAccess
-    @PUT
-    @Path( "bootstrap" )
-    public JSONWithPadding runSystemSetup( @Context UriInfo ui,
-                                           @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-        throws Exception {
-
-        ApiResponse response = createApiResponse();
-        response.setAction( "cassandra setup" );
-
-        logger.info( "Setting up Cassandra" );
-
-
-        emf.boostrap();
-        management.setup();
-
-        response.setSuccess();
-
-        return new JSONWithPadding( response, callback );
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
index f266441..fd85d94 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
@@ -22,6 +22,9 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.usergrid.rest.system.ApplicationsResource;
+import org.apache.usergrid.rest.system.DatabaseResource;
+import org.apache.usergrid.rest.system.QueueSystemResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
@@ -31,12 +34,6 @@ import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 
 import com.sun.jersey.api.json.JSONWithPadding;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicInteger;
-
 
 @Path( "/system" )
 @Component
@@ -96,6 +93,11 @@ public class SystemResource extends AbstractContextResource {
         return getSubResource( DatabaseResource.class );
     }
 
+    @Path( "queue" )
+    public QueueSystemResource queue() {
+        return getSubResource( QueueSystemResource.class );
+    }
+
     @Path( "applications" )
     public ApplicationsResource applications() {
         return getSubResource( ApplicationsResource.class );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/main/java/org/apache/usergrid/rest/system/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/system/ApplicationsResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/system/ApplicationsResource.java
new file mode 100644
index 0000000..724a8cf
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/system/ApplicationsResource.java
@@ -0,0 +1,168 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.rest.system;
+
+import com.sun.jersey.api.json.JSONWithPadding;
+import org.apache.usergrid.corepersistence.service.StatusService;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.apache.usergrid.rest.AbstractContextResource;
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Classy class class.
+ */
+@Component
+@Scope( "singleton" )
+@Produces( {
+    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
+    "application/ecmascript", "text/jscript"
+} )
+public class ApplicationsResource extends AbstractContextResource {
+
+    private static final Logger logger = LoggerFactory.getLogger(ApplicationsResource.class);
+
+
+    public ApplicationsResource() {
+
+        logger.info( "ApplicationsResource initialized" );
+    } {
+
+    }
+
+    @RequireSystemAccess
+    @DELETE
+    @Path( "{applicationId}" )
+    public JSONWithPadding clearApplication( @Context UriInfo ui,
+                                             @PathParam("applicationId") UUID applicationId,
+                                             @QueryParam( "confirmApplicationName" ) String
confirmApplicationName,
+                                             @QueryParam( "limit" ) int limit,
+                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
+
+        if(confirmApplicationName == null){
+            throw new IllegalArgumentException("please make add a QueryString for confirmApplicationName");
+        }
+
+        final UUID jobId = UUIDGenerator.newTimeUUID();
+
+        final EntityManager em =  emf.getEntityManager(applicationId);
+        final String name =  em.getApplication().getApplicationName();
+        if(!name.toLowerCase().equals(confirmApplicationName.toLowerCase())){
+            throw new IllegalArgumentException("confirmApplicationName: " + confirmApplicationName
+ " does not equal " + name);
+        }
+        final StatusService statusService = injector.getInstance(StatusService.class);
+
+        final ApiResponse response = createApiResponse();
+
+        response.setAction( "clear application" );
+
+        logger.info("clearing up application");
+
+
+        final Thread delete = new Thread() {
+
+            @Override
+            public void run() {
+                final AtomicInteger itemsDeleted = new AtomicInteger(0);
+                try {
+                    management.deleteAllEntities(applicationId, limit)
+                        .map(id -> itemsDeleted.incrementAndGet())
+                        .doOnNext(count -> {
+                            if( count % 100 == 0 ){
+                                Map<String,Object> map = new LinkedHashMap<>();
+                                map.put("count",itemsDeleted.intValue());
+                                final StatusService statusService = injector.getInstance(StatusService.class);
+                                statusService.setStatus(applicationId, jobId, StatusService.Status.INPROGRESS,map).subscribe();
+                            }
+                        })
+                        .doOnCompleted(() ->{
+                            Map<String,Object> map = new LinkedHashMap<>();
+                            map.put("count",itemsDeleted.intValue());
+                            final StatusService statusService = injector.getInstance(StatusService.class);
+                            statusService.setStatus(applicationId,jobId, StatusService.Status.COMPLETE,map).subscribe();
+                        })
+                        .subscribe();
+
+                } catch ( Exception e ) {
+                    Map<String,Object> map = new LinkedHashMap<>();
+                    map.put("exception",e);
+                    statusService.setStatus(applicationId,jobId, StatusService.Status.FAILED,map).subscribe();
+                    logger.error( "Failed to delete appid:"+applicationId + " jobid:"+jobId+"
count:"+itemsDeleted, e );
+                }
+            }
+        };
+
+        delete.setName("Delete for app : " + applicationId + " job: " + jobId);
+        delete.setDaemon(true);
+        delete.start();
+
+        statusService.setStatus(applicationId,jobId, StatusService.Status.STARTED,new LinkedHashMap<>()).subscribe();
+
+        Map<String,Object> data = new HashMap<>();
+        data.put("jobId",jobId);
+        data.put("status",StatusService.Status.STARTED);
+        response.setData(data);
+        response.setSuccess();
+        return new JSONWithPadding( response, callback );
+    }
+
+    @RequireSystemAccess
+    @GET
+    @Path( "{applicationId}/job/{jobId}" )
+    public JSONWithPadding getStatus( @Context UriInfo ui,
+                                             @PathParam("applicationId") UUID applicationId,
+                                            @PathParam("jobId") UUID jobId,
+                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback ) throws Exception{
+        final StatusService statusService = injector.getInstance(StatusService.class);
+
+        final ApiResponse response = createApiResponse();
+
+        response.setAction( "clear application" );
+
+        StatusService.JobStatus jobStatus = statusService.getStatus(applicationId, jobId).toBlocking().lastOrDefault(null);
+
+        Map<String,Object> data = new HashMap<>();
+        data.put("jobId",jobId);
+        data.put( "status", jobStatus.getStatus().toString() );
+        data.put( "metadata", jobStatus.getData() );
+        response.setData(data);
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/main/java/org/apache/usergrid/rest/system/DatabaseResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/system/DatabaseResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/system/DatabaseResource.java
new file mode 100644
index 0000000..f24bfc8
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/system/DatabaseResource.java
@@ -0,0 +1,100 @@
+/*
+ * 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.system;
+
+
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.usergrid.rest.AbstractContextResource;
+import org.apache.usergrid.rest.ApiResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
+
+import com.sun.jersey.api.json.JSONWithPadding;
+
+
+@Component
+@Scope( "singleton" )
+@Produces( {
+    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
+    "application/ecmascript", "text/jscript"
+} )
+public class DatabaseResource extends AbstractContextResource {
+
+    private static final Logger logger = LoggerFactory.getLogger( DatabaseResource.class
);
+
+
+    public DatabaseResource() {
+        logger.info( "DatabaseResource initialized" );
+    }
+
+
+    @RequireSystemAccess
+    @PUT
+    @Path( "setup" )
+    public JSONWithPadding runDatabaseSetup( @Context UriInfo ui,
+                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "cassandra setup" );
+
+        logger.info( "Setting up Cassandra" );
+
+
+        emf.setup();
+
+
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+    }
+
+
+    @RequireSystemAccess
+    @PUT
+    @Path( "bootstrap" )
+    public JSONWithPadding runSystemSetup( @Context UriInfo ui,
+                                           @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "cassandra setup" );
+
+        logger.info( "Setting up Cassandra" );
+
+
+        emf.boostrap();
+        management.setup();
+
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/main/java/org/apache/usergrid/rest/system/QueueSystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/system/QueueSystemResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/system/QueueSystemResource.java
new file mode 100644
index 0000000..0721d89
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/system/QueueSystemResource.java
@@ -0,0 +1,78 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.rest.system;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.sun.jersey.api.json.JSONWithPadding;
+import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
+import org.apache.usergrid.rest.AbstractContextResource;
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * retrieves queue stats
+ */
+@Component
+@Scope( "singleton" )
+@Produces( {
+    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
+    "application/ecmascript", "text/jscript"
+} )
+public class QueueSystemResource extends AbstractContextResource {
+    private static final Logger logger = LoggerFactory.getLogger(QueueSystemResource.class);
+
+    public QueueSystemResource(){logger.info("queue resource initialized");}
+
+    /**
+     * Return queue depth of this Usergrid instance in JSON format.
+     *
+     * By Default this end-point will ignore errors but if you call it with ignore_status=false
+     * then it will return HTTP 500 if either the Entity store or the Index for the management
+     * application are in a bad state.
+     *
+     */
+    @GET
+    @RequireSystemAccess
+    @Path("size")
+    public JSONWithPadding getQueueDepth(
+        @QueryParam("callback") @DefaultValue("callback") String callback ) {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "get queue depth" );
+
+        AsyncEventService eventService = injector.getInstance(AsyncEventService.class);
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+
+        node.put("queueDepth", eventService.getQueueDepth());
+
+        response.setProperty( "data", node );
+
+        return new JSONWithPadding( response, callback );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
index 55623dd..44fa036 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
@@ -24,6 +24,7 @@ import org.apache.usergrid.rest.test.resource.model.Entity;
 import org.apache.usergrid.rest.test.resource.model.QueryParameters;
 
 import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.UUID;
 
 import static org.junit.Assert.assertEquals;
@@ -63,7 +64,7 @@ public class SystemResourceIT extends AbstractRestIT {
         queryParameters.addParam( "access_token", clientSetup.getSuperuserToken().getAccessToken()
);
         queryParameters.addParam("confirmApplicationName", this.clientSetup.getAppName());
 
-        org.apache.usergrid.rest.test.resource.model.ApiResponse result = clientSetup.getRestClient().system().applications(this.clientSetup.getAppUuid()).delete(
queryParameters);
+        org.apache.usergrid.rest.test.resource.model.ApiResponse result = clientSetup.getRestClient().system().getSubResource("applications/"
+ this.clientSetup.getAppUuid()).delete(false, true, queryParameters);
 
         assertNotNull(result);
         assertNotNull("ok", result.getStatus());
@@ -80,7 +81,7 @@ public class SystemResourceIT extends AbstractRestIT {
                 Thread.sleep(100);
             }
         }
-        assertEquals(((LinkedHashMap)((LinkedHashMap) result.getData()).get("metadata")).get("count"),
10);
+        assertEquals(((LinkedHashMap) ((LinkedHashMap) result.getData()).get("metadata")).get("count"),
10);
 
     }
 
@@ -88,9 +89,9 @@ public class SystemResourceIT extends AbstractRestIT {
     @Test
     public void testBoostrapAlreadyRun() {
         QueryParameters queryParameters = new QueryParameters();
-        queryParameters.addParam( "access_token", clientSetup.getSuperuserToken().getAccessToken()
);
+        queryParameters.addParam("access_token", clientSetup.getSuperuserToken().getAccessToken());
 
-        Entity result = clientSetup.getRestClient().system().database().bootstrap().put(
queryParameters );
+        Entity result = clientSetup.getRestClient().system().database().bootstrap().put(queryParameters);
 
         assertNotNull( result );
         assertNotNull( "ok", ( String ) result.get( "status" ) );
@@ -98,6 +99,18 @@ public class SystemResourceIT extends AbstractRestIT {
         result = clientSetup.getRestClient().system().database().bootstrap().put( queryParameters
);
 
         assertNotNull( result );
-        assertNotNull( "ok", ( String ) result.get( "status" ) );
+        assertNotNull("ok", (String) result.get("status"));
+    }
+    @Test
+    public void testQueueDepth() {
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.addParam("access_token", clientSetup.getSuperuserToken().getAccessToken());
+
+        Entity result = clientSetup.getRestClient().system().getSubResource("queue/size").get(Entity.class,
queryParameters,false,true);
+
+        assertNotNull( result );
+        assertEquals(0, ((Map) result.get("data")).get("queueDepth"));
+
+
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
index 1a9c776..79ecb9e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
@@ -297,14 +297,21 @@ public class NamedResource implements UrlResource {
 
 
     public <T> T get(Class<T> type,QueryParameters queryParameters) {
-        return get( type, queryParameters, true );
+        return get(type, queryParameters, true);
     }
-
     public <T> T get(Class<T> type,QueryParameters queryParameters, boolean useToken)
{
+        return get(type,queryParameters,useToken,false);
+    }
+    public <T> T get(Class<T> type,QueryParameters queryParameters, boolean useToken,
boolean useSupertoken) {
         WebResource resource = getResource(useToken);
         if(queryParameters!=null) {
             resource = addParametersToResource(resource, queryParameters);
         }
+        if(useSupertoken) {
+            //added httpBasicauth filter to all setup calls because they all do verification
this way.
+            HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter("superuser",
"superpassword");
+            resource.addFilter(httpBasicAuthFilter);
+        }
         GenericType<T> gt = new GenericType<>((Class) type);
         return resource.type(MediaType.APPLICATION_JSON_TYPE)
             .accept( MediaType.APPLICATION_JSON )
@@ -318,7 +325,7 @@ public class NamedResource implements UrlResource {
 
     public ApiResponse post( boolean useToken, FormDataMultiPart multiPartForm ) {
         WebResource resource = getResource( useToken );
-        return resource.type( MediaType.MULTIPART_FORM_DATA_TYPE ).post( ApiResponse.class,
multiPartForm );
+        return resource.type( MediaType.MULTIPART_FORM_DATA_TYPE ).post(ApiResponse.class,
multiPartForm);
     }
 
     public ApiResponse post( FormDataMultiPart multiPartForm ) {
@@ -359,12 +366,29 @@ public class NamedResource implements UrlResource {
     public ApiResponse delete( boolean useToken ) {
         return getResource(useToken).delete(ApiResponse.class);
     }
-
     public ApiResponse delete( boolean useToken, QueryParameters queryParameters ) {
+        return delete(useToken,false,queryParameters);
+    }
+    public ApiResponse delete( boolean useToken, boolean useSupertoken, QueryParameters queryParameters
) {
         WebResource resource = getResource(useToken);
         if(queryParameters!=null) {
             resource = addParametersToResource(resource, queryParameters);
         }
-        return resource.delete( ApiResponse.class );
+        if(useSupertoken) {
+            //added httpBasicauth filter to all setup calls because they all do verification
this way.
+            HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter("superuser",
"superpassword");
+            resource.addFilter(httpBasicAuthFilter);
+        }
+        return resource.delete(ApiResponse.class);
+    }
+
+
+
+    public ClientContext getContext(){
+        return context;
+    }
+
+    public NamedResource getSubResource(final String path){
+        return SubResource.getInstance(path,this);
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
index 8537251..2671ff2 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
@@ -66,6 +66,11 @@ public class RootResource implements UrlResource {
         return null;
     }
 
+    @Override
+    public ClientContext getContext() {
+        return context;
+    }
+
     /**
      * Get the management resource
      * @return

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SubResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SubResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SubResource.java
new file mode 100644
index 0000000..69c9aab
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SubResource.java
@@ -0,0 +1,37 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.rest.test.resource.endpoints;
+
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+/**
+ * Classy class class.
+ */
+public class SubResource extends NamedResource {
+
+    private SubResource(final String path, final ClientContext context, final UrlResource
parent) {
+        super( path, context, parent );
+    }
+
+    public static NamedResource getInstance(final String path, final UrlResource parent ){
+        return new SubResource(path,parent.getContext(),parent);
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f04f50c1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
index eb16d4d..b040aee 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
@@ -40,5 +40,11 @@ public interface UrlResource {
      */
     public WebResource getResource();
 
+    /**
+     * get context
+     * @return
+     */
+    public ClientContext getContext();
+
 
 }


Mime
View raw message