Handling multiple environments

classic Classic list List threaded Threaded
3 messages Options
Tim
Reply | Threaded
Open this post in threaded view
|

Handling multiple environments

Tim
Hello,

We have a legacy system comprising two servers and up to 5 different environments that look a bit like this:

TEST_SERVER --> Dev / Test / QA / Ref
LIVE_SERVER --> Live

So the TEST_SERVER has 4 environments and the LIVE_SERVER just the one. To add to the confusion, the servers host both the RESTlet instances (under Tomcat) and the "backend" database, and the web apps are able to connect to the databases of either machine. In other words, you can be accessing the HTTP server of the test machine, but connect to the database of the live machine.

For reasons explained here http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3075356 I'm trying to develop a system using RESTlet where the "model" is implemented using stored procedures on the back-end system which can be mapped to URLs by configuration alone. The idea being that to implement some new business logic a stored procedure is written and then a new URL template mapping to that procedure is added to the configuration (and the app restarted to reload the routes). My RESTlet application provides the glue between the stored procedures and the web and automatically maps the parameters in the URL template, query parameters etc. to the stored procedure parameters prior to the call. The result from the stored procedures is then used as the model for Freemarker templates to create the desired representation, according to the "accepts" header and the template provided in the configuration for the stored procedure in question.

Although it's very much at the prototype stage it seems to work very well so far (largely thanks to Tim's help in the thread mentioned above!).

My problem is how best to deal with the multiple environments and especially how to make sure that relative URLs stay relative to the correct environment. I suspect this would be a good case for virtual hosts, with a separate VH for each environment like this:

http://{env}.TEST_SERVER:8080/ where "env" is the database/environment. This way I guess any URLs relative to the root ref will point to the correct environment.

However, our network set-up doesn't allow me to use sub-domains, and that isn't likely to change, so I think the only other approach I have is to do this:

http://TEST_SERVER:8080/restlet/{env}/

In this case, I would like the URL above to become the root so that any relative URLs specified are always relative this base part and it can be added to the Freemarker model to enable templates to generate URLs for links etc. with the correct base.

I thought perhaps this could be done by chaining routers such that the initial root is this:

http://TEST_SERVER:8080/restlet/{env}/

and have a restlet attached which changes the request's "rootRef" to the "resourceRef" and then chaining the routers for the remaining part of the URLs after.

Would this work or is there a better way to approach the whole problem? Any ideas and suggestion would be very welome!!

TIA,

Tim.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3083882
Reply | Threaded
Open this post in threaded view
|

Re: Handling multiple environments

Jerome Louvel-3
Hi Tim,

As long as your template use proper relative URIs (not starting with any '/', but potentially with '..' to move up the hierarchy then you should be fine with a http://TEST_SERVER:8080/restlet/{env}/ base URI.

You don't need to manually change the "rootRef" or the "resourceRef" as this is already done automatically during the call routing. To get the current base URI, you just call request.getResourceRef().getBaseRef() or getRemainingPart().

Hope this helps,
Jerome



On Wed, Jun 25, 2014 at 2:32 AM, Tim <[hidden email]> wrote:
Hello,

We have a legacy system comprising two servers and up to 5 different environments that look a bit like this:

TEST_SERVER --> Dev / Test / QA / Ref
LIVE_SERVER --> Live

So the TEST_SERVER has 4 environments and the LIVE_SERVER just the one. To add to the confusion, the servers host both the RESTlet instances (under Tomcat) and the "backend" database, and the web apps are able to connect to the databases of either machine. In other words, you can be accessing the HTTP server of the test machine, but connect to the database of the live machine.

For reasons explained here http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3075356 I'm trying to develop a system using RESTlet where the "model" is implemented using stored procedures on the back-end system which can be mapped to URLs by configuration alone. The idea being that to implement some new business logic a stored procedure is written and then a new URL template mapping to that procedure is added to the configuration (and the app restarted to reload the routes). My RESTlet application provides the glue between the stored procedures and the web and automatically maps the parameters in the URL template, query parameters etc. to the stored procedure parameters prior to the call. The result from the stored procedures is then used as the model for Freemarker templates to create the desired representation, according to the "accepts" header and the template provided in the configuration for the stored procedure in question.

Although it's very much at the prototype stage it seems to work very well so far (largely thanks to Tim's help in the thread mentioned above!).

My problem is how best to deal with the multiple environments and especially how to make sure that relative URLs stay relative to the correct environment. I suspect this would be a good case for virtual hosts, with a separate VH for each environment like this:

http://{env}.TEST_SERVER:8080/ where "env" is the database/environment. This way I guess any URLs relative to the root ref will point to the correct environment.

However, our network set-up doesn't allow me to use sub-domains, and that isn't likely to change, so I think the only other approach I have is to do this:

<a href="http://TEST_SERVER:8080/restlet/{env}/" target="_blank">http://TEST_SERVER:8080/restlet/{env}/

In this case, I would like the URL above to become the root so that any relative URLs specified are always relative this base part and it can be added to the Freemarker model to enable templates to generate URLs for links etc. with the correct base.

I thought perhaps this could be done by chaining routers such that the initial root is this:

<a href="http://TEST_SERVER:8080/restlet/{env}/" target="_blank">http://TEST_SERVER:8080/restlet/{env}/

and have a restlet attached which changes the request's "rootRef" to the "resourceRef" and then chaining the routers for the remaining part of the URLs after.

Would this work or is there a better way to approach the whole problem? Any ideas and suggestion would be very welome!!

TIA,

Tim.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3083882

Tim
Reply | Threaded
Open this post in threaded view
|

RE: Re: Handling multiple environments

Tim
Hi Jerome,

Thanks for the reply, I will check that out and see how I get on.

Tim.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3084078