You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2014/11/14 03:19:48 UTC
[06/29] ambari git commit: AMBARI-8269. Merge branch-windows-dev
changes to trunk. (Jayush Luniya via yusaku)
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/stack_advisor.py
new file mode 100644
index 0000000..cf35e47
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDPWIN/2.1/services/stack_advisor.py
@@ -0,0 +1,414 @@
+#!/usr/bin/env ambari-python-wrap
+"""
+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.
+"""
+
+import re
+import sys
+from math import ceil
+
+from stack_advisor import DefaultStackAdvisor
+
+class HDPWIN21StackAdvisor(DefaultStackAdvisor):
+
+ def getComponentLayoutValidations(self, services, hosts):
+ """Returns array of Validation objects about issues with hostnames components assigned to"""
+ items = []
+
+ # Validating NAMENODE and SECONDARY_NAMENODE are on different hosts if possible
+ hostsList = [host["Hosts"]["host_name"] for host in hosts["items"]]
+ hostsCount = len(hostsList)
+
+ componentsListList = [service["components"] for service in services["services"]]
+ componentsList = [item for sublist in componentsListList for item in sublist]
+ nameNodeHosts = [component["StackServiceComponents"]["hostnames"] for component in componentsList if component["StackServiceComponents"]["component_name"] == "NAMENODE"]
+ secondaryNameNodeHosts = [component["StackServiceComponents"]["hostnames"] for component in componentsList if component["StackServiceComponents"]["component_name"] == "SECONDARY_NAMENODE"]
+
+ # Validating cardinality
+ for component in componentsList:
+ if component["StackServiceComponents"]["cardinality"] is not None:
+ componentName = component["StackServiceComponents"]["component_name"]
+ componentDisplayName = component["StackServiceComponents"]["display_name"]
+ componentHostsCount = 0
+ if component["StackServiceComponents"]["hostnames"] is not None:
+ componentHostsCount = len(component["StackServiceComponents"]["hostnames"])
+ cardinality = str(component["StackServiceComponents"]["cardinality"])
+ # cardinality types: null, 1+, 1-2, 1, ALL
+ message = None
+ if "+" in cardinality:
+ hostsMin = int(cardinality[:-1])
+ if componentHostsCount < hostsMin:
+ message = "At least {0} {1} components should be installed in cluster.".format(hostsMin, componentDisplayName)
+ elif "-" in cardinality:
+ nums = cardinality.split("-")
+ hostsMin = int(nums[0])
+ hostsMax = int(nums[1])
+ if componentHostsCount > hostsMax or componentHostsCount < hostsMin:
+ message = "Between {0} and {1} {2} components should be installed in cluster.".format(hostsMin, hostsMax, componentDisplayName)
+ elif "ALL" == cardinality:
+ if componentHostsCount != hostsCount:
+ message = "{0} component should be installed on all hosts in cluster.".format(componentDisplayName)
+ else:
+ if componentHostsCount != int(cardinality):
+ message = "Exactly {0} {1} components should be installed in cluster.".format(int(cardinality), componentDisplayName)
+
+ if message is not None:
+ items.append({"type": 'host-component', "level": 'ERROR', "message": message, "component-name": componentName})
+
+ # Validating host-usage
+ usedHostsListList = [component["StackServiceComponents"]["hostnames"] for component in componentsList if not self.isComponentNotValuable(component)]
+ usedHostsList = [item for sublist in usedHostsListList for item in sublist]
+ nonUsedHostsList = [item for item in hostsList if item not in usedHostsList]
+ for host in nonUsedHostsList:
+ items.append( { "type": 'host-component', "level": 'ERROR', "message": 'Host is not used', "host": str(host) } )
+
+ return items
+
+ def getServiceConfigurationRecommenderDict(self):
+ return {
+ "YARN": self.recommendYARNConfigurations,
+ "MAPREDUCE2": self.recommendMapReduce2Configurations,
+ "OOZIE": self.recommendOozieConfigurations,
+ "HIVE": self.recommendHiveConfigurations,
+ "TEZ": self.recommendTezConfigurations
+ }
+
+ def putProperty(self, config, configType):
+ config[configType] = {"properties": {}}
+ def appendProperty(key, value):
+ config[configType]["properties"][key] = str(value)
+ return appendProperty
+
+ def recommendYARNConfigurations(self, configurations, clusterData):
+ putYarnProperty = self.putProperty(configurations, "yarn-site")
+ putYarnProperty('yarn.nodemanager.resource.memory-mb', int(round(clusterData['containers'] * clusterData['ramPerContainer'])))
+ putYarnProperty('yarn.scheduler.minimum-allocation-mb', int(clusterData['ramPerContainer']))
+ putYarnProperty('yarn.scheduler.maximum-allocation-mb', int(round(clusterData['containers'] * clusterData['ramPerContainer'])))
+
+ def recommendMapReduce2Configurations(self, configurations, clusterData):
+ putMapredProperty = self.putProperty(configurations, "mapred-site")
+ putMapredProperty('yarn.app.mapreduce.am.resource.mb', int(clusterData['amMemory']))
+ putMapredProperty('yarn.app.mapreduce.am.command-opts', "-Xmx" + str(int(round(0.8 * clusterData['amMemory']))) + "m")
+ putMapredProperty('mapreduce.map.memory.mb', clusterData['mapMemory'])
+ putMapredProperty('mapreduce.reduce.memory.mb', int(clusterData['reduceMemory']))
+ putMapredProperty('mapreduce.map.java.opts', "-Xmx" + str(int(round(0.8 * clusterData['mapMemory']))) + "m")
+ putMapredProperty('mapreduce.reduce.java.opts', "-Xmx" + str(int(round(0.8 * clusterData['reduceMemory']))) + "m")
+ putMapredProperty('mapreduce.task.io.sort.mb', min(int(round(0.4 * clusterData['mapMemory'])), 1024))
+
+ def recommendOozieConfigurations(self, configurations, clusterData):
+ if "FALCON_SERVER" in clusterData["components"]:
+ putMapredProperty = self.putProperty(configurations, "oozie-site")
+ putMapredProperty("oozie.services.ext",
+ "org.apache.oozie.service.JMSAccessorService," +
+ "org.apache.oozie.service.PartitionDependencyManagerService," +
+ "org.apache.oozie.service.HCatAccessorService")
+
+ def recommendHiveConfigurations(self, configurations, clusterData):
+ containerSize = clusterData['mapMemory'] if clusterData['mapMemory'] > 2048 else int(clusterData['reduceMemory'])
+ containerSize = min(clusterData['containers'] * clusterData['ramPerContainer'], containerSize)
+ putHiveProperty = self.putProperty(configurations, "hive-site")
+ putHiveProperty('hive.auto.convert.join.noconditionaltask.size', int(round(containerSize / 3)) * 1048576)
+ putHiveProperty('hive.tez.java.opts', "-server -Xmx" + str(int(round(0.8 * containerSize)))
+ + "m -Djava.net.preferIPv4Stack=true -XX:NewRatio=8 -XX:+UseNUMA -XX:+UseParallelGC")
+ putHiveProperty('hive.tez.container.size', containerSize)
+
+ def recommendTezConfigurations(self, configurations, clusterData):
+ putTezProperty = self.putProperty(configurations, "tez-site")
+ putTezProperty("tez.am.resource.memory.mb", int(clusterData['amMemory']))
+ putTezProperty("tez.am.java.opts",
+ "-server -Xmx" + str(int(0.8 * clusterData["amMemory"]))
+ + "m -Djava.net.preferIPv4Stack=true -XX:+UseNUMA -XX:+UseParallelGC")
+
+ def getConfigurationClusterSummary(self, servicesList, hosts, components):
+
+ hBaseInstalled = False
+ if 'HBASE' in servicesList:
+ hBaseInstalled = True
+
+ cluster = {
+ "cpu": 0,
+ "disk": 0,
+ "ram": 0,
+ "hBaseInstalled": hBaseInstalled,
+ "components": components
+ }
+
+ if len(hosts["items"]) > 0:
+ host = hosts["items"][0]["Hosts"]
+ cluster["cpu"] = host["cpu_count"]
+ cluster["disk"] = len(host["disk_info"])
+ cluster["ram"] = int(host["total_mem"] / (1024 * 1024))
+
+ ramRecommendations = [
+ {"os":1, "hbase":1},
+ {"os":2, "hbase":1},
+ {"os":2, "hbase":2},
+ {"os":4, "hbase":4},
+ {"os":6, "hbase":8},
+ {"os":8, "hbase":8},
+ {"os":8, "hbase":8},
+ {"os":12, "hbase":16},
+ {"os":24, "hbase":24},
+ {"os":32, "hbase":32},
+ {"os":64, "hbase":64}
+ ]
+ index = {
+ cluster["ram"] <= 4: 0,
+ 4 < cluster["ram"] <= 8: 1,
+ 8 < cluster["ram"] <= 16: 2,
+ 16 < cluster["ram"] <= 24: 3,
+ 24 < cluster["ram"] <= 48: 4,
+ 48 < cluster["ram"] <= 64: 5,
+ 64 < cluster["ram"] <= 72: 6,
+ 72 < cluster["ram"] <= 96: 7,
+ 96 < cluster["ram"] <= 128: 8,
+ 128 < cluster["ram"] <= 256: 9,
+ 256 < cluster["ram"]: 10
+ }[1]
+ cluster["reservedRam"] = ramRecommendations[index]["os"]
+ cluster["hbaseRam"] = ramRecommendations[index]["hbase"]
+
+ cluster["minContainerSize"] = {
+ cluster["ram"] <= 4: 256,
+ 4 < cluster["ram"] <= 8: 512,
+ 8 < cluster["ram"] <= 24: 1024,
+ 24 < cluster["ram"]: 2048
+ }[1]
+
+ totalAvailableRam = cluster["ram"] - cluster["reservedRam"]
+ if cluster["hBaseInstalled"]:
+ totalAvailableRam -= cluster["hbaseRam"]
+ cluster["totalAvailableRam"] = max(2048, totalAvailableRam * 1024)
+ '''containers = max(3, min (2*cores,min (1.8*DISKS,(Total available RAM) / MIN_CONTAINER_SIZE))))'''
+ cluster["containers"] = round(max(3,
+ min(2 * cluster["cpu"],
+ min(ceil(1.8 * cluster["disk"]),
+ cluster["totalAvailableRam"] / cluster["minContainerSize"]))))
+
+ '''ramPerContainers = max(2GB, RAM - reservedRam - hBaseRam) / containers'''
+ cluster["ramPerContainer"] = abs(cluster["totalAvailableRam"] / cluster["containers"])
+ '''If greater than 1GB, value will be in multiples of 512.'''
+ if cluster["ramPerContainer"] > 1024:
+ cluster["ramPerContainer"] = int(cluster["ramPerContainer"] / 512) * 512
+
+ cluster["mapMemory"] = int(cluster["ramPerContainer"])
+ cluster["reduceMemory"] = cluster["ramPerContainer"]
+ cluster["amMemory"] = max(cluster["mapMemory"], cluster["reduceMemory"])
+
+ return cluster
+
+ def getConfigurationsValidationItems(self, services, hosts):
+ """Returns array of Validation objects about issues with configuration values provided in services"""
+ items = []
+
+ recommendations = self.recommendConfigurations(services, hosts)
+ recommendedDefaults = recommendations["recommendations"]["blueprint"]["configurations"]
+
+ configurations = services["configurations"]
+ for service in services["services"]:
+ serviceName = service["StackServices"]["service_name"]
+ validator = self.validateServiceConfigurations(serviceName)
+ if validator is not None:
+ siteName = validator[0]
+ method = validator[1]
+ if siteName in recommendedDefaults:
+ siteProperties = getSiteProperties(configurations, siteName)
+ if siteProperties is not None:
+ resultItems = method(siteProperties, recommendedDefaults[siteName]["properties"], configurations)
+ items.extend(resultItems)
+ return items
+
+ def getServiceConfigurationValidators(self):
+ return {
+ "MAPREDUCE2": ["mapred-site", self.validateMapReduce2Configurations],
+ "YARN": ["yarn-site", self.validateYARNConfigurations]
+ "HIVE": ["hive-site", self.validateHiveConfigurations],
+ "TEZ": ["tez-site", self.validateTezConfigurations]
+ }
+
+ def validateServiceConfigurations(self, serviceName):
+ return self.getServiceConfigurationValidators().get(serviceName, None)
+
+ def toConfigurationValidationProblems(self, validationProblems, siteName):
+ result = []
+ for validationProblem in validationProblems:
+ validationItem = validationProblem.get("item", None)
+ if validationItem is not None:
+ problem = {"type": 'configuration', "level": validationItem["level"], "message": validationItem["message"],
+ "config-type": siteName, "config-name": validationProblem["config-name"] }
+ result.append(problem)
+ return result
+
+ def getWarnItem(self, message):
+ return {"level": "WARN", "message": message}
+
+ def getErrorItem(self, message):
+ return {"level": "ERROR", "message": message}
+
+ def validatorLessThenDefaultValue(self, properties, recommendedDefaults, propertyName):
+ if not propertyName in properties:
+ return self.getErrorItem("Value should be set")
+ value = to_number(properties[propertyName])
+ if value is None:
+ return self.getErrorItem("Value should be integer")
+ defaultValue = to_number(recommendedDefaults[propertyName])
+ if defaultValue is None:
+ return None
+ if value < defaultValue:
+ return self.getWarnItem("Value is less than the recommended default of {0}".format(defaultValue))
+ return None
+
+ def validateXmxValue(self, properties, recommendedDefaults, propertyName):
+ if not propertyName in properties:
+ return self.getErrorItem("Value should be set")
+ value = properties[propertyName]
+ defaultValue = recommendedDefaults[propertyName]
+ if defaultValue is None:
+ return self.getErrorItem("Config's default value can't be null or undefined")
+ if not checkXmxValueFormat(value):
+ return self.getErrorItem('Invalid value format')
+ valueInt = formatXmxSizeToBytes(getXmxSize(value))
+ defaultValueXmx = getXmxSize(defaultValue)
+ defaultValueInt = formatXmxSizeToBytes(defaultValueXmx)
+ if valueInt < defaultValueInt:
+ return self.getWarnItem("Value is less than the recommended default of -Xmx" + defaultValueXmx)
+ return None
+
+ def validateMapReduce2Configurations(self, properties, recommendedDefaults, configurations):
+ validationItems = [ {"config-name": 'mapreduce.map.java.opts', "item": self.validateXmxValue(properties, recommendedDefaults, 'mapreduce.map.java.opts')},
+ {"config-name": 'mapreduce.reduce.java.opts', "item": self.validateXmxValue(properties, recommendedDefaults, 'mapreduce.reduce.java.opts')},
+ {"config-name": 'mapreduce.task.io.sort.mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'mapreduce.task.io.sort.mb')},
+ {"config-name": 'mapreduce.map.memory.mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'mapreduce.map.memory.mb')},
+ {"config-name": 'mapreduce.reduce.memory.mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'mapreduce.reduce.memory.mb')},
+ {"config-name": 'yarn.app.mapreduce.am.resource.mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'yarn.app.mapreduce.am.resource.mb')},
+ {"config-name": 'yarn.app.mapreduce.am.command-opts', "item": self.validateXmxValue(properties, recommendedDefaults, 'yarn.app.mapreduce.am.command-opts')} ]
+ return self.toConfigurationValidationProblems(validationItems, "mapred-site")
+
+ def validateYARNConfigurations(self, properties, recommendedDefaults, configurations):
+ validationItems = [ {"config-name": 'yarn.nodemanager.resource.memory-mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'yarn.nodemanager.resource.memory-mb')},
+ {"config-name": 'yarn.scheduler.minimum-allocation-mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'yarn.scheduler.minimum-allocation-mb')},
+ {"config-name": 'yarn.scheduler.maximum-allocation-mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'yarn.scheduler.maximum-allocation-mb')} ]
+ return self.toConfigurationValidationProblems(validationItems, "yarn-site")
+
+ def validateHiveConfigurations(self, properties, recommendedDefaults, configurations):
+ validationItems = [ {"config-name": 'hive.tez.container.size', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'hive.tez.container.size')},
+ {"config-name": 'hive.tez.java.opts', "item": self.validateXmxValue(properties, recommendedDefaults, 'hive.tez.java.opts')},
+ {"config-name": 'hive.auto.convert.join.noconditionaltask.size', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'hive.auto.convert.join.noconditionaltask.size')} ]
+ return self.toConfigurationValidationProblems(validationItems, "hive-site")
+
+ def validateTezConfigurations(self, properties, recommendedDefaults, configurations):
+ validationItems = [ {"config-name": 'tez.am.resource.memory.mb', "item": self.validatorLessThenDefaultValue(properties, recommendedDefaults, 'tez.am.resource.memory.mb')},
+ {"config-name": 'tez.am.java.opts', "item": self.validateXmxValue(properties, recommendedDefaults, 'tez.am.java.opts')} ]
+ return self.toConfigurationValidationProblems(validationItems, "tez-site")
+
+ def getMastersWithMultipleInstances(self):
+ return ['ZOOKEEPER_SERVER', 'HBASE_MASTER']
+
+ def getNotValuableComponents(self):
+ return ['JOURNALNODE', 'ZKFC', 'APP_TIMELINE_SERVER']
+
+ def getNotPreferableOnServerComponents(self):
+ return ['STORM_UI_SERVER', 'DRPC_SERVER', 'STORM_REST_API', 'NIMBUS']
+
+ def getCardinalitiesDict(self):
+ return {
+ 'ZOOKEEPER_SERVER': {"min": 3},
+ 'HBASE_MASTER': {"min": 1},
+ }
+
+ def getComponentLayoutSchemes(self):
+ return {
+ 'NAMENODE': {"else": 0},
+ 'SECONDARY_NAMENODE': {"else": 1},
+ 'HBASE_MASTER': {6: 0, 31: 2, "else": 3},
+
+ 'HISTORYSERVER': {31: 1, "else": 2},
+ 'RESOURCEMANAGER': {31: 1, "else": 2},
+
+ 'OOZIE_SERVER': {6: 1, 31: 2, "else": 3},
+
+ 'HIVE_SERVER': {6: 1, 31: 2, "else": 4},
+ 'HIVE_METASTORE': {6: 1, 31: 2, "else": 4},
+ 'WEBHCAT_SERVER': {6: 1, 31: 2, "else": 4},
+ 'APP_TIMELINE_SERVER': {31: 1, "else": 2},
+ 'FALCON_SERVER': {6: 1, 31: 2, "else": 3}
+ }
+
+# Validation helper methods
+def getSiteProperties(configurations, siteName):
+ siteConfig = configurations.get(siteName)
+ if siteConfig is None:
+ return None
+ return siteConfig.get("properties")
+
+def to_number(s):
+ try:
+ return int(re.sub("\D", "", s))
+ except ValueError:
+ return None
+
+def checkXmxValueFormat(value):
+ p = re.compile('-Xmx(\d+)(b|k|m|g|p|t|B|K|M|G|P|T)?')
+ matches = p.findall(value)
+ return len(matches) == 1
+
+def getXmxSize(value):
+ p = re.compile("-Xmx(\d+)(.?)")
+ result = p.findall(value)[0]
+ if len(result) > 1:
+ # result[1] - is a space or size formatter (b|k|m|g etc)
+ return result[0] + result[1].lower()
+ return result[0]
+
+def formatXmxSizeToBytes(value):
+ value = value.lower()
+ if len(value) == 0:
+ return 0
+ modifier = value[-1]
+
+ if modifier == ' ' or modifier in "0123456789":
+ modifier = 'b'
+ m = {
+ modifier == 'b': 1,
+ modifier == 'k': 1024,
+ modifier == 'm': 1024 * 1024,
+ modifier == 'g': 1024 * 1024 * 1024,
+ modifier == 't': 1024 * 1024 * 1024 * 1024,
+ modifier == 'p': 1024 * 1024 * 1024 * 1024 * 1024
+ }[1]
+ return to_number(value) * m
+
+def getPort(address):
+ """
+ Extracts port from the address like 0.0.0.0:1019
+ """
+ if address is None:
+ return None
+ m = re.search(r'(?:http(?:s)?://)?([\w\d.]*):(\d{1,5})', address)
+ if m is not None:
+ return int(m.group(2))
+ else:
+ return None
+
+def isSecurePort(port):
+ """
+ Returns True if port is root-owned at *nix systems
+ """
+ if port is not None:
+ return port < 1024
+ else:
+ return False
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/main/windows/ambari-server.cmd
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/windows/ambari-server.cmd b/ambari-server/src/main/windows/ambari-server.cmd
new file mode 100644
index 0000000..34d1ccc
--- /dev/null
+++ b/ambari-server/src/main/windows/ambari-server.cmd
@@ -0,0 +1,2 @@
+@echo off
+powershell -File ambari-server.ps1 %*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/main/windows/ambari-server.ps1
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/windows/ambari-server.ps1 b/ambari-server/src/main/windows/ambari-server.ps1
new file mode 100644
index 0000000..9afb341
--- /dev/null
+++ b/ambari-server/src/main/windows/ambari-server.ps1
@@ -0,0 +1,303 @@
+# 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
+
+# description: ambari-server service
+# processname: ambari-server
+
+$VERSION="1.3.0-SNAPSHOT"
+$HASH="testhash"
+
+switch ($($args[0])){
+ "--version" {
+ echo "$VERSION"
+ exit 0
+ }
+ "--hash" {
+ echo "$HASH"
+ exit 0
+ }
+}
+
+$AMBARI_SERVER="ambari-server"
+$AMBARI_SVC_NAME = "Ambari Server"
+$current_directory = (Get-Item -Path ".\" -Verbose).FullName
+#environment variables used in python, check if they exists, otherwise set them to $current_directory
+#and pass to child python process
+$Env:PYTHONPATH="$current_directory\sbin;$($Env:PYTHONPATH)"
+$Env:PYTHON = "python.exe"
+
+$AMBARI_LOG_DIR="\var\log\ambari-server"
+$OUTFILE_STDOUT=Join-Path -path $AMBARI_LOG_DIR -childpath "ambari-server.stdout"
+$OUTFILE_STDERR=Join-Path -path $AMBARI_LOG_DIR -childpath "ambari-server.stderr"
+$LOGFILE=Join-Path -path $AMBARI_LOG_DIR -childpath "ambari-server.log"
+$AMBARI_SERVER_PY_SCRIPT=Join-Path -path $PSScriptRoot -childpath "sbin\ambari-server-windows.py"
+if($AMBARI_SERVER_PY_SCRIPT.Contains(' '))
+{
+ $AMBARI_SERVER_PY_SCRIPT = """" + $AMBARI_SERVER_PY_SCRIPT + """"
+}
+
+$OK=1
+$NOTOK=0
+
+
+# Reading the environment file
+#if [ -a /var/lib/ambari-server/ambari-env.sh ]; then
+# . /var/lib/ambari-server/ambari-env.sh
+#fi
+
+
+#echo $AMBARI_PASSPHRASE
+
+$retcode=0
+
+function _exit($code)
+{
+ $host.SetShouldExit($code)
+ exit $code
+}
+
+function _detect_python()
+{
+ if(![boolean]$(Get-Command $Env:PYTHON -ErrorAction SilentlyContinue))
+ {
+ echo "ERROR: Can not find python.exe in PATH. Add python executable to PATH and try again."
+ _exit(1)
+ }
+}
+function _detect_local_sql()
+{
+ $services = Get-Service -Include @("MSSQL$*")
+ if($services)
+ {
+ echo "Detected following local SQL Server instances:"
+ foreach ($instance in $services) {
+ echo $instance
+ }
+ } else {
+ echo "WARNING: No local SQL Server instances detected. Make sure you have properly configured SQL Server"
+ }
+}
+
+function _echo([switch]$off)
+{
+ if($off)
+ {
+ try
+ {
+ stop-transcript|out-null
+ }
+ catch [System.InvalidOperationException]
+ {}
+ }
+ else
+ {
+ try
+ {
+ start-transcript|out-null
+ }
+ catch [System.InvalidOperationException]
+ {}
+ }
+}
+
+Function _pstart_brief($cmd_args)
+{
+ #start python with -u to make stdout and stderr unbuffered
+ $arguments = @("-u",$AMBARI_SERVER_PY_SCRIPT) + $cmd_args
+
+ $psi = New-Object System.Diagnostics.ProcessStartInfo
+
+ $psi.RedirectStandardError = $True
+ $psi.RedirectStandardOutput = $True
+
+ $psi.UseShellExecute = $False
+
+ $psi.FileName = $Env:PYTHON
+ $psi.Arguments = $arguments
+ #$psi.WindowStyle = WindowStyle.Hidden
+
+ $process = [Diagnostics.Process]::Start($psi)
+
+ $process.WaitForExit()
+
+ Write-Output $process.StandardOutput.ReadToEnd()
+}
+
+Function _start($cmd_args)
+{
+ echo "Starting $AMBARI_SVC_NAME..."
+ _echo -off
+
+ _pstart_brief($cmd_args)
+
+ $cnt = 0
+ do
+ {
+ Start-Sleep -Milliseconds 250
+ $svc = Get-Service -Name $AMBARI_SVC_NAME
+ $cnt += 1
+ if ($cnt -eq 120)
+ {
+ echo "$AMBARI_SVC_NAME still starting...".
+ return
+ }
+ }
+ until($svc.status -eq "Running")
+
+ echo "$AMBARI_SVC_NAME is running"
+}
+
+Function _pstart($cmd_args)
+{
+ New-Item -ItemType Directory -Force -Path $AMBARI_LOG_DIR | Out-Null
+
+ $arguments = @($AMBARI_SERVER_PY_SCRIPT) + $cmd_args
+
+ $p = New-Object System.Diagnostics.Process
+ $p.StartInfo.UseShellExecute = $false
+ $p.StartInfo.FileName = $Env:PYTHON
+ $p.StartInfo.Arguments = $arguments
+ [void]$p.Start();
+
+ echo "Verifying $AMBARI_SERVER process status..."
+ if (!$p){
+ echo "ERROR: $AMBARI_SERVER start failed"
+ $host.SetShouldExit(-1)
+ exit
+ }
+ echo "Server log at: $LOGFILE"
+
+ $p.WaitForExit()
+}
+
+Function _pstart_ioredir($cmd_args)
+{
+ New-Item -ItemType Directory -Force -Path $AMBARI_LOG_DIR | Out-Null
+
+ #start python with -u to make stdout and stderr unbuffered
+ $arguments = @("-u",$AMBARI_SERVER_PY_SCRIPT) + $cmd_args
+ $process = Start-Process -FilePath $Env:PYTHON -ArgumentList $arguments -WindowStyle Hidden -RedirectStandardError $OUTFILE_STDERR -RedirectStandardOutput $OUTFILE_STDOUT -PassThru
+ echo "Verifying $AMBARI_SERVER process status..."
+ if (!$process){
+ echo "ERROR: $AMBARI_SERVER start failed"
+ $host.SetShouldExit(-1)
+ exit
+ }
+ echo "Server stdout at: $OUTFILE_STDOUT"
+ echo "Server stderr at: $OUTFILE_STDERR"
+ echo "Server log at: $LOGFILE"
+
+ $process.WaitForExit()
+}
+
+Function _upgrade($cmd_args){
+ _pstart($cmd_args)
+}
+
+Function _stop($cmd_args){
+ echo "Stopping $AMBARI_SVC_NAME..."
+ _pstart_brief($cmd_args)
+
+ $cnt = 0
+ do
+ {
+ Start-Sleep -Milliseconds 250
+ $svc = Get-Service -Name $AMBARI_SVC_NAME
+ $cnt += 1
+ if ($cnt -eq 40)
+ {
+ echo "$AMBARI_SVC_NAME still stopping...".
+ return
+ }
+ }
+ until($svc.status -eq "Stopped")
+ echo "$AMBARI_SVC_NAME is stopped"
+}
+
+Function _status($cmd_args){
+ echo "Getting $AMBARI_SVC_NAME status..."
+ _pstart_brief($cmd_args)
+}
+
+# check for python before any action
+_detect_python
+switch ($($args[0])){
+ "start" {_start $args}
+ "pstart"
+ {
+ echo "Starting Ambari Server"
+ _pstart_ioredir $args
+ echo "Ambari Server Start finished"
+ }
+ "stop"
+ {
+ echo "Stopping Ambari Server"
+ _stop $args
+ echo "Ambari Server Stop finished"
+ }
+ "reset"
+ {
+ echo "Reseting Ambari Server"
+ _pstart $args
+ echo "Ambari Server Reset finished"
+ }
+ "restart"
+ {
+ echo "Restarting Ambari Server"
+ _stop @("stop")
+ _start @("start")
+ echo "Ambari Server Restart finished"
+ }
+ "upgrade"
+ {
+ echo "Upgrade Ambari Server"
+ _upgrade $args
+ echo "Ambari Server Upgrade finished"
+ }
+ "status"
+ {
+ echo "Checking Ambari Server status"
+ _status $args
+ }
+# "upgradestack" {_pstart $args}
+ "setup"
+ {
+ echo "Installing Ambari Server"
+ _detect_local_sql
+ _pstart $args
+ echo "Ambari Server Installation finished"
+ }
+ "setup-ldap"
+ {
+ echo "Setting up LDAP for Ambari Server"
+ _pstart $args
+ echo "Ambari Server LDAP setup finished"
+ }
+ "setup-security"
+ {
+ echo "Setting up security for Ambari Server"
+ _pstart $args
+ echo "Ambari Server security setup finished"
+ }
+ default
+ {
+ echo "Usage: ambari-server {start|stop|restart|setup|upgrade|status|upgradestack|setup-ldap|setup-security} [options]"
+ echo "Use ambari-server <action> --help to get details on options available."
+ echo "Or, simply invoke ambari-server.py --help to print the options."
+ $retcode=1
+ }
+}
+
+_exit($retcode)
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index 6ab35c2..faaafa6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -610,7 +610,10 @@ public class AmbariMetaInfoTest {
Assert.assertTrue(metaInfo.isOsSupported("suse11"));
Assert.assertTrue(metaInfo.isOsSupported("sles11"));
Assert.assertTrue(metaInfo.isOsSupported("ubuntu12"));
- Assert.assertFalse(metaInfo.isOsSupported("windows"));
+ Assert.assertFalse(metaInfo.isOsSupported("win2008server6"));
+ Assert.assertFalse(metaInfo.isOsSupported("win2008serverr26"));
+ Assert.assertFalse(metaInfo.isOsSupported("win2012server6"));
+ Assert.assertFalse(metaInfo.isOsSupported("win2012serverr26"));
}
@Test
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
index 7ed8459..1f5d9aa 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
@@ -223,7 +223,8 @@ public class ClientConfigResourceProviderTest {
expect(configHelper.getEffectiveConfigProperties(cluster, configTags)).andReturn(properties);
expect(clusterConfig.getType()).andReturn(Configuration.HIVE_CONFIG_TAG).anyTimes();
expect(configHelper.getEffectiveConfigAttributes(cluster, configTags)).andReturn(attributes);
- expect(configuration.getProperty("server.tmp.dir")).andReturn(Configuration.SERVER_TMP_DIR_DEFAULT);
+ expect(configuration.getProperty(Configuration.SERVER_TMP_DIR_KEY)).andReturn(Configuration.SERVER_TMP_DIR_DEFAULT);
+ expect(configuration.getProperty(Configuration.AMBARI_PYTHON_WRAP_KEY)).andReturn(Configuration.AMBARI_PYTHON_WRAP_DEFAULT);
expect(configuration.getExternalScriptTimeout()).andReturn(Integer.parseInt(Configuration.EXTERNAL_SCRIPT_TIMEOUT_DEFAULT));
Map<String,String> props = new HashMap<String, String>();
props.put(Configuration.HIVE_METASTORE_PASSWORD_PROPERTY, "pass");
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/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 ebce460..caa87cc 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -16,6 +16,8 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
+from stacks.utils.RMFTestCase import *
+
import StringIO
import re
from unittest import TestCase
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/TestBootstrap.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestBootstrap.py b/ambari-server/src/test/python/TestBootstrap.py
index 6bcc94f..d0295a2 100644
--- a/ambari-server/src/test/python/TestBootstrap.py
+++ b/ambari-server/src/test/python/TestBootstrap.py
@@ -16,6 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
+from stacks.utils.RMFTestCase import *
import bootstrap
import time
import subprocess
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/TestCheckHost.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestCheckHost.py b/ambari-server/src/test/python/TestCheckHost.py
index 3cc590b..d68c903 100644
--- a/ambari-server/src/test/python/TestCheckHost.py
+++ b/ambari-server/src/test/python/TestCheckHost.py
@@ -17,9 +17,13 @@ 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.
'''
+
+from stacks.utils.RMFTestCase import *
import json
import os
import socket
+import subprocess
+from ambari_commons import inet_utils
from resource_management import Script,ConfigDictionary
from mock.mock import patch
from mock.mock import MagicMock
@@ -60,12 +64,12 @@ class TestCheckHost(TestCase):
@patch.object(Script, 'get_config')
@patch.object(Script, 'get_tmp_dir')
- @patch("check_host.Execute")
+ @patch("check_host.download_file")
@patch("resource_management.libraries.script.Script.put_structured_out")
@patch("subprocess.Popen")
@patch("check_host.format")
@patch("os.path.isfile")
- def testDBConnectionCheck(self, isfile_mock, format_mock, popenMock, structured_out_mock, execute_mock, get_tmp_dir_mock, mock_config):
+ def testDBConnectionCheck(self, isfile_mock, format_mock, popenMock, structured_out_mock, download_file_mock, get_tmp_dir_mock, mock_config):
# test, download DBConnectionVerification.jar failed
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
"java_home" : "test_java_home",
@@ -75,9 +79,10 @@ class TestCheckHost(TestCase):
"db_connection_url" : "test_db_connection_url",
"user_name" : "test_user_name",
"user_passwd" : "test_user_passwd",
- "jdk_name" : "test_jdk_name"}}
+ "jdk_name" : "test_jdk_name"},
+ "hostLevelParams": { "agentCacheDir": "/nonexistent_tmp" }}
get_tmp_dir_mock.return_value = "/tmp"
- execute_mock.side_effect = Exception("test exception")
+ download_file_mock.side_effect = Exception("test exception")
isfile_mock.return_value = True
checkHost = CheckHost()
checkHost.actionexecute(None)
@@ -85,11 +90,6 @@ class TestCheckHost(TestCase):
self.assertEquals(structured_out_mock.call_args[0][0], {'db_connection_check': {'message': 'Error downloading ' \
'DBConnectionVerification.jar from Ambari Server resources. Check network access to Ambari ' \
'Server.\ntest exception', 'exit_code': 1}})
-
- self.assertEquals(format_mock.call_args_list[2][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
- "--retry 5 {jdk_location}{check_db_connection_jar_name} -o {check_db_connection_jar_name}'")
-
- self.assertEquals(format_mock.call_args_list[3][0][0], "[ -f /usr/lib/ambari-agent/{check_db_connection_jar_name}]")
# test, download jdbc driver failed
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
@@ -100,11 +100,12 @@ class TestCheckHost(TestCase):
"db_connection_url" : "test_db_connection_url",
"user_name" : "test_user_name",
"user_passwd" : "test_user_passwd",
- "jdk_name" : "test_jdk_name"}}
+ "jdk_name" : "test_jdk_name"},
+ "hostLevelParams": { "agentCacheDir": "/nonexistent_tmp" }}
format_mock.reset_mock()
- execute_mock.reset_mock()
+ download_file_mock.reset_mock()
p = MagicMock()
- execute_mock.side_effect = [p, Exception("test exception")]
+ download_file_mock.side_effect = [p, Exception("test exception")]
checkHost.actionexecute(None)
@@ -114,24 +115,21 @@ class TestCheckHost(TestCase):
'Server host to make the JDBC driver available for download and to enable testing '
'the database connection.\n')
self.assertEquals(structured_out_mock.call_args[0][0]['db_connection_check']['exit_code'], 1)
- self.assertEquals(format_mock.call_args_list[4][0][0], "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -kf " \
- "--retry 5 {jdbc_url} -o {jdbc_name}'")
-
- self.assertEquals(format_mock.call_args_list[5][0][0], "[ -f /usr/lib/ambari-agent/{jdbc_name}]")
# test, no connection to remote db
mock_config.return_value = {"commandParams" : {"check_execute_list" : "db_connection_check",
"java_home" : "test_java_home",
"ambari_server_host" : "test_host",
"jdk_location" : "test_jdk_location",
- "db_name" : "postgresql",
+ "db_name" : "postgres",
"db_connection_url" : "test_db_connection_url",
"user_name" : "test_user_name",
"user_passwd" : "test_user_passwd",
- "jdk_name" : "test_jdk_name"}}
+ "jdk_name" : "test_jdk_name"},
+ "hostLevelParams": { "agentCacheDir": "/nonexistent_tmp" }}
format_mock.reset_mock()
- execute_mock.reset_mock()
- execute_mock.side_effect = [p, p]
+ download_file_mock.reset_mock()
+ download_file_mock.side_effect = [p, p]
s = MagicMock()
s.communicate.return_value = ("test message", "")
s.returncode = 1
@@ -141,14 +139,14 @@ class TestCheckHost(TestCase):
self.assertEquals(structured_out_mock.call_args[0][0], {'db_connection_check': {'message': 'test message',
'exit_code': 1}})
- self.assertEquals(format_mock.call_args[0][0],'{java64_home}/bin/java -cp /usr/lib/ambari-agent/{check_db_' \
- 'connection_jar_name}:/usr/lib/ambari-agent/{jdbc_name} org.' \
- 'apache.ambari.server.DBConnectionVerification \'{db_connection_url}\' ' \
- '{user_name} {user_passwd!p} {jdbc_driver}')
+ self.assertEquals(format_mock.call_args[0][0],'{java_exec} -cp '\
+ '{check_db_connection_path}{class_path_delimiter}{jdbc_path} -Djava.library.path={agent_cache_dir} '\
+ 'org.apache.ambari.server.DBConnectionVerification {db_connection_url} '\
+ '{user_name} {user_passwd!p} {jdbc_driver}')
# test, db connection success
- execute_mock.reset_mock()
- execute_mock.side_effect = [p, p]
+ download_file_mock.reset_mock()
+ download_file_mock.side_effect = [p, p]
s.returncode = 0
checkHost.actionexecute(None)
@@ -164,7 +162,8 @@ class TestCheckHost(TestCase):
"db_connection_url" : "test_db_connection_url",
"user_name" : "test_user_name",
"user_passwd" : "test_user_passwd",
- "db_name" : "postgresql"}}
+ "db_name" : "postgres"},
+ "hostLevelParams": { "agentCacheDir": "/nonexistent_tmp" }}
isfile_mock.return_value = False
checkHost.actionexecute(None)
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/TestOSCheck.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestOSCheck.py b/ambari-server/src/test/python/TestOSCheck.py
index 1f60964..20b8890 100644
--- a/ambari-server/src/test/python/TestOSCheck.py
+++ b/ambari-server/src/test/python/TestOSCheck.py
@@ -28,6 +28,7 @@ from unittest import TestCase
from mock.mock import patch
from ambari_commons import OSCheck
+from ambari_commons.os_check import get_os_distribution
import os_check_type
utils = __import__('ambari_server.utils').utils
@@ -45,11 +46,13 @@ class TestOSCheck(TestCase):
# 1 - Any system
mock_exists.return_value = False
mock_linux_distribution.return_value = ('my_os', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_type()
self.assertEquals(result, 'my_os')
# 2 - Negative case
mock_linux_distribution.return_value = ('', 'aaaa', 'bbbbb')
+ OSCheck._dist = get_os_distribution()
try:
result = OSCheck.get_os_type()
self.fail("Should throw exception in OSCheck.get_os_type()")
@@ -61,12 +64,14 @@ class TestOSCheck(TestCase):
# 3 - path exist: '/etc/oracle-release'
mock_exists.return_value = True
mock_linux_distribution.return_value = ('some_os', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_type()
self.assertEquals(result, 'oraclelinux')
# 4 - Common system
mock_exists.return_value = False
mock_linux_distribution.return_value = ('CenToS', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_type()
self.assertEquals(result, 'centos')
@@ -74,16 +79,19 @@ class TestOSCheck(TestCase):
mock_exists.return_value = False
# Red Hat Enterprise Linux Server release 6.5 (Santiago)
mock_linux_distribution.return_value = ('Red Hat Enterprise Linux Server', '6.5', 'Santiago')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_type()
self.assertEquals(result, 'redhat')
# Red Hat Enterprise Linux Workstation release 6.4 (Santiago)
mock_linux_distribution.return_value = ('Red Hat Enterprise Linux Workstation', '6.4', 'Santiago')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_type()
self.assertEquals(result, 'redhat')
# Red Hat Enterprise Linux AS release 4 (Nahant Update 3)
mock_linux_distribution.return_value = ('Red Hat Enterprise Linux AS', '4', 'Nahant Update 3')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_type()
self.assertEquals(result, 'redhat')
@@ -94,18 +102,21 @@ class TestOSCheck(TestCase):
# 1 - Any system
mock_exists.return_value = False
mock_linux_distribution.return_value = ('MY_os', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_family()
self.assertEquals(result, 'my_os')
# 2 - Redhat
mock_exists.return_value = False
mock_linux_distribution.return_value = ('Centos Linux', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_family()
self.assertEquals(result, 'redhat')
# 3 - Ubuntu
mock_exists.return_value = False
mock_linux_distribution.return_value = ('Ubuntu', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_family()
self.assertEquals(result, 'ubuntu')
@@ -113,16 +124,19 @@ class TestOSCheck(TestCase):
mock_exists.return_value = False
mock_linux_distribution.return_value = (
'suse linux enterprise server', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_family()
self.assertEquals(result, 'suse')
mock_exists.return_value = False
mock_linux_distribution.return_value = ('SLED', '', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_family()
self.assertEquals(result, 'suse')
# 5 - Negative case
mock_linux_distribution.return_value = ('', '111', '2222')
+ OSCheck._dist = get_os_distribution()
try:
result = OSCheck.get_os_family()
self.fail("Should throw exception in OSCheck.get_os_family()")
@@ -136,11 +150,13 @@ class TestOSCheck(TestCase):
# 1 - Any system
mock_linux_distribution.return_value = ('', '123.45', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_version()
self.assertEquals(result, '123.45')
# 2 - Negative case
mock_linux_distribution.return_value = ('ssss', '', 'ddddd')
+ OSCheck._dist = get_os_distribution()
try:
result = OSCheck.get_os_version()
self.fail("Should throw exception in OSCheck.get_os_version()")
@@ -154,11 +170,13 @@ class TestOSCheck(TestCase):
# 1
mock_linux_distribution.return_value = ('', '123.45.67', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_major_version()
self.assertEquals(result, '123')
# 2
mock_linux_distribution.return_value = ('Suse', '11', '')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_major_version()
self.assertEquals(result, '11')
@@ -167,11 +185,13 @@ class TestOSCheck(TestCase):
# 1 - Any system
mock_linux_distribution.return_value = ('', '', 'MY_NEW_RELEASE')
+ OSCheck._dist = get_os_distribution()
result = OSCheck.get_os_release_name()
self.assertEquals(result, 'my_new_release')
# 2 - Negative case
mock_linux_distribution.return_value = ('aaaa', 'bbbb', '')
+ OSCheck._dist = get_os_distribution()
try:
result = OSCheck.get_os_release_name()
self.fail("Should throw exception in OSCheck.get_os_release_name()")
@@ -233,6 +253,7 @@ class TestOSCheck(TestCase):
mock_linux_distribution.return_value = ('aaa', '11', 'bb')
base_args = ["os_check_type.py", "aaa11"]
sys.argv = list(base_args)
+ OSCheck._dist = get_os_distribution()
try:
os_check_type.main()
@@ -244,6 +265,7 @@ class TestOSCheck(TestCase):
mock_linux_distribution.return_value = ('ddd', '33', 'bb')
base_args = ["os_check_type.py", "zzz_x77"]
sys.argv = list(base_args)
+ OSCheck._dist = get_os_distribution()
try:
os_check_type.main()
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py b/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py
index f7926f7..086fa2b 100644
--- a/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py
+++ b/ambari-server/src/test/python/stacks/1.3.2/HDFS/test_datanode.py
@@ -17,8 +17,6 @@ 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.
'''
-from ambari_commons import OSCheck
-from mock.mock import MagicMock, patch
from stacks.utils.RMFTestCase import *
class TestDatanode(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/1.3.2/hooks/before-ANY/test_before_any.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-ANY/test_before_any.py b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-ANY/test_before_any.py
index 16aa939..d0f8bbf 100644
--- a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-ANY/test_before_any.py
+++ b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-ANY/test_before_any.py
@@ -18,9 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
-from mock.mock import MagicMock, call, patch
-from resource_management import *
from stacks.utils.RMFTestCase import *
+from mock.mock import MagicMock, call, patch
+from resource_management import Hook
@patch.object(Hook, "run_custom_hook", new = MagicMock())
class TestHookBeforeInstall(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
index 1f508c7..904c469 100644
--- a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
+++ b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
@@ -18,9 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
+from stacks.utils.RMFTestCase import *
from mock.mock import MagicMock, call, patch
from resource_management import *
-from stacks.utils.RMFTestCase import *
@patch.object(Hook, "run_custom_hook", new = MagicMock())
class TestHookBeforeInstall(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/1.3.2/hooks/before-START/test_before_start.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-START/test_before_start.py b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-START/test_before_start.py
index d27ed5a..7fc033e 100644
--- a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-START/test_before_start.py
+++ b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-START/test_before_start.py
@@ -18,9 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
-from mock.mock import MagicMock, call, patch
-from resource_management import *
from stacks.utils.RMFTestCase import *
+from mock.mock import MagicMock, call, patch
+from resource_management import Hook
import json
@patch("os.path.exists", new = MagicMock(return_value=True))
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py
index 5372e2a..465f42b 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py
@@ -17,10 +17,10 @@ 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.
'''
+from stacks.utils.RMFTestCase import *
from ambari_commons import OSCheck
import json
from mock.mock import MagicMock, patch
-from stacks.utils.RMFTestCase import *
class TestDatanode(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
index ec63d9b..3a576eb 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
@@ -411,8 +411,8 @@ class TestNamenode(RMFTestCase):
bin_dir = '/usr/bin',
kinit_override = True)
self.assertNoMoreResources()
-
-
+
+
def test_decommission_secured(self):
self.executeScript("2.0.6/services/HDFS/package/scripts/namenode.py",
classname = "NameNode",
@@ -510,7 +510,7 @@ class TestNamenode(RMFTestCase):
recursive = True,
mode = 0755,
)
-
+
@patch("resource_management.libraries.script.Script.put_structured_out")
def test_rebalance_hdfs(self, pso):
Popen_Mock.return_value = 1
@@ -526,7 +526,7 @@ class TestNamenode(RMFTestCase):
self.fail("Exception was not thrown")
except resource_management.core.exceptions.Fail:
pass ##expected
-
+
pso.reset_mock()
Popen_Mock.return_value = 0
ll = subprocess.Popen()
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py
index 7b241fb..558d37a 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py
@@ -466,5 +466,3 @@ class TestHDP206StackAdvisor(TestCase):
pass
actualItems.append(next)
self.checkEqual(expectedItems, actualItems)
-
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
index 8b5a698..552da62 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-ANY/test_before_any.py
@@ -18,9 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
-from mock.mock import MagicMock, call, patch
-from resource_management import *
from stacks.utils.RMFTestCase import *
+from mock.mock import MagicMock, call, patch
+from resource_management import Hook
@patch.object(Hook, "run_custom_hook", new = MagicMock())
class TestHookBeforeInstall(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
index 1ae0e60..cec41b7 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
@@ -18,9 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
+from stacks.utils.RMFTestCase import *
from mock.mock import MagicMock, call, patch
from resource_management import *
-from stacks.utils.RMFTestCase import *
@patch.object(Hook, "run_custom_hook", new = MagicMock())
class TestHookBeforeInstall(RMFTestCase):
http://git-wip-us.apache.org/repos/asf/ambari/blob/8de3425f/ambari-server/src/test/python/stacks/2.0.6/hooks/before-START/test_before_start.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-START/test_before_start.py b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-START/test_before_start.py
index 4b7ffa5..5fceb8a 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-START/test_before_start.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-START/test_before_start.py
@@ -18,9 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
-from mock.mock import MagicMock, call, patch
-from resource_management import *
from stacks.utils.RMFTestCase import *
+from mock.mock import MagicMock, call, patch
+from resource_management import Hook
import json
@patch("os.path.exists", new = MagicMock(return_value=True))