incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject git commit: Revert "AMBARI-3244. Ambari Client improve errors handling. (Andrew vi mahadev)"
Date Tue, 17 Sep 2013 20:12:58 GMT
Updated Branches:
  refs/heads/trunk 6dcb9f860 -> 741746124


Revert "AMBARI-3244. Ambari Client improve errors handling. (Andrew vi mahadev)"

This reverts commit d98cfd9ca0ddd24f1e293bf0d3e877118a171765.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/74174612
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/74174612
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/74174612

Branch: refs/heads/trunk
Commit: 7417461245c32093516491be93e8a8fa33271feb
Parents: 6dcb9f8
Author: Mahadev Konar <mahadev@apache.org>
Authored: Tue Sep 17 13:07:58 2013 -0700
Committer: Mahadev Konar <mahadev@apache.org>
Committed: Tue Sep 17 13:08:04 2013 -0700

----------------------------------------------------------------------
 .../python/ambari_client/core/rest_resource.py  | 26 +++++++-----
 .../main/python/ambari_client/model/cluster.py  | 16 +++----
 .../python/ambari_client/model/component.py     | 16 +++----
 .../python/ambari_client/model/configuration.py | 16 ++++---
 .../src/main/python/ambari_client/model/host.py | 33 +++++++--------
 .../main/python/ambari_client/model/service.py  | 18 ++++----
 .../main/python/ambari_client/model/stack.py    |  8 ++--
 .../main/python/ambari_client/model/status.py   |  3 --
 .../main/python/ambari_client/model/utils.py    | 44 +-------------------
 .../src/test/python/TestAmbariClient.py         | 30 ++++++-------
 10 files changed, 81 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index 506308c..f7e2e23 100755
--- a/ambari-client/src/main/python/ambari_client/core/rest_resource.py
+++ b/ambari-client/src/main/python/ambari_client/core/rest_resource.py
@@ -63,19 +63,23 @@ class RestResource(object):
 
     LOG.debug ("RESPONSE from the REST request >>>>>>> \n" + str(resp))
     LOG.debug ("\n===========================================================")
-
+    #take care of REST calls with no response
+    if not resp and (code != 200 and code != 201):
+        LOG.error("Command '%s %s' failed with error %s" % (http_method, path, code))
+        return {"status":code , "message":"Command '%s %s' failed with error %s" % (http_method,
path, code)}
+        #raise Exception("Command '%s %s' failed with error %s" % (http_method, path, code))
+    if resp and (code == 404 or code == 405 or code == 500):
+        LOG.error("Command '%s %s' failed with error %s" % (http_method, path, code))
+        return {"status":code , "message":"Command '%s %s' failed with error %s" % (http_method,
path, code)}
+        #raise Exception("Command '%s %s' failed with error %s" % (http_method, path, code))
     try:
-        isOK = (code == 200 or code == 201)
-        
-        if isOK and not resp:
-          json_dict = {"status":code}
-        else:
-          json_dict = json.loads(resp)
-          
-        return json_dict, isOK
+        if (code == 200 or code == 201) and not resp:
+          return {"status":code}
+        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)}, False
+        LOG.error('JSON decode error: %s' % (resp,))
+        raise ex
 
 
   def get(self, path=None):

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index d3ee609..75ac0c9 100755
--- a/ambari-client/src/main/python/ambari_client/model/cluster.py
+++ b/ambari-client/src/main/python/ambari_client/model/cluster.py
@@ -31,8 +31,8 @@ def _get_cluster(resource_root, cluster_name):
   @param cluster_name: cluster_name
   @return: A ClusterModel object
   """
-  dic, is_success = resource_root.get("%s/%s" % (paths.CLUSTERS_PATH, cluster_name))
-  return utils.ModelUtils.create_model_or_error(ClusterModel , dic, resource_root, "Clusters",
is_success)
+  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):
@@ -41,8 +41,8 @@ def _get_all_clusters(root_resource):
   @param root_resource: The root Resource .
   @return: A list of ClusterModel objects.
   """
