Skip to content

Commit

Permalink
Merge pull request #40 from grandmasterlinux/master
Browse files Browse the repository at this point in the history
* applied patchfile.txt from issue #30 upstream

* bugfix for directory separator / instead of :

* adding support for -shell command line option

* adding support for customShell

* increase for expected number of arguments

Co-authored-by: Nicholas Hadaway - c002286 <Nicholas.Hadaway@footlocker.com>
Co-authored-by: Raimondas Širvinskas <raimis.sirvis@gmail.com>
  • Loading branch information
fixy and Nicholas Hadaway - c002286 committed Nov 4, 2020
2 parents 82afaa2 + f1100be commit 891d992
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 101 deletions.
15 changes: 0 additions & 15 deletions lib/globus/bouncycastle.LICENSE

This file was deleted.

3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fast-data-transfer</groupId>
<artifactId>fdt</artifactId>
<version>0.26.2-SNAPSHOT</version>
<version>0.27.0-SNAPSHOT</version>
<description>Fast data transfer</description>
<packaging>jar</packaging>

Expand Down Expand Up @@ -215,6 +215,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<!-- DO NOT include log4j.properties file in your Jar -->
<excludes>
Expand Down
23 changes: 0 additions & 23 deletions project

This file was deleted.

87 changes: 50 additions & 37 deletions src/lia/util/net/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.opentsdb.client.HttpClientImpl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.*;
Expand Down Expand Up @@ -37,7 +38,7 @@ public class Config {
"-N", "-bio", "-gsi", "-gsissh", "-notmp", "-nolock", "-nolocks", "-nettest", "-genb", "-autoport"};
public static final String[] VALUE_CMDLINE_ARGS = {"-bs", "-P", "-ss", "-limit", "-preFilters", "-postFilters",
"-monID", "-ms", "-c", "-p", "-sshp", "-gsip", "-iof", "-sn", "-rCount", "-wCount", "-pCount", "-d",
"-writeMode", "-lisa_rep_delay", "-apmon_rep_delay", "-fl", "-reportDelay", "-ka", "-tp"};
"-writeMode", "-lisa_rep_delay", "-apmon_rep_delay", "-fl", "-reportDelay", "-ka", "-tp", "-shell"};
public static final String POSSIBLE_VALUE_CMDLINE_ARGS[] = {"-enable_apmon", "-lisafdtclient", "-lisafdtserver",
"-f", "-F", "-h", "-H", "--help", "-help," + "-u", "-U", "--update", "-update"};
/**
Expand All @@ -47,12 +48,12 @@ public class Config {
public static final String REGEX_REMAP_DELIMITER = "(\\s)+/(\\s)+";
// all of this are set by the ant script
public static final String FDT_MAJOR_VERSION = "0";
public static final String FDT_MINOR_VERSION = "26";
public static final String FDT_MAINTENANCE_VERSION = "2";
public static final String FDT_MINOR_VERSION = "27";
public static final String FDT_MAINTENANCE_VERSION = "0";
public static final String FDT_FULL_VERSION = FDT_MAJOR_VERSION + "." + FDT_MINOR_VERSION + "."
+ FDT_MAINTENANCE_VERSION;
public static final String FDT_RELEASE_DATE = "2017-08-08";
public static final String FDT_RELEASE_TIME = "1830";
public static final String FDT_RELEASE_DATE = "2019-07-02";
public static final String FDT_RELEASE_TIME = "0530";
// the size of header packet sent over the wire -
// TODO - this should be dynamic ... or not ( performance resons ?! )
public static final int HEADER_SIZE = 56;
Expand All @@ -70,6 +71,8 @@ public class Config {
public static final long DEFAULT_KEEP_ALIVE_NANOS = TimeUnit.MINUTES.toNanos(2);
public static final int DEFAULT_PORT_NO_GSI = 54320;
public static final int DEFAULT_PORT_NO_SSH = 22;
public static final String DEFAULT_SHELL = "/bin/bash";

/**
* Check if remote server is needed. We use SSH channels to control remote startup. <br>
* In SSH/SCP mode we have three types of syntax we need to support:
Expand Down Expand Up @@ -202,7 +205,8 @@ public class Config {
private Map<String, Integer> sessionPortMap = new HashMap<>();
private Map<Integer, List<Object>> sessionSocketMap = new HashMap<>();
private HttpClientImpl httpClient = null;

private String customShell = null;

/**
* @param configMap
* @throws InvalidFDTParameterException if incorrect values are supplied for parameters
Expand Down Expand Up @@ -307,6 +311,8 @@ private Config(final Map<String, Object> configMap) throws InvalidFDTParameterEx

portNo = Utils.getIntValue(configMap, "-p", DEFAULT_PORT_NO);
transportPorts = Utils.getTransportPortsValue(configMap, "-tp", DEFAULT_TRANSFER_PORT_NO);
if(transportPorts.size() == 1 && transportPorts.element().intValue() == DEFAULT_TRANSFER_PORT_NO)
transportPorts.clear();
tp = Arrays.asList(transportPorts.toArray());
isCoordinatorMode = (configMap.get("-coord") != null);
isThirdPartyCopyAgent = (configMap.get("-agent") != null);
Expand Down Expand Up @@ -349,7 +355,8 @@ private Config(final Map<String, Object> configMap) throws InvalidFDTParameterEx
listFilesFrom = Utils.getStringValue(configMap, "-ls", null);
bComputeMD5 = (configMap.get("-md5") != null);
sshKeyPath = Utils.getStringValue(configMap, "-sshKey", null);

customShell = Utils.getStringValue(configMap, "-shell", DEFAULT_SHELL);

if (isNetTest) {
destDir = "/dev/null";
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -710,7 +717,7 @@ private static void closeSessionRelatedSocks(List<Object> socks) {
}

private String[] getLogFiles(String sessionID) {
return new String[]{"/tmp/" + sessionID + ".log"};
return new String[] { System.getProperty("java.io.tmpdir") + File.pathSeparatorChar + sessionID + ".log" };
}

public String getListFilesFrom() {
Expand Down Expand Up @@ -912,48 +919,51 @@ public void registerTransferPortForSession(int newTransferPort, String sessionID
}

public int getNewRemoteTransferPort() {
int rtp = -1;
try {
if (autoPort)
{
return getRandomPort(getDefaultPort());
}
if (!transportPorts.isEmpty()) {
int rtp = this.transportPorts.poll(20, TimeUnit.SECONDS);
System.out.println("Took new remote transfer port " + rtp);
return rtp;
rtp = this.transportPorts.poll(20, TimeUnit.SECONDS);
logger.log(Level.FINER,"Reusing remote transfer port " + rtp);
} else {
rtp = findAvailablePort();
logger.log(Level.FINER,"Used new remote transfer port " + rtp);
}

} catch (Exception e) {
if (transportPorts.size() == 0) {
logger.log(Level.WARNING, "No transfer ports defined or no free transfer ports left...", e);
} else {
logger.log(Level.WARNING, "Failed to retrieve remote transfer port", e);
}
}
return -1;
}

private int getRandomPort(int defaultPort)
{
int randomPort = -1;
try {
Random r = new Random();
randomPort = r.nextInt(((defaultPort + portRange) - defaultPort) + 1) + defaultPort;
logger.log(Level.INFO, "Auto FDT on port " + randomPort);
new Thread(new Runnable() {
@Override
public void run() {
new FDTMain();
}
}, "FDT custom port " + randomPort).start();
}
catch (Exception e)
{
logger.log(Level.INFO, " FAILED auto FDT on port " + randomPort);
}
return randomPort;
}

public void setSessionSocket(ServerSocketChannel ssc, ServerSocket ss, SocketChannel sc, Socket s, int port) {
}
return rtp;
}

private int findAvailablePort() {

/**
* Returns a free port number on localhost.
* @since December 2017
* @author will
* @return a free port number on localhost
* @throws IllegalStateException if unable to find a free port
*/
try(ServerSocket socket = new ServerSocket(0)) {
socket.setReuseAddress(true);
return socket.getLocalPort();
} catch(IOException e)
{
logger.log(Level.WARNING, "Unable to find a free Socket", e);
}

