stop application entry point

Change-Id: Ia4a8fab765f4878b30b6f7adb430f01ef2757605
Reviewed-on: https://asterix-gerrit.ics.uci.edu/827
Reviewed-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/ClusterControllerService.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/ClusterControllerService.java
index 8fb83d1..2aa3f37 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/ClusterControllerService.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/ClusterControllerService.java
@@ -249,10 +249,7 @@
         workQueue.start();
         connectNCs();
         LOGGER.log(Level.INFO, "Started ClusterControllerService");
-        if (aep != null) {
-            // Sometimes, there is no application entry point. Check hyracks-client project
-            aep.startupCompleted();
-        }
+        notifyApplication();
     }
 
     private void startApplication() throws Exception {
@@ -288,9 +285,17 @@
         }
     }
 
+    private void notifyApplication() throws Exception {
+        if (aep != null) {
+            // Sometimes, there is no application entry point. Check hyracks-client project
+            aep.startupCompleted();
+        }
+    }
+
     @Override
     public void stop() throws Exception {
         LOGGER.log(Level.INFO, "Stopping ClusterControllerService");
+        stopApplication();
         webServer.stop();
         sweeper.cancel();
         workQueue.stop();
@@ -301,6 +306,12 @@
         LOGGER.log(Level.INFO, "Stopped ClusterControllerService");
     }
 
+    private void stopApplication() throws Exception {
+        if (aep != null) {
+            aep.stop();
+        }
+    }
+
     public ServerContext getServerContext() {
         return serverCtx;
     }