Skip to content

Commit

Permalink
Move run_mon_job to cthulhu
Browse files Browse the repository at this point in the history
The patch moves run_mon_job and accompanying functions to cthulhu
manager. It also removes RemoteViewset since it only contain the
run_mon_job and two other accompanying function.

Signed-off-by: Boris Ranto <branto@redhat.com>
  • Loading branch information
b-ranto committed Oct 11, 2016
1 parent de48211 commit 44994d3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 77 deletions.
53 changes: 53 additions & 0 deletions cthulhu/cthulhu/manager/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,59 @@ def status_by_service(self, services):
return [({'running': ss.running, 'server': ss.server_state.fqdn, 'status': ss.status} if ss else None)
for ss in result]

def _get_up_mon_servers(self, fsid):
# Resolve FSID to list of mon FQDNs
servers = self.client.server_list_cluster(fsid)

This comment has been minimized.

Copy link
@lowyjoe

lowyjoe Mar 16, 2017

This is not right .In my code I use "servers = self.server_list_cluster(fsid)" replace.

# Sort to get most recently contacted server first; drop any
# for whom last_contact is None
servers = [s for s in servers if s['last_contact']]
servers = sorted(servers,
key=lambda t: dateutil_parse(t['last_contact']),
reverse=True)
mon_fqdns = []
for server in servers:
for service in server['services']:
service_id = ServiceId(*(service['id']))
if service['running'] and service_id.service_type == MON and service_id.fsid == fsid:
mon_fqdns.append(server['fqdn'])

return mon_fqdns

def run_mon_job(self, fsid, job_cmd, job_args):
"""
Attempt to run a Salt job on a mon server, trying each until we find one
where the job runs (where running includes running and returning an error)
"""

# TODO: in order to support radosgw-admin commands we might need to be able to identify running RGW services
# alternatively it may be possible to run radosgw-admin on a mon node that isn't running the RGW service
mon_fqdns = self._get_up_mon_servers(fsid)

client = LocalClient(config.get('cthulhu', 'salt_config_path'))
log.debug("run_mon_job: mons for %s are %s" % (fsid, mon_fqdns))
# For each mon FQDN, try to go get ceph/$cluster.log, if we succeed return it, if we fail try the next one
# NB this path is actually customizable in ceph as `mon_cluster_log_file` but we assume user hasn't done that.
for mon_fqdn in mon_fqdns:
results = client.cmd(mon_fqdn, job_cmd, job_args)
if results:
return results[mon_fqdn]
else:
log.info("Failed execute mon command on %s" % mon_fqdn)

# If none of the mons gave us what we wanted, return a 503 service unavailable
raise ServiceUnavailable("No mon servers are responding")

def run_job(self, fqdn, job_cmd, job_args):
"""
Attempt to run a Salt job on a specific server.
"""
client = LocalClient(config.get('cthulhu', 'salt_config_path'))
results = client.cmd(fqdn, job_cmd, job_args)
if not results:
raise ServiceUnavailable("Server '{0}' not responding".format(fqdn))
else:
return results[fqdn]


class RpcThread(gevent.greenlet.Greenlet):
"""
Expand Down
71 changes: 0 additions & 71 deletions rest-api/calamari_rest/views/remote_view_set.py

This file was deleted.

11 changes: 5 additions & 6 deletions rest-api/calamari_rest/views/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from calamari_rest.views.exceptions import ServiceUnavailable
from calamari_rest.views.paginated_mixin import PaginatedMixin
from rest_framework.permissions import IsAuthenticated
from calamari_rest.views.remote_view_set import RemoteViewSet
from calamari_rest.views.rpc_view import RPCViewSet, DataObject
from calamari_rest.permissions import IsRoleAllowed
from calamari_rest.views.crush_node import lookup_ancestry
Expand Down Expand Up @@ -871,7 +870,7 @@ def list_server(self, request, fqdn):
return Response(self._paginate(request, self._filter_by_severity(request, self.queryset.filter_by(fqdn=fqdn))))


class LogTailViewSet(RemoteViewSet):
class LogTailViewSet(RpcViewSet):
"""
A primitive remote log viewer.
Expand Down Expand Up @@ -1048,7 +1047,7 @@ def list(self, request, fsid):
return Response(self.serializer_class([DataObject(m) for m in self._get_mons(fsid)], many=True).data)


class CliViewSet(RemoteViewSet):
class CliViewSet(RpcViewSet):
"""
Access the `ceph`, `rbd`, and `radosgw-admin` CLI tools remotely.
Expand Down Expand Up @@ -1094,15 +1093,15 @@ def create(self, request, fsid):
try:
if principle == 'ceph':
command.pop(0)
result = self.run_mon_job(fsid, "ceph.ceph_command", [name, command])
result = self.client.run_mon_job(fsid, "ceph.ceph_command", [name, command])
elif principle == 'rbd':
command.pop(0)
result = self.run_mon_job(fsid, "ceph.rbd_command", [command])
result = self.client.run_mon_job(fsid, "ceph.rbd_command", [command])
elif principle == 'radosgw-admin':
raise APIException("radosgw-admin calls are not yet supported %s" % str(result))
else:
# Try the default 'ceph' target to maintain backwards compatibility
result = self.run_mon_job(fsid, "ceph.ceph_command", [name, command])
result = self.client.run_mon_job(fsid, "ceph.ceph_command", [name, command])
except Exception as ex:
raise APIException("Error in cli command: %s" % ex)

Expand Down

1 comment on commit 44994d3

@lowyjoe
Copy link

@lowyjoe lowyjoe commented on 44994d3 Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cthulhu/cthulhu/manager/rpc.py 434 .I use "servers = self.server_list_cluster(fsid)" replace.

Please sign in to comment.