Repository: ambari Updated Branches: refs/heads/trunk 6cf54ca53 -> e19a0c8e2
AMBARI-6553. Python client: Add all required methods for removing a slave node(Greg Hill via Subin) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e19a0c8e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e19a0c8e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e19a0c8e Branch: refs/heads/trunk Commit: e19a0c8e2933ec29d605ace1846bbbc9ea678ebe Parents: 6cf54ca Author: subin <[email protected]> Authored: Tue Aug 12 01:50:52 2014 +0530 Committer: subin <[email protected]> Committed: Tue Aug 12 01:50:52 2014 +0530 ---------------------------------------------------------------------- .../main/python/ambari_client/core/coreutils.py | 11 +++ .../python/ambari_client/model/component.py | 83 +++++++++++++++++++- .../src/main/python/ambari_client/model/host.py | 80 +++++++++++++++++++ .../main/python/ambari_client/model/paths.py | 2 +- 4 files changed, 174 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e19a0c8e/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py ---------------------------------------------------------------------- diff --git a/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py b/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py index 278df2e..56f10c3 100644 --- a/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py +++ b/ambari-client/python-client/src/main/python/ambari_client/core/coreutils.py @@ -14,3 +14,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +import re + +def normalize_all_caps(name): + """ + This converts all caps words into normal case. + i.e. 'NAGIOS_SERVER' becomes 'Nagios Server' + """ + normalized = name.lower() + normalized = re.sub('_(\w)', lambda match: ' ' + match.group(1).upper(), normalized) + return normalized[0].upper() + normalized[1:] http://git-wip-us.apache.org/repos/asf/ambari/blob/e19a0c8e/ambari-client/python-client/src/main/python/ambari_client/model/component.py ---------------------------------------------------------------------- diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/component.py b/ambari-client/python-client/src/main/python/ambari_client/model/component.py index 5e04fc8..c0323ab 100644 --- a/ambari-client/python-client/src/main/python/ambari_client/model/component.py +++ b/ambari-client/python-client/src/main/python/ambari_client/model/component.py @@ -16,6 +16,7 @@ # limitations under the License. import logging +from ambari_client.core.coreutils import normalize_all_caps from ambari_client.model.base_model import BaseModel, ModelList from ambari_client.model import paths, utils, status @@ -73,9 +74,22 @@ def _get_service_component( resource_root, "ServiceComponentInfo") +def _delete_host_component( + resource_root, + cluster_name , + host_name , + component_name): + path = paths.HOSTS_COMPONENT_PATH % ( + cluster_name, host_name , component_name) + resp = resource_root.delete(path) + return utils.ModelUtils.create_model( + status.StatusModel, + resp, + resource_root, + "NO_KEY") -class ComponentModel(BaseModel): +class ComponentModel(BaseModel): """ The ComponentModel class """ @@ -124,3 +138,70 @@ class ComponentModel(BaseModel): self._get_cluster_name(), self.host_name, self.component_name) + "?fields=metrics" metricjson = self._get_resource_root().get(metricpath) return metricjson + + + def delete(self): + return _delete_host_component(self._get_resource_root(), self._get_cluster_name(), self.host_name, self.component_name) + + def install(self): + data = { + "RequestInfo": { + "context": "Install %s" % normalize_all_caps(self.component_name), + }, + "HostRoles": { + "state": "INSTALLED", + }, + } + root_resource = self._get_resource_root() + resp = root_resource.put(path=self._path() + '/' + self.component_name, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY") + + def start(self): + data = { + "RequestInfo": { + "context": "Start %s" % normalize_all_caps(self.component_name), + }, + "HostRoles": { + "state": "STARTED", + }, + } + root_resource = self._get_resource_root() + resp = root_resource.put(path=self._path() + '/' + self.component_name, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY") + + def stop(self): + data = { + "RequestInfo": { + "context": "Stop %s" % normalize_all_caps(self.component_name), + }, + "HostRoles": { + "state": "INSTALLED", + }, + } + root_resource = self._get_resource_root() + resp = root_resource.put(path=self._path() + '/' + self.component_name, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY") + + def restart(self): + # need to move this to utils, handle _ gracefully + data = { + "RequestInfo": { + "command": "RESTART", + "context": "Restart %s" % normalize_all_caps(self.component_name), + "operation_level": { + "level": "SERVICE", + "cluster_name": self._get_cluster_name(), + "service_name": self.service_name, + + }, + }, + "Requests/resource_filters": [{ + "service_name": self.service_name, + "component_name": self.component_name, + "hosts": self.host_name, + }], + } + root_resource = self._get_resource_root() + path = paths.CLUSTER_REQUESTS_PATH % self._get_cluster_name() + resp = root_resource.post(path=path, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY") http://git-wip-us.apache.org/repos/asf/ambari/blob/e19a0c8e/ambari-client/python-client/src/main/python/ambari_client/model/host.py ---------------------------------------------------------------------- diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/host.py b/ambari-client/python-client/src/main/python/ambari_client/model/host.py index bc0e396..dd4bcb4 100644 --- a/ambari-client/python-client/src/main/python/ambari_client/model/host.py +++ b/ambari-client/python-client/src/main/python/ambari_client/model/host.py @@ -321,3 +321,83 @@ class HostModel(BaseModel): self._get_cluster_name(), self.host_name, component_name) + + def install_all_components(self): + root_resource = self._get_resource_root() + path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(), + self.host_name) + data = { + "RequestInfo": { + "context" :"Install All Components", + }, + "Body": { + "HostRoles": {"state": "INSTALLED"}, + }, + } + resp = root_resource.put(path=path, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, + root_resource, "NO_KEY") + + def start_all_components(self): + root_resource = self._get_resource_root() + path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(), + self.host_name) + data = { + "RequestInfo": { + "context" :"Start All Components", + }, + "Body": { + "HostRoles": {"state": "STARTED"}, + }, + } + resp = root_resource.put(path=path, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, + root_resource, "NO_KEY") + + def stop_all_components(self): + root_resource = self._get_resource_root() + path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(), + self.host_name) + data = { + "RequestInfo": { + "context" :"Stop All Components", + }, + "Body": { + "HostRoles": {"state": "INSTALLED"}, + }, + } + resp = root_resource.put(path=path, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, + root_resource, "NO_KEY") + + def enable_maintenance_mode(self): + root_resource = self._get_resource_root() + path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(), + self.host_name) + data = { + "RequestInfo": { + "context" :"Start Maintanence Mode", + }, + "Body": { + "HostRoles": {"maintenance_state": "ON"}, + }, + } + resp = root_resource.put(path=path, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, + root_resource, "NO_KEY") + + def disable_maintenance_mode(self): + root_resource = self._get_resource_root() + path = paths.HOSTS_COMPONENTS_PATH % (self._get_cluster_name(), + self.host_name) + data = { + "RequestInfo": { + "context" :"Stop Maintanence Mode", + }, + "Body": { + "HostRoles": {"maintenance_state": "OFF"}, + }, + } + resp = root_resource.put(path=path, payload=data) + return utils.ModelUtils.create_model(status.StatusModel, resp, + root_resource, "NO_KEY") http://git-wip-us.apache.org/repos/asf/ambari/blob/e19a0c8e/ambari-client/python-client/src/main/python/ambari_client/model/paths.py ---------------------------------------------------------------------- diff --git a/ambari-client/python-client/src/main/python/ambari_client/model/paths.py b/ambari-client/python-client/src/main/python/ambari_client/model/paths.py index e111824..17a4633 100644 --- a/ambari-client/python-client/src/main/python/ambari_client/model/paths.py +++ b/ambari-client/python-client/src/main/python/ambari_client/model/paths.py @@ -21,7 +21,7 @@ CLUSTER_HOSTS_PATH = "/clusters/%s/hosts" CLUSTER_HOST_PATH = "/clusters/%s/hosts/%s" CLUSTER_START_ALL_SERVICES = "/clusters/%s/services?ServiceInfo/state=INSTALLED" CLUSTER_STOP_ALL_SERVICES = "/clusters/%s/services?ServiceInfo" - +CLUSTER_REQUESTS_PATH = "/clusters/%s/requests" SERVICES_PATH = "/clusters/%s/services" SERVICE_PATH = "/clusters/%s/services/%s"
