예제 #1
0
def model_event(event, event_state, obj, **kwargs):
    # pylint: disable=unused-argument
    line_end = "\n" if event_state == events.states.FINISHED else ""
    six.print_("%s %s '%s': %s%s" %
               (utils.normalize_underscore_case(event),
                utils.normalize_camel_case(obj.__class__.__name__),
                obj.identifier, event_state, line_end))
예제 #2
0
    def restart(self, component_names=None):
        """Restarts components of this service, if already installed and started."""

        components = self.components
        if component_names:
            components = components(component_names)

        resource_filters = []
        for component in components:
            hosts = [hc.host_name for hc in component.host_components]
            if hosts:
                resource_filters.append({
                    "service_name": self.service_name,
                    "component_name": component.component_name,
                    "hosts": ','.join(hosts),
                })

        if resource_filters:
            self.load(self.client.post(self.cluster.requests.url, data={
                "RequestInfo": {
                    "command": "RESTART",
                    "context": "Restart all components for %s" % normalize_underscore_case(
                        self.service_name),
                    "operation_level": {
                        "level": "SERVICE",
                        "cluster_name": self.cluster_name,
                        "service_name": self.service_name,
                    },
                },
                "Requests/resource_filters": resource_filters,
            }))
        return self
예제 #3
0
    def restart(self, component_names=None):
        """Restarts components of this service, if already installed and started."""

        components = self.components
        if component_names:
            components = components(component_names)

        resource_filters = []
        for component in components:
            hosts = [hc.host_name for hc in component.host_components]
            if hosts:
                resource_filters.append({
                    "service_name": self.service_name,
                    "component_name": component.component_name,
                    "hosts": ','.join(hosts),
                })

        if resource_filters:
            self.load(self.client.post(self.cluster.requests.url, data={
                "RequestInfo": {
                    "command": "RESTART",
                    "context": "Restart all components for %s" % normalize_underscore_case(
                        self.service_name),
                    "operation_level": {
                        "level": "SERVICE",
                        "cluster_name": self.cluster_name,
                        "service_name": self.service_name,
                    },
                },
                "Requests/resource_filters": resource_filters,
            }))
        return self
예제 #4
0
 def restart(self):
     """Restarts this component on its host, if already installed and started."""
     hosts = [hc.host_name for hc in self.host_components]
     if hosts:
         self.load(
             self.client.post(
                 self.cluster.requests.url,
                 data={
                     "RequestInfo": {
                         "command":
                         "RESTART",
                         "context":
                         "Restart %s" %
                         normalize_underscore_case(self.component_name),
                         "operation_level": {
                             "level": "SERVICE",
                             "cluster_name": self.cluster_name,
                             "service_name": self.service_name,
                         },
                     },
                     "Requests/resource_filters": [{
                         "service_name": self.service_name,
                         "component_name": self.component_name,
                         "hosts": ','.join(hosts)
                     }],
                 }))
     return self
예제 #5
0
 def restart(self):
     """Restarts this component on its host, if already installed and started."""
     hosts = [hc.host_name for hc in self.host_components]
     if hosts:
         self.load(
             self.client.post(
                 self.cluster.requests.url,
                 data={
                     "RequestInfo": {
                         "command": "RESTART",
                         "context": "Restart %s" % normalize_underscore_case(self.component_name),
                         "operation_level": {
                             "level": "SERVICE",
                             "cluster_name": self.cluster_name,
                             "service_name": self.service_name,
                         },
                     },
                     "Requests/resource_filters": [
                         {
                             "service_name": self.service_name,
                             "component_name": self.component_name,
                             "hosts": ",".join(hosts),
                         }
                     ],
                 },
             )
         )
     return self
예제 #6
0
    def commission(self, service, hosts, commission_type):
        """Decommission/Recommission slave components on a cluster.

        This should make it safe to remove these hosts from the cluster.

        :param service: The name of the service that the components are for
        :param hosts: Comma separated list of hosts to decommission/recommission
        :param commission_type: type of commission decommission or recommission
        :return: Current status of the request
        """

        components = {
            'YARN': {'slave': 'NODEMANAGER', 'master': 'RESOURCEMANAGER'},
            'HDFS': {'slave': 'DATANODE', 'master': 'NAMENODE'},
            'HBASE': {'slave': 'HBASE_REGIONSERVER', 'master': 'HBASE_MASTER'},
        }

        desired_admin_state = {
            "decommission" : "DECOMMISSIONED",
            "recommission" : "LIVE"
        }

        include_or_exclude_hosts = "excluded_hosts" if commission_type == "decommission" else "included_hosts"

        if service not in components:
            raise ValueError("{0} is not a valid service to {1}".format(service, commission_type))

        slave = components[service]['slave']
        # filter off hosts where the slave component is already decommissioned
        hosts = [host for host in hosts
                 if self.hosts(host).components(slave).desired_admin_state != desired_admin_state[commission_type]]
        if len(hosts) == 0:
            # no action required, all hosts are already decommissioned
            return self

        operation_level = {
            "level": "HOST_COMPONENT",
            "cluster_name": self.cluster_name
        }
        if len(hosts) == 1:
            # if there's only one host, it requires a more specific operation_level
            operation_level.update({
                "host_name": hosts[0],
                "service_name": service
            })
        self.load(self.client.post(self.cluster.requests.url, data={
            "RequestInfo": {
                "command": "DECOMMISSION",
                "context": "Decommission {0}".format(normalize_underscore_case(slave)),
                "parameters": {"slave_type": slave, include_or_exclude_hosts: ','.join(hosts)},
                "operation_level": operation_level,
            },
            "Requests/resource_filters": [{
                "service_name": service,
                "component_name": components[service]['master'],
            }],
        }))
        return self
