Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/common/src/main/java/alluxio/conf/PropertyKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,13 @@ public String toString() {
.setConsistencyCheckLevel(ConsistencyCheckLevel.ENFORCE)
.setScope(Scope.MASTER)
.build();
public static final PropertyKey HOST_SSH_PORT =
intBuilder(Name.HOST_SSH_PORT)
.setDefaultValue(22)
.setDescription("The SSH Port that used for shell remote connect between nodes.")
.setConsistencyCheckLevel(ConsistencyCheckLevel.WARN)
.setScope(Scope.ALL)
.build();
/**
* UFS related properties.
*/
Expand Down Expand Up @@ -6354,6 +6361,7 @@ public static final class Name {
public static final String ZOOKEEPER_AUTH_ENABLED = "alluxio.zookeeper.auth.enabled";
public static final String ZOOKEEPER_LEADER_CONNECTION_ERROR_POLICY =
"alluxio.zookeeper.leader.connection.error.policy";
public static final String HOST_SSH_PORT = "alluxio.host.ssh.port";
//
// UFS related properties
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import alluxio.grpc.Scope;
import alluxio.util.ConfigurationUtils;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -162,15 +163,26 @@ protected ValidationTaskResult validateImpl(Map<String, String> optionMap)

private Properties getNodeConf(String node) throws IOException {
String homeDir = mConf.getString(PropertyKey.HOME);
int sshPort = getHostSSHPort();
String remoteCommand = String.format(
"%s/bin/alluxio getConf", homeDir);
String localCommand = String.format(
"ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt %s \"bash %s\"",
node, remoteCommand);
"ssh -p %d -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt %s \"bash %s\"",
sshPort, node, remoteCommand);
String[] command = {"bash", "-c", localCommand};
Properties properties = new Properties();
Process process = Runtime.getRuntime().exec(command);
properties.load(process.getInputStream());
return properties;
}

/**
* get ssh port from conf and this method is used for test.
*
* @return return host ssh port
*/
@VisibleForTesting
protected int getHostSSHPort() {
return mConf.getInt(PropertyKey.HOST_SSH_PORT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import alluxio.util.CommonUtils;
import alluxio.util.ConfigurationUtils;

import com.google.common.annotations.VisibleForTesting;

import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -55,13 +57,25 @@ public ValidationTaskResult validateImpl(Map<String, String> optionsMap) {
}

ValidationUtils.State state = ValidationUtils.State.OK;
int sshPort = getHostSSHPort();
for (String nodeName : nodes) {
if (!CommonUtils.isAddressReachable(nodeName, 22, 30 * Constants.SECOND_MS)) {
msg.append(String.format("Unable to reach ssh port 22 on node %s.%n", nodeName));
if (!CommonUtils.isAddressReachable(nodeName, sshPort,
30 * Constants.SECOND_MS)) {
msg.append(String.format("Unable to reach ssh port %d on node %s.%n", sshPort, nodeName));
advice.append(String.format("Please configure password-less ssh to node %s.%n", nodeName));
state = ValidationUtils.State.FAILED;
}
}
return new ValidationTaskResult(state, getName(), msg.toString(), advice.toString());
}

/**
* get ssh port from conf and this method is used for test.
*
* @return return host ssh port
*/
@VisibleForTesting
protected int getHostSSHPort() {
return mConf.getInt(PropertyKey.HOST_SSH_PORT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import alluxio.util.ConfigurationUtils;
import alluxio.util.network.NetworkAddressUtils.ServiceType;

import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -248,8 +249,9 @@ private boolean validateRemote(Collection<String> nodes, String target,
private boolean validateRemote(String node, String target, String name,
CommandLine cmd) throws InterruptedException {
System.out.format("Validating %s environment on %s...%n", target, node);
if (!CommonUtils.isAddressReachable(node, 22, 30 * Constants.SECOND_MS)) {
System.err.format("Unable to reach ssh port 22 on node %s.%n", node);
int sshPort = getHostSSHPort();
if (!CommonUtils.isAddressReachable(node, sshPort, 30 * Constants.SECOND_MS)) {
System.err.format("Unable to reach ssh port %d on node %s.%n", sshPort, node);
return false;
}

Expand All @@ -260,8 +262,8 @@ private boolean validateRemote(String node, String target, String name,
"%s/bin/alluxio validateEnv %s %s %s",
homeDir, target, name == null ? "" : name, argStr);
String localCommand = String.format(
"ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt %s \"bash %s\"",
node, remoteCommand);
"ssh -p %d -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt %s \"bash %s\"",
sshPort, node, remoteCommand);
String[] command = {"bash", "-c", localCommand};
try {
ProcessBuilder builder = new ProcessBuilder(command);
Expand Down Expand Up @@ -481,4 +483,14 @@ private static CommandLine parseArgsAndOptions(Options options, String... args)
}
return cmd;
}

/**
* get ssh port from conf and this method is used for test.
*
* @return return host ssh port
*/
@VisibleForTesting
protected int getHostSSHPort() {
return mConf.getInt(PropertyKey.HOST_SSH_PORT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package alluxio.cli;

import static org.junit.Assert.assertEquals;

import alluxio.conf.InstancedConfiguration;
import alluxio.conf.PropertyKey;

import org.junit.Test;

public class SSHPortTest {

@Test
public void getHostSshPortTest() {
InstancedConfiguration mConf = InstancedConfiguration.defaults();
mConf.set(PropertyKey.HOST_SSH_PORT, 22022);

int sshPort1 = new SshValidationTask(mConf).getHostSSHPort();
int sshPort2 = new ClusterConfConsistencyValidationTask(mConf).getHostSSHPort();
int sshPort3 = new ValidateEnv("", mConf).getHostSSHPort();

assertEquals(sshPort1, 22022);
assertEquals(sshPort2, 22022);
assertEquals(sshPort3, 22022);
}
}