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/26 19:18:49 UTC

[16/50] [abbrv] incubator-usergrid git commit: changes to get REST tests working with Arquillian: - Add setenv.sh to set memory and debug options for Tomcat - Make Arqillian profile active by default - Add shutdown hook to stop job service when Usergrid

changes to get REST tests working with Arquillian:
- Add setenv.sh to set memory and debug options for Tomcat
- Make Arqillian profile active by default
- Add shutdown hook to stop job service when Usergrid is underplayed


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

Branch: refs/heads/USERGRID-280
Commit: c9198a6c324e9bb159be41ac6cc07efe2a6d4dc2
Parents: 949c22a
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Feb 24 09:41:45 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Feb 24 09:41:45 2015 -0500

----------------------------------------------------------------------
 stack/rest/catalina_base/bin/setenv.sh          |  9 +++
 stack/rest/pom.xml                              |  3 +-
 .../usergrid/rest/JobServiceBoostrap.java       |  4 +-
 .../apache/usergrid/rest/ShutdownListener.java  | 73 ++++++++++++++++++++
 .../applications/ApplicationsResource.java      |  1 +
 stack/rest/src/main/webapp/WEB-INF/web.xml      | 13 ++--
 6 files changed, 93 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9198a6c/stack/rest/catalina_base/bin/setenv.sh
----------------------------------------------------------------------
diff --git a/stack/rest/catalina_base/bin/setenv.sh b/stack/rest/catalina_base/bin/setenv.sh
new file mode 100644
index 0000000..dbcad13
--- /dev/null
+++ b/stack/rest/catalina_base/bin/setenv.sh
@@ -0,0 +1,9 @@
+
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8089 "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false "
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
+JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"
+JAVA_OPTS="$JAVA_OPTS -Xmx4000m -Xms4000m"
+
+CATALINA_PID="$CATALINA_BASE/tomcat.pid"
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9198a6c/stack/rest/pom.xml
----------------------------------------------------------------------
diff --git a/stack/rest/pom.xml b/stack/rest/pom.xml
index 7746b5d..b3c3663 100644
--- a/stack/rest/pom.xml
+++ b/stack/rest/pom.xml
@@ -45,7 +45,7 @@
             <id>arquillian-tomcat</id>
 
             <activation>
-                <activeByDefault>false</activeByDefault>
+                <activeByDefault>true</activeByDefault>
             </activation>
 
             <dependencies>
@@ -96,6 +96,7 @@
                     <groupId>org.jboss.arquillian.container</groupId>
                     <artifactId>arquillian-tomcat-remote-7</artifactId>
                     <version>1.0.0.CR7</version>
+                    <scope>test</scope>
                 </dependency>
 
             </dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9198a6c/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java b/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
index 6d31fac..c6721ea 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
@@ -31,13 +31,12 @@ import java.util.Properties;
  * Simple class that starts the job store after the application context has been fired up. We don't
  * want to start the service until all of spring has been initialized in our webapp context
  */
-//@Component( "jobServiceBoostrap" )
 public class JobServiceBoostrap implements
         ApplicationListener<ContextRefreshedEvent> {
 
     private static final Logger logger = LoggerFactory.getLogger( JobServiceBoostrap.class );
 
-    private static final String START_SCHEDULER_PROP = "usergrid.scheduler.enabled";
+    public static final String START_SCHEDULER_PROP = "usergrid.scheduler.enabled";
 
     @Autowired
     private JobSchedulerService schedulerService;
@@ -60,7 +59,6 @@ public class JobServiceBoostrap implements
         String start = properties.getProperty( START_SCHEDULER_PROP, "true" );
         if ( Boolean.parseBoolean( start ) ) {
             logger.info( "Starting Scheduler Service..." );
-            // start the scheduler service
             schedulerService.startAndWait();
 
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9198a6c/stack/rest/src/main/java/org/apache/usergrid/rest/ShutdownListener.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/ShutdownListener.java b/stack/rest/src/main/java/org/apache/usergrid/rest/ShutdownListener.java
new file mode 100644
index 0000000..7b038c2
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/ShutdownListener.java
@@ -0,0 +1,73 @@
+/*
+ * 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 org.apache.usergrid.batch.service.JobSchedulerService;
+import org.apache.usergrid.batch.service.SchedulerService;
+import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import java.util.Properties;
+
+
+/**
+ * Shutdown job service when context is destroyed (useful when testing).
+ */
+public class ShutdownListener implements ServletContextListener {
+    private static final Logger logger = LoggerFactory.getLogger(ShutdownListener.class);
+    JobSchedulerService schedulerService;
+    Properties properties;
+
+    public ShutdownListener() {
+    }
+
+    public void contextInitialized(ServletContextEvent sce) {
+
+        ApplicationContext ctx = WebApplicationContextUtils
+            .getWebApplicationContext(sce.getServletContext());
+
+        schedulerService = ctx.getBean( JobSchedulerService.class );
+        properties = (Properties)ctx.getBean("properties");
+
+        logger.info("ShutdownListener initialized");
+    }
+
+    public void contextDestroyed(ServletContextEvent sce) {
+
+        logger.info("ShutdownListener invoked");
+
+        boolean started = Boolean.parseBoolean(
+            properties.getProperty(JobServiceBoostrap.START_SCHEDULER_PROP, "true"));
+
+        if ( started ) {
+            schedulerService.stopAndWait();
+            logger.info( "Stopping Scheduler Service..." );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9198a6c/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
index 56d2f98..0c8ee06 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
@@ -142,6 +142,7 @@ public class ApplicationsResource extends AbstractContextResource {
 
     @RequireOrganizationAccess
     @Path(RootResource.APPLICATION_ID_PATH)
+    @PUT
     public ApplicationResource restoreApplicationFromOrganizationByApplicationId(
         @Context UriInfo ui,
         @PathParam( "applicationId" )

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9198a6c/stack/rest/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/webapp/WEB-INF/web.xml b/stack/rest/src/main/webapp/WEB-INF/web.xml
index 24a82ca..23c0751 100644
--- a/stack/rest/src/main/webapp/WEB-INF/web.xml
+++ b/stack/rest/src/main/webapp/WEB-INF/web.xml
@@ -27,11 +27,15 @@
     <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
-  
+
     <listener>
         <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
     </listener>
 
+    <listener>
+        <listener-class>org.apache.usergrid.rest.ShutdownListener</listener-class>
+    </listener>
+
     <filter>
         <filter-name>swaggerFilter</filter-name>
         <filter-class>org.apache.usergrid.rest.SwaggerServlet</filter-class>
@@ -59,7 +63,7 @@
         <filter-name>contentTypeFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
-    
+
     <filter>
         <filter-name>shiroFilter</filter-name>
         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
@@ -72,7 +76,7 @@
         <filter-name>shiroFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
-	
+
     <filter>
         <filter-name>Usergrid REST API Server</filter-name>
         <filter-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</filter-class>
@@ -126,7 +130,4 @@
         </taglib>
     </jsp-config>
 
-
-
-
 </web-app>