예제 #7
0
 def stop(self):
     """Starts this component on its host, if already installed and started."""
     self.load(self.client.put(self.url, data={
         "RequestInfo": {
             "context": "Stop %s" % normalize_underscore_case(self.component_name),
         },
         "HostRoles": {
             "state": "INSTALLED",
         },
     }))
     return self
예제 #8
0
 def install(self):
     """Installs this component on the host in question."""
     self.load(self.client.put(self.url, data={
         "RequestInfo": {
             "context": "Install %s" % normalize_underscore_case(self.component_name),
         },
         "HostRoles": {
             "state": "INSTALLED",
         },
     }))
     return self
예제 #9
0
 def stop(self):
     """Starts this component on its host, if already installed and started."""
     self.load(self.client.put(self.url, data={
         "RequestInfo": {
             "context": "Stop %s" % normalize_underscore_case(self.component_name),
         },
         "HostRoles": {
             "state": "INSTALLED",
         },
     }))
     return self
예제 #10
0
 def install(self):
     """Installs this component on the host in question."""
     self.load(self.client.put(self.url, data={
         "RequestInfo": {
             "context": "Install %s" % normalize_underscore_case(self.component_name),
         },
         "HostRoles": {
             "state": "INSTALLED",
         },
     }))
     return self
예제 #11
0
    def start(self, context=None):
        if not context:
            context = "Start %s" % normalize_underscore_case(self.component_name)

        """Starts this component on its host, if already installed."""
        self.load(self.client.put(self.url, data={
            "RequestInfo": {
                "context": context,
            },
            "HostRoles": {
                "state": "STARTED",
            },
        }))
        return self
예제 #12
0
    def decommission(self, service, hosts):
        """Decommission slave components on a cluster.

        This should make it safe to remove these hosts from the cluster.

        :param service: The name of the service that the components are for
        :param hosts: Comma separated list of hosts to decommission
        :return: Current status of the request
        """

        components = {
            "YARN": {"slave": "NODEMANAGER", "master": "RESOURCEMANAGER"},
            "HDFS": {"slave": "DATANODE", "master": "NAMENODE"},
            "HBASE": {"slave": "HBASE_REGIONSERVER", "master": "HBASE_MASTER"},
        }
        if service not in components:
            raise ValueError("{0} is not a valid service to decommission".format(service))

        slave = components[service]["slave"]
        # filter off hosts where the slave component is already decommissioned
        hosts = [host for host in hosts if self.hosts(host).components(slave).desired_admin_state != "DECOMMISSIONED"]
        if len(hosts) == 0:
            # no action required, all hosts are already decommissioned
            return self

        operation_level = {"level": "HOST_COMPONENT", "cluster_name": self.cluster_name}
        if len(hosts) == 1:
            # if there's only one host, it requires a more specific operation_level
            operation_level.update({"host_name": hosts[0], "service_name": service})
        self.load(
            self.client.post(
                self.cluster.requests.url,
                data={
                    "RequestInfo": {
                        "command": "DECOMMISSION",
                        "context": "Decommission {0}".format(normalize_underscore_case(slave)),
                        "parameters": {"slave_type": slave, "excluded_hosts": ",".join(hosts)},
                        "operation_level": operation_level,
                    },
                    "Requests/resource_filters": [
                        {"service_name": service, "component_name": components[service]["master"]}
                    ],
                },
            )
        )
        return self
예제 #13
0
 def restart(self):
     """Restarts this component on its host, if already installed and started."""
     if self.state in ('STARTED', 'STOPPED', 'UNKNOWN'):
         self.load(self.client.post(self.cluster.requests.url, data={
             "RequestInfo": {
                 "command": "RESTART",
                 "context": "Restart %s" % normalize_underscore_case(self.component_name),
                 "operation_level": {
                     "level": "SERVICE",
                     "cluster_name": self.cluster_name,
                     "service_name": self.service_name,
                 },
             },
             "Requests/resource_filters": [{
                 "service_name": self.service_name,
                 "component_name": self.component_name,
                 "hosts": self.host_name,
             }],
         }))
     return self
예제 #14
0
    def restart(self, context=None):
        if not context:
            context = "Restart %s" % normalize_underscore_case(self.component_name)

        """Restarts this component on its host, if already installed and started."""
        self.load(self.client.post(self.cluster.requests.url, data={
            "RequestInfo": {
                "command": "RESTART",
                "context": context,
                "operation_level": {
                    "level": "SERVICE",
                    "cluster_name": self.cluster_name,
                    "service_name": self.service_name,
                },
            },
            "Requests/resource_filters": [{
                "service_name": self.service_name,
                "component_name": self.component_name,
                "hosts": self.host_name,
            }],
        }))
        return self
예제 #15
0
def model_event(event, event_state, obj, **kwargs):
    # pylint: disable=unused-argument
    line_end = "\n" if event_state == events.states.FINISHED else ""
    six.print_("%s %s '%s': %s%s" % (utils.normalize_underscore_case(event),
                                     utils.normalize_camel_case(obj.__class__.__name__),
                                     obj.identifier, event_state, line_end))
예제 #16
0
def test_normalize_underscore_case(original, expected):
    assert utils.normalize_underscore_case(original) == expected
예제 #17
0
def test_normalize_underscore_case(original, expected):
    assert utils.normalize_underscore_case(original) == expected