I have Swing front end for use as a client to kick off Selenium tests. At the point where I kick off the test process, the first thing I do is fire up a local Selenium hub and node using the following code:
String[] nodeCmd = new String[]{"java", "-jar", "selenium-server-standalone-2.39.0.jar", "-role node", "-nodeConfig config\\DefaultNode.json"};
ProcessBuilder pbNode = new ProcessBuilder(nodeCmd);
pbNode.directory(new File("C:\\selenium\\"));
File nodeLog = new File("C:\\selenium\\logs\\nodeOut.log");
pbNode.redirectErrorStream(true);
pbNode.redirectOutput(nodeLog);
Process nodeP = pbNode.start();
String[] hubCmd = new String[]{"java", "-jar", "selenium-server-standalone-2.39.0.jar", "-role hub", "-hubConfig config\\DefaultHub.json"};
ProcessBuilder pbHub = new ProcessBuilder(hubCmd);
pbHub.directory(new File("C:\\selenium\\"));
File hubLog = new File("C:\\selenium\\logs\\hubOut.log");
pbHub.redirectErrorStream(true);
pbHub.redirectOutput(hubLog);
Process hubP = pbHub.start();
Whilst the hub is started up correctly, when the node process is started it seems to be doing so as a hub (log output is exactly the same) with the result that it complains the port is already in use.
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:491)
at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:300)
at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:96)
Any ideas what I am doing wrong? I have checked the config files and they are definitely right.
Update
So I finally worked out what I was doing wrong! My mistake is in the way I was constructing my Array of parameters to pass into the ProcessBuilder constructor.
Wrong:
String[] nodeCmd = new String[]{"java", "-jar", "selenium-server-standalone-2.39.0.jar", "-role node", "-nodeConfig config\\DefaultNode.json"};
Right:
String[] nodeCmd = new String[]{"java", "-jar", "selenium-server-standalone-2.39.0.jar", "-role", "node", "-nodeConfig", "config\\DefaultNode.json"};
I wan't splitting the key string and value string for the role and config params. Grrr!
Make sure that your nodeConfig.json is using the "port" property of an unused port (defaults to 5555), and make sure that in your hubConfig.json, it is using the "port" property of an unused port (defaults to 4444)
If you can validate that the above are both correct, then the only other issue that i can imagine, is that the previous hubs (probably started up when testing this very functionality) were left open.
I would ensure that all java.exe processes are terminated, and add a failsafe in your code to quit the grid.
Related
I am using Jmeter to do load test using Ant plugin. Currently capturing server's JVM metrics during the test using JFR GUI mode, for each node. It is cumbersome to start for each node and sometimes its getting missed to start. Is there a way to start doing them together via code?
Client details
Hotspot JDK 1.8_131,
Mac OS,
Jmeter 4.0
Server details
Hotspot 1.8.0_152,
OEL ,
Tomcat
In internet I am getting the options to start JFR programmatically in server node, which will not work for me.
If you have terminal access, you could create a script and start a recording using the command line tool jcmd.
$ jcmd <class/jarfile> VM.unlock_commercial_features
$ jcmd <class/jarfile> JFR.start
or
$ jcmd (to list available pids)
$ jcmd <pid> VM.unlock_commercial_features
$ jcmd <pid> JFR.start
For more details, see
Example 2-1 Dynamic Interaction Using jcmd
If you can't access the server over SSH, or don't want to do it in the shell, you could use JMX and send the same conmands as diagnostic commands.
In JMC, in the Management/JMX Console you can inspect the MBeans on the server. There you will find the "com.sun.management / DiagnosticCommand" MXBean and the operations which you can write code against. The object name is com.sun.management:type=DiagnosticCommand and you need to call it with jfrStart.
You can set up the connection like this.
String host ="myHost";
int port = 1234;
HashMap map = new HashMap();
String[] credentials = new String[2];
credentials[0] = user;
credentials[1] = password;
map.put("jmx.remote.credentials", credentials);
String s = "/jndi/rmi://" + host + ":" + port + "/jmxrmi";
JMXServiceURL url = new JMXServiceURL("rmi", "", 0, s);
JMXConnector c= JMXConnectorFactory.newJMXConnector(url, map);
c.connect();
MBeanServerConnection conn = c.getMBeanServerConnection();
If you don't care about security, you can set map to null. Then you create an object name and invoke the operation you like to execute, for example:
ObjectName on = new ObjectName("com.sun.management:type=DiagnosticCommand");
Object[] args = new Object[] {
new String[] {
"dumponexit=true",
"filename=/recordings/rec.jfr",
"duration=600s"
}
};
String[] sig = new String[] {"[Ljava.lang.String;"};
conn.invoke(on, "jfrStart", args, sig);
In JDK 9 and later there is a FlightRecorderMXBean that can be used for remote access (including recording download), but if you are stuck on JDK 8, I would do the above. There is a MBean in Oracle JDK 8 as well, but it is unsupported, undocumented and black magic is needed to make it work.
i need to send some messages from my java web application to some servers using Diameter protocol, in particular CCR-CCA scenario. I had a look at jdiameter opensource project, but my usecase does not require such complexity, since that i just need to send a single request and log the response (actually i don't even need the CER-CEA part).
So i thought i could just have used Seagull running under my webapp. I downloaded Seagull (for Windows), and what i'm trying to do is basically to run the .bat file coming from Seagull for the diameter environment from my java environment.
That's what i've done till now..
1) A simple test to invoke the client.. Here wrapper simply sets working dir and starts the process
public static void main(String[] args) {
List<String> cmd=new ArrayList<>();
cmd.add("cmd.exe");
cmd.add("/c");
cmd.add("my_start_client.bat");
JavaProcessBuilderWrapper wrapper = new JavaProcessBuilderWrapper();
Process p = wrapper.createProcess(RedirectErrorsTo.STDERR,
new HashMap<>(), new File("my_working_dir"), cmd);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder output = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
output.append(line);
}
System.out.println(line);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
2) I modified the client's and server's .bat files coming from Seagull to use CCR-CCA protocol.
Running Java main with this configuration caused a
Fatal: Keyboard saved configuration failure error
on my logs.
3) So, as mentioned here i further modified my client's .bat file to run in background mode, adding -bg at the end. Now my client's bat look like this
#ECHO OFF
rem
"Diameter Start Script Sample"
"Local env"
SET RUN_DIR=C:\Program Files\Seagull
set PATH=%PATH%;%RUN_DIR%
set LD_LIBRARY_PATH=%RUN_DIR%
set RUN_DIR=%RUN_DIR%\diameter-env\run
cd %RUN_DIR%
cls
mode 81,25
echo "Seagull Diameter Client Sample Start"
seagull -conf ..\config\conf.client.xml -dico ..\config\base_ro_3gpp.xml -scen ..\scenario\ccr-cca.ro.client.xml -log ..\logs\ccr-cca.client.log -llevel ETM -bg
pause
Since i was facing some troubles, to keep things simple, i just tried to make it work at least via cmd (not using my java method), but i think background mode is messing around, because now when i start my server and then my client in bg mode, sometimes i get a
Fatal: Forking error
but the most of the times, the client send a single message and then on my console i see that my software is causing connection abort (error code -1), and from the log i see that the channel just get closed, and my client does not even receive an answer. (NB for now i left the configuration files untouched)
Has any of you faced this behaviour? Is something else closing the connection (firewall perhaps)? Do i have to provide other configurations to make this work?
Once i can get this working, can i use my java web app (with a method similar to the one i already mentioned) to make diameter calls?
Thanks in advance, any help is really welcomed.
I try to create a console with "spring shell", I would like to run my own netty socket server command. I have a command:
#CliCommand(value = "server", help = "Start socket server")
public String server(
#CliOption(key = {"port", "p"}, mandatory = true, help = "Port number [49152-65535]") final String port,
#CliOption(key = {"maxclients", "mc"}, mandatory = false, help = "Max clients", unspecifiedDefaultValue = "50") final String maxClients
)
{
NettyServer nettyServer = new NettyServer(Integer.parseInt(port), Integer.parseInt(maxClients));
nettyServer.run();
return "::CliCommand return::";
}
While the server is running, it blocks the console and can not enter other commands. Should not you have a solution? For example, how to let it run alone and only influence the server by the command. For example, I would like to send messages from my console to clients.
I can't answer for the whole architecture of your application, but your server object should not be created inside your command method.
It should be created prior to that (or at the very least, it should not be a local parameter of your command method that dies when your command ends) and acted upon by commands, using a different thread I assume.
I need to copy some files from hdfs:///user/hdfs/path1 to hdfs:///user/hdfs/path2. I wrote a java code to do the job:-
ugi = UserGroupInformation.createRemoteUser("hdfs", AuthMethod.SIMPLE);
System.out.println(ugi.getUserName());
conf = new org.apache.hadoop.conf.Configuration();
// TODO: Change IP
conf.set("fs.defaultFS", URL);
conf.set("hadoop.job.ugi", user);
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
// paths = new ArrayList<>();
fs = FileSystem.get(conf);
I am getting all paths for the wild card as
fs.globStatus(new Path(regPath));
and copy as
FileUtil.copy(fs, p, fs, new Path(to + "/" + p.getName()), false, true, conf);
However copying is failing with following message whereas globstatus execute successfully
WARN BlockReaderFactory:682 - I/O error constructing remote block reader.
org.apache.hadoop.net.ConnectTimeoutException: 60000 millis timeout while waiting for channel to be ready for connect. ch : java.nio.channels.SocketChannel[connection-pending remote=/10.110.80.177:50010]
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:532)
at org.apache.hadoop.hdfs.DFSClient.newConnectedPeer(DFSClient.java:3044)
at org.apache.hadoop.hdfs.BlockReaderFactory.nextTcpPeer(BlockReaderFactory.java:744)
at org.apache.hadoop.hdfs.BlockReaderFactory.getRemoteBlockReaderFromTcp(BlockReaderFactory.java:659)
at org.apache.hadoop.hdfs.BlockReaderFactory.build(BlockReaderFactory.java:327)
at org.apache.hadoop.hdfs.DFSInputStream.blockSeekTo(DFSInputStream.java:574)
at org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:797)
at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:844)
at java.io.DataInputStream.read(DataInputStream.java:100)
at org.apache.hadoop.io.IOUtils.copyBytes(IOUtils.java:78)
at org.apache.hadoop.io.IOUtils.copyBytes(IOUtils.java:52)
at org.apache.hadoop.io.IOUtils.copyBytes(IOUtils.java:112)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:366)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:338)
Note that I am running code remotely over Internet using port forwarding. I.e.
192.168.1.10[JAVA API] ---> 154.23.56.116:8082[Name Node Public I/P]======10.1.3.4:8082[Name Node private IP]
I guess following is the reason:-
Query is made to namenode for globStatus which is successfully executed by the name node
Copying command is passed to namenode which will return 10.110.80.177:50010 for other data nodes address on other machines, and then Java IP will try to pass the copy commands to these data nodes, since they are not exported to outside world I got this error!
Am I right in this deduction? How to solve the issue? Do I need to create a java server at namenode which will collect copy command and copy the files locally in the cluster.
I am creating a Java APP that manages a database. I've been starting the JAVA DB server manually by right clicking - start server. with NetBeans but since I am not going to be the one that runs the application that can't be done anymore. I need a way to start it without NetBeans. Embedded or server mode, I don't really mind.
I've searched a lot but nothing seems to work.
I tried this: Java DB - Starting Server within application
NetworkServerControl server = new NetworkServerControl(InetAddress.getLocalHost(),1527);
server.start(null)
I got java.net.ConnectException: Error al conectarse al servidor localhost en el puerto 1527 con el mensaje Connection refused: connect.
I tried also starting it with the command line
String[] command =
{
"cmd",
};
Process p = Runtime.getRuntime().exec(command);
new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
try (PrintWriter stdin = new PrintWriter(p.getOutputStream())) {
stdin.println("cd C:\\Program Files\\Java\\jdk1.8.0_31\\db\\lib");
stdin.println("java -jar derbyrun.jar server start");
}
int returnCode = p.waitFor();
Also got connection refused, (database Citas not found) so the only way it could work is this:
String host = "jdbc:derby://localhost:1527/Citas";
con = DriverManager.getConnection(host, username, password);
But it works only if I start the server by clicking in Java DB -> start.
Any help would be higly appreciated
Can you try starting it using Runtime?
Runtime runtime = Runtime.getRuntime();
runtime.exec(new String[]{ "java", "-jar", "/path/to/derbyrun.jar", "server", "start");
If you were to do this in its own thread, you could also append .waitFor() to the .exec command which will hang until the process finishes. This would be good to determine if the db closed unexpectedly.
Also using runtime, you can get read the stdout / stderr of the process, and kill it if need be. Possibilities are endless.