show caution dialog if shutting down or if server is unresponsive

and include shutting down message in rest api.
tested that i can stop and restart the server and it nicely cycles through 
sequence of:
"shutting down", "server unreachable", then "starting up", then restores page.


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

Branch: refs/heads/master
Commit: 7d0f1a0efeffd0e16bdca35ec73f0d7ebbd956ed
Parents: 65d7ee3
Author: Alex Heneveld <[email protected]>
Authored: Mon Apr 27 14:30:26 2015 +0100
Committer: Alex Heneveld <[email protected]>
Committed: Mon Apr 27 14:30:26 2015 +0100

----------------------------------------------------------------------
 .../assets/js/model/server-extended-status.js   | 25 +++++++++++++++++---
 usage/jsgui/src/main/webapp/assets/js/router.js | 18 +++++++++++---
 .../src/main/webapp/assets/tpl/help/page.html   |  5 ++--
 .../webapp/assets/tpl/home/server-caution.html  | 18 +++++++++++---
 .../main/java/brooklyn/rest/api/ServerApi.java  |  7 +++++-
 .../brooklyn/rest/resources/ServerResource.java | 11 +++++++++
 6 files changed, 72 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d0f1a0e/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
----------------------------------------------------------------------
diff --git 
a/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js 
b/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
index 88e1ef2..2f5ccb3 100644
--- a/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
+++ b/usage/jsgui/src/main/webapp/assets/js/model/server-extended-status.js
@@ -22,6 +22,20 @@ define(["backbone", "brooklyn", "view/viewutils"], function 
(Backbone, Brooklyn,
         callbacks: [],
         loaded: false,
         url: "/v1/server/up/extended",
+        onError: function(thiz,xhr,modelish) {
+            log("ServerExtendedStatus: error contacting Brooklyn server");
+            log(xhr);
+            if (xhr.readyState==0) {
+                // server not contactable
+                this.loaded = false;
+            } else {
+                // server error
+                log(xhr.responseText);
+                // simply set unhealthy
+                this.set("healthy", false);
+            }
+            this.applyCallbacks();
+        },
         whenUp: function(f) {
             var that = this;
             if (this.isUp()) {
@@ -48,6 +62,7 @@ define(["backbone", "brooklyn", "view/viewutils"], function 
(Backbone, Brooklyn,
         },
 
         isUp: function() { return this.get("up") },
+        isShuttingDown: function() { return this.get("shuttingDown") },
         isHealthy: function() { return this.get("healthy") },
         isMaster: function() {
             ha = this.get("ha") || {};
@@ -70,15 +85,19 @@ define(["backbone", "brooklyn", "view/viewutils"], function 
(Backbone, Brooklyn,
                 return master.nodeUri;
             }
         },
+        applyCallbacks: function() {
+            var currentCallbacks = this.callbacks;
+            this.callbacks = [];
+            _.invoke(currentCallbacks, "apply");
+        },
     });
 
     var serverExtendedStatus = new ServerExtendedStatus();
     serverExtendedStatus.on("sync", function() {
         serverExtendedStatus.loaded = true;
-        var currentCallbacks = serverExtendedStatus.callbacks;
-        serverExtendedStatus.callbacks = [];
-        _.invoke(currentCallbacks, "apply");
+        serverExtendedStatus.applyCallbacks();
     });
+    serverExtendedStatus.on("error", serverExtendedStatus.onError);
 
     // Will returning the instance rather than the object be confusing?
     // It breaks the pattern used by all the other models.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d0f1a0e/usage/jsgui/src/main/webapp/assets/js/router.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/router.js 
b/usage/jsgui/src/main/webapp/assets/js/router.js
index 4c7689a..8eb9c34 100644
--- a/usage/jsgui/src/main/webapp/assets/js/router.js
+++ b/usage/jsgui/src/main/webapp/assets/js/router.js
@@ -48,15 +48,22 @@ define([
             var state = {
                     loaded: serverStatus.loaded,
                     up: serverStatus.isUp(),
+                    shuttingDown: serverStatus.isShuttingDown(),
                     healthy: serverStatus.isHealthy(),
                     master: serverStatus.isMaster(),
                     masterUri: serverStatus.getMasterUri(),
                 };
-            if (state.loaded && state.up && state.healthy && state.master) 
return this.renderEmpty();
+            
+            if (state.loaded && state.up && state.healthy && state.master) {
+                // this div shows nothing in normal operation
+                return this.renderEmpty();
+            }
             
             this.warningActive = true;
             this.$el.html(this.template(state));
-                
+            $('#application-content').fadeTo(500,0.1);
+            this.$el.fadeTo(200,1);
+            
             $("#dismiss-standby-warning", this.$el).click(function() {
                 that.carryOnRegardless = true;
                 if (that.redirectPending) {
@@ -91,8 +98,13 @@ define([
             return this;
         },
         renderEmpty: function() {
+            var that = this;
             this.warningActive = false;
-            this.$el.empty();
+            this.$el.fadeTo(200,0.2, function() {
+                if (!that.warningActive)
+                    that.$el.empty();
+            });
+            $('#application-content').fadeTo(200,1);
             return this;
         },
         beforeClose: function() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d0f1a0e/usage/jsgui/src/main/webapp/assets/tpl/help/page.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/tpl/help/page.html 
b/usage/jsgui/src/main/webapp/assets/tpl/help/page.html
index 7d3ef0a..dc35b17 100644
--- a/usage/jsgui/src/main/webapp/assets/tpl/help/page.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/help/page.html
@@ -52,10 +52,11 @@ under the License.
                 url:"/v1/server/shutdown",
                 data: { stopAppsFirst: stopAppsFirst, shutdownTimeout: 0, 
requestTimeout: 0 },
                 success:function (data) {
-                    $('#help-page').fadeTo(500,0.1);
+                    // unfaded if server restarted, in router.js 
ServerCautionOverlay
+                    $('#application-content').fadeTo(500,0.1);
                 },
                 error: function(data) {
-                    $('#help-page')
+                    $('#application-content')
                         .fadeTo(200,0.2)
                         .delay(200).fadeTo(200,1)
                         .delay(200).fadeTo(100,0.2)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d0f1a0e/usage/jsgui/src/main/webapp/assets/tpl/home/server-caution.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/tpl/home/server-caution.html 
b/usage/jsgui/src/main/webapp/assets/tpl/home/server-caution.html
index 0f767c0..94bd622 100644
--- a/usage/jsgui/src/main/webapp/assets/tpl/home/server-caution.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/home/server-caution.html
@@ -27,16 +27,28 @@ under the License.
         <p><strong>
             Connecting to server...</strong></p>
 
-            <center><img src="/assets/images/throbber.gif"/></center>        
         <p>
             No response from server (yet). 
-            Please check your network connection, or if you are on a slow 
connection simply be patient!
+            Please check your network connection and the URL, or if you are on 
a slow connection simply be patient!
             This dialog will disappear if and when the server responds.</p>
         
         <p><i>
             If you understand the risks, that information may be unavailable 
and operations may fail, 
             and wish to proceed regardless, click <a 
id="dismiss-standby-warning">here</a>.</i></p>
 
+<% } else if (shuttingDown) { %>
+        <p><strong>
+            Server shutting down...</strong></p>
+                    
+        <p>
+            The Brooklyn server is shutting down.
+            This dialog will disappear if and when the server is restarted at 
this address.
+            If in doubt, contact your system administrator.</p>
+        
+        <p><i>
+            If you understand the risks, that information may be unavailable 
and operations may fail, 
+            and wish to proceed regardless, click <a 
id="dismiss-standby-warning">here</a>.</i></p>
+
 <% } else if (!up) { %>
             <div style="float: right; position: relative; top: -45px; height: 
0; overflow: visible;">
                 <img src="/assets/img/icon-status-starting.gif" 
width="60"/></div>
@@ -50,7 +62,7 @@ under the License.
             This dialog will disappear when the server is ready.</p>
         
         <p><i>
-            If you understand the risks, that information may be unavailable 
and operations may fail, 
+            If you understand the risks, that information may be incomplete 
and operations may fail, 
             and wish to proceed regardless, click <a 
id="dismiss-standby-warning">here</a>.</i></p>
 
 <% } else if (healthy && !master) { %>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d0f1a0e/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java 
b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
index a1ac60c..d779f68 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
@@ -88,6 +88,11 @@ public interface ServerApi {
     public boolean isUp();
     
     @GET
+    @Path("/shuttingDown")
+    @ApiOperation(value = "Returns whether this server is shutting down")
+    public boolean isShuttingDown();
+    
+    @GET
     @Path("/healthy")
     @ApiOperation(value = "Returns whether this node is healthy - fully 
started, not stopping, and no errors")
     public boolean isHealthy();
@@ -102,7 +107,7 @@ public interface ServerApi {
 
     @GET
     @Path("/up/extended")
-    @ApiOperation(value = "Returns extended server-up information, a map 
including up (/up), healthy (/healthy), and ha (/ha/states) (qv)")
+    @ApiOperation(value = "Returns extended server-up information, a map 
including up (/up), shuttingDown (/shuttingDown), healthy (/healthy), and ha 
(/ha/states) (qv)")
     public Map<String,Object> getUpExtended();
 
     @GET

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d0f1a0e/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
----------------------------------------------------------------------
diff --git 
a/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java 
b/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
index ecefd4c..a9a2225 100644
--- 
a/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
+++ 
b/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
@@ -277,6 +277,16 @@ public class ServerResource extends 
AbstractBrooklynRestResource implements Serv
     }
     
     @Override
+    public boolean isShuttingDown() {
+        if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), 
Entitlements.SERVER_STATUS, null))
+            throw WebResourceUtils.unauthorized("User '%s' is not authorized 
for this operation", Entitlements.getEntitlementContext().user());
+        Maybe<ManagementContext> mm = mgmtMaybe();
+        if (mm.isAbsent()) return false;
+        ManagementContext m = mm.get();
+        return (m.isStartupComplete() && !m.isRunning());
+    }
+    
+    @Override
     public boolean isHealthy() {
         if (!isUp()) return false;
         if (!((ManagementContextInternal)mgmt()).errors().isEmpty()) return 
false;
@@ -287,6 +297,7 @@ public class ServerResource extends 
AbstractBrooklynRestResource implements Serv
     public Map<String,Object> getUpExtended() {
         return MutableMap.<String,Object>of(
             "up", isUp(),
+            "shuttingDown", isShuttingDown(),
             "healthy", isHealthy(),
             "ha", getHighAvailabilityPlaneStates());
     }

Reply via email to