Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

"Website will be down for maintenance" implementation  RSS feed

 
Saurabh Pillai
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So we need to inform all active users of the website that "Website will be down after so and so time for maintenance".

This is how I see the implementation.

User can be in any part of the application. So any time user request comes to server, it goes through the controllers. I can write a method (and call from each controller) that checks if message needs to be displayed. Put that into application context and display it. Along with that I will also have a flag that keeps track that if the message has already been displayed or not (to the user). If message has been displayed, no need to call that method again.

Any inputs?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saurabh Pillai wrote:and call from each controller

It is completely unnecessary to infect each and every controller with this undesirable extra code. Look up how to use servlet filters.
 
Saurabh Pillai
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I have implemented this and it's been working great. I am bit concerned about amount of queries it executes so I want to improve it. I am thinking about using cookies. A Cookie to decide whether to show the message or not. For "very first request" (when cookie is not present/ cookie expired) , it will create a cookie and use it to display message. In this way for every request, it does not need to hit the database.

Any comments/suggestions?

PS:- I have not implemented cookies before.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to hit a database to show a "site is down" message?
 
Saurabh Pillai
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The message we show is, "Website will be down in X minutes." So that users have time to prepare for it. This message is shown in advance for upcoming take down.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Why do you need to hit a database to show a "site is down" message?
 
Saurabh Pillai
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not fix when we take down the website for maintenance. So let's say we decide to take down after 2 PM. We make an entry into the table and mark it as an active entry. Now, for every request it looks into this table, if it needs to show the message. If there is an active entry, it calculates the minutes after which system will be down and displays the message. I hope it is clear now.

Is there a better way?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do not want to incur database hits in order to determine if and when the system will be down, then don't store that info in the database. Cookies aren't useful because those are stored on each user's browser and you need to know when to set them, so that's no good.

I'd store the info in a properties file for quick and easy access without the need to involve the database.
 
Saurabh Pillai
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Cookies aren't useful because those are stored on each user's browser and you need to know when to set them, so that's no good.

I don't have any experience with cookies. But this is how I see it working. You look for cookie in request, if found, pass it as an attribute. If it is not found, set it and also pass it as attribute.

Bear Bibeault wrote:I'd store the info in a properties file for quick and easy access without the need to involve the database.

How do you make it dynamic then?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it need to be dynamic? Read it once to get the down time and store as a scoped variable in app context. The filter can check to see if it's there and compute the interval for display. Remove the scoped variable when the time has passed.

If the time needs to be variable, the filter can read the properties file on each invocation, which will still avoid hitting the database.

Depends upon your requirements.
 
Junilu Lacar
Sheriff
Posts: 10880
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you might want to look at some of the advice here: http://moz.com/blog/how-to-handle-downtime-during-site-maintenance

If your webapp is not actually going to be brought down but rather you just want to temporarily disable it, you can set up a "maintenance window check" filter in front of other filters that does something like what Bear described. We have this in our apps and it's useful when we just want to do maintenance work on the database and not bring down the app itself. In our case we have the filter look in the application context for an object that has maintenance window information. If that object is there, the filter can decide to block further processing and generate a 503 error (see a list of error codes: http://www.informit.com/articles/article.aspx?p=29817&seqNum=7)

Your web.xml can be configured to show a certain resource when you get a 503 error. See http://www.onehippo.org/library/concepts/error-pages-and-error-handling/1.-handling-error-codes-and-exceptions-by-the-web.xml.html

You can have an "admin" route/URL/service that's only known to admin folks and they can submit a request to that URL to setup a maintenance window. The request is first authenticated and authorized and if successful, it processes the request and puts a "maintenance window" object that the filter I mentioned before is checking for. You can either have the maintenance window object contain expiration date/time or you can have the maintenance window filter check for other parameters that indicate that the current maintenance window is to be terminated. There are a number of variations you can introduce to this design but that's the general idea.
 
Saurabh Pillai
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext is the key here. I will accommodate this and let you guys know.

Thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!