-  dic, is_success = root_resource.get(paths.CLUSTERS_PATH)
-  return utils.ModelUtils.get_model_list_or_error(ModelList, ClusterModel, dic, root_resource
, "Clusters", is_success)
+  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):
@@ -66,7 +66,7 @@ def _delete_cluster(root_resource, cluster_name):
   @param root_resource: The root Resource .
   @param name: Cluster name
   """
-  resp, is_success = root_resource.delete("%s/%s" % (paths.CLUSTERS_PATH, 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")
 
 
@@ -78,7 +78,7 @@ def _install_all_services(root_resource, cluster_name):
   """
   cpath = paths.CLUSTER_START_ALL_SERVICES % cluster_name
   data = {"RequestInfo": {"context" :"Install Services"}, "Body": {"ServiceInfo": {"state":
"INSTALLED"}}}
-  resp, is_success = root_resource.put(path=cpath , payload=data)
+  resp = root_resource.put(path=cpath , payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -90,7 +90,7 @@ def _stop_all_services(root_resource, cluster_name):
   """
   cpath = paths.CLUSTER_STOP_ALL_SERVICES % cluster_name
   data = {"RequestInfo": {"context" :"Stop All Services"}, "Body": {"ServiceInfo": {"state":
"INSTALLED"}}}
-  resp, is_success = root_resource.put(path=cpath , payload=data)
+  resp = root_resource.put(path=cpath , payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -104,7 +104,7 @@ def _start_all_services(root_resource, cluster_name , run_smoke_test=False):
   if run_smoke_test:
      cpath = "%s&%s" % (cpath, "params/run_smoke_test=true&params/reconfigure_client=false")
   data = {"RequestInfo": {"context" :"Start All Services"}, "Body": {"ServiceInfo": {"state":
"STARTED"}}}
-  resp, is_success = root_resource.put(path=cpath , payload=data)
+  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")

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index b9d879a..586f21a 100755
--- a/ambari-client/src/main/python/ambari_client/model/component.py
+++ b/ambari-client/src/main/python/ambari_client/model/component.py
@@ -26,28 +26,28 @@ LOG = logging.getLogger(__name__)
 
 def get_host_components(resource_root, cluster_name , host_name):
   path = paths.HOSTS_COMPONENTS_PATH % (cluster_name, host_name)
-  dic, is_success = resource_root.get(path)
-  return utils.ModelUtils.get_model_list_or_error(ModelList, ComponentModel, dic, resource_root
, "HostRoles", is_success)
+  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, is_success = resource_root.get(path)
-  comp_model = utils.ModelUtils.create_model_or_error(ComponentModel, dic, resource_root
, "HostRoles" , is_success)
+  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, is_success = resource_root.get(path)
-  return utils.ModelUtils.get_model_list_or_error(ModelList, ComponentModel, dic, resource_root
, "ServiceComponentInfo", is_success)
+  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, is_success = resource_root.get(path)
-  return utils.ModelUtils.create_model_or_error(ComponentModel, dic, resource_root , "ServiceComponentInfo",
is_success)
+  dic = resource_root.get(path)
+  return utils.ModelUtils.create_model(ComponentModel, dic, resource_root , "ServiceComponentInfo")
 
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index 32bcd7a..222ce5c 100755
--- a/ambari-client/src/main/python/ambari_client/model/configuration.py
+++ b/ambari-client/src/main/python/ambari_client/model/configuration.py
@@ -30,13 +30,11 @@ def _get_configuration(resource_root, cluster_name , type , tag="version1"):
   @param type: type of config
   @return: A ConfigModel object
   """
-  dic, is_success = resource_root.get(paths.CONFIGURATION_PATH % (cluster_name, type, tag))
-  config_model, err_model = utils.ModelUtils.create_model_or_error(ConfigModel , dic["items"][0],
resource_root, "NO_KEY", is_success)
-  if not err_model:
-    ref_clss = utils.getREF_class_name("cluster_name")
-    config_model._setattr(ref_clss, dic["items"][0]['Config']['cluster_name'])
-    
-  return config_model, err_model
+  dic = resource_root.get(paths.CONFIGURATION_PATH % (cluster_name, type, tag))
+  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 _update_configuration(resource_root, cluster_name , type , tag , config_model):
@@ -63,7 +61,7 @@ def _add_config(root_resource, cluster_name, type, tag , properties):
   """
   cpath = paths.CLUSTERS_CONFIG_PATH % cluster_name
   data = {"Clusters":{"desired_configs":{"type":type, "tag":tag, "properties":properties}}}
-  resp, is_success = root_resource.put(path=cpath , payload=data)
+  resp = root_resource.put(path=cpath , payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")

     
 
@@ -77,7 +75,7 @@ def _create_config(root_resource, cluster_name, type, tag , properties):
   """
   cpath = paths.CLUSTERS_CONFIG_PATH % cluster_name
   data = {"type":type, "tag":tag, "properties":properties}
-  resp, is_success = root_resource.put(path=cpath , payload=data)
+  resp = root_resource.put(path=cpath , payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")

 
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index 5c6ce8d..2a0e101 100755
--- a/ambari-client/src/main/python/ambari_client/model/host.py
+++ b/ambari-client/src/main/python/ambari_client/model/host.py
@@ -34,13 +34,12 @@ def _get_host(root_resource, host_name):
   @param root_resource: The root Resource object.
   @param cluster_name: Cluster name
   @param host_name: Host name
-  @return model: A HostModel of the host
-  @return err_resp: StatusModel object of the error response
+  @return: A HostModel object
   """
   path = paths.HOST_PATH % (host_name)
-  dic, is_success = root_resource.get(path)
- 
-  return utils.ModelUtils.create_model_or_error(HostModel , dic, root_resource, "Hosts",
is_success)
+  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):
   """
@@ -51,8 +50,8 @@ def _get_cluster_host(root_resource, cluster_name , host_name):
   @return: A HostModel object
   """
   path = paths.CLUSTER_HOST_PATH % (cluster_name, host_name)
-  dic, is_success = root_resource.get(path)
-  return utils.ModelUtils.create_model_or_error(HostModel , dic, root_resource, "Hosts",
is_success)
+  dic = root_resource.get(path)
+  return utils.ModelUtils.create_model(HostModel , dic, root_resource, "Hosts")
 
 
 
@@ -68,7 +67,7 @@ def _create_hosts(root_resource, host_list):
   
   data = [{"Hosts":{"host_name":x.host_name,"ip":x.ip,"rack_info":x.rack_info}} 
           for x in host_list]
-  resp, is_success = root_resource.post(paths.HOSTS_PATH, payload=data)
+  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):
@@ -94,7 +93,7 @@ def _add_hosts(root_resource, cluster_name , host_list):
   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, is_success = root_resource.post(path=cpath, payload=data)
+  resp = root_resource.post(path=cpath, payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -121,7 +120,7 @@ def _assign_role(root_resource, cluster_name , host_name , component_name):
   """
   data = {"host_components":[{"HostRoles":{"component_name":component_name}}]}
   cpath = paths.HOSTS_ASSIGN_ROLE % (cluster_name, host_name)
-  resp, is_success = root_resource.post(path=cpath, payload=data)
+  resp = root_resource.post(path=cpath, payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -131,7 +130,7 @@ def _get_all_hosts(root_resource):
   @param root_resource: The root Resource.
   @return: A list of HostModel objects.
   """
-  dic, is_success = root_resource.get(paths.HOSTS_PATH)
+  dic = root_resource.get(paths.HOSTS_PATH)
   return utils.ModelUtils.get_model_list(ModelList, HostModel, dic, root_resource , "Hosts")
   
   
@@ -144,8 +143,8 @@ def _get_all_cluster_hosts(root_resource, cluster_name):
   """
   path = paths.CLUSTER_HOSTS_PATH % (cluster_name)
   path = path + '?fields=*'
-  dic, is_success = root_resource.get(path)
-  return utils.ModelUtils.get_model_list_or_error(ModelList, HostModel, dic, root_resource
, "Hosts", is_success)
+  dic = root_resource.get(path)
+  return utils.ModelUtils.get_model_list(ModelList, HostModel, dic, root_resource , "Hosts")
 
 
 def _delete_host(root_resource, host_name):
@@ -155,8 +154,8 @@ def _delete_host(root_resource, host_name):
   @param host_name: Host name
   @return: StatusModel object
   """
-  resp, is_success = root_resource.delete(paths.HOST_PATH % (host_name))
-  return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY",
is_success)
+  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):
@@ -168,7 +167,7 @@ def _delete_cluster_host(root_resource, cluster_name , host_name):
   @return: StatusModel object
   """
   path = paths.CLUSTER_HOST_PATH % (cluster_name, host_name)
-  resp, is_success = root_resource.delete(path)
+  resp = root_resource.delete(path)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -180,7 +179,7 @@ def _bootstrap_hosts(root_resource , hosts_list, ssh_key):
   """
   #payload_dic = {'sshKey':ssh_key , 'hosts':hosts_list}
   payload_dic = {'sshKey':ssh_key.encode('string_escape') , 'hosts':hosts_list}
-  resp, is_success = root_resource.post(paths.BOOTSTRAP_PATH, payload_dic , content_type="application/json")
+  resp = root_resource.post(paths.BOOTSTRAP_PATH, payload_dic , content_type="application/json")
   LOG.debug(resp)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index cafbc29..c384473 100755
--- a/ambari-client/src/main/python/ambari_client/model/service.py
+++ b/ambari-client/src/main/python/ambari_client/model/service.py
@@ -32,8 +32,8 @@ def _get_all_services(resource_root, cluster_name):
   """
   path = paths.SERVICES_PATH % (cluster_name,)
   path = path + '?fields=*'
-  dic, is_success = resource_root.get(path)
-  return utils.ModelUtils.get_model_list_or_error(ModelList, ServiceModel, dic, resource_root
, "ServiceInfo", is_success)
+  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):
@@ -44,8 +44,8 @@ def _get_service(resource_root, service_name, cluster_name):
   @return: A  ServiceModel object.
   """
   path = "%s/%s" % (paths.SERVICES_PATH % (cluster_name,), service_name)
-  dic, is_success = resource_root.get(path)
-  return utils.ModelUtils.create_model_or_error(ServiceModel , dic, resource_root, "ServiceInfo",
is_success) 
+  dic = resource_root.get(path)
+  return utils.ModelUtils.create_model(ServiceModel , dic, resource_root, "ServiceInfo")

 
 
 def _create_services(root_resource, cluster_name , service_names):
@@ -58,7 +58,7 @@ def _create_services(root_resource, cluster_name , service_names):
   """
   data = [{"ServiceInfo":{"service_name":x}} for x in service_names]
   cpath = paths.SERVICES_PATH % cluster_name
-  resp, is_success = root_resource.post(path=cpath, payload=data)
+  resp = root_resource.post(path=cpath, payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -72,7 +72,7 @@ def _create_service(root_resource, cluster_name , service_name):
   """
   data = {"ServiceInfo":{"service_name":service_name}} 
   cpath = paths.SERVICES_PATH % cluster_name
-  resp, is_success = root_resource.post(path=cpath, payload=data)
+  resp = root_resource.post(path=cpath, payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -88,7 +88,7 @@ def _create_service_components(root_resource, cluster_name , version , service_n
   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, is_success = root_resource.post(path=cpath, payload=data)
+  resp = root_resource.post(path=cpath, payload=data)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -102,7 +102,7 @@ def _create_service_component(root_resource, cluster_name , version ,
service_na
   @return: An ServiceModel object
   """
   cpath = paths.SERVICE_COMPONENT_PATH % (cluster_name, service_name, component_name)
-  resp, is_success = root_resource.post(path=cpath, payload=None)
+  resp = root_resource.post(path=cpath, payload=None)
   return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
 
 
@@ -114,7 +114,7 @@ def _delete_service(root_resource, service_name, cluster_name):
   @param cluster_name: Cluster service_name
   @return: The StatusModel object
   """
-  resp, is_success = root_resource.delete("%s/%s" % (paths.SERVICES_PATH % (cluster_name,),
service_name))
+  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")
    

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index 1b6b4be..40088f7 100755
--- a/ambari-client/src/main/python/ambari_client/model/stack.py
+++ b/ambari-client/src/main/python/ambari_client/model/stack.py
@@ -28,8 +28,8 @@ def _get_configuration_from_stack(resource_root, version , service_name
, tag="v
   @param type: type of config
   @return: A ModelList of ConfigModel object
   """
-  dic, is_success = resource_root.get(paths.STACK_SERVICES_CONFIG_PATH % (version, service_name))
-  return utils.ModelUtils.get_model_list_or_error(ModelList, StackConfigModel, dic, resource_root
, "StackConfigurations", is_success)
+  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"):
@@ -41,8 +41,8 @@ def _get_components_from_stack(resource_root, version , service_name , tag="vers
   @return: A ModelList of ConfigModel object
   """
   path = paths.STACK_SERVICES_COMPONENTS_PATH % (version, service_name)
-  dic, is_success = resource_root.get(path)
-  return utils.ModelUtils.get_model_list_or_error(ModelList, StackComponentModel, dic, resource_root
, "StackServiceComponents", is_success)
+  dic = resource_root.get(path)
+  return utils.ModelUtils.get_model_list(ModelList, StackComponentModel, dic, resource_root
, "StackServiceComponents")
 
 
 class StackConfigModel(BaseModel):

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index d81177b..1eba35d 100755
--- a/ambari-client/src/main/python/ambari_client/model/status.py
+++ b/ambari-client/src/main/python/ambari_client/model/status.py
@@ -42,9 +42,6 @@ class StatusModel(BaseModel):
 
   def get_request_path(self):
     return paths.REQUEST_PATH % (self._get_id())
-  
-  def is_error(self):
-    return (self.status != 200 and self.status != 201)
 
   def _get_message(self):
     if hasattr(self, 'message'):

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/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
index 1dbb366..4a7fa5e 100755
--- a/ambari-client/src/main/python/ambari_client/model/utils.py
+++ b/ambari-client/src/main/python/ambari_client/model/utils.py
@@ -28,28 +28,6 @@ ref_pkg_dic = {"ClusterModelRef":"ambari_client.model.cluster"}
 LIST_KEY = "items"
   
 class ModelUtils(object):
-  
-  @staticmethod
-  def get_model_list_or_error(member_list_clss, member_cls, collection_dict, resource_root
, RESOURCE_KEY_WORD, is_success):
-    """
-    create a model list or error response.
-    @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 model_list: A  ModelList object.
-    @return err_resp: StatusModel object of the error response
-    """
-    model_list = err_resp = None
-  
-    if is_success:
-      model_list = ModelUtils.get_model_list(member_list_clss, member_cls, collection_dict,
resource_root , RESOURCE_KEY_WORD)
-    else:
-      from ambari_client.model.status import StatusModel
-      err_resp = ModelUtils.create_model(StatusModel, collection_dict, resource_root, "NO_KEY")
-  
-    return model_list, err_resp
 
   @staticmethod
   def get_model_list(member_list_clss, member_cls, collection_dict, resource_root , RESOURCE_KEY_WORD):
@@ -86,27 +64,7 @@ class ModelUtils(object):
     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_or_error(model_cls, model_dict, resource_root, RESOURCE_KEY_WORD, is_success,
exception_cls=None):
-    """
-    create a model or error response.
-    @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 model: A model cls object
-    @return err_resp: StatusModel object of the error response
-    """
-    model = err_resp = None
-  
-    if is_success:
-      model = ModelUtils.create_model(model_cls , model_dict, resource_root, RESOURCE_KEY_WORD,
exception_cls)
-    else:
-      from ambari_client.model.status import StatusModel
-      err_resp = ModelUtils.create_model(StatusModel, model_dict, resource_root, "NO_KEY")
-  
-    return model, err_resp
+
 
   @staticmethod
   def create_model(model_cls, model_dict, resource_root, RESOURCE_KEY_WORD, exception_cls=None):

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/74174612/ambari-client/src/test/python/TestAmbariClient.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/test/python/TestAmbariClient.py b/ambari-client/src/test/python/TestAmbariClient.py
index e30991f..0fba169 100755
--- a/ambari-client/src/test/python/TestAmbariClient.py
+++ b/ambari-client/src/test/python/TestAmbariClient.py
@@ -58,7 +58,7 @@ class TestAmbariClient(unittest.TestCase):
     http_client_mock = MagicMock()
     http_client.return_value = http_client_mock
     
-    mocked_code = 200
+    mocked_code = "200" 
     mocked_content = "text/plain"
     expected_output = {'items': [{'cluster_name': u'test1', 'version': u'HDP-1.2.1'}]}
     
@@ -68,10 +68,9 @@ class TestAmbariClient(unittest.TestCase):
    
       
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1 , client=http_client_mock)
-    all_clusters, err = client.get_all_clusters()
+    all_clusters = client.get_all_clusters()
       
     self.assertEqual(len(all_clusters), 1, "There should be a cluster from the response")
-    self.assertEqual(err, None, "No error should be present")
     self.assertEqual(all_clusters.to_json_dict(), expected_output, "to_json_dict should convert
ModelList")
     
   @patch("ambari_client.core.http_client.HttpClient")  
@@ -83,7 +82,7 @@ class TestAmbariClient(unittest.TestCase):
     http_client_mock = MagicMock()
     http_client.return_value = http_client_mock
     
-    mocked_code = 200
+    mocked_code = "200" 
     mocked_content = "text/plain"
     
     linestring = open('json/get_all_hosts.json', 'r').read()
@@ -105,7 +104,7 @@ class TestAmbariClient(unittest.TestCase):
     """
     http_client_mock = MagicMock()
     http_client.returned_obj = http_client_mock
-    mocked_code = 200 
+    mocked_code = "200" 
     mocked_content = "text/plain"
     
     linestring = open('json/get_cluster.json', 'r').read()
@@ -114,10 +113,9 @@ class TestAmbariClient(unittest.TestCase):
     
     http_client_mock.invoke.return_value = mocked_response , mocked_code , mocked_content
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)
-    cluster, err = client.get_cluster('test1')
+    cluster = client.get_cluster('test1')
     
     self.assertEqual(cluster.cluster_name, "test1", "cluster_name should be test1 ")
-    self.assertEqual(err, None, "No error should be present")
     self.assertEqual(cluster.to_json_dict(), expected_dict_output, "to_json_dict should convert
ClusterModel")
 
 
@@ -130,20 +128,19 @@ class TestAmbariClient(unittest.TestCase):
     """
     http_client_mock = MagicMock()
     http_client.returned_obj = http_client_mock
-    mocked_code = 200
+    mocked_code = "200" 
     mocked_content = "text/plain"
     
     expected_dict_output = {'cluster_name': u'test1', 'version': u'HDP-1.2.1'}
     
     http_client_mock.invoke.side_effect = http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)
-    cluster, err = client.get_cluster('test1')
-    serviceList, err = cluster.get_all_services()
+    cluster = client.get_cluster('test1')
+    serviceList = cluster.get_all_services()
     
     self.assertEqual(cluster.cluster_name, "test1", "cluster_name should be test1 ")
     self.assertEqual(cluster.to_json_dict(), expected_dict_output, "to_json_dict should convert
ClusterModel")
     self.assertEqual(len(serviceList), 3, "There should be a 3 services from the response")
-    self.assertEqual(err, None, "No error should be present")
  
   @patch("ambari_client.core.http_client.HttpClient")  
   def test_get_cluster_service_valid(self , http_client):
@@ -153,23 +150,22 @@ class TestAmbariClient(unittest.TestCase):
     """
     http_client_mock = MagicMock()
     http_client.returned_obj = http_client_mock
-    mocked_code = 200 
+    mocked_code = "200" 
     mocked_content = "text/plain"
     
     expected_dict_output = {'cluster_name': u'test1', 'version': u'HDP-1.2.1'}
     
     http_client_mock.invoke.side_effect = http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)
-    cluster, err = client.get_cluster('test1')
-    serviceList, err = cluster.get_all_services()
-    ganglia, err = cluster.get_service("GANGLIA")  
+    cluster = client.get_cluster('test1')
+    serviceList = cluster.get_all_services()
+    ganglia = cluster.get_service("GANGLIA")  
 
     self.assertEqual(cluster.cluster_name, "test1", "cluster_name should be test1 ")
     self.assertEqual(cluster.to_json_dict(), expected_dict_output, "to_json_dict should convert
ClusterModel")
     self.assertEqual(len(serviceList), 3, "There should be a 3 services from the response")
     self.assertEqual(str(ganglia.state), "STARTED", "The ganglia service state should be
fetched as STARTED")
     self.assertEqual(ganglia.clusterRef.cluster_name, cluster.cluster_name, "The clusterRef
value for  service  should be fetched ")
-    self.assertEqual(err, None, "No error should be present")
     
 
 
@@ -177,7 +173,7 @@ class TestAmbariClient(unittest.TestCase):
 
 def http_client_invoke_side_effects(*args, **kwargs):
     print locals()
-    mocked_code = 200 
+    mocked_code = "200" 
     mocked_content = "text/plain"
     if args[1] == "//clusters/test1":
         mocked_response = open('json/get_cluster.json', 'r').read()


Mime
View raw message