Testing a Spring application on multiple JVMs - java

I have coded a Spring MVC Hibernate application with RabbitMQ as a messaging server & a MySQL DB. I have also used Hazelcast an in-memory distributed cache to centralize the state of the application, moving the local tomcat session to a centralized session & implementing distributed locks.
The app right now is hosted on a single tomcat server in my local system.
I want to test my application on a multiple JVM node environment i'e app running on multiple tomcat servers.
What would be the best approach to test the app.
Few things that come to my mind
A. Install & configure a load balancer & set up a tomcat cluster in my local system. This I believe is a tedious task & requires much effort.
B. Host the application on a PAAS like OpenShift, cloudfoundry but I am not sure if I will be able to test my application on several nodes.
C. Any other way to simulate a clustered environment on my local windows system?

I would suggest first you should understand your application requirement. For the real production/live environment, are you going to use Infrastructure as a service or PAAS.
If Infrastructure as a service then
I would suggest create local cluster environment and use the tomcat and spring application sticky session concept. Persist the session in Hazelcast or redis server installed on different node. Configure load balancer for multiple nodes having tomcat server. 2-3 VMs for testing purpose would be suitable.
If requirement is PAAS then
Don't think about local environment. Test directly on OpenShift or AWS free account and trust me you would be able to test on PAAS if all setup is fine.

Related

How to start slaves on different machines in spring remote partitioning strategy

I am using spring batch local partitioning to process my Job.In local partitioning multiple slaves will be created in same instance i.e in the same job. How Remote partitioning is different from local partitioning.What i am assuming is that in Remote partitioning each slave will be executed in different machine. Is my understanding correct. If my understanding is correct how to start the slaves in different machines without using cloudfoundry. I have seen Michael Minella talk on Remote partitioning https://www.youtube.com/watch?v=CYTj5YT7CZU tutorial. I am curious to know how remote partitioning works without using cloudfoundry. How can I start slaves in different machines?
While that video uses CloudFoundry, the premise of how it works applies off CloudFoundry as well. In that video I launch multiple JVM processes (web apps in that case). Some are configured as slaves so they listen for work. The other is configured as a master and he's the one I use to do the actual launching of the job.
Off of CloudFoundry, this would be no different than deploying WAR files onto Tomcat instances on multiple servers. You could also use Spring Boot to package executable jar files that run your Spring applications in a web container. In fact, the code for that video (which is available on Github here: https://github.com/mminella/Spring-Batch-Talk-2.0) can be used in the same way it was on CF. The only change you'd need to make is to not use the CF specific connection factories and use traditional configuration for your services.
In the end, the deployment model is the same off CloudFoundry or on. You launch multiple JVM processes on multiple machines (connected by middleware of your choice) and Spring Batch handles the rest.

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.

What is and what do a WebLogic Server domain?

I am a Java developer and I am pretty new in web application development using Java and I have the following doubts.
We are developing web app deployed on Oracle WebLogic Server.
What exactly is the weblogic domains? From what I understand each application use a definied domain. But what it exactly does?
From Oracle documentation:
A domain is the basic administrative unit of WebLogic Server. It
consists of one or more WebLogic Server instances, and logically
related resources and services that are managed, collectively, as one
unit.
So it's an administrative container, you should think of the following: 1 domain equals 1 Administration Server.
The Administration Server:
A domain includes one WebLogic Server instance that is configured as
an administration server. All changes to configuration and deployment
of applications are done through the administration server.
The administration server provides a central point for managing the
domain and providing access to the WebLogic Server administration
tools. These tools include the following:
WebLogic Server Administration Console: Graphical user interface to the administration server.
WebLogic Server Node Manager: A Java program that enables you to start and stop server instances—both administration servers and
managed servers—remotely, and to monitor and automatically restart
them after an unexpected failure.
Note that the node manager is installed on all the machines that host any server instance – both administration server and managed
servers.
A WebLogic Domain is a concept that represents an environment.
A Domain includes an Administration Server, and 1 or more Managed Servers
Managed Servers are basically Java servers running on the physical machine or VM, which can each contain 1 or more Managed Servers.
Managed Servers can be organized into Clusters
A Domain also contains Resources, such as database connections pools, which can be used by Applications.
Applications and Resources are deployed on to specific Managed Servers or Cluster(s) (a Resource should be deployed on the same Managed Server or Cluster as the Application that needs it)
A Domain usually contains multiple applications.
Clusters abstract the Managed Servers as a group, so it's easy to scale an Application deployment by adding Managed Servers to a Cluster.
Multiple Clusters in the same Domain can help segregate Applications and Resources according to their usage requirements.
Dynamic Clusters include rules for scaling the number of Managed Servers in and out according to specific metrics.
Furthermore:
There is 1 Admin Server per Domain. Usually there is 1 Domain per group of machines running Managed Servers in the Domain.
While the Admin Server manages what is deployed where, another service, the Node Manager, runs on each physical machine or VM to manage the life-cycle of the Managed Server (start, stop, health check) and reports to the Admin Server.
This link from oracle docs has precisely defined weblogic domain.It has detailed the various ways of dividing your application may be logically,physically or based on size.Specifically below sections from the link might answer your question
What Is a Domain?
Organizing Domains
https://docs.oracle.com/cd/E13222_01/wls/docs103/domain_config/understand_domains.html
I found the below link useful as well:
http://middlewaremagic.com/weblogic/?p=1914

convert weblogic admin server into managed server

I'm currently having 2 Weblogic admin servers in 2 different domains created on the same machine.
I want to convert one of the admin server to a managed server and then use them together to deploy a Java application. Is this feasible? If yes, how?
I'm currently using Weblogic Server 10.3.
PS: I'm quite new to Weblogic domain creation and administration. Please revert for any more details needed.
The simple answer is no, however, adding a managed server to a domain is extremely simple. See the documentation here. When deploying your application you'll need to target both servers or create a cluster (also very easy), add both machines to it and give the cluster name as the target.
Note, it is generally not concidered best practice to target applications to the Admin server (although it's fine when you're developing on your local machine). If you have the resources available on your environment, you could create two managed servers and put them in a cluster. Depending on the configuration of your Admin server, you may be able to reduce it's size if memory is tight.

Clustering Apache Tomcat6

I've got a Java Enterprise Web Application which uses Tomcat6+Struts+Hibernate+MySql. at the time being it's publicly up and running on a single server. In order to performance issues we should move the application to a clustered environment. Anyhow I wanna use Tomcat6 clustering as below:
A Load Balancing machine including a web server (Apache+mod_proxy) as front-end
Some application server machines, each one running a tomcat6 instance
A session management back-end
And finally a db server
something like this
The load balancer machine receives all the requests and depending on the balancing algorithm redirects them to the respective tomacat6 machine. After doing the business part, the response is returned to the webserver and at the end to the user. In this scenario the front-end machine processes all the requests and responses so it'd be a bottleneck point in the application.
In Apache Tomcat clustering, is there a way to load balancing mechanism and web servers? I mean putting a load balancer in the front end and leave the request/response processing part to multiple web servers.
Tomcat has no support for clustering built in. What happens is that the load balancer distributes requests, so the various Tomcat instances don't need to know what is happening.
What you have to do is to make sure your application can handle it. For example, you must be aware that caches can be stale.
Say instance 1 has object X in it's cache and X is modified by a request processed on instance 2. The cache in instance 2 will be correct, the cache from instance 1 will be stale now.
The solution is to use a cache which supports clustering or disable caching for instances which can be modified. But that doesn't matter to Tomcat.

Categories