how to deploy an app on glassfish without without crashing the service? - java

I have an app that take long time to deploy/redeploy because this use EJB3, JPA2, JSF, Icefaces
The app is deployed on glassfish 3 on ec2 in amazon web services. Each i redeploy the app, while is redeploying the app, the service isn't available.
How can i redeploy an existing application and still the service available, until the redeploy finish?
thanks in advance

Depending on your architecture, you will always lose the service for a few seconds whilst you redeploy.
The proper way to architect this would be to have a software load balancer sitting in front of 2 or more glassfish server instances which are set in a cluster. The load balancer will automatically route all requests to the server holding the older available service. Once the new service is up and running, it will route requests there again. Using mod_jk inside apache works well as the load balancer.

Related

Need to deploy a container to multiple KIE servers running behind a load-balancer

I have a docker swarm running multiple services. One of these services is a KIE server. I use Bamboo to deploy my services and I need to be able to do the same (automated deployment) for the kJar into my KIE server.
Also, I will have multiple replicas of this KIE server running so I need to be able to deploy to all of them. They will be running behind the Docker swarm load-balancer.
My question is how can I do this? The only methodology I've seen so far is to place the kJar into the .m2 directory of the server and then use a REST call to create the container.
This would work fine for a single server but not for many behind a load-balancer.
Has anyone else done this and, if so, how did you implement it?

How do I automatically restart tomcat in linux

I have created a Spring Boot microservice and hosted inside a Tomcat on a Linux machine.
Everything is inside the container and the container is inside the IBM cloud private platform.
Now the microservice should be running continuously.
But suppose for any reasons the microservice got stop or tomcat got crashed.
Is there any way we could restart the Tomcat server or microservice automatically without manual intervention?
Why are you deploying a Spring boot app in your local tomcat? By default Springboot comes with embedded Tomcat server in it, so if you just build and run the jar, a tomcat will be started with the service itself.You can also , configure the server type(tomcat or jetty) and other server properties in the application.yml file. More details here - https://www.springboottutorial.com/spring-boot-with-embedded-servers-tomcat-jetty
Coming to the second part, of the question,about how to make sure , that if one service crashes, a new instance should be started automatically, for this you might be needing to do some reading on container managers like dockerswarm or kubernetes, which support auto-scaling, and can take care of restarting services (pods) as and when required,they can even scale up, meaning increase the number of instances of a service if existing containers reach a resource usage threshold and then load balancing requests to that service through some discovery and registry client.I think this would be helpful to you - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy

spring boot application in cluster

I am developing a spring boot application.
Since spring boot created a .jar file for an application.
I want to cluster this particular application on different server. Lets say I build a jar file and ran a project then it should run in cluster mode from number of defined servers and should be able to serve end user needs.
My jar will reside on only one server but it will be clustered across number of servers. When end user calls a web service from my spring boot app he never know from where it is getting called.
The reason behind clustering is suppose any of the server goes down in future, end user will still be able to access web services from another server. But I don't know how to make it clustered.
Can any one please give me insight on this ?
If you want to have it clustered, you just run your Spring Boot application on multiple servers (of course, the JAR must be present on those servers, otherwise you can't run it). You would then place a loadbalancer in front of the application servers to distribute the load.
If all services you are going to expose are stateless so you only need to use load balancer in front of your nodes for ex. apache or nginx, if your services are stateful "store any state [session, store data in db]" so you have to use distributed cache or in memory data grid:
for session you can use spring-session project which could used rails to store sessions.
for store data in DB you need to cluster DB it self and can use distributed cache above your DB layer like Hazelcast.
Look into spring cloud, they have used some netflix open software along with amazons to create 12 factor apps for micro services.
Ideally you would need a load balancer, service registry that can help you achieve multiple instances of spring boot. I believe you have to add a dependency called eureka.
Check the below link
Spring cloud
You can deploy it in cloud foundry and use autoscale function to increase your application instances.

Can a Tomcat web application tell a load balancer its Tomcat is down?

I have two Tomcat servers deployed behind an Nginx load balancer that's using proxy_pass to route the requests. This works well, but there is now an use case in my application for which I need to pull one of the servers out of the cluster (but keep it running), have the web application on it do something and when that's done place the Tomcat back.
Right now I'm reloading the Nginx configuration manually and mark the server down to give time to the application to do its thing, but what I would like is have the web application "trick" Nginx that its Tomcat server is down, do it's stuff, then rejoin the cluster.
I'm thinking that I need to have some custom Tomcat Connector that's controlled by the web application but everything online is about proxying with Apache or using AJP and that's not what I need, I need this to be a HTTP proxy with Nginx.
Anyone has some pointers on how I might go about doing this?
When tomcat goes down, your webapp will go with it - you shouldn't rely on it to do any meaningful work to delay the shutdown. Rather have proper systems management procedures to first change the LB, then shutdown tomcat. That's a solution external to tomcat - and should be easy as you say that you pull one of the tomcats from your cluster.
For unplanned downtimes, use the LB's detection of tomcat being down, like #mikhailov described.
Try max_fails and fail_timeout configuration of Upstream module, for instance
upstream backend {
server tomcat1.localhost max_fails=3 fail_timeout=15s;
server tomcat2.localhost max_fails=3 fail_timeout=15s;
}
UPDATE:
To solve "mark as down by demand" task you can put maintenance.html file into the public directory, handle it via "try files" and produce error code 503 if the file exists. It helps you to configure balancer efficiently.

Scaling Scheduler Web Service

We are developing an application which periodically syncs the LDAP servers of different clients with our database. This application needs to be accessed via a web portal. A web user will create, modify or delete scheduled tasks on this application. So, we have developed this application as a web service.
Now, we have to scale this application and also ensure high availability.
The application is an Axis2 based web service running on Tomcat. We have thought of httpd + mod_jk + tomcat combination for load balancing. The problem is that if a request for modification/deletion comes, then it should land on the same tomcat server on which the task was created initially. But, since, the request can come from different web users accessing web portal from different ip addresses, we can not have same session id (sticky session).
Any solutions? Different architecture? Anything.
We have also thought of using Quartz scheduler api. The site says it supports load balancing and clustering. Does anyone has experience of working on such scenario with Quartz?
If you are using Quartz for your scheduling, that can be backed by a database (see JDBCJobStore). Then you could access any Tomcat server and the scheduling would be centralized. I would recommend using a key in the database that you return back to the Axis service, so that the user can reference the same data between calls.
Alternatively it is not difficult to use the database as a job scheduler, then have your tasks run on Tomcat (any location), and put the results into the database. If the results of the job (such as its status) are small, this would work fine.

Categories