How to create user defined routes in cloud foundry for deploying java application
We all know that sometime there is a need for having different URL for the existing java application, in that case we find it difficult as how we can have the different URL altogether with same piece of code without hindering the existing application
Sometime there is a need to deploy brand new application into any specified workspace in cloud foundry at that point of time it is always advised to have new routes created so that our application could be deployed to the cloud foundry without impacting already running application instances.
This blog shows step by step description as how we can create new routes in cloud foundry and how that can be binded with new application instance.
let’s consider that you already have a java application created if not then please create a simple maven project with basic api calls
- If everything is working fine, please navigate to cloud foundry cockpit and navigate to your account and create the DB instances if you don’t have any, if the DB instances is available you can ignore this step
Account overview page:
Navigate to spaces where you want to create the route, incase no space is there you can go ahead and create a new space
When you navigate inside any space and if you have any application running you will see screen like below and then you can locate the routes on the left-hand side of the screen
Once you click on route, it will show the routes along with mapped application, in case if we don’t have any routes it will be blank, and we have to click on new route
Click on new route and provide all the required details which we want for our application, here you see domain field where we can go ahead and select the domain which we want to use for our application and host name would again be user defined which we want to use for future references.
For reference I am taking the domain name as cfapps.sap.hana.ondemand.com from the dropdown and host name I m defining as DB-demo–dev
–dev denotes the owner of that route in demo space
after entering the details click on save button
Now we see that new route is created but under the mapped application column we don’t see any application name ye under mapped application, reason being no application is deployed with the new route, there are two ways either we bind the existing application with new route or we deploy the application to new route, I would recommend deploying application to the new route to avoid inconsistencies.
Now we might have the question how to deploy the code to the new route, for that we to make minor changes at our code level, we need to locate your manifest file which we will be deploying to the cloud foundry, there in the manifest file we have to define the route
Here in the above code snippet, you can see that I have specified the app name as DB-demo-api this app name would be created once the application is created to the specified route DB-demo–dev but in the code snippet you see it as DB-demo–((owner)).((domain)) where owner is dev and domain is the name of the domain that we selected from the dropdown while creating the route.
Now since we have made the changes, lets deploy the code to cloud foundry via cmd-cli
Cf login, enter the credentials, select the org, select the space
Now change the directory to locate your code base having the path to manifest file which you want to deploy
Change directory to the project path as
cd <location of manifest file>
then set owner=dev, set domain= cfapps.sap.hana.ondemand.com
then finally push the code to cloud foundry with
cf push –var owner=%owner% –var domain=%domain% -f manifest-dev.yml
Once the code is pushed successfully you can see the cmd screen stating that code is deployed successfully, and app is started
Now if we navigate to cloud foundry cockpit, we will see that new application is deployed with defined route
Also, the application screen will show the deployed application
Now in-order to test the deployed application we need to take the application detail url which we can get after clicking on application link
Now go to postman and hit the request with get call having the endpoint as system which will look like
system is the endpoint which shows the details from the system table
Please do comment and give your feedback if something could be improved.