How to run a Java jar consecutively? - java

I have 5 java jars in server "A" and a dozen of jars in other server "B". Now I need to run them consecutively. Say if 1 jar in server A has run complete, then 2 jars related to the jar 1 should start to run in server B. How to achieve this?
One option we have considered is to club related jars in one aws server and run through script detecting the jar completion through the log files, but is there any other efficient way to achieve the synchronisation through spring framework or by any other means?

I would look into having two "manager apps" on each server that can communicate with each other through sockets. Say manager app on server A detects jar 1 is completed, then it would send a message to manager app on server B with a command to run the jars related to the jar 1 on server A. To complete this I would look into Server Sockets and Sockets.

Related

How to confirm if the same task is finished on multiple server instances

I have scheduler job which every X minutes checks if there is some file on sftp server, downloads it, parse and upload status file which says that file is downloaded successfully. If file is not downloaded and parsed successfully we don't upload status file.
Status file is used by 3rd party application which based if the status file exists on sftp server, it starts doing some another job. If there is no status file it will not start the job.
Problem starts with multiple server instances which are running the same scheduler job. I can't figure it the best way how to ensure that all servers are successfully downloaded file and tell to 3rd party app with status file that it can start his job?
The only way how I can communicate with this 3rd party app is through status file.
Some solutions:
before we were running a scheduler job only on one server and have shared disk between them to use this files. This not a option anymore
I was thinking to upload a status file in wrong format (so that 3rd party app don't start his job) with some server id and that will be confirmation that this server has downloaded the file. All other servers will also put their id's in the same file. Then, first server which will find out that there are at least 3x times mentioned the same server id's ( 3x server1, 3x server2, 3x server3) it will change status file in correct format and then 3rd party can start his job. In theory problems could happen if in file was mention 3x times server1 and server2, but server3 was not mentioned at all (all servers have same the same cron expression, like every 2 minutes)
Use some configuration where will be defined number of servers which need to download file, and based on that config I could check if all of them has write their id's in fake status file. Problems is if I add new server I need to update config file.
I guess this is common problem and there is some pattern or algorithm?
If I were you, I would try to create an "interface file" between the 3rd party app and the sftp servers. The "interface file" would periodically (every X minutes) be updated. If the status files are ready (all of them), then only the "interface file" will be marked as "ready". Then send this "interface file" to the 3rd party app.
Hope it helps with your problem
EDIT : syntax

How to run Spark Java application on AWS?

I have developed an app using Spark Java Framework (www.sparkjava.com). I am able to build the artifact on my windows as a JAR file. I can confirm I am able to run it via command line "java -jar App.jar Main.java". It hosts a web app at localhost:4567.
What's the most convenient/quickest way to load this onto an AWS server? I created an EC2 instance (AMI Instance), copied over the jar file to it, ran the command. The log seems to run successfully, but I can't hit the DNS server. It doesn't seem to be up.
I found the solution.
Log into AWS
Click on Instances and click on your Instance
In description, see Security Groups, click on your Security Group
In the Inbound tab, click on Add Rule
Add HTTP, HTTPS, and Custom
For Custom, set the Port to the port that you'd like to be
available to all incoming traffic. Hit apply.

Copy file with a lock on it

I have an application running on a server which is doing stuff and writing everything it does to a log file.
I also have secondary application which is kind of like a monitoring panel also running on the server but is a different process. What I would like to do is the following:
I would like my monitoring file to be able to copy the log file which currently has a lock on it from the other application and then email it to me.
I have tried using scp to connect to the server and copy it manually to my computer(and it did work), however I would like to be able to do that through my java monitoring application. And I have no idea where to start.
I have tried using scp to connect to the server and copy it manually to my computer(and it did work)
The JSch library has a ScpFrom module that you can use to scp copy the data from the server to your computer or application. This can be done by one of the following:
Manually running the module (eg java -jar)
Copying the source of the module into your project and adding the JSch library to classpath (more programmatic control - preferred approach)
Using the library module programmatically eg String[] args = {user#remotehost:file1" "localfile"}; SCPFrom.main(args);

Run Maven project on web server in the background

Problem
I have got a working Maven project that I would like to deploy on my web server. I have just discovered Maven and Java is not exactly the primary language I write my projects in, so please excuse any mistakes. When I run my project, a continuous HTTP connection is established and it should permanently run on the server (Basically Push Notifications based on made requests).
Further Information
The server is running on Amazon's Linux AMI.
Proposed Solution
I pack the whole Maven project into a .jar file and run it there.
Q1 How do I run the java file on a server (in the background) ?
Monitoring
Q2 How can I monitor which or how many processes are working in the background ? (I would NOT want the java file to run multiple times, thus PREVENTING it from establishing multiple connections)
Termination
Q3 How would I terminate any background processes, if needed (terminate the continuous http connection)?
Connected Questions
Run java jar file on a server as background process
EDIT
Possibly what I was looking for (I'll test it out and report back): https://serverfault.com/questions/152378/run-jar-in-background-on-linux

Can ANT start restart jobs on remote servers?

Is it possible to have ANT restart your java application on a remote server from a build script? If so any pointers to where that might be defined?
I'm using ant now to push the new code over to the remote server but I still have to login to actually restart the app
Using the <sshexec> task you can do pretty much anything on a remote machine (assuming it's got an sshd running). If you don't want to worry about authenticating the ssh session every time, you can set up RSA keys.
<sshexec host="remotehost" username="remoteuser" command="/restart/application/command"/>
Heed the statement at the beginning of the above link:
This task depends on external libraries
You'll need to grab JCraft's JSch jar and put it on Ant's classpath.

Categories

Resources