Package cm_api :: Package endpoints :: Module parcels
[hide private]
[frames] | no frames]

Source Code for Module cm_api.endpoints.parcels

  1  # Licensed to Cloudera, Inc. under one 
  2  # or more contributor license agreements.  See the NOTICE file 
  3  # distributed with this work for additional information 
  4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
  5  # to you under the Apache License, Version 2.0 (the 
  6  # "License"); you may not use this file except in compliance 
  7  # with the License.  You may obtain a copy of the License at 
  8  # 
  9  #     http://www.apache.org/licenses/LICENSE-2.0 
 10  # 
 11  # Unless required by applicable law or agreed to in writing, software 
 12  # distributed under the License is distributed on an "AS IS" BASIS, 
 13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 14  # See the License for the specific language governing permissions and 
 15  # limitations under the License. 
 16   
 17  from cm_api.endpoints.types import * 
 18   
 19  __docformat__ = "epytext" 
 20   
 21  PARCELS_PATH = "/clusters/%s/parcels" 
 22  PARCEL_PATH = "/clusters/%s/parcels/products/%s/versions/%s" 
 23   
24 -def get_parcel(resource_root, product, version, cluster_name="default"):
25 """ 26 Lookup a parcel by name 27 @param resource_root: The root Resource object. 28 @param product: Parcel product name 29 @param version: Parcel version 30 @param cluster_name: Cluster name 31 @return: An ApiService object 32 """ 33 return _get_parcel(resource_root, PARCEL_PATH % (cluster_name, product, version))
34
35 -def _get_parcel(resource_root, path):
36 return call(resource_root.get, path, ApiParcel, api_version=3)
37
38 -def get_all_parcels(resource_root, cluster_name="default", view=None):
39 """ 40 Get all parcels 41 @param resource_root: The root Resource object. 42 @param cluster_name: Cluster name 43 @return: A list of ApiParcel objects. 44 @since: API v3 45 """ 46 return call(resource_root.get, PARCELS_PATH % (cluster_name,), 47 ApiParcel, True, params=view and dict(view=view) or None, api_version=3)
48
49 -class ApiParcelState(BaseApiObject):
50 """ 51 An object that represents the state of a parcel. 52 """ 53 _ATTRIBUTES = { 54 'progress' : ROAttr(), 55 'totalProgress' : ROAttr(), 56 'count' : ROAttr(), 57 'totalCount' : ROAttr(), 58 'warnings' : ROAttr(), 59 'errors' : ROAttr(), 60 } 61
62 - def __init__(self, resource_root):
63 BaseApiObject.init(self, resource_root)
64
65 - def __str__(self):
66 return "<ApiParcelState>: (progress: %s) (totalProgress: %s) (count: %s) (totalCount: %s)" % ( 67 self.progress, self.totalProgress, self.count, self.totalCount)
68
69 -class ApiParcel(BaseApiResource):
70 """ 71 An object that represents a parcel and allows administrative operations. 72 73 @since: API v3 74 """ 75 _ATTRIBUTES = { 76 'product' : ROAttr(), 77 'version' : ROAttr(), 78 'stage' : ROAttr(), 79 'state' : ROAttr(ApiParcelState), 80 'clusterRef' : ROAttr(ApiClusterRef), 81 } 82
83 - def __init__(self, resource_root):
84 BaseApiObject.init(self, resource_root)
85
86 - def __str__(self):
87 return "<ApiParcel>: %s-%s (stage: %s) (state: %s) (cluster: %s)" % ( 88 self.product, self.version, self.stage, self.state, self._get_cluster_name())
89
90 - def _api_version(self):
91 return 3
92
93 - def _path(self):
94 """ 95 Return the API path for this service. 96 """ 97 return PARCEL_PATH % (self._get_cluster_name(), self.product, self.version)
98
99 - def _get_cluster_name(self):
100 if self.clusterRef: 101 return self.clusterRef.clusterName 102 return None
103
104 - def start_download(self):
105 """ 106 Start the download of the parcel 107 108 @return: Reference to the completed command. 109 """ 110 return self._cmd('startDownload')
111
112 - def cancel_download(self):
113 """ 114 Cancels the parcel download. If the parcel is not 115 currently downloading an exception is raised. 116 117 @return: Reference to the completed command. 118 """ 119 return self._cmd('cancelDownload')
120
121 - def remove_download(self):
122 """ 123 Removes the downloaded parcel 124 125 @return: Reference to the completed command. 126 """ 127 return self._cmd('removeDownload')
128
129 - def start_distribution(self):
130 """ 131 Start the distribution of the parcel to all hosts 132 in the cluster. 133 134 @return: Reference to the completed command. 135 """ 136 return self._cmd('startDistribution')
137
138 - def cancel_distribution(self):
139 """ 140 Cancels the parcel distrubution. If the parcel is not 141 currently distributing an exception is raised. 142 143 @return: Reference to the completed command 144 """ 145 return self._cmd('cancelDistribution')
146
148 """ 149 Start the removal of the distribution of the parcel 150 from all the hosts in the cluster. 151 152 @return: Reference to the completed command. 153 """ 154 return self._cmd('startRemovalOfDistribution')
155
156 - def activate(self):
157 """ 158 Activate the parcel on all the hosts in the cluster. 159 160 @return: Reference to the completed command. 161 """ 162 return self._cmd('activate')
163
164 - def deactivate(self):
165 """ 166 Deactivates the parcel on all the hosts in the cluster. 167 168 @return: Reference to the completed command. 169 """ 170 return self._cmd('deactivate')
171