You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/06/14 19:44:04 UTC
svn commit: r1493182 - in /incubator/ambari/trunk/ambari-server/src:
main/java/org/apache/ambari/server/bootstrap/ main/python/ test/python/
Author: swagle
Date: Fri Jun 14 17:44:03 2013
New Revision: 1493182
URL: http://svn.apache.org/r1493182
Log:
AMBARI-2320. Ambari server should check agent machine can reach ambari server. (Myroslav Papirkovskyy via swagle)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapImpl.java
incubator/ambari/trunk/ambari-server/src/main/python/bootstrap.py
incubator/ambari/trunk/ambari-server/src/main/python/setupAgent.py
incubator/ambari/trunk/ambari-server/src/test/python/TestBootstrap.py
incubator/ambari/trunk/ambari-server/src/test/python/TestSetupAgent.py
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java?rev=1493182&r1=1493181&r2=1493182&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java Fri Jun 14 17:44:03 2013
@@ -54,11 +54,12 @@ class BSRunner extends Thread {
private BootStrapImpl bsImpl;
private final String clusterOsType;
private String projectVersion;
+ private int serverPort;
public BSRunner(BootStrapImpl impl, SshHostInfo sshHostInfo, String bootDir,
String bsScript, String agentSetupScript, String agentSetupPassword,
int requestId, long timeout, String hostName, boolean isVerbose, String clusterOsType,
- String projectVersion)
+ String projectVersion, int serverPort)
{
this.requestId = requestId;
this.sshHostInfo = sshHostInfo;
@@ -73,6 +74,7 @@ class BSRunner extends Thread {
this.clusterOsType = clusterOsType;
this.projectVersion = projectVersion;
this.bsImpl = impl;
+ this.serverPort = serverPort;
BootStrapStatus status = new BootStrapStatus();
status.setLog("RUNNING");
status.setStatus(BSStat.RUNNING);
@@ -151,7 +153,7 @@ class BSRunner extends Thread {
if (user == null || user.isEmpty()) {
user = DEFAULT_USER;
}
- String commands[] = new String[10];
+ String commands[] = new String[11];
String shellCommand[] = new String[3];
BSStat stat = BSStat.RUNNING;
String scriptlog = "";
@@ -190,13 +192,14 @@ class BSRunner extends Thread {
commands[6] = this.ambariHostname;
commands[7] = this.clusterOsType;
commands[8] = this.projectVersion;
+ commands[9] = this.serverPort+"";
if (this.passwordFile != null) {
- commands[9] = this.passwordFile.toString();
+ commands[10] = this.passwordFile.toString();
}
LOG.info("Host= " + hostString + " bs=" + this.bsScript + " requestDir=" +
requestIdDir + " user=" + user + " keyfile=" + this.sshKeyFile +
" passwordFile " + this.passwordFile + " server=" + this.ambariHostname +
- " version=" + projectVersion);
+ " version=" + projectVersion + " serverPort=" + this.serverPort);
String[] env = new String[] { "AMBARI_PASSPHRASE=" + agentSetupPassword };
if (this.verbose)
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapImpl.java?rev=1493182&r1=1493181&r2=1493182&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapImpl.java Fri Jun 14 17:44:03 2013
@@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFac
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import org.apache.ambari.server.controller.AmbariServer;
@Singleton
public class BootStrapImpl {
@@ -50,6 +51,7 @@ public class BootStrapImpl {
private FifoLinkedHashMap<Long, BootStrapStatus> bsStatus;
private final String clusterOsType;
private String projectVersion;
+ private int serverPort;
@Inject
public BootStrapImpl(Configuration conf, AmbariMetaInfo ambariMetaInfo) throws IOException {
@@ -62,6 +64,7 @@ public class BootStrapImpl {
InetAddress.getLocalHost().getCanonicalHostName());
this.clusterOsType = conf.getServerOsType();
this.projectVersion = ambariMetaInfo.getServerVersion();
+ this.serverPort = conf.getClientApiPort();
}
/**
@@ -109,7 +112,7 @@ public class BootStrapImpl {
bsRunner = new BSRunner(this, info, bootStrapDir.toString(),
bootScript, bootSetupAgentScript, bootSetupAgentPassword, requestId, 0L,
- this.masterHostname, info.isVerbose(), this.clusterOsType, this.projectVersion);
+ this.masterHostname, info.isVerbose(), this.clusterOsType, this.projectVersion, this.serverPort);
bsRunner.start();
response.setStatus(BSRunStat.OK);
response.setLog("Running Bootstrap now.");
Modified: incubator/ambari/trunk/ambari-server/src/main/python/bootstrap.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/bootstrap.py?rev=1493182&r1=1493181&r2=1493182&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/bootstrap.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/bootstrap.py Fri Jun 14 17:44:03 2013
@@ -255,7 +255,7 @@ class BootStrap:
""" BootStrapping the agents on a list of hosts"""
- def __init__(self, hosts, user, sshkeyFile, scriptDir, boottmpdir, setupAgentFile, ambariServer, cluster_os_type, ambariVersion, passwordFile = None):
+ def __init__(self, hosts, user, sshkeyFile, scriptDir, boottmpdir, setupAgentFile, ambariServer, cluster_os_type, ambariVersion, server_port, passwordFile = None):
self.hostlist = hosts
self.successive_hostlist = hosts
self.hostlist_to_remove_password_file = None
@@ -269,6 +269,7 @@ class BootStrap:
self.ambariVersion = ambariVersion
self.passwordFile = passwordFile
self.statuses = None
+ self.server_port = server_port
"""Prepare temp file names"""
self.osCheckScriptRemoteLocation = os.path.join(self.TEMP_FOLDER, self.generateRandomFileName(self.OS_CHECK_SCRIPT_FILE_TEMPLATE))
pass
@@ -423,13 +424,19 @@ class BootStrap:
else:
return self.ambariVersion
+ def getAmbariPort(self):
+ if self.server_port is None or self.server_port == "null":
+ return "null"
+ else:
+ return self.server_port
+
def getRunSetupWithPasswordCommand(self):
return "sudo -S python /tmp/setupAgent.py " + os.environ[AMBARI_PASSPHRASE_VAR_NAME] + " " + self.ambariServer +\
- " " + self.getAmbariVersion() + " < " + self.getPasswordFile()
+ " " + self.getAmbariVersion() + " " + self.getAmbariPort() + " < " + self.getPasswordFile()
def getRunSetupWithoutPasswordCommand(self):
return "sudo python /tmp/setupAgent.py " + os.environ[AMBARI_PASSPHRASE_VAR_NAME] + " " + self.ambariServer +\
- " " + self.getAmbariVersion()
+ " " + self.getAmbariVersion() + " " + self.getAmbariPort()
def getRunSetupCommand(self):
if self.hasPassword():
@@ -661,7 +668,7 @@ def main(argv=None):
onlyargs = argv[1:]
if len(onlyargs) < 3:
sys.stderr.write("Usage: <comma separated hosts> "
- "<tmpdir for storage> <user> <sshkeyFile> <agent setup script> <ambari-server name> <cluster os type> <ambari version> <passwordFile>\n")
+ "<tmpdir for storage> <user> <sshkeyFile> <agent setup script> <ambari-server name> <cluster os type> <ambari version> <ambari port> <passwordFile>\n")
sys.exit(2)
pass
#Parse the input
@@ -673,7 +680,8 @@ def main(argv=None):
ambariServer = onlyargs[5]
cluster_os_type = onlyargs[6]
ambariVersion = onlyargs[7]
- passwordFile = onlyargs[8]
+ server_port = onlyargs[8]
+ passwordFile = onlyargs[9]
# ssh doesn't like open files
stat = subprocess.Popen(["chmod", "600", sshKeyFile], stdout=subprocess.PIPE)
@@ -684,8 +692,8 @@ def main(argv=None):
logging.info("BootStrapping hosts " + pprint.pformat(hostList) +
"using " + scriptDir + " cluster primary OS: " + cluster_os_type +
" with user '" + user + "' sshKey File " + sshKeyFile + " password File " + passwordFile +
- " using tmp dir " + bootdir + " ambari: " + ambariServer + "; ambari version: " + ambariVersion)
- bootstrap = BootStrap(hostList, user, sshKeyFile, scriptDir, bootdir, setupAgentFile, ambariServer, cluster_os_type, ambariVersion, passwordFile)
+ " using tmp dir " + bootdir + " ambari: " + ambariServer +"; server_port: " + server_port + "; ambari version: " + ambariVersion)
+ bootstrap = BootStrap(hostList, user, sshKeyFile, scriptDir, bootdir, setupAgentFile, ambariServer, cluster_os_type, ambariVersion, server_port, passwordFile)
ret = bootstrap.run()
#return ret
return 0 # Hack to comply with current usage
Modified: incubator/ambari/trunk/ambari-server/src/main/python/setupAgent.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/setupAgent.py?rev=1493182&r1=1493181&r2=1493182&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/setupAgent.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/setupAgent.py Fri Jun 14 17:44:03 2013
@@ -136,6 +136,19 @@ def findNearestAgentPackageVersion(proje
yumCommand = ["bash", "-c", "yum list available ambari-agent | grep ' " + projectVersion + "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1"]
return execOsCommand(yumCommand)
+def checkServerReachability(host, port):
+ ret = {}
+ s = socket.socket()
+ try:
+ s.connect((host, port))
+ return
+ except socket.error, e:
+ ret["exitstatus"] = 1
+ ret["log"] = "Host registration aborted. Ambari Agent host cannot reach Ambari Server '" + host+":"+str(port) + "'. "+\
+ "Please check the network connectivity between the Ambari Agent host and the Ambari Server"
+ sys.exit(ret)
+ pass
+
def main(argv=None):
scriptDir = os.path.realpath(os.path.dirname(argv[0]))
# Parse the input
@@ -143,12 +156,22 @@ def main(argv=None):
passPhrase = onlyargs[0]
hostName = onlyargs[1]
projectVersion = None
+ server_port = 8080
if len(onlyargs) > 2:
projectVersion = onlyargs[2]
+ if len(onlyargs) > 3:
+ server_port = onlyargs[3]
+ try:
+ server_port = int(server_port)
+ except (Exception), e:
+ server_port = 8080
+
if projectVersion is None or projectVersion == "null":
projectVersion = ""
+ checkServerReachability(hostName, server_port)
+
projectVersion = getOptimalVersion(projectVersion)
if projectVersion != "":
projectVersion = "-" + projectVersion
Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestBootstrap.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestBootstrap.py?rev=1493182&r1=1493181&r2=1493182&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestBootstrap.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestBootstrap.py Fri Jun 14 17:44:03 2013
@@ -79,7 +79,7 @@ class TestBootstrap(TestCase):
SSH_writeLogToFile_method.return_value = None
SSH_writeDoneToFile_method.return_value = None
communicate_method.return_value = ("", "")
- bootstrap = BootStrap(["hostname"], "root", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None)
+ bootstrap = BootStrap(["hostname"], "root", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "8440")
bootstrap.statuses = {
"hostname" : {
"exitstatus" : 0,
@@ -115,7 +115,7 @@ class TestBootstrap(TestCase):
changePasswordFileModeOnHost_method.return_value = 0
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
- bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "passwordFile")
+ bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "8440", "passwordFile")
def side_effect():
bootstrap.copyPasswordFile_called = True
bootstrap.hostlist_to_remove_password_file = ["hostname"]
@@ -151,7 +151,7 @@ class TestBootstrap(TestCase):
changePasswordFileModeOnHost_method.return_value = 0
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
- bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None)
+ bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "8440")
bootstrap.copyPasswordFile_called = False
def side_effect():
bootstrap.copyPasswordFile_called = True
@@ -187,7 +187,7 @@ class TestBootstrap(TestCase):
getMoveRepoFileWithPasswordCommand_method.return_value = ""
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
- bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "passwordFile")
+ bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "8440", "passwordFile")
ret = bootstrap.run()
self.assertTrue(getRunSetupWithPasswordCommand_method.called)
self.assertTrue(getMoveRepoFileWithPasswordCommand_method.called)
@@ -216,7 +216,7 @@ class TestBootstrap(TestCase):
getMoveRepoFileWithoutPasswordCommand_method.return_value = ""
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
- bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None)
+ bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", None, "8440")
ret = bootstrap.run()
self.assertTrue(getRunSetupWithoutPasswordCommand_method.called)
self.assertTrue(getMoveRepoFileWithoutPasswordCommand_method.called)
@@ -241,7 +241,7 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir",
"bootdir", "setupAgentFile", "ambariServer",
- "centos6", None)
+ "centos6", None, "8440")
ret = bootstrap.run()
self.assertTrue(copyOsCheckScript_method.called)
self.assertTrue(runOsCheckScript_method.called)
@@ -259,7 +259,7 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir",
"bootdir", "setupAgentFile", "ambariServer",
- "centos6", None)
+ "centos6", None, "8440")
res = bootstrap.copyOsCheckScript()
self.assertTrue(run_method.called)
self.assertTrue(getstatus_method.called)
@@ -279,7 +279,7 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir",
"bootdir", "setupAgentFile", "ambariServer",
- "centos6", None)
+ "centos6", None, "8440")
bootstrap.statuses = good_stats
bootstrap.runOsCheckScript()
@@ -301,7 +301,7 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir",
"bootdir", "setupAgentFile", "ambariServer",
- "centos6", None)
+ "centos6", None, "8440")
bootstrap.statuses = good_stats
bootstrap.runOsCheckScript()
@@ -328,9 +328,9 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
version = "1.1.1"
- bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", version)
+ bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", version, "8440")
runSetupCommand = bootstrap.getRunSetupCommand()
- self.assertTrue(runSetupCommand.endswith(version))
+ self.assertTrue(runSetupCommand.endswith(version + " 8440"))
@patch.object(SCP, "writeLogToFile")
@patch.object(SSH, "writeLogToFile")
@@ -350,9 +350,9 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
version = None
- bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", version)
+ bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir", "bootdir", "setupAgentFile", "ambariServer", "centos6", version, "8440")
runSetupCommand = bootstrap.getRunSetupCommand()
- self.assertTrue(runSetupCommand.endswith("ambariServer "))
+ self.assertTrue(runSetupCommand.endswith(" 8440"))
@patch.object(BootStrap, "createDoneFiles")
@@ -414,7 +414,7 @@ class TestBootstrap(TestCase):
os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
bootstrap = BootStrap([c6hstr, c5hstr], "user", "sshKeyFile", "scriptDir",
"bootdir", "setupAgentFile", "ambariServer",
- "centos6", None)
+ "centos6", None, "8440")
ret = bootstrap.run()
self.assertTrue(c5hstr not in bootstrap.successive_hostlist)
Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestSetupAgent.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestSetupAgent.py?rev=1493182&r1=1493181&r2=1493182&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestSetupAgent.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestSetupAgent.py Fri Jun 14 17:44:03 2013
@@ -19,10 +19,55 @@ limitations under the License.
from unittest import TestCase
from mock.mock import patch
from subprocess import Popen
+import sys
setup_agent = __import__('setupAgent')
class TestSetupAgent(TestCase):
+ @patch("sys.exit")
+ @patch.object(setup_agent, 'is_suse')
+ @patch.object(setup_agent, 'runAgent')
+ @patch.object(setup_agent, 'configureAgent')
+ @patch.object(setup_agent, 'installAgentSuse')
+ @patch.object(setup_agent, 'checkServerReachability')
+ @patch.object(setup_agent, 'checkAgentPackageAvailabilitySuse')
+ @patch.object(setup_agent, 'checkAgentPackageAvailability')
+ @patch.object(setup_agent, 'findNearestAgentPackageVersionSuse')
+ @patch.object(setup_agent, 'findNearestAgentPackageVersion')
+ def test_checkServerReachability(self, findNearestAgentPackageVersion_method,
+ findNearestAgentPackageVersionSuse_method,
+ checkAgentPackageAvailability_method,
+ checkAgentPackageAvailabilitySuse_method,
+ checkServerReachability_method,
+ installAgentSuse_method,
+ configureAgent_method,
+ runAgent_method,
+ is_suse_method,
+ exit_mock):
+
+ checkServerReachability_method.return_value = {
+
+ }
+
+ checkAgentPackageAvailabilitySuse_method.return_value = {
+ "exitstatus" : 0
+ }
+
+ findNearestAgentPackageVersionSuse_method.return_value = {
+ "exitstatus" : 0,
+ "log": ["1.1.1", ""]
+ }
+
+ installAgentSuse_method.return_value = {}
+ configureAgent_method.return_value = {}
+ runAgent_method.return_value = 0
+
+
+ setup_agent.main(("/root/","password","1.1.1","8080"))
+ self.assertTrue(checkServerReachability_method.called)
+ pass
+
+
@patch.object(setup_agent, 'is_suse')
@patch.object(setup_agent, 'checkAgentPackageAvailabilitySuse')
@patch.object(setup_agent, 'checkAgentPackageAvailability')