2010/02/18

How to provide settings to your applications part two

How to provide settings to your applications
part two
using your database



This is a second look at providing access to settings.  For the original please see http://gcruscoe.blogspot.com/2010/01/how-to-provide-settings-to-your-web.html

Overview

Please read the original article and then come back.  I'll wait, I promise.

Okay, great, glad you're back.  We are now going to supplement the previously described procedure to make the system more robust.  In order to do so we will need to look at what drawbacks there are to the method and how we can overcome them.  The description here is going to describe using a database for this approach although with a little imagination, we could come up with many different ways to get these settings.


Details
The rest of this article will focus on the setting up application servers, applications, and databases to handle settings that can change in different environments.  There are many aspects of this that will stay outside the scope of this article, like setting up the databases, proper naming conventions, etc.

So after our last look into property files, we have decided not to hard code the settings into the applications, and not to make a build specific to a particular environment.  But we still need all of the information in the application when it is built.  So what happens when a new environment is setup or an existing one changes?  This will require changing the properties files and redeploying the archive to all of the machines.  There has got to be a better way we must all be thinking right now.  And of course now we now that putting these settings in the database can offer us many benefits.  Most importantly all we need to do is change the settings in the database and the app will automatically get these new changes.  No deployment necessary.  It does has the drawback on requiring a database, but if the application already has that requirement then this is a non issue.  If it is an issue then there are plenty of other ways this can be handled.  A JNDI look up to an LDAP server, a web service call, etc.

For now we are going to focus on setting up our application to use the database.


Lets look at this in more detail...

Because you can setup a datasource at the container level, we have to question whether we even need the aforementioned, ServerEnv variable at all.  Each application server is setup to talk to a database in its environment (DEV, TEST, PROD, etc.) -- so why do we even need a setting?  You might not.  However there are situations where different types of servers may talk to the same database so in this case you will still need the ServerEnv variable.  We want the container to know what environment its in just in case.  The implementation of this is app/web server dependent but in general it will be something along the lines of edit the server.xml for your container or domain and add a system property ServerEnv pointing to the appropriate Environment.

e.g.
<jvm-options>-DServerEnv=DEV</jvm-options>

Okay now that that's set (and the app server is restarted), what else do we need?  We need a way to talk to the database -- again this is out of scope but we are going to assume there is a datasource setup for the app server and our application will be able to talk to it without knowing where it came from (this is of course a very common and highly recommended way to set up a system).

So our application needs at least one piece of information to be deployed with it -- the application name.  You can expand on what information is required as needed for security but we'll keep it simple here.  So the application will have a small property file that will contain its name and for fun you may want to add a version number.

When the application wants to get its settings, it will get them from the database that is linked up with the (or one of the) data source(s).  Okay so then the application gets all the properties using the getProperties(filter) library command that is included in every new application.  This only needs to be written once and everyone gets to benefit. 

What goes into the filter?
  • app name
  • version
  • environment

So the database has everything it needs to find properties.  Of course it can be normalized or just a string concated together, but the idea is that each key contains

appname.version.environment.propertyname = value

and you get all the properties from the database and then in the application you have your hashmap of just

propertyname = value

So now the archive can be deployed anywhere -- even in environments that were not thought of when the application was made.  All that is necessary is to create the appropriate settings in the database for each application.


Summary
So in summary, the ServerEnv needs to be in every server so that each server can fine tune what information it needs from the database.  The application only needs to know its name and version.  One build can go to any environment, even if it doesn't exist yet.  Each database connection is setup for the app server so the app doesn't even need to know about that.


Happy Coding!






2010/01/27

How to provide settings to your web a...

How to provide settings to your web applications


Overview

An app shouldn't need to know what environment its going to be deployed into, however the maker of the app should know about the resources that are going to be required.  So there are [at least] two good ways to do this.  Store all the settings for an application in the database and then the only thing that is required is the database configuration for each environment -- which is usually handled by the container.  Or you can have all of these settings in in property files with an extension that indicates which environment (DEV, PRD, etc.) that the setting is for.

The down side to the database is that anyone can change a setting that they think is only for their app and it will change all of the apps that are using it.  The downside of having the settings in a property file for each app is if the resource does need to change it requires the change to be made in all of the applications.  It is similar to the battle between deploying dependent libs where they are accessible to everyone all at once or deploying the dependent libraries with each application.


