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/10/08 00:53:08 UTC
[40/51] [partial] AMBARI-7621. Import initial contribution for Ambari
support on Windows to branch-windows-dev. (Jayush Luniya and Florian Barca
via yusaku)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/groovy-client/src/test/resources/blueprint-config.json
----------------------------------------------------------------------
diff --git a/ambari-client/groovy-client/src/test/resources/blueprint-config.json b/ambari-client/groovy-client/src/test/resources/blueprint-config.json
deleted file mode 100644
index bf3f67d..0000000
--- a/ambari-client/groovy-client/src/test/resources/blueprint-config.json
+++ /dev/null
@@ -1,61 +0,0 @@
-{
- "Blueprints": {
- "blueprint_name": "single-node-hdfs-yarn",
- "stack_version": "2.0",
- "stack_name": "HDP"
- },
- "configurations": [
- {
- "yarn-site": {
- "property-key": "property-value",
- "yarn.nodemanager.local-dirs": "/mnt/fs1/,/mnt/fs2/"
- }
- },
- {
- "hdfs-site": {
- "dfs.datanode.data.dir": "/mnt/fs1/,/mnt/fs2/"
- }
- }
- ],
- "host_groups": [
- {
- "name": "host_group_1",
- "components": [
- {
- "name": "NAMENODE"
- },
- {
- "name": "SECONDARY_NAMENODE"
- },
- {
- "name": "DATANODE"
- },
- {
- "name": "HDFS_CLIENT"
- },
- {
- "name": "RESOURCEMANAGER"
- },
- {
- "name": "NODEMANAGER"
- },
- {
- "name": "YARN_CLIENT"
- },
- {
- "name": "HISTORYSERVER"
- },
- {
- "name": "MAPREDUCE2_CLIENT"
- },
- {
- "name": "ZOOKEEPER_SERVER"
- },
- {
- "name": "ZOOKEEPER_CLIENT"
- }
- ],
- "cardinality": "1"
- }
- ]
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/groovy-client/src/test/resources/hdp-multinode-default.json
----------------------------------------------------------------------
diff --git a/ambari-client/groovy-client/src/test/resources/hdp-multinode-default.json b/ambari-client/groovy-client/src/test/resources/hdp-multinode-default.json
deleted file mode 100644
index f6c7f3f..0000000
--- a/ambari-client/groovy-client/src/test/resources/hdp-multinode-default.json
+++ /dev/null
@@ -1,200 +0,0 @@
-{
- "configurations" : [
- {
- "global" : {
- "nagios_contact" : "admin@localhost"
- }
- }
- ],
- "host_groups" : [
- {
- "name" : "master_1",
- "components" : [
- {
- "name" : "NAMENODE"
- },
- {
- "name" : "ZOOKEEPER_SERVER"
- },
- {
- "name" : "HBASE_MASTER"
- },
- {
- "name" : "GANGLIA_SERVER"
- },
- {
- "name" : "HDFS_CLIENT"
- },
- {
- "name" : "YARN_CLIENT"
- },
- {
- "name" : "HCAT"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "master_2",
- "components" : [
-
- {
- "name" : "ZOOKEEPER_CLIENT"
- },
- {
- "name" : "HISTORYSERVER"
- },
- {
- "name" : "HIVE_SERVER"
- },
- {
- "name" : "SECONDARY_NAMENODE"
- },
- {
- "name" : "HIVE_METASTORE"
- },
- {
- "name" : "HDFS_CLIENT"
- },
- {
- "name" : "HIVE_CLIENT"
- },
- {
- "name" : "YARN_CLIENT"
- },
- {
- "name" : "MYSQL_SERVER"
- },
- {
- "name" : "GANGLIA_MONITOR"
- },
- {
- "name" : "WEBHCAT_SERVER"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "master_3",
- "components" : [
- {
- "name" : "RESOURCEMANAGER"
- },
- {
- "name" : "ZOOKEEPER_SERVER"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "master_4",
- "components" : [
- {
- "name" : "OOZIE_SERVER"
- },
- {
- "name" : "ZOOKEEPER_SERVER"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "slave_1",
- "components" : [
- {
- "name" : "HBASE_REGIONSERVER"
- },
- {
- "name" : "NODEMANAGER"
- },
- {
- "name" : "DATANODE"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "${slavesCount}"
- },
- {
- "name" : "SLAVE_2",
- "components" : [
- {
- "name" : "HBASE_REGIONSERVER"
- },
- {
- "name" : "NODEMANAGER"
- },
- {
- "name" : "DATANODE"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "${slavesCount}"
- },
- {
- "name" : "gateway",
- "components" : [
- {
- "name" : "AMBARI_SERVER"
- },
- {
- "name" : "NAGIOS_SERVER"
- },
- {
- "name" : "GANGLIA_SERVER"
- },
- {
- "name" : "ZOOKEEPER_CLIENT"
- },
- {
- "name" : "PIG"
- },
- {
- "name" : "OOZIE_CLIENT"
- },
- {
- "name" : "HBASE_CLIENT"
- },
- {
- "name" : "HCAT"
- },
- {
- "name" : "SQOOP"
- },
- {
- "name" : "HDFS_CLIENT"
- },
- {
- "name" : "HIVE_CLIENT"
- },
- {
- "name" : "YARN_CLIENT"
- },
- {
- "name" : "MAPREDUCE2_CLIENT"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- }
- ],
- "Blueprints" : {
- "blueprint_name" : "hdp-multinode-default",
- "stack_name" : "HDP",
- "stack_version" : "2.1"
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/groovy-client/src/test/resources/hdp-multinode-default2.json
----------------------------------------------------------------------
diff --git a/ambari-client/groovy-client/src/test/resources/hdp-multinode-default2.json b/ambari-client/groovy-client/src/test/resources/hdp-multinode-default2.json
deleted file mode 100644
index 4db3680..0000000
--- a/ambari-client/groovy-client/src/test/resources/hdp-multinode-default2.json
+++ /dev/null
@@ -1,164 +0,0 @@
-{
- "configurations" : [
- {
- "global" : {
- "nagios_contact" : "admin@localhost"
- }
- }
- ],
- "host_groups" : [
- {
- "name" : "master_1",
- "components" : [
- {
- "name" : "NAMENODE"
- },
- {
- "name" : "ZOOKEEPER_SERVER"
- },
- {
- "name" : "HBASE_MASTER"
- },
- {
- "name" : "GANGLIA_SERVER"
- },
- {
- "name" : "HDFS_CLIENT"
- },
- {
- "name" : "YARN_CLIENT"
- },
- {
- "name" : "HCAT"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "master_2",
- "components" : [
-
- {
- "name" : "ZOOKEEPER_CLIENT"
- },
- {
- "name" : "HISTORYSERVER"
- },
- {
- "name" : "HIVE_SERVER"
- },
- {
- "name" : "SECONDARY_NAMENODE"
- },
- {
- "name" : "HIVE_METASTORE"
- },
- {
- "name" : "HDFS_CLIENT"
- },
- {
- "name" : "HIVE_CLIENT"
- },
- {
- "name" : "YARN_CLIENT"
- },
- {
- "name" : "MYSQL_SERVER"
- },
- {
- "name" : "GANGLIA_MONITOR"
- },
- {
- "name" : "WEBHCAT_SERVER"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "master_3",
- "components" : [
- {
- "name" : "RESOURCEMANAGER"
- },
- {
- "name" : "ZOOKEEPER_SERVER"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "master_4",
- "components" : [
- {
- "name" : "OOZIE_SERVER"
- },
- {
- "name" : "ZOOKEEPER_SERVER"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- },
- {
- "name" : "gateway",
- "components" : [
- {
- "name" : "AMBARI_SERVER"
- },
- {
- "name" : "NAGIOS_SERVER"
- },
- {
- "name" : "GANGLIA_SERVER"
- },
- {
- "name" : "ZOOKEEPER_CLIENT"
- },
- {
- "name" : "PIG"
- },
- {
- "name" : "OOZIE_CLIENT"
- },
- {
- "name" : "HBASE_CLIENT"
- },
- {
- "name" : "HCAT"
- },
- {
- "name" : "SQOOP"
- },
- {
- "name" : "HDFS_CLIENT"
- },
- {
- "name" : "HIVE_CLIENT"
- },
- {
- "name" : "YARN_CLIENT"
- },
- {
- "name" : "MAPREDUCE2_CLIENT"
- },
- {
- "name" : "GANGLIA_MONITOR"
- }
- ],
- "cardinality" : "1"
- }
- ],
- "Blueprints" : {
- "blueprint_name" : "hdp-multinode-default",
- "stack_name" : "HDP",
- "stack_version" : "2.1"
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn-config.json
----------------------------------------------------------------------
diff --git a/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn-config.json b/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn-config.json
deleted file mode 100644
index 16f4938..0000000
--- a/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn-config.json
+++ /dev/null
@@ -1,89 +0,0 @@
-{
- "configurations": [
- {
- "global": {
- "nagios_contact": "admin@localhost"
- }
- },
- {
- "hdfs-site": {
- "dfs.datanode.data.dir": "/mnt/fs1/,/mnt/fs2/"
- }
- },
- {
- "yarn-site": {
- "yarn.nodemanager.local-dirs": "apple",
- "property-key": "property-value"
- }
- },
- {
- "core-site": {
- "fs.defaultFS": "localhost:9000"
- }
- }
- ],
- "host_groups": [
- {
- "name": "master",
- "components": [
- {
- "name": "NAMENODE"
- },
- {
- "name": "GANGLIA_SERVER"
- },
- {
- "name": "HISTORYSERVER"
- },
- {
- "name": "SECONDARY_NAMENODE"
- },
- {
- "name": "RESOURCEMANAGER"
- },
- {
- "name": "HISTORYSERVER"
- },
- {
- "name": "NAGIOS_SERVER"
- },
- {
- "name": "ZOOKEEPER_SERVER"
- }
- ],
- "cardinality": "1"
- },
- {
- "name": "slave_1",
- "components": [
- {
- "name": "DATANODE"
- },
- {
- "name": "GANGLIA_MONITOR"
- },
- {
- "name": "HDFS_CLIENT"
- },
- {
- "name": "NODEMANAGER"
- },
- {
- "name": "YARN_CLIENT"
- },
- {
- "name": "MAPREDUCE2_CLIENT"
- },
- {
- "name": "ZOOKEEPER_CLIENT"
- }
- ],
- "cardinality": "2"
- }
- ],
- "Blueprints": {
- "blueprint_name": "multi-node-hdfs-yarn",
- "stack_name": "HDP",
- "stack_version": "2.1"
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn.json
----------------------------------------------------------------------
diff --git a/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn.json b/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn.json
deleted file mode 100644
index fce02ad..0000000
--- a/ambari-client/groovy-client/src/test/resources/multi-node-hdfs-yarn.json
+++ /dev/null
@@ -1,83 +0,0 @@
-{
- "configurations": [
- {
- "global": {
- "nagios_contact": "admin@localhost"
- }
- },
- {
- "hdfs-site": {
- "dfs.datanode.data.dir": "/mnt/fs1/,/mnt/fs2/"
- }
- },
- {
- "yarn-site": {
- "yarn.nodemanager.local-dirs": "/mnt/fs1/,/mnt/fs2/"
- }
- }
- ],
- "host_groups": [
- {
- "name": "master",
- "components": [
- {
- "name": "NAMENODE"
- },
- {
- "name": "GANGLIA_SERVER"
- },
- {
- "name": "HISTORYSERVER"
- },
- {
- "name": "SECONDARY_NAMENODE"
- },
- {
- "name": "RESOURCEMANAGER"
- },
- {
- "name": "HISTORYSERVER"
- },
- {
- "name": "NAGIOS_SERVER"
- },
- {
- "name": "ZOOKEEPER_SERVER"
- }
- ],
- "cardinality": "1"
- },
- {
- "name": "slave_1",
- "components": [
- {
- "name": "DATANODE"
- },
- {
- "name": "GANGLIA_MONITOR"
- },
- {
- "name": "HDFS_CLIENT"
- },
- {
- "name": "NODEMANAGER"
- },
- {
- "name": "YARN_CLIENT"
- },
- {
- "name": "MAPREDUCE2_CLIENT"
- },
- {
- "name": "ZOOKEEPER_CLIENT"
- }
- ],
- "cardinality": "2"
- }
- ],
- "Blueprints": {
- "blueprint_name": "multi-node-hdfs-yarn",
- "stack_name": "HDP",
- "stack_version": "2.1"
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/pom.xml b/ambari-client/python-client/pom.xml
index 74fc0f5..e16bbc2 100644
--- a/ambari-client/python-client/pom.xml
+++ b/ambari-client/python-client/pom.xml
@@ -75,7 +75,7 @@
<executions>
<execution>
<configuration>
- <executable>${project.basedir}/../../ambari-common/src/main/unix/ambari-python-wrap</executable>
+ <executable>python</executable>
<workingDirectory>src/test/python</workingDirectory>
<arguments>
<argument>unitTests.py</argument>
@@ -93,7 +93,7 @@
</execution>
<execution>
<configuration>
- <executable>${project.basedir}/../../ambari-common/src/main/unix/ambari-python-wrap</executable>
+ <executable>python</executable>
<workingDirectory>target/python-client-${project.version}</workingDirectory>
<arguments>
<argument>${project.basedir}/src/main/python/setup.py</argument>
@@ -115,7 +115,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
- <version>2.0.1</version>
+ <version>2.1-alpha-2</version>
<executions>
<execution>
<phase>none</phase>
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py b/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
index d3832c8..a79d907 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
@@ -145,22 +145,6 @@ class AmbariClient(RestResource):
"""
return cluster._create_cluster(self, cluster_name, version)
- def create_cluster_from_blueprint(self, cluster_name, blueprint_name,
- host_groups, configurations=None,
- default_password=None):
- """
- Create a new cluster.
- @param cluster_name: Cluster cluster_name
- @param blueprint_name: the name of the blueprint
- @param host_groups: an array of host_group information
- @param configurations: an array of configuration overrides
- @param default_password: the default password to use for all password-requiring services
- @return ClusterModel object.
- """
- return cluster._create_cluster_from_blueprint(self, cluster_name,
- blueprint_name, host_groups, configurations=configurations,
- default_password=default_password)
-
def delete_cluster(self, cluster_name):
"""
Delete a cluster
@@ -256,7 +240,7 @@ class AmbariClient(RestResource):
"""
return status._get_N_requests(self, cluster_name, noOfrequest)
- def get_blueprint(self, blueprint_name):
+ def get_blueprint(self, blueprint_name=None):
"""
get blueprint
@param blueprint_name:blueprint_name name.
@@ -272,7 +256,7 @@ class AmbariClient(RestResource):
"""
return blueprint.get_cluster_blueprint(self, cluster_name)
- def delete_blueprint(self, blueprint_name):
+ def delete_blueprint(self, blueprint_name=None):
"""
get blueprint
@param blueprint_name:blueprint_name name.
@@ -280,13 +264,13 @@ class AmbariClient(RestResource):
"""
return blueprint.delete_blueprint(self, blueprint_name)
- def create_blueprint(self, blueprint_name, blueprint_schema):
+ def create_blueprint(self, blueprint_name=None):
"""
get blueprint
@param blueprint_name:blueprint_name name.
@return: A BlueprintModel object
"""
- return blueprint.create_blueprint(self, blueprint_name, blueprint_schema)
+ return blueprint.create_blueprint(self, blueprint_name)
def get_root_resource(
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py b/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py
index 56f10c3..278df2e 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py
@@ -14,14 +14,3 @@
# 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
-
-def normalize_all_caps(name):
- """
- This converts all caps words into normal case.
- i.e. 'NAGIOS_SERVER' becomes 'Nagios Server'
- """
- normalized = name.lower()
- normalized = re.sub('_(\w)', lambda match: ' ' + match.group(1).upper(), normalized)
- return normalized[0].upper() + normalized[1:]
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/core/http_client.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/core/http_client.py b/ambari-client/python-client/src/main/python/ambari_client/core/http_client.py
index 7f7e526..39b9961 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/core/http_client.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/core/http_client.py
@@ -99,7 +99,6 @@ class HttpClient(object):
(path,))
payload = None
- self.c.unsetopt(pycurl.CUSTOMREQUEST)
buf = cStringIO.StringIO()
self.c.setopt(pycurl.WRITEFUNCTION, buf.write)
self.c.setopt(pycurl.SSL_VERIFYPEER, 0)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py b/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
index 21b0b33..e207a6b 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
@@ -88,16 +88,16 @@ def delete_blueprint(resource_root, blueprint_name):
"NO_KEY")
-def create_blueprint(resource_root, blueprint_name, blueprint_schema):
+def create_blueprint(resource_root, blueprint_name, json_data):
"""
Create a blueprint
@param root_resource: The root Resource.
@param blueprint_name: blueprint_name
- @param blueprint_schema: blueprint json
+ @param json_data: blueprint json
@return: An ClusterModel object
"""
path = paths.BLUEPRINT_PATH % blueprint_name
- resp = resource_root.post(path=path, payload=blueprint_schema)
+ resp = resource_root.post(path=path, payload=json_data)
return utils.ModelUtils.create_model(
status.StatusModel,
resp,
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py b/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
index 7e0b378..87cd86e 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
@@ -72,37 +72,6 @@ def _create_cluster(root_resource, cluster_name, version):
"NO_KEY")
-def _create_cluster_from_blueprint(root_resource, cluster_name, blueprint_name,
- host_groups, configurations=None,
- default_password=None):
- """
- Create a cluster
- @param root_resource: The root Resource.
- @param cluster_name: Cluster cluster_name
- @param blueprint_name: the name of the blueprint
- @param host_groups: an array of host_group information
- @param configurations: an array of configuration overrides
- @param default_password: the default password to use for all password-requiring services
- @return: An StatusModel object
- """
- data = {
- "blueprint" : blueprint_name,
- "host_groups" : host_groups,
- }
- if configurations is not None:
- data['configurations'] = configurations
- if default_password is not None:
- data['default_password'] = default_password
-
- path = paths.CLUSTERS_PATH + "/%s" % (cluster_name)
- resp = root_resource.post(path=path, payload=data)
- return utils.ModelUtils.create_model(
- status.StatusModel,
- resp,
- root_resource,
- "NO_KEY")
-
-
def _delete_cluster(root_resource, cluster_name):
"""
Delete a cluster by name
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/model/component.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/component.py b/ambari-client/python-client/src/main/python/ambari_client/model/component.py
index c0323ab..5e04fc8 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/model/component.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/model/component.py
@@ -16,7 +16,6 @@
# limitations under the License.
import logging
-from ambari_client.core.coreutils import normalize_all_caps
from ambari_client.model.base_model import BaseModel, ModelList
from ambari_client.model import paths, utils, status
@@ -74,22 +73,9 @@ def _get_service_component(
resource_root,
"ServiceComponentInfo")
-def _delete_host_component(
- resource_root,
- cluster_name ,
- host_name ,
- component_name):
- path = paths.HOSTS_COMPONENT_PATH % (
- cluster_name, host_name , component_name)
- resp = resource_root.delete(path)
- return utils.ModelUtils.create_model(
- status.StatusModel,
- resp,
- resource_root,
- "NO_KEY")
-
class ComponentModel(BaseModel):
+
"""
The ComponentModel class
"""
@@ -138,70 +124,3 @@ class ComponentModel(BaseModel):
self._get_cluster_name(), self.host_name, self.component_name) + "?fields=metrics"
metricjson = self._get_resource_root().get(metricpath)
return metricjson
-
-
- def delete(self):
- return _delete_host_component(self._get_resource_root(), self._get_cluster_name(), self.host_name, self.component_name)
-
- def install(self):
- data = {
- "RequestInfo": {
- "context": "Install %s" % normalize_all_caps(self.component_name),
- },
- "HostRoles": {
- "state": "INSTALLED",
- },
- }
- root_resource = self._get_resource_root()
- resp = root_resource.put(path=self._path() + '/' + self.component_name, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
- def start(self):
- data = {
- "RequestInfo": {
- "context": "Start %s" % normalize_all_caps(self.component_name),
- },
- "HostRoles": {
- "state": "STARTED",
- },
- }
- root_resource = self._get_resource_root()
- resp = root_resource.put(path=self._path() + '/' + self.component_name, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
- def stop(self):
- data = {
- "RequestInfo": {
- "context": "Stop %s" % normalize_all_caps(self.component_name),
- },
- "HostRoles": {
- "state": "INSTALLED",
- },
- }
- root_resource = self._get_resource_root()
- resp = root_resource.put(path=self._path() + '/' + self.component_name, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
- def restart(self):
- # need to move this to utils, handle _ gracefully
- data = {
- "RequestInfo": {
- "command": "RESTART",
- "context": "Restart %s" % normalize_all_caps(self.component_name),
- "operation_level": {
- "level": "SERVICE",
- "cluster_name": self._get_cluster_name(),
- "service_name": self.service_name,
-
- },
- },
- "Requests/resource_filters": [{
- "service_name": self.service_name,
- "component_name": self.component_name,
- "hosts": self.host_name,
- }],
- }
- root_resource = self._get_resource_root()
- path = paths.CLUSTER_REQUESTS_PATH % self._get_cluster_name()
- resp = root_resource.post(path=path, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/model/host.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/host.py b/ambari-client/python-client/src/main/python/ambari_client/model/host.py
index dd4bcb4..f6c39d6 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/model/host.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/model/host.py
@@ -222,7 +222,7 @@ def _bootstrap_hosts(root_resource, hosts_list, ssh_key, ssh_user):
payload_dic = {
"verbose": True,
"sshKey": ssh_key,
- "hosts": hosts_list,
+ "hosts": str(hosts_list),
"user": ssh_user}
resp = root_resource.post(
paths.BOOTSTRAP_PATH,
@@ -321,83 +321,3 @@ class HostModel(BaseModel):
self._get_cluster_name(),
self.host_name,
component_name)
-
- def install_all_components(self):
- root_resource = self._get_resource_root()
- path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(),
- self.host_name)
- data = {
- "RequestInfo": {
- "context" :"Install All Components",
- },
- "Body": {
- "HostRoles": {"state": "INSTALLED"},
- },
- }
- resp = root_resource.put(path=path, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp,
- root_resource, "NO_KEY")
-
- def start_all_components(self):
- root_resource = self._get_resource_root()
- path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(),
- self.host_name)
- data = {
- "RequestInfo": {
- "context" :"Start All Components",
- },
- "Body": {
- "HostRoles": {"state": "STARTED"},
- },
- }
- resp = root_resource.put(path=path, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp,
- root_resource, "NO_KEY")
-
- def stop_all_components(self):
- root_resource = self._get_resource_root()
- path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(),
- self.host_name)
- data = {
- "RequestInfo": {
- "context" :"Stop All Components",
- },
- "Body": {
- "HostRoles": {"state": "INSTALLED"},
- },
- }
- resp = root_resource.put(path=path, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp,
- root_resource, "NO_KEY")
-
- def enable_maintenance_mode(self):
- root_resource = self._get_resource_root()
- path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(),
- self.host_name)
- data = {
- "RequestInfo": {
- "context" :"Start Maintanence Mode",
- },
- "Body": {
- "HostRoles": {"maintenance_state": "ON"},
- },
- }
- resp = root_resource.put(path=path, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp,
- root_resource, "NO_KEY")
-
- def disable_maintenance_mode(self):
- root_resource = self._get_resource_root()
- path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(),
- self.host_name)
- data = {
- "RequestInfo": {
- "context" :"Stop Maintanence Mode",
- },
- "Body": {
- "HostRoles": {"maintenance_state": "OFF"},
- },
- }
- resp = root_resource.put(path=path, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp,
- root_resource, "NO_KEY")
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/main/python/ambari_client/model/paths.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/paths.py b/ambari-client/python-client/src/main/python/ambari_client/model/paths.py
index 17a4633..e111824 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/model/paths.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/model/paths.py
@@ -21,7 +21,7 @@ CLUSTER_HOSTS_PATH = "/clusters/%s/hosts"
CLUSTER_HOST_PATH = "/clusters/%s/hosts/%s"
CLUSTER_START_ALL_SERVICES = "/clusters/%s/services?ServiceInfo/state=INSTALLED"
CLUSTER_STOP_ALL_SERVICES = "/clusters/%s/services?ServiceInfo"
-CLUSTER_REQUESTS_PATH = "/clusters/%s/requests"
+
SERVICES_PATH = "/clusters/%s/services"
SERVICE_PATH = "/clusters/%s/services/%s"
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/test/python/TestAmbariClient.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/test/python/TestAmbariClient.py b/ambari-client/python-client/src/test/python/TestAmbariClient.py
index c044e1d..0013d1b 100755
--- a/ambari-client/python-client/src/test/python/TestAmbariClient.py
+++ b/ambari-client/python-client/src/test/python/TestAmbariClient.py
@@ -116,7 +116,7 @@ class TestAmbariClient(unittest.TestCase):
self.assertEqual(len(all_hosts), 12, "There should be 12 hosts from the response")
self.assertEqual(all_hosts.to_json_dict(), expected_hosts_dict)
- def ADisabledtest_bootstrap_hosts(self):
+ def test_bootstrap_hosts(self):
"""
Test Bootstrap
"""
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-client/python-client/src/test/python/TestStatusModel.py
----------------------------------------------------------------------
diff --git a/ambari-client/python-client/src/test/python/TestStatusModel.py b/ambari-client/python-client/src/test/python/TestStatusModel.py
index 107bd84..9a2eb06 100644
--- a/ambari-client/python-client/src/test/python/TestStatusModel.py
+++ b/ambari-client/python-client/src/test/python/TestStatusModel.py
@@ -65,7 +65,7 @@ class TestStatusModel(unittest.TestCase):
self.assertTrue(error_model.is_error())
self.assertFalse(ok_model.is_error())
- def ADisabledtest_get_bootstrap_path(self):
+ def test_get_bootstrap_path(self):
http_client_mock = MagicMock()
ssh_key = 'abc!@#$%^&*()_:"|<>?[];\'\\./'
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/__init__.py b/ambari-common/src/main/python/ambari_commons/__init__.py
index df4d7d6..b759e76 100644
--- a/ambari-common/src/main/python/ambari_commons/__init__.py
+++ b/ambari-common/src/main/python/ambari_commons/__init__.py
@@ -19,11 +19,8 @@ limitations under the License.
'''
from ambari_commons.os_check import OSCheck, OSConst
-from ambari_commons.firewall import Firewall, FirewallChecks
__all__ = [
'OSCheck',
'OSConst',
- 'Firewall',
- 'FirewallChecks'
]
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/ambari_service.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/ambari_service.py b/ambari-common/src/main/python/ambari_commons/ambari_service.py
new file mode 100644
index 0000000..8418e74
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/ambari_service.py
@@ -0,0 +1,79 @@
+'''
+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 os
+
+import win32service
+
+from ambari_commons.os_windows import WinService
+
+
+AMBARI_VERSION_VAR = "AMBARI_VERSION_VAR"
+
+ENV_PYTHON_PATH = "PYTHONPATH"
+
+
+class AmbariService(WinService):
+ _svc_name_ = "Ambari Service"
+ _svc_display_name_ = "Ambari Service"
+ _svc_description_ = "Ambari Service"
+
+ # Sets the current dir and adjusts the PYTHONPATH env variable before calling SvcDoRun()
+ def SvcRun(self):
+ self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
+
+ import servicemanager
+
+ parser = self._InitOptionsParser()
+ (self.options, args) = parser.parse_args()
+
+ try:
+ is_debugging = servicemanager.Debugging()
+ except:
+ is_debugging = False
+
+ if not is_debugging:
+ # Save the current dir, or the script dir if none set (typical for services)
+ script_path = os.path.dirname(__file__.replace('/', os.sep))
+ # the script resides in the sbin/ambari_commons subdir
+ self.options.current_dir = os.path.normpath(script_path + "\\..\\..")
+ os.chdir(self.options.current_dir)
+
+ python_path = os.path.normpath(script_path + "\\..")
+
+ #update the environment vars: set PYTHONPATH = $script_dir\sbin;%PYTHONPATH%
+ if os.environ.has_key(ENV_PYTHON_PATH):
+ python_path += os.pathsep + os.environ[ENV_PYTHON_PATH]
+ os.environ[ENV_PYTHON_PATH] = python_path
+
+ self.SvcDoRun()
+ pass
+
+ # Call during initialization to implement standard service versioning
+ @classmethod
+ def _AdjustServiceVersion(cls):
+ if os.environ.has_key(AMBARI_VERSION_VAR):
+ ambariVer = os.environ[AMBARI_VERSION_VAR]
+ else:
+ ambariVer = "1.3.0-SNAPSHOT"
+ AmbariService._svc_display_name_ += "-" + ambariVer
+ AmbariService._svc_description_ += " v" + ambariVer
+
+ # Override to customize the command-line arguments
+ def _InitOptionsParser(self):
+ pass
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/exceptions.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/exceptions.py b/ambari-common/src/main/python/ambari_commons/exceptions.py
new file mode 100644
index 0000000..c5ed85d
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/exceptions.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+'''
+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.
+'''
+
+class FatalException(Exception):
+ def __init__(self, code, reason):
+ self.code = code
+ self.reason = reason
+
+ def __str__(self):
+ return repr("Fatal exception: %s, exit code %s" % (self.reason, self.code))
+
+
+class NonFatalException(Exception):
+ def __init__(self, reason):
+ self.reason = reason
+
+ def __str__(self):
+ return repr("NonFatal exception: %s" % self.reason)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/firewall.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/firewall.py b/ambari-common/src/main/python/ambari_commons/firewall.py
deleted file mode 100644
index b73cc0c..0000000
--- a/ambari-common/src/main/python/ambari_commons/firewall.py
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/usr/bin/env python
-
-'''
-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 subprocess
-import shlex
-from ambari_commons import OSCheck, OSConst
-
-
-class Firewall(object):
- def __init__(self):
- # OS info
- self.OS_VERSION = OSCheck().get_os_major_version()
- self.OS_TYPE = OSCheck.get_os_type()
- self.OS_FAMILY = OSCheck.get_os_family()
-
- def getFirewallObject(self):
- if self.OS_TYPE == OSConst.OS_UBUNTU:
- return UbuntuFirewallChecks()
- elif self.OS_TYPE == OSConst.OS_FEDORA and int(self.OS_VERSION) >= 18:
- return Fedora18FirewallChecks()
- elif self.OS_FAMILY == OSConst.SUSE_FAMILY:
- return SuseFirewallChecks()
- else:
- return FirewallChecks()
-
-class FirewallChecks(object):
- def __init__(self):
- self.FIREWALL_SERVICE_NAME = "iptables"
- self.SERVICE_SUBCMD = "status"
- # service cmd
- self.SERVICE_CMD = "/sbin/service"
- self.returncode = None
- self.stdoutdata = None
- self.stderrdata = None
-
- def get_command(self):
- return "%s %s %s" % (self.SERVICE_CMD, self.FIREWALL_SERVICE_NAME, self.SERVICE_SUBCMD)
-
- def check_result(self, retcode, out, err):
- result = False
- if retcode == 3:
- result = False
- elif retcode == 0:
- if "Table: filter" in out:
- result = True
- return result
-
- def check_iptables(self):
- try:
- retcode, out, err = self.run_os_command(self.get_command())
- return self.check_result(retcode, out, err)
- except OSError:
- return False
-
- def run_os_command(self, cmd):
- if type(cmd) == str:
- cmd = shlex.split(cmd)
-
- process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
- stderr=subprocess.PIPE)
- (stdoutdata, stderrdata) = process.communicate()
- self.returncode = process.returncode
- self.stdoutdata = stdoutdata
- self.stderrdata = stderrdata
- return self.returncode, self.stdoutdata, self.stderrdata
-
-
-
-class UbuntuFirewallChecks(FirewallChecks):
- def __init__(self):
- super(UbuntuFirewallChecks, self).__init__()
- self.FIREWALL_SERVICE_NAME = "ufw"
-
- def get_command(self):
- return "%s %s" % (self.FIREWALL_SERVICE_NAME, self.SERVICE_SUBCMD)
-
- def check_result(self, retcode, out, err):
- # On ubuntu, the status command returns 0 whether running or not
- result = False
- if retcode == 0:
- if "Status: inactive" in out:
- result = False
- elif "Status: active" in out:
- result = True
- return result
-
-class Fedora18FirewallChecks(FirewallChecks):
- def __init__(self):
- super(Fedora18FirewallChecks, self).__init__()
-
- def get_command(self):
- return "systemctl is-active %s" % (self.FIREWALL_SERVICE_NAME)
-
- def check_result(self, retcode, out, err):
- result = False
- if retcode == 0:
- if "active" in out:
- result = True
- return result
-
-class SuseFirewallChecks(FirewallChecks):
- def __init__(self):
- super(SuseFirewallChecks, self).__init__()
- self.FIREWALL_SERVICE_NAME = "SuSEfirewall2"
-
- def get_command(self):
- return "%s %s" % (self.FIREWALL_SERVICE_NAME, self.SERVICE_SUBCMD)
-
- def check_result(self, retcode, out, err):
- result = False
- if retcode == 0:
- if "SuSEfirewall2 not active" in out:
- result = False
- elif "### iptables" in out:
- result = True
- return result
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/inet_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/inet_utils.py b/ambari-common/src/main/python/ambari_commons/inet_utils.py
new file mode 100644
index 0000000..6ccb742
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/inet_utils.py
@@ -0,0 +1,148 @@
+#!/usr/bin/env python
+
+'''
+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 os
+import sys
+import urllib2
+
+from exceptions import *
+from logging import *
+
+def download_file(link, destination, chunk_size=16 * 1024):
+ print_info_msg("Downloading {0} to {1}".format(link, destination))
+ if os.path.exists(destination):
+ print_warning_msg("File {0} already exists, assuming it was downloaded before".format(destination))
+ return
+
+ force_download_file(link, destination, chunk_size)
+
+
+def download_progress(file_name, downloaded_size, blockSize, totalSize):
+ percent = int(downloaded_size * 100 / totalSize)
+ status = "\r" + file_name
+
+ if totalSize < blockSize:
+ status += "... %d%%" % (100)
+ else:
+ status += "... %d%% (%.1f MB of %.1f MB)" % (
+ percent, downloaded_size / 1024 / 1024.0, totalSize / 1024 / 1024.0)
+ sys.stdout.write(status)
+ sys.stdout.flush()
+
+
+def find_range_components(meta):
+ file_size = 0
+ seek_pos = 0
+ hdr_range = meta.getheaders("Content-Range")
+ if len(hdr_range) > 0:
+ range_comp1 = hdr_range[0].split('/')
+ if len(range_comp1) > 1:
+ range_comp2 = range_comp1[0].split(' ') #split away the "bytes" prefix
+ if len(range_comp2) == 0:
+ raise FatalException(12, 'Malformed Content-Range response header: "{}".' % hdr_range)
+ range_comp3 = range_comp2[1].split('-')
+ seek_pos = int(range_comp3[0])
+ if range_comp1[1] != '*': #'*' == unknown length
+ file_size = int(range_comp1[1])
+
+ if file_size == 0:
+ #Try the old-fashioned way
+ hdrLen = meta.getheaders("Content-Length")
+ if len(hdrLen) == 0:
+ raise FatalException(12, "Response header doesn't contain Content-Length. Chunked Transfer-Encoding is not supported for now.")
+ file_size = int(hdrLen[0])
+
+ return (file_size, seek_pos)
+
+
+def force_download_file(link, destination, chunk_size = 16 * 1024, progress_func = download_progress):
+ request = urllib2.Request(link)
+
+ if os.path.exists(destination) and not os.path.isfile(destination):
+ #Directory specified as target? Must be a mistake. Bail out, don't assume anything.
+ err = 'Download target {} is a directory.' % destination
+ raise FatalException(1, err)
+
+ (dest_path, file_name) = os.path.split(destination)
+
+ temp_dest = destination + ".tmpdownload"
+ partial_size = 0
+
+ if os.path.exists(temp_dest):
+ #Support for resuming downloads, in case the process is killed while downloading a file
+ # set resume range
+ # See http://stackoverflow.com/questions/6963283/python-urllib2-resume-download-doesnt-work-when-network-reconnects
+ partial_size = os.stat(temp_dest).st_size
+ if partial_size > chunk_size:
+ #Re-download the last chunk, to minimize the possibilities of file corruption
+ resume_pos = partial_size - chunk_size
+ request.add_header("Range", "bytes=%s-" % resume_pos)
+ else:
+ #Make sure the full dir structure is in place, otherwise file open will fail
+ if not os.path.exists(dest_path):
+ os.makedirs(dest_path)
+
+ response = urllib2.urlopen(request)
+ (file_size, seek_pos) = find_range_components(response.info())
+
+ print_info_msg("Downloading to: %s Bytes: %s" % (destination, file_size))
+
+ if partial_size < file_size:
+ if seek_pos == 0:
+ #New file, create it
+ open_mode = 'wb'
+ else:
+ #Resuming download of an existing file
+ open_mode = 'rb+' #rb+ doesn't create the file, using wb to create it
+ f = open(temp_dest, open_mode)
+
+ try:
+ #Resume the download from where it left off
+ if seek_pos > 0:
+ f.seek(seek_pos)
+
+ file_size_dl = seek_pos
+ while True:
+ buffer = response.read(chunk_size)
+ if not buffer:
+ break
+
+ file_size_dl += len(buffer)
+ f.write(buffer)
+
+ progress_func(file_name, file_size_dl, chunk_size, file_size)
+ finally:
+ f.close()
+
+ sys.stdout.write('\n')
+ sys.stdout.flush()
+
+ print_info_msg("Finished downloading {0} to {1}".format(link, destination))
+
+ downloaded_size = os.stat(temp_dest).st_size
+ if downloaded_size != file_size:
+ err = 'Size of downloaded file {} is {} bytes, it is probably damaged or incomplete' % (destination, downloaded_size)
+ raise FatalException(1, err)
+
+ # when download is complete -> mv temp_dest destination
+ if os.path.exists(destination):
+ #Windows behavior: rename fails if the destination file exists
+ os.unlink(destination)
+ os.rename(temp_dest, destination)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/logging.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/logging.py b/ambari-common/src/main/python/ambari_commons/logging.py
new file mode 100644
index 0000000..9d45fdb
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/logging.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+'''
+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.
+'''
+
+VERBOSE = False
+SILENT = False
+DEBUG_MODE = False
+
+# terminal styles
+BOLD_ON = '\033[1m'
+BOLD_OFF = '\033[0m'
+
+#
+# Prints an "info" messsage.
+#
+def print_info_msg(msg):
+ if VERBOSE:
+ print("INFO: " + msg)
+
+#
+# Prints an "error" messsage.
+#
+def print_error_msg(msg):
+ print("ERROR: " + msg)
+
+#
+# Prints a "warning" messsage.
+#
+def print_warning_msg(msg, bold=False):
+ if bold:
+ print(BOLD_ON + "WARNING: " + msg + BOLD_OFF)
+ else:
+ print("WARNING: " + msg)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/os_check.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_check.py b/ambari-common/src/main/python/ambari_commons/os_check.py
index 2bab473..5509476 100644
--- a/ambari-common/src/main/python/ambari_commons/os_check.py
+++ b/ambari-common/src/main/python/ambari_commons/os_check.py
@@ -22,23 +22,42 @@ import os
import sys
import platform
-
def linux_distribution():
PYTHON_VER = sys.version_info[0] * 10 + sys.version_info[1]
if PYTHON_VER < 26:
- linux_distribution = platform.dist()
+ (distname, version, id) = platform.dist()
else:
- linux_distribution = platform.linux_distribution()
+ (distname, version, id) = platform.linux_distribution()
+
+ return (platform.system(), os.name, distname, version, id)
+
+def windows_distribution():
+ from os_windows import get_windows_version
+
+ # Only support Windows Server 64 bit
+ (win_release, win_version, win_csd, win_ptype) = platform.win32_ver()
- return linux_distribution
+ if win_version.startswith("6.2."):
+ # win32_ver() doesn't work correctly for Windows Server 2012 R2 and Windows 8.1
+ (win_ver_major, win_ver_minor, win_ver_build) = get_windows_version()
+ if win_ver_major == 6 and win_ver_minor == 3:
+ win_release = "2012ServerR2"
+ win_version = "%d.%d.%d" % (win_ver_major, win_ver_minor, win_ver_build)
+ #if win_version
+ return (platform.system(), os.name, "win" + win_release, win_version, win_ptype)
class OS_CONST_TYPE(type):
+ # os platforms
+ LINUX_OS = 'linux'
+ WINDOWS_OS = 'windows'
+
# os families
REDHAT_FAMILY = 'redhat'
- UBUNTU_FAMILY = 'ubuntu'
+ DEBIAN_FAMILY = 'debian'
SUSE_FAMILY = 'suse'
+ WINSRV_FAMILY = 'winsrv'
# Declare here os type mapping
OS_FAMILY_COLLECTION = [
@@ -49,19 +68,33 @@ class OS_CONST_TYPE(type):
'cloudlinux', 'slc', 'scientific', 'psbm',
'centos linux']
},
- {'name': UBUNTU_FAMILY,
+ {'name': DEBIAN_FAMILY,
'os_list': ['ubuntu', 'debian']
},
{'name': SUSE_FAMILY,
'os_list': ['sles', 'sled', 'opensuse', 'suse']
}
]
+ WIN_OS_FAMILY_COLLECTION = [
+ {'name': WINSRV_FAMILY,
+ 'os_list':
+ ['win2008Server', 'win2008ServerR2', 'win2012Server', 'win2012ServerR2']
+ },
+ ]
# Would be generated from Family collection definition
OS_COLLECTION = []
def __init__(cls, name, bases, dct):
- for item in cls.OS_FAMILY_COLLECTION:
- cls.OS_COLLECTION += item['os_list']
+ if platform.system() == 'Windows':
+ for item in cls.WIN_OS_FAMILY_COLLECTION:
+ cls.OS_COLLECTION += item['os_list']
+ else:
+ if platform.system() == 'Mac':
+ raise Exception("MacOS not supported. Exiting...")
+ else:
+ dist = linux_distribution()
+ for item in cls.OS_FAMILY_COLLECTION:
+ cls.OS_COLLECTION += item['os_list']
def __getattr__(cls, name):
"""
@@ -77,17 +110,45 @@ class OS_CONST_TYPE(type):
else:
raise Exception("Unknown class property '%s'" % name)
+def get_os_distribution():
+ if platform.system() == 'Windows':
+ dist = windows_distribution()
+ else:
+ if platform.system() == 'Mac':
+ raise Exception("MacOS not supported. Exiting...")
+ else:
+ # Linux
+ # Read content from /etc/*-release file
+ # Full release name
+ dist = linux_distribution()
+ return dist
class OSConst:
__metaclass__ = OS_CONST_TYPE
class OSCheck:
+ _dist = get_os_distribution()
+
+ @staticmethod
+ def get_os_os():
+ """
+ Return values:
+ windows, linux
+
+ In case cannot detect - exit.
+ """
+ # Read content from /etc/*-release file
+ # Full release name
+ os_os = OSCheck._dist[0].lower()
+
+ return os_os
@staticmethod
def get_os_type():
"""
Return values:
+ win2008server, win2012server,
redhat, fedora, centos, oraclelinux, ascendos,
amazon, xenserver, oel, ovs, cloudlinux, slc, scientific, psbm,
ubuntu, debian, sles, sled, opensuse, suse ... and others
@@ -96,8 +157,7 @@ class OSCheck:
"""
# Read content from /etc/*-release file
# Full release name
- dist = linux_distribution()
- operatingSystem = dist[0].lower()
+ operatingSystem = OSCheck._dist[2].lower()
# special cases
if os.path.exists('/etc/oracle-release'):
@@ -120,11 +180,14 @@ class OSCheck:
In case cannot detect raises exception( from self.get_operating_system_type() ).
"""
- os_family = OSCheck.get_os_type()
- for os_family_item in OSConst.OS_FAMILY_COLLECTION:
- if os_family in os_family_item['os_list']:
- os_family = os_family_item['name']
- break
+ if(OSCheck._dist[0] == 'Windows'):
+ os_family = OSConst.WIN_OS_FAMILY_COLLECTION[0]['name']
+ else:
+ os_family = OSCheck.get_os_type()
+ for os_family_item in OSConst.OS_FAMILY_COLLECTION:
+ if os_family in os_family_item['os_list']:
+ os_family = os_family_item['name']
+ break
return os_family.lower()
@@ -135,10 +198,7 @@ class OSCheck:
In case cannot detect raises exception.
"""
- # Read content from /etc/*-release file
- # Full release name
- dist = linux_distribution()
- dist = dist[1]
+ dist = OSCheck._dist[3]
if dist:
return dist
@@ -161,8 +221,7 @@ class OSCheck:
In case cannot detect raises exception.
"""
- dist = linux_distribution()
- dist = dist[2].lower()
+ dist = OSCheck._dist[4].lower()
if dist:
return dist
@@ -172,14 +231,14 @@ class OSCheck:
# Exception safe family check functions
@staticmethod
- def is_ubuntu_family():
+ def is_debian_family():
"""
Return true if it is so or false if not
This is safe check for debian family, doesn't generate exception
"""
try:
- if OSCheck.get_os_family() == OSConst.UBUNTU_FAMILY:
+ if OSCheck.get_os_family() == OSConst.DEBIAN_FAMILY:
return True
except Exception:
pass
@@ -212,3 +271,52 @@ class OSCheck:
except Exception:
pass
return False
+
+ @staticmethod
+ def is_windows_family():
+ """
+ Return true if it is so or false if not
+
+ This is safe check for windows family, doesn't generate exception
+ """
+ try:
+ if OSCheck.get_os_family() == OSConst.WINSRV_FAMILY:
+ return True
+ except Exception:
+ pass
+ return False
+
+ @staticmethod
+ def is_linux_os():
+ """
+ Return true if it is so or false if not
+
+ This is safe check for linux os, doesn't generate exception
+ """
+ try:
+ if OSCheck.get_os_os() == OSConst.LINUX_OS:
+ return True
+ except Exception:
+ pass
+ return False
+
+ @staticmethod
+ def is_windows_os():
+ """
+ Return true if it is so or false if not
+
+ This is safe check for windows os, doesn't generate exception
+ """
+ try:
+ if OSCheck.get_os_os() == OSConst.WINDOWS_OS:
+ return True
+ except Exception:
+ pass
+ return False
+
+
+# OS info
+OS_VERSION = OSCheck().get_os_major_version()
+OS_TYPE = OSCheck.get_os_type()
+OS_FAMILY = OSCheck.get_os_family()
+OS_OS = OSCheck.get_os_os()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/os_linux.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_linux.py b/ambari-common/src/main/python/ambari_commons/os_linux.py
new file mode 100644
index 0000000..9e7c9a3
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/os_linux.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+'''
+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 getpass
+
+import os
+import pwd
+import shlex
+import subprocess
+
+from logging import *
+
+
+NR_CHMOD_CMD = 'chmod {0} {1} {2}'
+NR_CHOWN_CMD = 'chown {0} {1} {2}'
+
+ULIMIT_CMD = "ulimit -n"
+
+
+def run_os_command(cmd):
+ print_info_msg('about to run command: ' + str(cmd))
+ if type(cmd) == str:
+ cmd = shlex.split(cmd)
+ process = subprocess.Popen(cmd,
+ stdout=subprocess.PIPE,
+ stdin=subprocess.PIPE,
+ stderr=subprocess.PIPE
+ )
+ (stdoutdata, stderrdata) = process.communicate()
+ return process.returncode, stdoutdata, stderrdata
+
+def os_change_owner(filePath, user):
+ uid = pwd.getpwnam(user).pw_uid
+ gid = pwd.getpwnam(user).pw_gid
+ os.chown(filePath, uid, gid)
+
+def os_is_root():
+ '''
+ Checks effective UUID
+ Returns True if a program is running under root-level privileges.
+ '''
+ return os.geteuid() == 0
+
+def os_set_file_permissions(file, mod, recursive, user):
+ WARN_MSG = "Command {0} returned exit code {1} with message: {2}"
+ if recursive:
+ params = " -R "
+ else:
+ params = ""
+ command = NR_CHMOD_CMD.format(params, mod, file)
+ retcode, out, err = run_os_command(command)
+ if retcode != 0:
+ print_warning_msg(WARN_MSG.format(command, file, err))
+ command = NR_CHOWN_CMD.format(params, user, file)
+ retcode, out, err = run_os_command(command)
+ if retcode != 0:
+ print_warning_msg(WARN_MSG.format(command, file, err))
+
+def os_set_open_files_limit(maxOpenFiles):
+ command = "%s %s" % (ULIMIT_CMD, str(maxOpenFiles))
+ run_os_command(command)
+
+
+def os_getpass(prompt):
+ return getpass.unix_getpass(prompt)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/os_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_utils.py b/ambari-common/src/main/python/ambari_commons/os_utils.py
new file mode 100644
index 0000000..df51f09
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/os_utils.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+
+'''
+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 shutil
+import string
+
+from os_check import *
+
+if OSCheck.is_windows_os():
+ from os_windows import *
+else:
+ # MacOS not supported
+ from os_linux import *
+
+from logging import *
+from exceptions import FatalException
+
+
+def is_valid_filepath(filepath):
+ if not filepath or not os.path.exists(filepath) or os.path.isdir(filepath):
+ print 'Invalid path, please provide the absolute file path.'
+ return False
+ else:
+ return True
+
+def quote_path(filepath):
+ if(filepath.find(' ') != -1):
+ filepath_ret = '"' + filepath + '"'
+ else:
+ filepath_ret = filepath
+ return filepath_ret
+
+def search_file(filename, search_path, pathsep=os.pathsep):
+ """ Given a search path, find file with requested name """
+ for path in string.split(search_path, pathsep):
+ candidate = os.path.join(path, filename)
+ if os.path.exists(candidate):
+ return os.path.abspath(candidate)
+ return None
+
+def copy_file(src, dest_file):
+ try:
+ shutil.copyfile(src, dest_file)
+ except Exception, e:
+ err = "Can not copy file {0} to {1} due to: {2} . Please check file " \
+ "permissions and free disk space.".format(src, dest_file, e.message)
+ raise FatalException(1, err)
+
+def copy_files(files, dest_dir):
+ if os.path.isdir(dest_dir):
+ for filepath in files:
+ shutil.copy(filepath, dest_dir)
+ return 0
+ else:
+ return -1
+
+def remove_file(filePath):
+ if os.path.exists(filePath):
+ try:
+ os.remove(filePath)
+ except Exception, e:
+ print_warning_msg('Unable to remove file: ' + str(e))
+ return 1
+ pass
+ return 0
+
+def set_file_permissions(file, mod, user, recursive):
+ if os.path.exists(file):
+ os_set_file_permissions(file, mod, recursive, user)
+ else:
+ print_info_msg("File %s does not exist" % file)
+
+def is_root():
+ return os_is_root()
+
+# Proxy to the os implementation
+def change_owner(filePath, user):
+ os_change_owner(filePath, user)
+
+# Proxy to the os implementation
+def set_open_files_limit(maxOpenFiles):
+ os_set_open_files_limit(maxOpenFiles)
+
+def get_password(prompt):
+ return os_getpass(prompt)
\ No newline at end of file