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/05/31 09:21:09 UTC
[05/12] AMBARI-5482. Integrate Ambari Shell. (Janos Matyas and
Krisztian Horvath via yusaku)
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/core/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/core/__init__.py b/ambari-client/src/main/python/ambari_client/core/__init__.py
deleted file mode 100755
index 278df2e..0000000
--- a/ambari-client/src/main/python/ambari_client/core/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# 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.
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/core/coreutils.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/core/coreutils.py b/ambari-client/src/main/python/ambari_client/core/coreutils.py
deleted file mode 100755
index d3e1b4f..0000000
--- a/ambari-client/src/main/python/ambari_client/core/coreutils.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# 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.
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/core/errors.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/core/errors.py b/ambari-client/src/main/python/ambari_client/core/errors.py
deleted file mode 100755
index c691241..0000000
--- a/ambari-client/src/main/python/ambari_client/core/errors.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-# 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 ResourceError(Exception):
-
- def __init__(self, response, resource_root=None):
- """
- Create new exception based on not successful server response
- @param response: StatusModel response
- @param resource_root: The resource which sent an error response
- """
- self.response = response
- self.resource_root = resource_root
- Exception.__init__(self)
-
- def get_message(self):
- """ Get an error message """
- return self.response.get_message()
-
- def get_status_code(self):
- """ Get a status(error) code from the server response """
- return self.response.status
-
- def get_reponse(self):
- """ StatusModel object """
- return self.reponse
-
- def get_root_resource(self):
- """ AmbariClient object """
- return self.resource_root
-
- def __str__(self):
- if self.get_message():
- return "exception: %s. %s" % (self.response.status, self.get_message())
- try:
- return self._fmt % self.__dict__
- except (NameError, ValueError, KeyError), e:
- return 'exception %s: %s' \
- % (self.__class__.__name__, str(e))
-
-class ResourceConflict(ResourceError):
- """ 409 status code """
-class ResourceNotFound(ResourceError):
- """ 404 status code """
-class BadRequest(ResourceError):
- """ 400 status code """
-class AuthorizationError(ResourceError):
- """ 401 status code """
-class ForbiddenError(ResourceError):
- """ 403 status code """
-class InternalServerError(ResourceError):
- """ 500 status code """
-class MethodNotAllowed(ResourceError):
- """ 405 status code """
-class UnknownServerError(ResourceError):
- """ Received other response code """
-
-_exceptions_to_codes = { 409:ResourceConflict,
- 404:ResourceNotFound,
- 400:BadRequest,
- 401:AuthorizationError,
- 403:ForbiddenError,
- 500:InternalServerError,
- 405:MethodNotAllowed }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/core/http_client.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/core/http_client.py b/ambari-client/src/main/python/ambari_client/core/http_client.py
deleted file mode 100755
index 484ef5d..0000000
--- a/ambari-client/src/main/python/ambari_client/core/http_client.py
+++ /dev/null
@@ -1,175 +0,0 @@
-#
-# 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 logging
-import posixpath
-import sys
-try:
- import pycurl
-# pycurl is not necessary for testcases, mock it
-except ImportError:
- from mock.mock import MagicMock
- pycurl = MagicMock()
-import cStringIO
-import StringIO
-import pdb
-try:
- import json
-except ImportError:
- import simplejson as json
-from ambari_client.core.http_utils import uri_encoding
-
-__docformat__ = "epytext"
-
-LOG = logging.getLogger(__name__)
-
-
-class HttpClient(object):
- """
- Basic HTTP client for rest APIs.
- """
- def __init__(self, host_url, user_name , password ):
- """
- @param host_url: The base url to the API.
-
- """
-
- self._host_url = host_url.rstrip('/')
- self._headers = { }
- self.c = pycurl.Curl()
- if user_name is not None:
- self.c.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
- userpass = user_name + ':'
- if password is not None:
- userpass += password
- LOG.debug( "pycurl.USERPWD value = "+str(userpass))
- self.c.setopt(pycurl.USERPWD, userpass)
-
-
- def set_headers(self, headers):
- """
- Add headers to the request
- """
- self._headers = headers
- return self
-
- @property
- def host_url(self):
- return self._host_url
-
- def _get_headers(self, headers):
- res = self._headers.copy()
- if headers:
- res.update(headers)
- return res
-
- def invoke(self, http_method, path, payload=None, headers=None):
- """
- Submit an HTTP request.
- @param http_method: GET, POST, PUT, DELETE
- @param path: The path of the resource.
- @param payload: The payload to attach to the body of the request.
- @param headers: The headers to set for this request.
-
- @return: The result of REST request
- """
- #pdb.set_trace()
- LOG.debug ("invoke : http_method = "+str(http_method))
- # Prepare URL and params
- url = self._normalize(path)
- if http_method in ("GET", "DELETE"):
- if payload is not None:
- self.logger.warn(
- "GET http_method does not pass any payload. Path '%s'" % (path,))
- payload = None
-
-
- buf = cStringIO.StringIO()
- self.c.setopt(pycurl.WRITEFUNCTION, buf.write)
- self.c.setopt(pycurl.SSL_VERIFYPEER, 0)
-
- LOG.debug ("invoke : url = "+str(url))
- # set http_method
- if http_method == "GET":
- self.c.setopt(pycurl.HTTPGET, 1)
- elif http_method == "HEAD":
- self.c.setopt(pycurl.HTTPGET, 1)
- self.c.setopt(pycurl.NOBODY, 1)
- elif http_method == "POST":
- self.c.setopt(pycurl.POST, 1)
- elif http_method == "PUT":
- self.c.setopt(pycurl.UPLOAD, 1)
- else:
- self.c.setopt(pycurl.CUSTOMREQUEST, http_method)
-
- data = None
- if http_method in ('POST','PUT'):
- LOG.debug( "data..........."+str(payload))
- data = json.dumps(payload)
- #data= data.decode('unicode-escape')
- #LOG.debug( "after unicode decode")
- #LOG.debug( data)
- data = self._to_bytestring(data)
- LOG.debug( "after _to_bytestring")
- LOG.debug( data)
- content = StringIO.StringIO(data)
- LOG.debug( content)
- content_length = len(data)
- LOG.debug( "content_length........."+str(content_length))
-
- if http_method == 'POST':
- self.c.setopt(pycurl.POSTFIELDSIZE, content_length)
- else:
- self.c.setopt(pycurl.INFILESIZE, content_length)
-
- self.c.setopt(pycurl.READFUNCTION, content.read)
-
-
- self.c.setopt(self.c.URL, url)
- headers = self._get_headers(headers)
- headers_l = ["%s: %s" % pair for pair in sorted(headers.iteritems())]
- LOG.debug( headers_l)
- self.c.setopt(pycurl.HTTPHEADER,headers_l)
-
-
- LOG.debug ("invoke : pycurl.EFFECTIVE_URL = "+self.c.getinfo(pycurl.EFFECTIVE_URL))
- try:
- self.c.perform()
- except Exception, ex:
- LOG.debug (sys.stderr, str(ex))
- raise ex
- contents_type= self.c.getinfo(pycurl.CONTENT_TYPE)
- LOG.debug ("invoke : pycurl.CONTENT_TYPE = "+contents_type)
- code = self.c.getinfo(pycurl.RESPONSE_CODE)
- LOG.debug ("invoke : pycurl.RESPONSE_CODE = "+str(code))
- response = buf.getvalue()
- buf.close()
- LOG.debug ("invoke : COMPLETED ")
- return response , code , contents_type
-
- def _to_bytestring(self ,s):
-# if not isinstance(s, basestring):
-# raise TypeError("value should be a str or unicode")
- if isinstance(s, unicode):
- return s.encode('utf-8')
- return s
-
- def _normalize(self, path):
- res = self._host_url
- if path:
- res += posixpath.normpath('/' + path.lstrip('/'))
- return uri_encoding(res)
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/core/http_utils.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/core/http_utils.py b/ambari-client/src/main/python/ambari_client/core/http_utils.py
deleted file mode 100755
index 07fea45..0000000
--- a/ambari-client/src/main/python/ambari_client/core/http_utils.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# 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 types
-import urllib
-import urllib2
-
-
-def uri_encoding(url):
- """
- Returns an ASCII string version of the URL.
- """
- if url is None:
- return url
- return urllib.quote(get_utf8_str(url), safe="/#%[]=:;$&()+,!?*@'~")
-
-
-
-def get_utf8_str(strr, encoding='utf-8'):
- """
- Returns a utf8 ecoded 'str'.
- """
- errors='strict'
- if not isinstance(strr, basestring):
- try:
- return str(strr)
- except UnicodeEncodeError:
- if isinstance(strr, Exception):
- return ' '.join([get_utf8_str(arg, encoding) for arg in strr])
- return unicode(strr).encode(encoding, errors)
- elif isinstance(strr, unicode):
- return strr.encode(encoding, errors)
- elif strr and encoding != 'utf-8':
- return strr.decode('utf-8', errors).encode(encoding, errors)
- else:
- return strr
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/core/rest_resource.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/core/rest_resource.py b/ambari-client/src/main/python/ambari_client/core/rest_resource.py
deleted file mode 100755
index 532fc53..0000000
--- a/ambari-client/src/main/python/ambari_client/core/rest_resource.py
+++ /dev/null
@@ -1,120 +0,0 @@
-#
-# 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.
-
-try:
- import json
-except ImportError:
- import simplejson as json
-import logging
-import posixpath
-
-LOG = logging.getLogger(__name__)
-
-
-class RestResource(object):
- """
- RestResource wrapper.
- """
- def __init__(self, client, path=""):
- """
- @param client: A Client object.
- @param path: The relative path of the resource.
- """
- self._client = client
- self._path = path.strip('/')
-
- @property
- def host_url(self):
- return self._client.host_url
-
- def _join_uri(self, relpath):
- if relpath is None:
- return self._path
- return self._path + posixpath.normpath('/' + relpath)
-
- def _set_headers(self, content_type=None):
- if content_type:
- return { 'Content-Type': content_type }
- return None
-
- def _make_invoke(self, http_method, payload, headers, path):
- return self._client.invoke(http_method, path, payload=payload, headers=headers)
-
- def invoke(self, http_method, url_path=None, payload=None, headers=None):
- """
- Invoke an API http_method.
- """
- path = self._join_uri(url_path)
- resp , code , content = self._make_invoke(http_method, payload, headers, path)
-
- LOG.debug ("RESPONSE from the REST request >>>>>>> \n" + str(resp))
- LOG.debug ("\n===========================================================")
- #take care of REST calls with no response
-
- try:
- isOK = (code == 200 or code == 201 or code == 202)
-
- if isOK and not resp:
- json_dict = {"status":code}
- else:
- json_dict = json.loads(resp)
-
- return json_dict
- except Exception, ex:
- LOG.error("Command '%s %s' failed with error %s\n%s" % (http_method, path, code ,resp))
- return {"status":code , "message":"Command '%s %s' failed with error %s" % (http_method, path, code)}
-
-
- def get(self, path=None):
- """
- Invoke the GET method .
- @param path: resource path
- @return: A dictionary of the REST result.
- """
- return self.invoke("GET", path)
-
-
- def put(self, path=None, payload=None, content_type=None):
- """
- Invoke the PUT method on a resource.
- @param path: resource path
- @param payload: Body of the request.
- @param content_type:
- @return: A dictionary of the REST result.
- """
- return self.invoke("PUT", path, payload, self._set_headers(content_type))
-
-
- def post(self, path=None, payload=None, content_type=None):
- """
- Invoke the POST method on a resource.
- @param path: resource path
- @param payload: Body of the request.
- @param content_type:
- @return: A dictionary of the REST result.
- """
- return self.invoke("POST", path, payload, self._set_headers(content_type))
-
-
- def delete(self, path=None, payload=None,):
- """
- Invoke the DELETE method on a resource.
- @param path: resource path
- @param payload: Body of the request.
- @return: A dictionary of the REST result.
- """
- return self.invoke("DELETE", path, payload)
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/__init__.py b/ambari-client/src/main/python/ambari_client/model/__init__.py
deleted file mode 100755
index 278df2e..0000000
--- a/ambari-client/src/main/python/ambari_client/model/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# 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.
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/base_model.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/base_model.py b/ambari-client/src/main/python/ambari_client/model/base_model.py
deleted file mode 100755
index 79fd9ad..0000000
--- a/ambari-client/src/main/python/ambari_client/model/base_model.py
+++ /dev/null
@@ -1,109 +0,0 @@
-#
-# 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 sys
-import logging
-import time
-from ambari_client.model.utils import get_REF_object, get_unicode, getREF_var_name , LIST_KEY
-from operator import itemgetter, attrgetter
-
-__docformat__ = "epytext"
-
-LOG = logging.getLogger(__name__)
-
-
-class BaseModel(object):
- """
- The BaseModel
-
- RW_ATTR - A list of mutable attributes
- RO_ATTR - A list of immutable attributes
- REF_ATTR - A REF attribute
-
- """
- RO_ATTR = ()
- RW_ATTR = ()
- REF_ATTR = ()
-
- def __init__(self, resource_root, **rw_attrs):
- #print" ================== base_model\n"
- #print locals()
- self._resource_root = resource_root
- for k, v in rw_attrs.items():
- if k not in self.RW_ATTR:
- raise ValueError("Unknown argument '%s' in %s" %
- (k, self.__class__.__name__))
- self._setattr(k, v)
-
- def _get_resource_root(self):
- return self._resource_root
-
- def to_json_dict(self):
- dic = { }
- for attr in self.RW_ATTR:
- value = getattr(self, attr)
- try:
- value = value.to_json_dict()
- except Exception:
- pass
- dic[attr] = value
- return dic
-
- def _setattr(self, k, v):
- """Set an attribute. """
- value = v
- if v and k.endswith("Ref"):
- cls_name = k[0].upper() + k[1:]
- cls_name = cls_name[:-3] + "ModelRef"
- cls = get_REF_object(cls_name)
- LOG.debug(str(cls_name) + " - " + str(cls))
- v = get_unicode(v)
- var_name = getREF_var_name(cls_name)
- c = {str(var_name):str(v)}
- LOG.debug(c)
- value = cls(self._get_resource_root(), **c)
- setattr(self, k, value)
-
-
-
-class ModelList(object):
- """A list of Model objects"""
-
- def __init__(self, objects):
- self.objects = objects
-
- def __str__(self):
- return "<<ModelList>>[size = %d]) = [%s]" % (
- len(self.objects),
- ", ".join([str(item) for item in self.objects]))
-
- def to_json_dict(self):
- return { LIST_KEY :
- [ x.to_json_dict() for x in self.objects ] }
-
- def __len__(self):
- return self.objects.__len__()
-
- def __iter__(self):
- return self.objects.__iter__()
-
- def sort(self, sortkey):
- self.objects = sorted(self.objects, key=sortkey ,reverse=True)
-
- def __getitem__(self, i):
- return self.objects.__getitem__(i)
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/cluster.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/cluster.py b/ambari-client/src/main/python/ambari_client/model/cluster.py
deleted file mode 100755
index 4a8cce6..0000000
--- a/ambari-client/src/main/python/ambari_client/model/cluster.py
+++ /dev/null
@@ -1,331 +0,0 @@
-#
-# 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 logging
-import time
-from ambari_client.model.base_model import BaseModel , ModelList
-from ambari_client.model import service , host , paths , status, configuration , utils
-
-
-LOG = logging.getLogger(__name__)
-
-
-def _get_cluster(resource_root, cluster_name):
- """
- Lookup a cluster by cluster_name
- @param resource_root: The root Resource .
- @param cluster_name: cluster_name
- @return: A ClusterModel object
- """
- dic = resource_root.get("%s/%s" % (paths.CLUSTERS_PATH, cluster_name))
- return utils.ModelUtils.create_model(ClusterModel , dic, resource_root, "Clusters")
-
-
-def _get_all_clusters(root_resource):
- """
- Get all clusters
- @param root_resource: The root Resource .
- @return: A list of ClusterModel objects.
- """
- dic = root_resource.get(paths.CLUSTERS_PATH)
- return utils.ModelUtils.get_model_list(ModelList, ClusterModel, dic, root_resource , "Clusters")
-
-
-def _create_cluster(root_resource, cluster_name, version):
- """
- Create a cluster
- @param root_resource: The root Resource.
- @param cluster_name: Cluster cluster_name
- @param version: HDP version
- @return: An ClusterModel object
- """
- data = {"Clusters":{"version":str(version)}}
- 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
- @param root_resource: The root Resource .
- @param name: Cluster name
- """
- resp = root_resource.delete("%s/%s" % (paths.CLUSTERS_PATH, cluster_name))
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _install_all_services(root_resource, cluster_name):
- """
- Start all services
- @param root_resource: The root Resource .
- @param name: Cluster name
- """
- cpath = paths.CLUSTER_START_ALL_SERVICES % cluster_name
- data = {"RequestInfo": {"context" :"Install Services"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}
- resp = root_resource.put(path=cpath , payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _stop_all_services(root_resource, cluster_name):
- """
- Start all services
- @param root_resource: The root Resource .
- @param name: Cluster name
- """
- cpath = paths.CLUSTER_STOP_ALL_SERVICES % cluster_name
- data = {"RequestInfo": {"context" :"Stop All Services"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}
- resp = root_resource.put(path=cpath , payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _start_all_services(root_resource, cluster_name , run_smoke_test=False):
- """
- Start all services
- @param root_resource: The root Resource .
- @param name: Cluster name
- """
- cpath = paths.CLUSTER_START_ALL_SERVICES % cluster_name
- if run_smoke_test:
- cpath = "%s&%s" % (cpath, "params/run_smoke_test=true¶ms/reconfigure_client=false")
- data = {"RequestInfo": {"context" :"Start All Services"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}
- resp = root_resource.put(path=cpath , payload=data)
- if isinstance(resp, dict) and resp.has_key("Requests"):
- resp = resp["Requests"]
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-
-
-class ClusterModel(BaseModel):
- """
- The ClusterModel class
- """
- RW_ATTR = ('cluster_name', 'version')
-
- def __init__(self, resource_root, cluster_name, version):
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<ClusterModel>> cluster_name = %s; version = %s" % (self.cluster_name, self.version)
-
- def _path(self):
- return "%s/%s" % (paths.CLUSTERS_PATH, self.cluster_name)
-
- def get_service(self, service_name):
- """
- Get a service by service_name.
- @param service_name: Service name
- @return: A ServiceModel object
- """
- return service._get_service(self._get_resource_root(), service_name, self.cluster_name)
-
- def get_all_services(self, detail=None):
- """
- Get all services in this cluster.
- @return: ModelList containing ServiceModel objects.
- """
- return service._get_all_services(self._get_resource_root(), self.cluster_name)
-
- def get_all_hosts(self, detail=None):
- """
- Get all hosts in this cluster.
- @return: ModelList containing HostModel objects.
- """
- return host._get_all_cluster_hosts(self._get_resource_root(), self.cluster_name)
-
- def get_host(self, hostname , detail=None):
- """
- Get a specific hosts in this cluster.
- @return: A HostModel object.
- """
- return host._get_cluster_host(self._get_resource_root(), self.cluster_name, hostname)
-
- def get_global_config(self, detail=None):
- """
- Get global configuration of cluster.
- @return: A ConfigModel object.
- """
- return configuration._get_configuration(self._get_resource_root(), self.cluster_name, "global")
-
- def get_core_site_config(self, tag="version1" ,detail=None):
- """
- Get core-site configuration of cluster.
- @return: A ConfigModel object or ModelList<ConfiObject>
- """
- if(detail == utils.ALL):
- return configuration._get_all_configuration(self._get_resource_root(), self.cluster_name, "core-site")
- else:
- return configuration._get_configuration(self._get_resource_root(), self.cluster_name, "core-site" ,tag)
-
- def get_hdfs_site_config(self, detail=None):
- """
- Get hdfs-site configuration of cluster.
- @return: A ConfigModel object.
- """
- return configuration._get_configuration(self._get_resource_root(), self.cluster_name, "hdfs-site")
-
- def get_mapred_site_config(self, detail=None):
- """
- Get mapred-site configuration of cluster.
- @return: A ConfigModel object.
- """
- return configuration._get_configuration(self._get_resource_root(), self.cluster_name, "mapred-site")
-
- def update_global_config(self, config_model , tag="version1" ,detail=None):
- """
- Updates the global configuration of cluster.
- @param config_model: The configModel object
- @return: A ConfigModel object.
- """
- return configuration._update_configuration(self._get_resource_root(), self.cluster_name, "global" , tag, config_model)
-
- def update_core_site_config(self, config_model , tag="version1" ,detail=None):
- """
- Updates the core-site configuration of cluster.
- @param config_model: The configModel object
- @return: A ConfigModel object.
- """
- return configuration._update_configuration(self._get_resource_root(), self.cluster_name, "core-site", tag, config_model)
-
- def update_hdfs_site_config(self, config_model , tag="version1" , detail=None):
- """
- Updates the hdfs-site configuration of cluster.
- @param config_model: The configModel object
- @return: A ConfigModel object.
- """
- return configuration._update_configuration(self._get_resource_root(), self.cluster_name, "hdfs-site", tag, config_model)
-
- def update_mapred_site_config(self, config_model ,tag="version1" , detail=None):
- """
- Updates the mapred-site configuration of cluster.
- @param config_model: The configModel object
- @return: A ConfigModel object.
- """
- return configuration._update_configuration(self._get_resource_root(), self.cluster_name, "mapred-site", tag, config_model)
-
- def create_services(self, services_list , detail=None):
- """
- Creates services.
- @param services_list: list of services
- @return: StatusModel.
- """
- return service._create_services(self._get_resource_root(), self.cluster_name , services_list)
-
- def create_service(self, service_name , detail=None):
- """
- Creates a single service
- @param service_name: service name
- @return: StatusModel.
- """
- return service._create_service(self._get_resource_root(), self.cluster_name , service_name)
-
- def create_service_components(self, version , service_name , detail=None):
- """
- Creates service with components
- @param version: version
- @param service_name: service_name
- @return: StatusModel.
- """
- return service._create_service_components(self._get_resource_root(), self.cluster_name , version, service_name)
-
- def create_service_component(self, version , service_name , component_name , detail=None):
- """
- Create service with component
- @param version: version
- @param service_name: service_name
- @return: StatusModel.
- """
- return service._create_service_component(self._get_resource_root(), self.cluster_name , version, service_name, component_name)
-
- def create_hosts(self, host_list , detail=None):
- """
- Creates hosts.
- @param host_list: list of HostModel
- @return: StatusModel.
- """
- return host._add_hosts(self._get_resource_root(), self.cluster_name , host_list)
-
- def create_host(self, host_name, ip, rack_info='/default-rack', detail=None):
- """
- Creates host.
- @param host_name: Host name
- @param ip: ip of Host
- @param rack_info: rack information
- @return: StatusModel.
- """
- return host._add_host(self._get_resource_root(), self.cluster_name , host_name , ip , rack_info)
-
- def delete_host(self, host_name, detail=None):
- """
- deletes a host.
- @param host_name: Host name
- @return: StatusModel.
- """
- return host._delete_cluster_host(self._get_resource_root(), self.cluster_name , host_name)
-
- def start_all_services(self, run_smoke_test=False , detail=None):
- """
- Start all the services.
- @return: StatusModel.
- """
- return _start_all_services(self._get_resource_root(), self.cluster_name, run_smoke_test)
-
- def stop_all_services(self, detail=None):
- """
- Stop all the services.
- @return: StatusModel.
- """
- return _stop_all_services(self._get_resource_root(), self.cluster_name)
-
- def install_all_services(self, detail=None):
- """
- INIT all the services.
- @return: StatusModel.
- """
- return _install_all_services(self._get_resource_root(), self.cluster_name)
-
- def add_config(self , type, tag , properties):
- """
- add configurations to the cluster
- @param type: the type of config
- @param tag: tag
- @param properties: a dict of properties
- @return: A StatusModel object
- """
- return configuration._add_config(self._get_resource_root(), self.cluster_name , type, tag , properties)
-
- def create_config(self , type, tag , properties):
- """
- create configurations to the cluster
- @param type: the type of config
- @param tag: tag
- @param properties: a dict of properties
- @return: A StatusModel object
- """
- return configuration._create_config(self._get_resource_root(), self.cluster_name , type, tag , properties)
-
-
-
-class ClusterModelRef(BaseModel):
- """
- The ClusterModelRef class
- Some models need reference to cluster
- """
- RW_ATTR = ('cluster_name',)
- def __init__(self, resource_root, cluster_name=None):
- utils.retain_self_helper(BaseModel, **locals())
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/component.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/component.py b/ambari-client/src/main/python/ambari_client/model/component.py
deleted file mode 100755
index 586f21a..0000000
--- a/ambari-client/src/main/python/ambari_client/model/component.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#
-# 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 logging
-from ambari_client.model.base_model import BaseModel , ModelList
-from ambari_client.model import paths , utils , status
-
-
-
-LOG = logging.getLogger(__name__)
-
-
-def get_host_components(resource_root, cluster_name , host_name):
- path = paths.HOSTS_COMPONENTS_PATH % (cluster_name, host_name)
- dic = resource_root.get(path)
- return utils.ModelUtils.get_model_list(ModelList, ComponentModel, dic, resource_root , "HostRoles")
-
-
-def get_host_component(resource_root, cluster_name , host_name , component_name):
- path = paths.HOSTS_COMPONENT_PATH % (cluster_name, host_name , component_name)
- dic = resource_root.get(path)
- comp_model = utils.ModelUtils.create_model(ComponentModel, dic, resource_root , "HostRoles" , status.StatusModel)
- #comp_model._setattr('host_name', dic["items"][0]['HostRoles']['host_name'])
- return comp_model
-
-
-def _get_service_components(resource_root, cluster_name , service_name):
- path = paths.SERVICE_COMPONENTS_PATH % (cluster_name, service_name)
- dic = resource_root.get(path)
- return utils.ModelUtils.get_model_list(ModelList, ComponentModel, dic, resource_root , "ServiceComponentInfo")
-
-
-def _get_service_component(resource_root, cluster_name , service_name , component_name):
- path = paths.SERVICE_COMPONENT_PATH % (cluster_name, service_name , component_name)
- dic = resource_root.get(path)
- return utils.ModelUtils.create_model(ComponentModel, dic, resource_root , "ServiceComponentInfo")
-
-
-
-
-
-
-
-
-class ComponentModel(BaseModel):
- """
- The ComponentModel class
- """
- RO_ATTR = ('stack_id',)
- RW_ATTR = ('host_name', 'component_name', 'service_name', 'state')
- REF_ATTR = ('cluster_name',)
-
- def __init__(self, resource_root, component_name, host_name=None , service_name=None , state=None):
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<ComponentModel>> component_name = %s; state = %s" % (self.component_name, self.state)
-
- def _get_cluster_name(self):
- if self.clusterRef:
- return self.clusterRef.cluster_name
- return None
-
- def _path(self):
- """
- Return the API path for this service.
- """
- if self._get_cluster_name():
- return paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(), self.host_name)
- else:
- return ''
-
- def get_metrics(self, detail=None):
- """
- Gets the json containing all the metrics data
- @return: json.
- """
- if self.service_name:
- metricpath = paths.SERVICE_COMPONENT_PATH % (self._get_cluster_name(), self.service_name , self.component_name) + "?fields=metrics"
- elif self.host_name:
- metricpath = paths.HOSTS_COMPONENT_PATH % (self._get_cluster_name(), self.host_name , self.component_name) + "?fields=metrics"
- metricjson = self._get_resource_root().get(metricpath)
- return metricjson
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/configuration.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/configuration.py b/ambari-client/src/main/python/ambari_client/model/configuration.py
deleted file mode 100755
index 883caf2..0000000
--- a/ambari-client/src/main/python/ambari_client/model/configuration.py
+++ /dev/null
@@ -1,138 +0,0 @@
-#
-# 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.
-
-
-from ambari_client.model.base_model import BaseModel , ModelList
-from ambari_client.model import paths , status , utils
-
-
-
-
-def _get_configuration(resource_root, cluster_name , type , tag="version1"):
- """
- Get configuration of a cluster
- @param resource_root: The root Resource .
- @param cluster_name: cluster_name
- @param type: type of config
- @return: A ConfigModel object
- """
- dic = resource_root.get(paths.CONFIGURATION_PATH % (cluster_name, type, tag))
-
- if len(dic["items"]) == 0:
- return None
-
- config_model = utils.ModelUtils.create_model(ConfigModel , dic["items"][0], resource_root, "NO_KEY")
- ref_clss = utils.getREF_class_name("cluster_name")
- config_model._setattr(ref_clss, dic["items"][0]['Config']['cluster_name'])
- return config_model
-
-
-def _get_all_configuration(resource_root, cluster_name , type ):
- """
- Gets ALL configuration of a cluster of a given type
- @param resource_root: The root Resource .
- @param cluster_name: cluster_name
- @param type: type of config
- @return: A ConfigModel object
- """
- dic = resource_root.get(paths.CONFIGURATION_ALL_PATH % (cluster_name, type))
-
- if len(dic["items"]) == 0:
- return None
-
- objects = []
- for cfgm in dic["items"]:
- config_model = utils.ModelUtils.create_model(ConfigModel , cfgm, resource_root, "NO_KEY")
- ref_clss = utils.getREF_class_name("cluster_name")
- config_model._setattr(ref_clss, cfgm['Config']['cluster_name'])
- objects.append(config_model)
- return ModelList(objects)
-
-
-def _update_configuration(resource_root, cluster_name , type , tag , config_model):
- """
- Update configuration of a cluster
- @param resource_root: The root Resource .
- @param cluster_name: cluster_name
- @param type: type of config
- @param config_model: config model object
- @return: A ConfigModel object
- """
- data = {"Clusters":{"desired_configs":{ "type":type, "tag":tag, "properties":config_model.properties}}}
- resp = resource_root.put(path=paths.UPDATE_CONFIGURATION_PATH % cluster_name , payload=data )
- return utils.ModelUtils.create_model(status.StatusModel, resp, resource_root, "NO_KEY")
-
-
-def _add_config(root_resource, cluster_name, type, tag , properties):
- """
- add configurations
- @param type: the type of config
- @param tag: tag
- @param properties: a dict of properties
- @return: A StatusModel object
- """
- cpath = paths.CLUSTERS_CONFIG_PATH % cluster_name
- data = {"Clusters":{"desired_configs":{"type":type, "tag":tag, "properties":properties}}}
- resp = root_resource.put(path=cpath , payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _create_config(root_resource, cluster_name, type, tag , properties):
- """
- create a new configurations
- @param type: the type of config
- @param tag: tag
- @param properties: a dict of properties
- @return: A StatusModel object
- """
- cpath = paths.CLUSTERS_CONFIG_PATH % cluster_name
- data = {"type":type, "tag":tag, "properties":properties}
- resp = root_resource.put(path=cpath , payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-
-class ConfigModel(BaseModel):
- """
- The ConfigModel class
- """
- RO_ATTR = ('properties',)
- RW_ATTR = ('tag', 'type')
- REF_ATTR = ('cluster_name',)
-
- def __init__(self, resource_root, tag , type=None):
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<ConfigModel>> tag = %s; type = %s" % (self.tag, self.type)
-
- def _get_cluster_name(self):
- if self.clusterRef:
- return self.clusterRef.cluster_name
- return None
-
- def __lt__(self, other):
- return self.tag < other.tag
-
- def _path(self):
- """
- Return the API path for this service.
- """
- if self._get_cluster_name():
- return paths.CONFIGURATION_PATH % (self._get_cluster_name(), self.type , self.tag)
- else:
- return ''
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/host.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/host.py b/ambari-client/src/main/python/ambari_client/model/host.py
deleted file mode 100755
index f261deb..0000000
--- a/ambari-client/src/main/python/ambari_client/model/host.py
+++ /dev/null
@@ -1,255 +0,0 @@
-#
-# 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.
-
-try:
- import json
-except ImportError:
- import simplejson as json
-import logging
-from ambari_client.model.base_model import BaseModel , ModelList
-from ambari_client.model import status , component , paths , utils
-
-
-
-LOG = logging.getLogger(__name__)
-
-
-def _get_host(root_resource, host_name):
- """
- Lookup up by host_name
- @param root_resource: The root Resource object.
- @param cluster_name: Cluster name
- @param host_name: Host name
- @return: A HostModel object
- """
- path = paths.HOST_PATH % (host_name)
- dic = root_resource.get(path)
-
- return utils.ModelUtils.create_model(HostModel , dic, root_resource, "Hosts")
-
-def _get_cluster_host(root_resource, cluster_name , host_name):
- """
- Lookup cluster host up by host_name
- @param root_resource: The root Resource object.
- @param cluster_name: Cluster name
- @param host_name: Host name
- @return: A HostModel object
- """
- path = paths.CLUSTER_HOST_PATH % (cluster_name, host_name)
- dic = root_resource.get(path)
- return utils.ModelUtils.create_model(HostModel , dic, root_resource, "Hosts")
-
-
-
-def _create_hosts(root_resource, host_list):
- """
- Create hosts from list
- @param root_resource: The root Resource.
- @param host_name: Host name
- @param ip: IP address
- @param rack_info: Rack id. Default None
- @return: An HostList object
- """
-
- data = [{"Hosts":{"host_name":x.host_name,"ip":x.ip,"rack_info":x.rack_info}}
- for x in host_list]
- resp = root_resource.post(paths.HOSTS_PATH, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-def _create_host(root_resource, host_name, ip, rack_info=None):
- """
- Create a host
- @param root_resource: The root Resource.
- @param host_name: Host name
- @param ip: IP address
- @param rack_info: Rack id. Default None
- @return: An HostModel object
- """
- host_list = ModelList([HostModel(root_resource, host_name, ip, rack_info)])
- return _create_hosts(root_resource, host_list)
-
-def _add_hosts(root_resource, cluster_name , host_list):
- """
- Adds a hosts to a cluster.
- @param root_resource: The root Resource object.
- @param cluster_name: Cluster name
- @param host_list: list of hosts
- @return: A StatusModel object
- """
- cpath = paths.HOSTS_CREATE_PATH % (cluster_name)
- data = [{"Hosts":{"host_name":x.host_name,"ip":x.ip,"rack_info":x.rack_info}}
- for x in host_list]
- resp = root_resource.post(path=cpath, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _add_host(root_resource, cluster_name , host_name , ip, rack_info=None):
- """
- Adds a host to a cluster.
- @param host_name: Host name
- @param ip: ip of Host
- @param rack_info: rack information
- @return: StatusModel.
- """
- host_list = ModelList([HostModel(root_resource, host_name, ip, rack_info)])
- return _add_hosts(root_resource, cluster_name, host_list)
-
-
-def _assign_role(root_resource, cluster_name , host_name , component_name):
- """
- Add a new component to a node
- @param root_resource: The root Resource object.
- @param cluster_name: Cluster name
- @param component_name : name of component.
- @param host_name: name of host
- @return: StatusModel
- """
- data = {"host_components":[{"HostRoles":{"component_name":component_name}}]}
- cpath = paths.HOSTS_ASSIGN_ROLE % (cluster_name, host_name)
- resp = root_resource.post(path=cpath, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _get_all_hosts(root_resource):
- """
- Get all hosts
- @param root_resource: The root Resource.
- @return: A list of HostModel objects.
- """
- dic = root_resource.get(paths.HOSTS_PATH)
- return utils.ModelUtils.get_model_list(ModelList, HostModel, dic, root_resource , "Hosts")
-
-
-def _get_all_cluster_hosts(root_resource, cluster_name):
- """
- Get all hosts in the cluster
- @param root_resource: The root Resource.
- @param cluster_name: The name of the cluster.
- @return: A list of HostModel objects.
- """
- path = paths.CLUSTER_HOSTS_PATH % (cluster_name)
- path = path + '?fields=*'
- dic = root_resource.get(path)
- return utils.ModelUtils.get_model_list(ModelList, HostModel, dic, root_resource , "Hosts")
-
-
-def _delete_host(root_resource, host_name):
- """
- Delete a host by id
- @param root_resource: The root Resource object.
- @param host_name: Host name
- @return: StatusModel object
- """
- resp = root_resource.delete(paths.HOST_PATH % (host_name))
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _delete_cluster_host(root_resource, cluster_name , host_name):
- """
- Delete a host by id
- @param root_resource: The root Resource object.
- @param host_name: Host name
- @param cluster_name: cluster name
- @return: StatusModel object
- """
- path = paths.CLUSTER_HOST_PATH % (cluster_name, host_name)
- resp = root_resource.delete(path)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _bootstrap_hosts(root_resource , hosts_list, ssh_key):
- """
- Bootstrap hosts.
- @param hosts_list list of host_names.
- @return: A StatusModel object.
- """
- payload_dic = {'sshKey':ssh_key.encode('string_escape') , 'hosts':hosts_list}
- resp = root_resource.post(paths.BOOTSTRAP_PATH, payload_dic , content_type="application/json")
- status_dict = _bootstrap_resp_to_status_dict(resp)
- return utils.ModelUtils.create_model(status.StatusModel, status_dict, root_resource, "NO_KEY")
-
-def _bootstrap_resp_to_status_dict(resp):
- """
- Bootstrap response has a little odd format
- that's why we have to convert it to the normal
- format to handle it properly later.
- """
-
- # if we got other response, like an error 400 happened on higher level
- if isinstance( resp['status'], int ):
- return resp
-
- new_resp = {}
-
- if resp['status'] == "OK":
- new_resp['status'] = 201
- else: # ERROR
- new_resp['status'] = 500
-
- new_resp['message'] = resp['log']
- new_resp['requestId'] = resp['requestId']
- return new_resp
-
-
-
-
-
-class HostModel(BaseModel):
- """
- The HostModel class
- """
- RO_ATTR = ('host_state', 'public_host_name')
- RW_ATTR = ('host_name', 'ip', 'rack_info')
- REF_ATTR = ('cluster_name',)
-
- def __init__(self, resource_root, host_name, ip=None , rack_info='/default-rack'):
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<HostModel>> hostname = %s; ip = %s ; rack_info = %s" % (self.host_name, self.ip, self.rack_info)
-
- def _get_cluster_name(self):
- if self.clusterRef:
- return self.clusterRef.cluster_name
- return None
-
- def _path(self):
- return paths.HOSTS_PATH + '/' + self.host_name
-
- def get_host_components(self, detail=None):
- """
- Get a specific host's components.
- @return: A ModelList containing ComponentModel objects.
- """
- return component.get_host_components(self._get_resource_root(), self._get_cluster_name(), self.host_name)
-
- def get_host_component(self, component_name , detail=None):
- """
- Get a specific host's ,specific component.
- @param component_name : name of component.
- @return: A ComponentModel object.
- """
- return component.get_host_component(self._get_resource_root(), self._get_cluster_name(), self.host_name , component_name)
-
- def assign_role(self, component_name , detail=None):
- """
- Assign a component role to the host
- @param component_name : name of component.
- @return: StatusModel.
- """
- return _assign_role(self._get_resource_root(), self._get_cluster_name(), self.host_name , component_name)
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/paths.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/paths.py b/ambari-client/src/main/python/ambari_client/model/paths.py
deleted file mode 100755
index f34c26d..0000000
--- a/ambari-client/src/main/python/ambari_client/model/paths.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# 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.
-
-CLUSTERS_PATH = "/clusters"
-CLUSTERS_CONFIG_PATH = "/clusters/%s"
-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"
-
-
-SERVICES_PATH = "/clusters/%s/services"
-SERVICE_PATH = "/clusters/%s/services/%s"
-SERVICE_CREATE_PATH = "/clusters/%s/services/?ServiceInfo/service_name=%s"
-SERVICE_COMPONENTS_PATH = "/clusters/%s/services/%s/components?fields=*"
-SERVICE_COMPONENT_PATH = "/clusters/%s/services/%s/components/%s"
-
-
-HOST_PATH = "/hosts/%s"
-HOSTS_PATH = "/hosts"
-HOSTS_CREATE_PATH = "/clusters/%s/hosts"
-HOSTS_COMPONENTS_PATH = "/clusters/%s/hosts/%s/host_components?fields=HostRoles/state"
-HOSTS_COMPONENT_PATH = "/clusters/%s/hosts/%s/host_components/%s"
-HOSTS_ASSIGN_ROLE = "/clusters/%s/hosts?Hosts/host_name=%s"
-
-BOOTSTRAP_PATH = "/bootstrap"
-REQUEST_STATUS_PATH = "/clusters/%s/requests/%s?fields=tasks/Tasks/status"
-REQUEST_PATH = "clusters/%s/requests/%s"
-
-CONFIGURATION_PATH = "/clusters/%s/configurations?type=%s&tag=%s"
-CONFIGURATION_ALL_PATH = "/clusters/%s/configurations?type=%s"
-CREATE_CONFIGURATION_PATH = "/clusters/%s/configurations"
-UPDATE_CONFIGURATION_PATH="/clusters/%s"
-
-STACK_SERVICES_COMPONENTS_PATH = "/stacks2/HDP/versions/%s/stackServices/%s/serviceComponents?fields=*"
-STACK_SERVICES_CONFIG_PATH = "/stacks2/HDP/versions/%s/stackServices/%s/configurations?fields=*"
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/service.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/service.py b/ambari-client/src/main/python/ambari_client/model/service.py
deleted file mode 100755
index ed91d7c..0000000
--- a/ambari-client/src/main/python/ambari_client/model/service.py
+++ /dev/null
@@ -1,203 +0,0 @@
-# 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 logging
-import time
-from ambari_client.model.base_model import BaseModel , ModelList
-from ambari_client.model import component , paths , status , stack , utils
-
-
-LOG = logging.getLogger(__name__)
-
-
-
-def _get_all_services(resource_root, cluster_name):
- """
- Get all services in a cluster.
- @param cluster_name :Cluster name.
- @return: A ModelList object.
- """
- path = paths.SERVICES_PATH % (cluster_name,)
- path = path + '?fields=*'
- dic = resource_root.get(path)
- return utils.ModelUtils.get_model_list(ModelList, ServiceModel, dic, resource_root , "ServiceInfo")
-
-
-def _get_service(resource_root, service_name, cluster_name):
- """
- Get a specific services in a cluster.
- @param service_name :Service name.
- @param cluster_name :Cluster name.
- @return: A ServiceModel object.
- """
- path = "%s/%s" % (paths.SERVICES_PATH % (cluster_name,), service_name)
- dic = resource_root.get(path)
- return utils.ModelUtils.create_model(ServiceModel , dic, resource_root, "ServiceInfo")
-
-
-def _create_services(root_resource, cluster_name , service_names):
- """
- Create services
- @param root_resource: The root Resource object.
- @param service_names: list of service_names
- @param cluster_name: Cluster name
- @return: StatusModel
- """
- data = [{"ServiceInfo":{"service_name":x}} for x in service_names]
- cpath = paths.SERVICES_PATH % cluster_name
- resp = root_resource.post(path=cpath, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _create_service(root_resource, cluster_name , service_name):
- """
- Create a single service
- @param root_resource: The root Resource object.
- @param service_name: service_name
- @param cluster_name: Cluster name
- @return: StatusModel
- """
- data = {"ServiceInfo":{"service_name":service_name}}
- cpath = paths.SERVICES_PATH % cluster_name
- resp = root_resource.post(path=cpath, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _create_service_components(root_resource, cluster_name , version , service_name):
- """
- Create service with components
- @param root_resource: The root Resource object.
- @param service_name: service_names
- @param cluster_name: Cluster service_name
- @return: An ServiceModel object
- """
- components = stack._get_components_from_stack(root_resource, version , service_name)
- list_componnetinfo = [{"ServiceComponentInfo":{"component_name":x.component_name }} for x in components]
- data = {"components":list_componnetinfo}
- cpath = paths.SERVICE_CREATE_PATH % (cluster_name, service_name)
- resp = root_resource.post(path=cpath, payload=data)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _create_service_component(root_resource, cluster_name , version , service_name, component_name):
- """
- Create service with single component
- @param root_resource: The root Resource object.
- @param service_name: service_names
- @param cluster_name: Cluster service_name
- @param component_name: name of component
- @return: An ServiceModel object
- """
- cpath = paths.SERVICE_COMPONENT_PATH % (cluster_name, service_name, component_name)
- resp = root_resource.post(path=cpath, payload=None)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-def _delete_service(root_resource, service_name, cluster_name):
- """
- Delete a service by service_name
- @param root_resource: The root Resource object.
- @param service_name: Service service_name
- @param cluster_name: Cluster service_name
- @return: The StatusModel object
- """
- resp = root_resource.delete("%s/%s" % (paths.SERVICES_PATH % (cluster_name,), service_name))
- time.sleep(3)
- return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
-
-
-
-class ServiceModel(BaseModel):
- """
- The ServiceModel class
- """
- #RO_ATTR = ('state', 'cluster_name')
- RW_ATTR = ('service_name', 'state')
- REF_ATTR = ('cluster_name',)
-
- def __init__(self, resource_root, service_name , state):
- #BaseModel.__init__(self, **locals())
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<ServiceModel>> = %s ;state = %s ; cluster_name = %s" % (self.service_name, self.state , self._get_cluster_name())
-
- def _get_cluster_name(self):
- if self.clusterRef:
- return self.clusterRef.cluster_name
- return None
-
- def _path(self):
- """
- Return the API path for this object.
- """
- if self._get_cluster_name():
- return paths.SERVICE_PATH % (self._get_cluster_name(), self.service_name)
- else:
- return ''
-
- def _action(self, data=None):
- path = self._path()
- resp = self._get_resource_root().put(path, payload=data)
- status_model = utils.ModelUtils.create_model(status.StatusModel, resp, self._get_resource_root(), "NO_KEY")
- if status_model._get_id() is not None:
- status_model.request_path = paths.REQUEST_PATH % (self._get_cluster_name(), status_model._get_id())
- else:
- status_model.request_path = None
- return status_model
-
- def start(self ,message = None):
- """
- Start a service.
- """
- data = None
- if message:
- data = {"RequestInfo":{"context":message},"Body":{"ServiceInfo":{"state":"STARTED"}}}
- else:
- data = {"ServiceInfo": {"state": "STARTED"}}
- return self._action(data)
-
- def stop(self ,message = None):
- """
- Stop a service.
- """
- data = None
- if message:
- data = {"RequestInfo":{"context":message},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}
- else:
- data = {"ServiceInfo": {"state": "INSTALLED"}}
- return self._action(data)
-
- def install(self):
- """
- Install a service.
- """
- data = {"ServiceInfo": {"state": "INSTALLED"}}
- return self._action(data)
-
- def get_service_components(self, detail=None):
- """
- Get a specific services's components.
- @return: A ComponentModel object.
- """
- return component._get_service_components(self._get_resource_root(), self._get_cluster_name(), self.service_name)
-
- def get_service_component(self, component_name , detail=None):
- """
- Get a specific services's components.
- @return: A ComponentModel object.
- """
- return component._get_service_component(self._get_resource_root(), self._get_cluster_name(), self.service_name, component_name)
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/stack.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/stack.py b/ambari-client/src/main/python/ambari_client/model/stack.py
deleted file mode 100755
index 40088f7..0000000
--- a/ambari-client/src/main/python/ambari_client/model/stack.py
+++ /dev/null
@@ -1,79 +0,0 @@
-#
-# 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.
-
-
-from ambari_client.model.base_model import BaseModel , ModelList
-from ambari_client.model import paths , utils
-
-
-def _get_configuration_from_stack(resource_root, version , service_name , tag="version1"):
- """
- Get configuration from stack
- @param resource_root: The root Resource .
- @param cluster_name: cluster_name
- @param type: type of config
- @return: A ModelList of ConfigModel object
- """
- dic = resource_root.get(paths.STACK_SERVICES_CONFIG_PATH % (version, service_name))
- return utils.ModelUtils.get_model_list(ModelList, StackConfigModel, dic, resource_root , "StackConfigurations")
-
-
-def _get_components_from_stack(resource_root, version , service_name , tag="version1"):
- """
- Get configuration from stack
- @param resource_root: The root Resource .
- @param cluster_name: cluster_name
- @param type: type of config
- @return: A ModelList of ConfigModel object
- """
- path = paths.STACK_SERVICES_COMPONENTS_PATH % (version, service_name)
- dic = resource_root.get(path)
- return utils.ModelUtils.get_model_list(ModelList, StackComponentModel, dic, resource_root , "StackServiceComponents")
-
-
-class StackConfigModel(BaseModel):
- """
- The StackConfigModel class
- """
- RO_ATTR = ('stack_name', 'type', 'property_description')
- RW_ATTR = ('property_name', 'property_value', 'service_name', 'stack_version')
- REF_ATTR = ()
-
- def __init__(self, resource_root, property_name , property_value=None , service_name=None , stack_version=None):
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<StackConfigModel>> property_name=%s; property_value=%s ;service_name= %s" % (self.property_name, self.property_value, self.service_name)
-
-
-
-
-
-class StackComponentModel(BaseModel):
- """
- The StackComponentModel class
- """
- RO_ATTR = ('stack_name', 'is_master', 'is_client', 'component_category')
- RW_ATTR = ('component_name', 'service_name', 'stack_version')
- REF_ATTR = ()
-
- def __init__(self, resource_root, component_name , service_name=None , stack_version=None):
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<StackComponentModel>> component_name = %s; service_name = %s" % (self.component_name, self.service_name)
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/status.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/status.py b/ambari-client/src/main/python/ambari_client/model/status.py
deleted file mode 100755
index f88a534..0000000
--- a/ambari-client/src/main/python/ambari_client/model/status.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# 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 logging
-from ambari_client.model.base_model import BaseModel
-from ambari_client.model import paths , utils
-
-
-LOG = logging.getLogger(__name__)
-
-
-class StatusModel(BaseModel):
- """
- The ServiceModel class
- """
- RO_ATTR = ('id',)
- RW_ATTR = ('status', 'requestId', "message")
- REF_ATTR = ('cluster_name',)
-
- def __init__(self, resource_root, status , requestId=None, message=None):
- #BaseModel.__init__(self, **locals())
- utils.retain_self_helper(BaseModel, **locals())
-
- def __str__(self):
- return "<<StatusModel>> status = %s ; requestId = %s ;message = %s" % (self._get_status(), self._get_id() , self.get_message())
-
- def get_bootstrap_path(self):
- return paths.BOOTSTRAP_PATH + '/' + str(self.requestId)
-
- def get_request_path(self):
- return self.request_path
-
- def get_message(self):
- if hasattr(self, 'message'):
- return self.message
- else:
- None
-
- def is_error(self):
- return (self.status != 200 and self.status != 201 and self.status != 202)
-
- def _get_id(self):
- if hasattr(self, 'requestId') and self.requestId:
- return self.requestId
- elif hasattr(self, 'id') and self.id:
- return self.id
- else:
- None
-
- def _get_status(self):
- if hasattr(self, 'status') and isinstance(self.status, basestring):
- self.message = self.status
- self.status = 200
- return self.status
- elif hasattr(self, 'status') and isinstance(self.status, int):
- return self.status
- else:
- None
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/model/utils.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/model/utils.py b/ambari-client/src/main/python/ambari_client/model/utils.py
deleted file mode 100755
index 0b3b6a0..0000000
--- a/ambari-client/src/main/python/ambari_client/model/utils.py
+++ /dev/null
@@ -1,231 +0,0 @@
-#
-# 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 logging
-import sys
-import unicodedata
-from ambari_client.core import errors
-
-LOG = logging.getLogger(__name__)
-
-
-ref_dic = {"cluster_name":"clusterRef"}
-ref_class_dic = {"ClusterModelRef":"cluster_name"}
-ref_pkg_dic = {"ClusterModelRef":"ambari_client.model.cluster"}
-LIST_KEY = "items"
-ALL="ALL"
-
-class ModelUtils(object):
-
- @staticmethod
- def _check_is_error(expected_class, model_dict, resource_root):
- from ambari_client.model.status import StatusModel
-
- if model_dict.has_key("status"):
- resp = ModelUtils.create_model(StatusModel, model_dict.copy(), resource_root, "NO_KEY", check_errors=False)
-
- if expected_class!=StatusModel or resp.is_error():
- if resp.status in errors._exceptions_to_codes:
- raise errors._exceptions_to_codes[resp.status](resp, resource_root)
- else:
- raise errors.UnknownServerError(resp, resource_root)
-
- @staticmethod
- def get_model_list(member_list_clss, member_cls, collection_dict, resource_root , RESOURCE_KEY_WORD, check_errors=True):
- """
- create a model.
- @param member_list_clss : model_list class.
- @param model_cls : model class.
- @param collection_dict : collection dict used for creating the list of objects.
- @param resource_root : resource object.
- @param RESOURCE_KEY_WORD : tsake subset of model_dict based on this key.
- @return: A ModelList object.
- """
- if check_errors:
- ModelUtils._check_is_error(member_list_clss, collection_dict, resource_root)
-
- #print locals()
- json_list = []
-
- #remove items
- if isinstance(collection_dict, dict) and collection_dict.has_key(LIST_KEY):
- json_list = collection_dict[LIST_KEY]
- LOG.debug("get_model_list: collection_dict is dict ? %s ; has_key = %s" % (isinstance(collection_dict, dict), collection_dict.has_key(LIST_KEY)))
- LOG.debug ("get_model_list: collection_dict has %s ;subset = %s" % (LIST_KEY, str(json_list)))
- else:
- json_list = collection_dict
- LOG.error("get_model_list: collection_dict is dict ? %s ; has_key = %s" % (isinstance(collection_dict, dict), collection_dict.has_key(LIST_KEY)))
-
- LOG.debug ("get_model_list: json_list value : \n\t" + str(json_list))
- if isinstance(json_list, list):
- json_list_new = [ x.get(RESOURCE_KEY_WORD) for x in json_list]
- LOG.debug("get_model_list: json_list is list ? %s ; " % (isinstance(json_list, list)))
- else:
- json_list_new = [json_list]
- LOG.error("get_model_list: json_list is list ? %s ; " % (isinstance(json_list, list)))
-
- LOG.debug ("get_model_list: json_list_new used for creating ModelList \n\t" + str(json_list_new))
- objects = [ ModelUtils.create_model(member_cls, x, resource_root , RESOURCE_KEY_WORD) for x in json_list_new ]
- LOG.debug (objects)
- return member_list_clss(objects)
-
-
- @staticmethod
- def create_model(model_cls, model_dict, resource_root, RESOURCE_KEY_WORD, check_errors=True):
- """
- create a model.
- @param model_cls : model class.
- @param model_dict : model dict used for creating the object.
- @param resource_root : resource object.
- @param RESOURCE_KEY_WORD : tsake subset of model_dict based on this key.
- @return: A model_cls object.
- """
- if check_errors:
- ModelUtils._check_is_error(model_cls, model_dict, resource_root)
-
- #print locals()
- rw_dict = { }
- LOG.debug ("model_dict = " + str(model_dict))
-
- if isinstance(model_dict, dict) and model_dict.has_key(RESOURCE_KEY_WORD):
- model_dict = model_dict[RESOURCE_KEY_WORD]
- LOG.debug ("model_dict has %s ;subset = %s" % (RESOURCE_KEY_WORD, str(model_dict.items())))
- if isinstance(model_dict, dict) and model_dict.has_key("Requests"):
- model_dict = model_dict["Requests"]
- LOG.debug ("model_dict has Requests ;subset = %s" % (str(model_dict.items())))
-
-
- for k, v in model_dict.items():
- LOG.debug("key = %s ; value = %s " % (str(k), str(v)))
- if k in model_cls.RW_ATTR:
- LOG.debug (k + " is there in RW_ATTR")
- rw_dict[k] = v
- del model_dict[k]
-
- rw_dict = get_unicode_kw(rw_dict)
- obj = model_cls(resource_root, **rw_dict)
-
- for attr in model_cls.RO_ATTR:
- obj._setattr(attr, None)
-
- for k, v in model_dict.items():
- if k in model_cls.RO_ATTR:
- obj._setattr(k, v)
- else:
- LOG.debug("Unexpected attribute '%s' in %s json" % (k, model_cls.__name__))
-
- for attr in model_cls.REF_ATTR:
- LOG.debug("%s found as reference var" % (attr))
- obj._setattr(getREF_class_name(attr), None)
-
- for k, v in model_dict.items():
- if k in model_cls.REF_ATTR:
- obj._setattr(getREF_class_name(k), v)
- else:
- LOG.debug("Unknown attribute '%s' found in model_dict for %s " % (k, model_cls.__name__))
- return obj
-
-
-#get attribute with REF
-def getREF_class_name(REF_name):
- if ref_dic.has_key(REF_name):
- return ref_dic[str(REF_name)]
- else:
- return None
-
-
-def getREF_var_name(REF_name):
- if ref_class_dic.has_key(REF_name):
- return ref_class_dic[str(REF_name)]
- else:
- return None
-
-
-def get_REF_object(ref_class_name):
- """
- Gets the Ref object based on class_name
- """
- class_ref = getattr(sys.modules[ref_pkg_dic[ref_class_name]], ref_class_name)
- LOG.debug(class_ref)
- return class_ref
-
-
-def get_unicode(v):
- #import unicodedata
- if v:
- if isinstance(v, unicode):
- v = unicodedata.normalize('NFKD', v).encode('ascii', 'ignore')
- LOG.debug(v)
- elif isinstance(v, str):
- LOG.debug("warning: string found while expecting unicode %s" % v)
- return v
-
-
-def retain_self_helper(memclass, self=None, **kwargs):
- #print locals()
- #from ambari_client.model.base_model import BaseModel
- memclass.__init__(self, **kwargs)
-
-
-def get_unicode_kw(dic):
- """
- We use unicode strings as keys in kwargs.
- """
- res = { }
- for k, v in dic.iteritems():
- res[str(k)] = v
- return res
-
-
-def get_config_type(service_name):
- """
- get the config type based on service_name
- """
- if service_name == "HDFS":
- type = "hdfs-site"
- elif service_name == "HDFS":
- type = "core-site"
- elif service_name == "MAPREDUCE":
- type = "mapred-site"
- elif service_name == "HBASE":
- type = "hbase-site"
- elif service_name == "OOZIE":
- type = "oozie-site"
- elif service_name == "HIVE":
- type = "hive-site"
- elif service_name == "WEBHCAT":
- type = "webhcat-site"
- else:
- type = "global"
- return type
-
-
-def get_key_value(dictt , key):
- """
- Search for some random key in the dict
- """
- if isinstance(dictt, dict) and dictt.has_key(key):
- return dictt[key]
- elif isinstance(dictt, dict) and not dictt.has_key(key):
- #check if values has it?
- for v in dictt.values():
- if isinstance(v, dict):
- return get_key_value(v, key)
- elif isinstance(v, list):
- for l in list:
- return get_key_value(l, key)
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/resources/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/resources/__init__.py b/ambari-client/src/main/python/ambari_client/resources/__init__.py
deleted file mode 100755
index 278df2e..0000000
--- a/ambari-client/src/main/python/ambari_client/resources/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# 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.
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/resources/clusters.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/resources/clusters.py b/ambari-client/src/main/python/ambari_client/resources/clusters.py
deleted file mode 100755
index ca3cca6..0000000
--- a/ambari-client/src/main/python/ambari_client/resources/clusters.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# 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.
-
-from ambari_client.model import cluster
-__docformat__ = "epytext"
-
-
-def _get_cluster(resource_root, cluster_name):
- """
- Get a cluster by cluster_name
- @param resource_root: The root Resource.
- @param cluster_name: Cluster's name
- @return: ClusterModel object
- """
- return cluster._get_cluster(resource_root, cluster_name)
-
-
-def _get_all_clusters(root_resource):
- """
- Get all clusters in Ambari.
- @param root_resource: The root Resource object.
- @return: A list of ClusterModel objects in ModelList.
- """
- return cluster._get_all_clusters(root_resource)
-
-
-def _create_cluster(root_resource, cluster_name, version):
- """
- Create a cluster
- @param root_resource: The root Resource.
- @param cluster_name: Cluster cluster_name
- @param version: HDP version
- @return: An ClusterModel object
- """
- return cluster._create_cluster(root_resource, cluster_name, version)
-
-
-def _delete_cluster(root_resource, cluster_name):
- """
- Create a cluster
- @param root_resource: The root Resource.
- @param cluster_name: Cluster cluster_name
- """
- return cluster._delete_cluster(root_resource, cluster_name)
http://git-wip-us.apache.org/repos/asf/ambari/blob/11dd9df8/ambari-client/src/main/python/ambari_client/resources/hosts.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/main/python/ambari_client/resources/hosts.py b/ambari-client/src/main/python/ambari_client/resources/hosts.py
deleted file mode 100755
index 0d53711..0000000
--- a/ambari-client/src/main/python/ambari_client/resources/hosts.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# 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.
-
-from ambari_client.model import host
-__docformat__ = "epytext"
-
-def _add_hosts(root_resource, cluster_name , host_list):
- """
- Adds a hosts to a cluster.
- @param root_resource: The root Resource object.
- @param cluster_name: Cluster name
- @param host_list: list of hosts
- @return: A StatusModel object
- """
- return _add_hosts(root_resource, cluster_name , host_list)
-
-def _add_host(root_resource, cluster_name , host_name , ip, rack_info=None):
- """
- Adds a host to a cluster.
- @param host_name: Host name
- @param ip: ip of Host
- @param rack_info: rack information
- @return: StatusModel.
- """
- return _add_host(root_resource, cluster_name , host_name , ip, rack_info)
-
-
-def _create_hosts(root_resource, host_list):
- """
- Create a host
- @param root_resource: The root Resource.
- @param host_list: ModelList list of hosts
- @return: A HostModel object
- """
- return host._create_hosts(root_resource, host_list)
-
-def _create_host(root_resource, host_name, ip, rack_info=None):
- """
- Create a host
- @param root_resource: The root Resource.
- @param host_name: Host name
- @param ip: IP address
- @param rack_info: Rack id. Default None
- @return: A HostModel object
- """
- return host._create_host(root_resource, host_name, ip, rack_info)
-
-
-def _get_host(root_resource, host_name):
- """
- Lookup a host by name
- @param root_resource: The root Resource.
- @param host_name: Host name
- @return: A HostModel object
- """
- return host._get_host(root_resource, host_name)
-
-def _get_cluster_host(root_resource, cluster_name, host_name):
- """
- Lookup a host by name
- @param root_resource: The root Resource.
- @param host_name: Host name
- @return: A HostModel object
- """
- return host._get_cluster_host(root_resource, cluster_name, host_name)
-
-
-
-
-def _get_all_hosts(root_resource):
- """
- Get all hosts
- @param root_resource: The root Resource.
- @return: A list of HostModel objects.
- """
- return host._get_all_hosts(root_resource)
-
-def _get_all_cluster_hosts(root_resource, cluster_name):
- """
- Get all cluster hosts
- @param root_resource: The root Resource.
- @return: A list of HostModel objects.
- """
- return host._get_all_cluster_hosts(root_resource, cluster_name)
-
-
-def _delete_host(root_resource, host_name):
- """
- Delete a host by id
- @param root_resource: The root Resource.
- @param host_name: Host name
- @return: The deleted HostModel object
- """
- return host._delete_host(root_resource, host_name)
-
-def _delete_cluster_host(root_resource, cluster_name , host_name):
- """
- Delete a cluster host by id
- @param root_resource: The root Resource.
- @param host_name: Host name
- @return: The deleted HostModel object
- """
- return host._delete_cluster_host(root_resource, cluster_name , host_name)
-
-
-def _bootstrap_hosts(root_resource , hosts_list , ssh_key):
- """
- Bootstrap hosts.
- @param hosts_list: list of host_names.
- @param ssh_key: ssh key for password-less access.
- @return: A StatusModel object.
- """
- return host._bootstrap_hosts(root_resource, hosts_list , ssh_key)