throw new IllegalStateException("Could not find a free TCP/IP port");
}

public void setSessionSocket(ServerSocketChannel ssc, ServerSocket ss, SocketChannel sc, Socket s, int port) {
List<Object> socks = new ArrayList<>();
socks.add(ssc);
socks.add(ss);
Expand Down Expand Up @@ -1219,4 +1229,7 @@ public void setOpentsdb(String opentsdb) {
this.opentsdb = opentsdb;
}

public String getCustomShell() {
return customShell;
}
}
4 changes: 2 additions & 2 deletions src/lia/util/net/common/ControlStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ControlStream {
*/
void connect() throws IOException;

public void startProgram(String cmd) throws IOException;
public void startProgram(String cmd, String customShell) throws IOException;

public InputStream getProgramStdOut() throws IOException;

Expand Down Expand Up @@ -59,4 +59,4 @@ public interface ControlStream {

public void close();

}
}
10 changes: 4 additions & 6 deletions src/lia/util/net/common/GSISSHControlStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ public class GSISSHControlStream implements ControlStream {
* the SSH connection & session
*/
private SshClient conn;

private SessionChannelClient sess;

private String cmd;

private String customShell;

/**
* Creates a new GSI SSH control connection on the default ssh port.
Expand Down Expand Up @@ -64,7 +62,7 @@ public GSISSHControlStream(String hostname, String username, int port) {
// TEST
public static void main(String[] args) throws IOException {
ControlStream cs = new GSISSHControlStream(args[0], args[1]);
cs.startProgram(args[2]);
cs.startProgram(args[2], args[3]);

/* read stdout */
InputStream stdout = new StreamGobbler(cs.getProgramStdOut());
Expand Down Expand Up @@ -115,8 +113,8 @@ public void connect() throws IOException {
*
* @see lia.util.net.common.ControlStream#startProgram(java.lang.String)
*/
public void startProgram(String cmd) throws IOException {
this.cmd = "/bin/bash --login -c '" + cmd + " 2>&1'";
public void startProgram(String cmd, String customShell) throws IOException {
this.cmd = customShell + " --login -c '" + cmd + " 2>&1'";
this.sess.executeCommand(this.cmd);
}

Expand Down
7 changes: 4 additions & 3 deletions src/lia/util/net/common/SSHControlStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SSHControlStream implements ControlStream {
private Connection conn;
private Session sess;
private String cmd;
private String customShell;

/**
* Creates a new SSH control connection on the default ssh port.
Expand Down Expand Up @@ -66,7 +67,7 @@ public SSHControlStream(String hostname, String username, int port) {
// TEST
public static void main(String[] args) throws IOException {
ControlStream cs = new SSHControlStream(args[0], args[1]);
cs.startProgram(args[2]);
cs.startProgram(args[2], args[3]);

/* read stdout */
InputStream stdout = new StreamGobbler(cs.getProgramStdOut());
Expand Down Expand Up @@ -247,8 +248,8 @@ public String getPassword(String message) throws IOException {
/* (non-Javadoc)
* @see lia.util.net.common.ControlStream#startProgram(java.lang.String)
*/
public void startProgram(String cmd) throws IOException {
this.cmd = "/bin/bash --login -c '" + cmd + " 2>&1'";
public void startProgram(String cmd, String customShell) throws IOException {
this.cmd = customShell + " --login -c '" + cmd + " 2>&1'";
this.sess.execCommand(this.cmd);
}

Expand Down
1 change: 0 additions & 1 deletion src/lia/util/net/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,6 @@ public static void closeIgnoringExceptions(Socket socket) {
}
}

@SuppressWarnings("SameParameterValue")
public static void cancelFutureIgnoringException(Future<?> f, boolean mayInterruptIfRunning) {
if (f != null) {
try {
Expand Down
6 changes: 5 additions & 1 deletion src/lia/util/net/common/usage
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Client specific:
By default, FDT will look for ssh keys in
$HOME/.ssh/id_dsa.fdt (DSA) and
$HOME/.ssh/id_rsa.fdt (RSA)
-shell <customShell> By default /bin/bash is used, but if you are on
something esoteric like a mainframe, you might have
an alternate location for bash.
i.e. - /rsusr/rocket/bin/bash

Server specific:
-S disable standalone mode; if specified, the server
Expand Down Expand Up @@ -113,4 +117,4 @@ Miscellaneous:
--version
-h, -help, --help print this help message and quit

Contact: support-fdt@monalisa.cern.ch
Contact: support-fdt@monalisa.cern.ch
Loading

0 comments on commit 891d992

Please sign in to comment.