My company has plans to implement a clustered system with a lot of services that will be deployed automatically in different machines and will interconnect with each other (SOA style). Sometimes the services will have interdependencies.
For example:
Service B (application) can be started up only when the Service A (Database) is up and running.
Each service is planned to be run as a different java process, possibly deployed as a WAR (inside dedicated tomcat) or even without web at all.
For now we have all the services in the same WAR and only single tomcat that deploys the WAR.
All the services are defined via Spring and Spring manages dependencies for us.
So I'm asking myself whether exist some frameworks that will help to manage the services in a distributed environment as I've described above?
Thanks in advance
Use ZooKeeper.
Correction, use Netflix's Curator, a framework on top of zookeeper which simplifies the work with it.
Where I work I recently implemented a Coordinator class which has two methods:
waitForDependencies - a synchronic method that checks for the liveness of the current service's dependnecies and blocks the current thread until notified that all dependency services are alive. The liveness check is done by verifying the existence of nodes which are created by the depenedency services, at the end of their initializing process, by calling notifyUp
notifyUp - a synchronic method that notifies the world that the current service that calls that method is alive. The notification is done by creating an ephemeral (temporal, stays alive just as long as the connection in which it was created is alive) node in the zk cluster, which is looked for by other services which depend on it, using waitForDependencies
Netflix released their open source tool - Asgard that manages and deploys instances to a cloud. It is tightly coupled with EC2 (the last time I checked). Depending on whether you deploy to the amazon cloud you might find that useful. I'm unaware if it supports dependencies but it does manage deployments on a distributed environment. Netflix does talk about service dependencies a lot on their blog, so the deployment solution might have a feature to solve for that.
I'm not aware of any other service / framework that does this. If you were to write this on your own I guess you could configure a couple of Jenkins tasks that deploy services. One task can depend on another to simulate the service dependency. Pinging URL endpoints can check if Service A exists before B is deployed.
There's another way to look at this. You would not need to check for dependency if you ensure your services are all running properly. Monitoring tools like Nagios can help here. Troubleshooting faulty services immediately can help you focus on deploying Service A instead of checking your dependencies on each deployment.
Related
I am new to applications deployments in web servers altogether. Is it OK to add different instances of jetty webserver for two application - One data service and another angular UI application. Or Do I need to deploy the two applications from the same jetty instance.
Suggestions
Single jetty server hosting both applications
Use this approach when you own both the services and understand the RPS/throughout/latency/memory requirements of both the services. A bottleneck in one service can cause issue to another service
If the available memory/cpu/capacity is limited and hence don't want to waste additional memory for server by running another server instance
Both services are light weight
Both services are not deployed frequently or there is proper a BCP
Separate jetty server per application - preferably containerized(Docker?)
Provides good isolation to services
Control over resources per application
Easy to manage/scale independently depending on load
Easy to identify and fix issues
Personally, i would prefer to run them independently with or without containerization.
I know that by sending a http post request to http://host:port/shutdown, we can shutdown a Springboot application. Is it possible to restart the whole springboot application by sending a http request in a production environment? So we don't need to login in the server to do that. Thank you.
I don't think such a thing exists, I'll be glad to be proven otherwise:
Spring boot doesn't do any assumptions about the environment it runs in. So when spring boot process gets shut down, re-starting it again is "out of competence" of spring boot infrastructure which is just a bunch of java classes running inside a JVM process.
You can find Here a list of endpoints exposed by the spring boot. There is a "shutdown" method that you've mentioned there, but there is no "restart" functionality exposed.
Now there are other techniques that probably can help:
If the application gets shut down because of some illegal state of some spring bean, maybe it makes sense to expose some endpoint that will "clean up" the state and make application operational again. If the application has to be restarted due to changes in configuration files or something, then you might want to consider using spring cloud's Refresh Scope for Beans. It's kind of hard to provide more information here, because you haven't mentioned the reason for shutting down the application, but I guess you've got the direction.
Having said that, there are probably some different ways to achieve what you want depending on the environment your application runs in:
If you're running in AWS for example, you can take advantage of their autoscaling policies, shut down the application remotely and AWS will run another instance for you. I'm not an expert in AWS, but I saw this working in ECS for example.
If you're running "java -jar" just on some server and want to make sure that when your process ends (by using 'shutdown') it should be started again, its possible to use some kind of wrapper that would wrap the process in service and track the service availability. There are even ready solutions for this, like Tanuki wrapper (I'm not affiliated with this product but used once its free version and it served us great)
If you're using Docker infrastructure you can change the policy and restart the container automatically when it gets shut down, I haven't used this by myself, but according to This excellent blog post is perfectly doable.
You should look at Spring boot jenkins You will also find a small article explaining how to configure the project on jenkins.
I am looking for a better logical solution of a situation where one core Java EE (Web) application will call/execute many other Java applications/workers (which can be core Java or J2EE(web) application (don't know what will be the best)) at a certain time.
Those other Java applications/workers will basically connect (individually) with different Data sources (can be from remote DB or REST or SOAP, etc...) and populate/update local DB at a certain period of time.
I was doing research on Java Quartz Scheduler recently. Do u have any good suggestion to me for this Enterprise level architecture?
Btw, I am using Spring 4, Java 7
Thank you as always for all good and professional ideas.
Sample diagram can be as follows:
You can connect your java application with others easy with spring's httpInvoker or rmiInvoker.
More information here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/remoting.html
Not sure to understand good, but you can look at a messaging mechanism. Typically, the WebApp will send a message that will be received by all the Workers.
Have a look a JMS which it designed for this kind of use, and integrates well with both JEE (it is a part of the JEE spec) and Spring.
There are basically two parts to your question:
How do I schedule jobs on a Java EE server?
How do I invoke remote services from that scheduled job?
Job Scheduling
The trick with job scheduling in a Java EE environment is that you are typically running jobs in a cluster, or more than one server. Thus, only one of the nodes should be running that job at a time "on behalf of" the cluster, otherwise, you'll get multiple calls to those remote resources for the same thing.
There is a standard out there for this, JSR-237, which covers Timers and WorkManagers. Each Java EE vendor has its own implementation. WebLogic has one, WebSphere has one, and JBoss has one (the JBoss one isn't compliant with the JSR, but it does the same thing).
If you are running one of the servers that only runs the web tier of the Java EE spec (i.e, Tomcat or Geronimo), then Quartz is a good choice.
How to invoke remote services from timed jobs
Echoing #Alexandre Cartapanis' answer, probably what you'll want to do is create a JMS Topic in your Java EE server, and then when the job runs, post a message to the topic. The remote services (whatever Java EE servers) subscribe to this topic, and then you can run your queries.
The big advantage here is that if you ever need to add another service that needs to populate the local DB, all you have to do is have that server subscribe to the topic - no code changes needed. With JSch or remoting, you'll have to make a code change every time a new service comes online. You also have to make code changes if DNS addresses or IP addresses change, etc, where as the JMS way is just configuration on the server. There's a lot more that you can do with JMS, and the support is much better across the board.
Spring has adapters for Quartz and I think there's one out there for WorkManagers and Timers too.
You can make use of JSch - Java Secure Channel to trigger remote ssh calls which can start a JVM and run the Worker class.
Here are some examples.
is it possible in JavaEE (JBoss AS5.1, EJB 3.0) to get notified when a jboss instance went offline? Specifically I want to receive a notification when a previously looked up ejb is not longer available or is available again (the ejb is not clustered, but that's another story).
My current workaround is to call a method called isAvailable which always returns true, when an exception occures I know the ejb is down. This online check obviously can't be the best way to do this.
If I understood it correctly, you are wanting to get alerted when a JBoss instance goes down. You would need an external monitoring and alerting tool such as RHQ or Hawkular to achieve this.
Having EJBs clustered would help providing high availability. However, you probably still want a motoring and alerting tool to monitor the cluster as well as other resources on the JBoss instances.
If you just care about when the EJB is unavailable and do not want to use an external tool, then you can create a Service MBean or a custom MBean. This way you can create a custom notification tied to your EJB lifecyle .
Please do keep in mind when you decide to upgrade to JBoss AS7 or Wildfly bits, this MBean will have to be changed since the MBean support is quite different in those versions.
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