Details
The rest of this article will focus on the later approach.

So we have decided that we want all of the settings in property files.  And we want each container to know what environment it is in.  Then we will have a library that will pull the correct setting for the property depending on the environment.  This library will be reused between all applications as part of the common framework.

Lets look at this in more detail...

We want the container to know what environment its in.  The implementation of this is app/web server dependent but in general it will be something along the lines of edit the server.xml for your container or domain and add a system property ServerEnv pointing to the appropriate Environment.

e.g.
<jvm-options>-DServerEnv=DEV</jvm-options>

Okay now that that's set (and the app server is restarted), we need to create our newly styled property file.  Oh but what does that look like?

Create a file myApp.properties and it would contain this:

# First we have LCL (Local)
theOtherServerLCL=192.168.1.1

theUserIdLCL=dev_user

# Now for DEV (Dev :-))
theOtherServerDEV=192.168.1.1

theUserIdDEV=dev_user

# Now for FT1 (Test)
theOtherServerFT1=16.32.64.128

theUserIdFT1=test_user

# Now for PRD (Production)
theOtherServerPRD=10.20.40.80

theUserIdPRD=prod_user

Now for more information about the available environments.  This really depends on the system architecture for the application or department but probably something like this:

LCL, DEV, FT1, FT2, TRN, PRD

Note that local (LCL) should probably have the same settings as DEV, but we can do additional optimizations like not combining resources so the build time is less, but by the time it goes to DEV it is the integrated build.  We'll talk more about those another time.

Next is the important decision of how to split up property files, but we'll also leave this for a different post.


Summary
So in summary, the ServerEnv needs to be in every server so that each server can indicate to the applications what environment it's in.  Each application should include all of the settings that it will need for all environments stored in its property files.  One build can go to any environment, and each environment doesn't need to know about all the possible configuration settings needed for the applications.


Happy Coding!






2009/04/23

The Setting Sun

You don't know what you've got, 'till its gone they say.  And I do believe its true.  Although, I've know for over a decade that Sun was the best company.  So many didn't see it that way, but it was so clear to me -- and it got better with every passing year.  Their products ranged far and wide.  The one that pulled me in was Java, but over time you learn about all of the other parts of the stack.  And over time that stack grew.  By the time they added mysql to the mix they had everything from the hardware, OS, the incredible ZFS filesystem, the JVM (and all those languages that it supports), Java, Java EE 5 (which IMO is the best framework ever created) and the mysql database.  To mix this into an enterprise you have the ldap and access manager providing single sign on and a portal.  Simply the most amazing stack, and they give it away to get you going and then offer support (a.k.a. RedHat's business model).  They had everything except good profits for their shareholders.

I believe in the freedom you don't get from Apple and Microsoft.  I also believe in products that have proven themselves.  I believe that there are many answers for the same problem, but some just feel better than others.  For the most part, Sun's solutions felt right.  There were certainly exceptions along the way, which I will not name here, but over time they were always improving them.  Always pushing forward, trying to make things better.  It seems that they were always improving.  Improving their products and improving their stack.  At this point it seemed that they were so far ahead of the competition in what they had put together, you would think that they would have been the monster everyone feared.  But they were not.  Instead this tech that Sun amassed is to be ripped apart for the benefit of others.

And so here lies Sun, sold to make a few dollars per share never to push forward again.  Could it be that they couldn't have survived?  Or was it really just the share holders wanted their money back.  I can't help but think about how many people didn't support them, all those other ways of doing things, their technologies didn't get the respect they deserved.  JavaFX could have been a great UI scripting language, Java EE 5 was a great platform for writing server code, JSF and Ajax worked great together, but now all we are left with is their competitors (free and proprietary alike).  I guess it doesn't really matter, they have been gobbled up by corporate America like everything else.  Their game changing days are over and I see an unsure future unsure ahead after having my path so obvious before me for so long.  It is the end of an era.  As with any end there is a new beginning, a new day, but this dawn will have to go on without the Sun.


R.I.P.
Sun
1982-2009

2008/05/15

First Thoughts On Java One

After attending JavaOne this year, I am more excited about Java then ever -- of course if I wasn't there would have to be something wrong with me or JavaOne. Anyway on to my take on some of the cool new technologies and how I see the current Java Space developing.

