Updated Branches: refs/heads/trunk 371186173 -> 665114fad
AMBARI-4425. Add upgradestack support for MySQL.(vbrodetskyi) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/665114fa Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/665114fa Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/665114fa Branch: refs/heads/trunk Commit: 665114fad0c12eb404f632915d3a967fa4da1fd8 Parents: 3711861 Author: Vitaly Brodetskyi <vbrodets...@hortonworks.com> Authored: Tue Jan 28 14:50:43 2014 +0200 Committer: Vitaly Brodetskyi <vbrodets...@hortonworks.com> Committed: Tue Jan 28 14:50:43 2014 +0200 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 18 +++++++++-- .../dml/Ambari-DML-MySQL-UPGRADE_STACK.sql | 34 ++++++++++++++++++++ .../src/test/python/TestAmbariServer.py | 14 +++++++- 3 files changed, 63 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/665114fa/ambari-server/src/main/python/ambari-server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py index 2ace986..f3c28ae 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -346,6 +346,8 @@ ORACLE_EXEC_ARGS = "-S -L '{0}/{1}@(description=(address=(protocol=TCP)(host={2} MYSQL_EXEC_ARGS_WITH_USER_VARS = "--host={0} --port={1} --user={2} --password={3} {4} " \ "-e\"set @schema=\'{4}\'; set @username=\'{2}\'; source {5};\"" MYSQL_EXEC_ARGS_WO_USER_VARS = "--force --host={0} --port={1} --user={2} --password={3} --database={4} < {5} 2> /dev/null" +MYSQL_UPGRADE_STACK_ARGS = "--host={0} --port={1} --user={2} --password={3} --database={4} " \ + "-e\"set @stackName=\'{6}\'; set @stackVersion=\'{7}\'; source {5};\"" ORACLE_UPGRADE_STACK_ARGS = "-S '{0}/{1}@(description=(address=(protocol=TCP)(host={2})(port={3}))(connect_data=({6}={4})))' @{5} {7} {8}" @@ -1336,6 +1338,7 @@ def remote_stack_upgrade(args, scriptPath, stackId): return -1, "Client wasn't found", "Client wasn't found" #TODO add support of other databases with scripts + stack_name, stack_version = stackId.split(STACK_NAME_VER_SEP) if args.database == "oracle": sid_or_sname = "sid" if (hasattr(args, 'sid_or_sname') and args.sid_or_sname == "sname") or \ @@ -1343,7 +1346,6 @@ def remote_stack_upgrade(args, scriptPath, stackId): print_info_msg("using SERVICE_NAME instead of SID for Oracle") sid_or_sname = "service_name" - stack_name, stack_version = stackId.split(STACK_NAME_VER_SEP) retcode, out, err = run_in_shell('{0} {1}'.format(tool, ORACLE_UPGRADE_STACK_ARGS.format( args.database_username, args.database_password, @@ -1356,6 +1358,18 @@ def remote_stack_upgrade(args, scriptPath, stackId): stack_version ))) return retcode, out, err + elif args.database == "mysql": + retcode, out, err = run_in_shell('{0} {1}'.format(tool, MYSQL_UPGRADE_STACK_ARGS.format( + args.database_host, + args.database_port, + args.database_username, + args.database_password, + args.database_name, + scriptPath, + stack_name, + stack_version + ))) + return retcode, out, err return -2, "Wrong database", "Wrong database" pass @@ -2510,7 +2524,7 @@ def upgrade_stack(args, stack_id): client_usage_cmd = DATABASE_CLI_TOOLS_USAGE[DATABASE_INDEX].format(DATABASE_STACK_UPGRADE_SCRIPTS[DATABASE_INDEX], args.database_username, BLIND_PASSWORD, args.database_name) #TODO temporarty code - if not args.database == "oracle": + if not args.database in ["oracle", "mysql"]: raise FatalException(-20, "Upgrade for remote database only supports Oracle.") if get_db_cli_tool(args): http://git-wip-us.apache.org/repos/asf/ambari/blob/665114fa/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-MySQL-UPGRADE_STACK.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-MySQL-UPGRADE_STACK.sql b/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-MySQL-UPGRADE_STACK.sql new file mode 100644 index 0000000..72c4774 --- /dev/null +++ b/ambari-server/src/main/resources/upgrade/dml/Ambari-DML-MySQL-UPGRADE_STACK.sql @@ -0,0 +1,34 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- Update stack_name and stack_version + +UPDATE clusters + SET desired_stack_version = CONCAT('{"stackName":"', @stackName, '",', '"stackVersion":"', @stackVersion, '"}'); +UPDATE clusterstate + SET current_stack_version = CONCAT('{"stackName":"', @stackName, '",', '"stackVersion":"', @stackVersion, '"}'); +UPDATE hostcomponentdesiredstate + SET desired_stack_version = CONCAT('{"stackName":"', @stackName, '",', '"stackVersion":"', @stackVersion, '"}'); +UPDATE hostcomponentstate + SET current_stack_version = CONCAT('{"stackName":"', @stackName, '",', '"stackVersion":"', @stackVersion, '"}'); +UPDATE servicecomponentdesiredstate + SET desired_stack_version = CONCAT('{"stackName":"', @stackName, '",', '"stackVersion":"', @stackVersion, '"}'); +UPDATE servicedesiredstate + SET desired_stack_version = CONCAT('{"stackName":"', @stackName, '",', '"stackVersion":"', @stackVersion, '"}'); +UPDATE hostcomponentstate + SET current_state = 'INSTALLED' WHERE current_state = 'UPGRADING'; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/665114fa/ambari-server/src/test/python/TestAmbariServer.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py index 0e90d7b..d54cf9d 100644 --- a/ambari-server/src/test/python/TestAmbariServer.py +++ b/ambari-server/src/test/python/TestAmbariServer.py @@ -2727,7 +2727,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV self.assertTrue(configure_postgres_username_password_mock.called) self.assertTrue(run_os_command_mock.called) - # Test remote + # Test remote oracle/mysql configure_postgres_username_password_mock.reset_mock() run_os_command_mock.reset_mock() args.persistence_type = "remote" @@ -2742,6 +2742,18 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV self.assertTrue(remote_stack_upgrade_mock.called) self.assertFalse(run_os_command_mock.called) + get_db_cli_tool_mock.reset_mock() + remote_stack_upgrade_mock.reset_mock() + run_os_command_mock.reset_mock() + + args.database = "mysql" + get_db_cli_tool_mock.return_value = "mysql" + remote_stack_upgrade_mock.return_value = (0, "test_mysql_stack_upgrade", "test_mysql_stack_upgrade") + ambari_server.upgrade_stack(args, 'HDP-2.0') + + self.assertTrue(get_db_cli_tool_mock.called) + self.assertTrue(remote_stack_upgrade_mock.called) + self.assertFalse(run_os_command_mock.called) @patch("__builtin__.open")