One application code with multiple contextpaths/deployments to connect to different databases - java

Encountered a requirement in our team when trying to migrate a WebSphere application into Tomcat and deploy onto Pivotal Cloud Foundry to have same application to connect to two different databases which have entirely same schema with different data, essentially having same application code deployed in different paths and be able to connect to the databases based on the URL being called for accessing the application.
Currently, we handle this situation in Websphere by using the deployment script to deploying the application into two servers and give the different database details in JNDI and access the application using the server names.
We use Jenkins to deploy the application onto PCF.
Tried to use maven to deploy on to different context paths which did not help and have ended up in the loop, Have anyone encountered a situation like this, Any thoughts would be appreciated.

I think there are a number of ways you could handle this.
Modify your application so it's aware and let's you pick. Perhaps have a query parameter to select or /dev/blah goes to one DB and /test/blah goes to another.
Push the same application twice, but bind different databases and routes to each app.
Attempt to run two instances of the same app code inside Tomcat in one app on CF.
Of those, #1 is fine but would probably require code changes. #2 would be my choice as it's very quick to do, #3 would be a lot of work because you'd be fighting against the Java buildpack, which is not recommended.
To accomplish #2, you would do the following:
Push your app code as app-A.
Bind the database service.
Map a route with a context path like my-cool-app.example.com/app-a.
Start your app.
Repeat the same for app-B, but use a different database and route/path (i.e. my-cool-app.example.com/app-b)`.
If you are deploying a WAR file, you will need to tell the Java buildpack to deploy your app on a context path (it should match the route context path you set).
cf set-env my-application JBP_CONFIG_TOMCAT '{tomcat: { context_path: /app-a }}'
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/container-tomcat.md#common-configurations
If you're using Spring Boot and a JAR deployment, you'd need to set server.contextPath=/app-a.
Hope that helps!

Related

How to deploy a Vuejs application

My application has two separate parts, back-end in Java (Spring boot) and front-end in Vuejs.
I can simply deploy the JAR for my back-end code where I need to, and that's it for deployment.
But when it comes to deploying the Vuejs app, I can do something similar and just put the compiled Vuejs application in the proper path in a Java Spring boot application and that will be all for the front-end too.
It just doesn't seem right to me to put that application in Spring boot when it doesn't really have to do anything with it really other than for deployment (Maybe I know nothing like Jon Snow).
Also, when its put under a Spring boot application, manual URL editing doesn't work.
This app doesn't do anything on its own, it fetches all its data from the back-end app.
So what are my options here, can someone please guide me in the right direction?
Do I just setup a nodejs server and deploy the Vuejs app in that? I am not sure how that works, or whether should I even be doing that for a production application. And if so, where do I start with setting up nodejs?
It makes sense to deploy it together with spring, and it's very common practice, at least from my experience with Angular (which I suppose would be very similar to VueJS).
You don't need to have 2 servers running. You just let Spring server your HTML/js/CSS files, which helps you avoid any problems with CORS.
I am not really sure what 'URL manual editing', do you mean by navigating the web page by editing the URL? I don't see much use cases there tbh and I would guess that is only a matter of few settings.
In gradle - I would set up a build task (not sure if task is correct word, 2 build.gradle files, each for FE/BE, the BE would depend on FE), the FE would be run when BE is run, it creates static HTML/js (in my case from angular, but it should be similar for Vue) and BE task adds the output to the classpath of the java application so that Spring can register the HTML and serve it to you.
You could use Docker to create a Dockerized version of your Vue.js app and then you can deploy this onto a cloud service provider such as AWS (e.g. EC2).
Check out this link for a basic guide https://v2.vuejs.org/v2/cookbook/dockerize-vuejs-app.html
My approach is to deploy front-end and back-end separately.
You can use web-server to proxy requests to Vuejs or Spring boot.
For example, if you use Nginx, you can use this configuration to pass requests
# pass root request to index file
location / {
root /front_files/;
index /index.html;
}
# pass requests to static files
location ~ ^/(js|styles) {
root /front_files/;
}
# pass requests to back-end
location /api/ {
proxy_pass http://127.0.0.1:8080/;
}

What's the procedure of upload a java spring based web application to the real server, and how to use load balance to the server?

I am creating a simple web project with mysql database using Java Spring-MVC. Now I want to understand the full workflow of the web system development cycle.
How to upload a project to a real server?.
How to sync the database to a real server?.
How DC and DRC is sync with each other?.
Why and how to use "Load balancer" to the server?.
Apologize, if I said something non-technical.
I'll not go into too much details but here is the gist of it.
Before anything, the first thing to get sorted is the operating system of the server be it Linux, Windows Server and so on. The choice of operating system will depend on the constraints and requirements.
How to upload a project to a real server?
Any files which needs to be served should be hosted and served by a web application server such as Apache Tomcat, IIS, Websphere and many more.
The choice of web application server depends on a few things, such as the server operating system, the web application implementation and so on. For your case, which is a Spring MVC implemented in Java, you'll need to use a web application server that supports that, such as Apache Tomcat for example.
Once the choice is made, install the web application server on the server. After that, install your web application on the web application server.
How to sync the database to a real server?
I infer that you're referring about the connectivity between the Java web application to the database? Do comment if its not.
The Spring MVC web application can connect directly to the database via JDBC or JNDI (provided that the necessary configuration is configured on the web application server).
Of course, the database can be connected locally (if installed on the same server) or remotely.
How DC and DRC is sync with each other?
This is too broad to cover and the recovery strategy differs for every Data Center providers. But broadly, they employ redundancy and replication strategy to ensure the data is always backed up and available. Check with the providers individually for a better picture.
Why and how to use "Load balancer" to the server?
The load balancer primary purpose is to distribute the work load across multiple servers to achieve better TTFB. To do so, it sits in front of the servers and routes the request accordingly. Some of the load balancing solutions such as f5 explains about load balancing in greater detail.
Step 1: Install Application Server on your machine.
Step 2: Install JDK, Database server which are dependent on your application.
Step 3: Export your war from Eclipse/Netbeans
Step 4: Paste your war file on app server's deployment folder (webapps incase of tomcat)
Step 5: your application deployed

Container-less java application in openshift PaaS

Is it possible to deploy container-less java application in Openshift PaaS? Everybody knows that java server application can be created using embedded jetty which bypasses the need of any java application server like jboss/weblogic, hence saving a lot more resources in terms of memory in a resource constraint environment like cloud. As Openshift started supporting vert.x, I am curious is it possible to deploy container-less java application there?
The intended application logic is more or less like this : http://www.jamesward.com/2012/08/13/containerless-spring-mvc
I know openshift does not offer cartridges like this, but I am eager to know is it possible by creating a diy cartridge?
You should be able to use the DIY cartridge and use action hooks to start your application any way that you want to.

Deploying a Java Web Service on a server

I have been asked to create a JAVAX-WS web service which basically performs some basic computation on the input to return the output. I also need to lookup some values from a database.
I am using this book :
Java Web Services: Up and Running
What I've done so far :
1. Created the main java program containing the methods that perform the computations.
2. Used wsgen and wsimport to generate the various artifacts.
3. Used Endpoint to publish the service on localhost.
What I need to do :
I need to get it running on something like a windows server for .NET services. So that it can serve multiple machines.
I know next to nothing about web services and servers, and have just gone through the first chapter of the aforementioned book so far.
From what all resources I've gone through I believe I could use GlassFish, but I don't know if it serves my purposes.
So if anyone could point to some helpful resources for the same, it would be extremely helpful.
P.S : I have no idea about looking up the required values from the database, so please point to some resource for that as well.
Endpoint can also serve requests concurrently, you can enable thread pooling by creating a ThreadPoolExecutor and registering it with the endpoint. See Endpoint.setExecutor(Executor executor)
If you want to deploy your Web Service on GlassFish you should change it into a WAR project, see http://docs.oracle.com/javaee/6/tutorial/doc/bnayl.html

web application auto install

I need to have an autoinstall/update a web application running on JBoss 6.
I need at least to:
* stop the server
* copy the war in the deployment directory
* apply DB update scripts
* start the server
Do you know an tool or open source project for that?
Thx
Christophe
Most Servlet containers have the ability to deploy without stopping the server. Some do it by dropping the WAR file in a specific directory which is polled by the webserver (if configured properly) while others expose "upload" web APIs.
JBoss typically uses Tomcat as its servlet container. While I don't know which version your version of JBoss is using, Tomcat has supported deploying on a running server for a very long time. Perhaps the documentation for Tomcat 5.5 is enough for you to determine what changes (if any) you need to make.
In the event that you really need to stop the server Tomcat has the ability to stop the server from an external program (it only requires the right kind of message to be sent); however, once stopped, Tomcat can't receive a "startup" message, it will have to be started manually.
A better solution would be to detect when the application started by looking at servlet lifecycle events, and then to "check" the database upon a "first started up" event. In the off chance that your database detection shows the database doesn't match the expected version, apply the changes. After the database detection shows the database is up-to-date, then start normal request processing. This isolates the code within your web application in such a manner that allows for easy deployment and upgrades, although it does mean more work in tailoring the application to encapsulate it's own database maintenance duties.
In the event that such a technique isn't an option, you will have to rely on an external tool to get the job done. Typically such a tool requires heavy integration of resources (sometimes across multiple machines). In such a case, an Enterprise Job Scheduler, or a workflow engine (with your own written adapters) is generally applied to solve the issues at hand.
For information, we finally implemented our own solution. Basically
One job downloads from a FTP a ZIP file containing an installer application written in Java
One unzipped, the installer is run. This one executes SQL update scripts, then deploy the WAR file using the JBoss JMX API. However for JBoss cluster support, we had to write our own MBean in order to copy the WAR file on each node.

Categories

Resources