First off, I've been telling people for a long time that the best way to develop applications is to create a UI (probably best to use Swing) and have it connect to an app server to offer a consistent view of your data no matter where you run the app. I've also been trying to tell everyone that Java Web Start rocks. Well interestingly enough, this is _exactly_ what people want. Now of course they've given it the fancy name, RIA (Rich Internet Application for those freshly out of a timewarp from 2001).

Now I'm not going to tell you that AJAX applications suck -- in fact quite the opposite. If I have to run an app in a web browser, I really do hope it uses AJAX. However, for running applications, I'd rather them not run inside the web browser at all. In fact I'd like to only need to use the web browser to find the app in the first place. After that, I really don't want to go to my web browser to launch applications. Secondly and more importantly to me... I don't want to have to tie together a bunch of miscellaneous toolkits and custom javascript to make a web browser do what it is not yet meant to do. In addition, since the web browser's applications are, by definition, only available when you are connected to the Internet, I don't want to be limited in that way either. I know what you're thinking, google gears and blah and blah. Do you not see what we're doing? We are getting out the duck tape and the chewing gum and doing everything possible to make the web browser something its not.

In addition, every time I restart my web browser (or it crashes), I don't want all of my applications going down with it. Or if one application crashes, I'd hate for it to take down all of my other applications and the web browser.

Okay enough rants about why I think separate applications are better than everything running in the browser. On to more interesting things... Like synchronization of disconnected distributed applications. Basically this is all about if you have a central repository for all your data, but you want to be able to run in a disconnected mode (think on an airplane or no Starbucks near by :-)) then you want to be able to run in disconnected mode. Well if the data is updated on the server by someone else and you update your local copy, this has to be resolved. In the source code world, we often call this conflict resolution. In the app and data world we are calling this synchronization. Anyway you get the point. I'll save the gory details of this for another time.

So here we have it, great independent apps, data synchronization and a central data respository (it is doing backups and versioning isn't it?).

So what's missing? Oh yeah, a super cool user interface. And that's what most of this Java One was about -- at least for me. There were many other topics (SOA, JPA, new web toolkits, and on and on). But for me, right now I want to make apps that make you say wow (and of course have them connected to the servers, etc, etc...).

This is the type of app (RIA) that I have been focusing on for quite a while and now I'm ready to try to start adding the
"wow" part. Please go check out all of the great information (google: JavaOne). Soon I will be talking about my JavaFX coding experiences as well. For right now I just want to say how cool its bind feature is. Oh yeah, and built in SceneGraphs. I will also be adding SceneGraphs to my code to enable 3D effects to regular swing components (basically put a panel onto the SceneGraph node and do with the node what you will). So much exciting stuff to play with!

Can't wait to add some new applications to my web site. Stay tuned! So I will be adding some more details about the new application development details as I get some time to get into them some more.

Please let me know what you think!





2007/01/08

Okay, so it has been so long and I still haven't published the papers on No Silver Bullet I was talking about. I actually have split it into two papers and have the first one finished, but I want to read it and procrastinate some more. In the mean time, I figured I better put something up here after looking at my friend's website and Blog Chris Lynch Programming. So since I don't have a whole lot to say as of yet, let me start by saying that after reviewing my friends Blog entries (Jan 3rd -> 7th) I think I must try the following:

  • Brain Age
  • MyBrainTrainer.com
  • Sheep Dash!
  • Keep up with Chris' s Progress
  • Work on my hand eye coordination and work on parts of my brain that don't function very well (both of these can be accomplished using the 17 button two joystick Sixaxis controller for the PS3). I think the best tool for this will be Resistance - Fall of Man.

So a big part of my regiment is going to be playing PS3 games. That is pretty darned exciting I must say. Another thing is playing the Brain Age types of games, which for me is going to include
weboggle (google it), and Lemmings (PS3). Of course I will continue my work with Web Services, Java SE 5, Java EE 5, and Java ME.

I will also continue to look for the best available phone/PDA combo. My current criteria are:
  • Linux
  • Java
  • Qwerty Keyboard
  • High speed connectivity in my Area
  • GPS


Not sure if this qualifies me for the Enhance-athon...



2006/10/21

Welcome

I have just created my account and am getting ready to post a response to some information I have recently read about the famous "No Silver Bullet" article. Please come back soon!