From f42be0875d06a5d3ec0d5304d2f01a41b1f6a477 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 5 Aug 2010 16:11:59 -0500 Subject: [PATCH] almost there on random scheduler. not pushing to correct compute node topic, yet, apparently... --- bin/nova-scheduler | 32 ++++++++++++++ nova/endpoint/cloud.py | 2 +- nova/flags.py | 1 + nova/scheduler/__init__.py | 33 +++++++++++++++ nova/scheduler/service.py | 87 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100755 bin/nova-scheduler create mode 100644 nova/scheduler/__init__.py create mode 100644 nova/scheduler/service.py diff --git a/bin/nova-scheduler b/bin/nova-scheduler new file mode 100755 index 000000000000..1ad41bbd3979 --- /dev/null +++ b/bin/nova-scheduler @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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. + +""" + Twistd daemon for the nova scheduler nodes. +""" + +from nova import twistd +from nova.scheduler import service + + +if __name__ == '__main__': + twistd.serve(__file__) + +if __name__ == '__builtin__': + application = service.SchedulerService.create() diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py index 0ee278f84065..a808e54c348a 100644 --- a/nova/endpoint/cloud.py +++ b/nova/endpoint/cloud.py @@ -576,7 +576,7 @@ class CloudController(object): inst['private_dns_name'] = str(address) # TODO: allocate expresses on the router node inst.save() - rpc.cast(FLAGS.compute_topic, + rpc.cast(FLAGS.scheduler_topic, {"method": "run_instance", "args": {"instance_id" : inst.instance_id}}) logging.debug("Casting to node for %s's instance with IP of %s" % diff --git a/nova/flags.py b/nova/flags.py index f35f5fa10c89..7f92e3f70b67 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -41,6 +41,7 @@ DEFINE_integer('s3_port', 3333, 's3 port') DEFINE_string('s3_host', '127.0.0.1', 's3 host') #DEFINE_string('cloud_topic', 'cloud', 'the topic clouds listen on') DEFINE_string('compute_topic', 'compute', 'the topic compute nodes listen on') +DEFINE_string('scheduler_topic', 'scheduler', 'the topic scheduler nodes listen on') DEFINE_string('volume_topic', 'volume', 'the topic volume nodes listen on') DEFINE_string('network_topic', 'network', 'the topic network nodes listen on') diff --git a/nova/scheduler/__init__.py b/nova/scheduler/__init__.py new file mode 100644 index 000000000000..516ea61bc621 --- /dev/null +++ b/nova/scheduler/__init__.py @@ -0,0 +1,33 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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. + +""" +:mod:`nova.scheduler` -- Scheduler Nodes +===================================================== + +.. automodule:: nova.scheduler + :platform: Unix + :synopsis: Daemon that picks a host for a VM instance. +.. moduleauthor:: Jesse Andrews +.. moduleauthor:: Devin Carlen +.. moduleauthor:: Vishvananda Ishaya +.. moduleauthor:: Joshua McKenty +.. moduleauthor:: Manish Singh +.. moduleauthor:: Andy Smith +.. moduleauthor:: Chris Behrens +""" diff --git a/nova/scheduler/service.py b/nova/scheduler/service.py new file mode 100644 index 000000000000..aca5b5db686c --- /dev/null +++ b/nova/scheduler/service.py @@ -0,0 +1,87 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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. + +""" +Scheduler Service +""" + +import logging +import random +import sys +from twisted.internet import defer +from twisted.internet import task + +from nova import exception +from nova import flags +from nova import process +from nova import rpc +from nova import service +from nova import utils +from nova.compute import model +from nova.datastore import Redis + +FLAGS = flags.FLAGS + + +class SchedulerService(service.Service): + """ + Manages the running instances. + """ + def __init__(self): + super(SchedulerService, self).__init__() + self.instdir = model.InstanceDirectory() + + def noop(self): + """ simple test of an AMQP message call """ + return defer.succeed('PONG') + + @defer.inlineCallbacks + def report_state(self, nodename, daemon): + # TODO(termie): make this pattern be more elegant. -todd + try: + record = model.Daemon(nodename, daemon) + record.heartbeat() + if getattr(self, "model_disconnected", False): + self.model_disconnected = False + logging.error("Recovered model server connection!") + + except model.ConnectionError, ex: + if not getattr(self, "model_disconnected", False): + self.model_disconnected = True + logging.exception("model server went away") + yield + + @property + def compute_identifiers(self): + return [identifier for identifier in Redis.instance().smembers("daemons") if (identifier.split(':')[1] == "nova-compute")] + + def pick_node(self, instance_id, **_kwargs): + identifiers = self.compute_identifiers + return identifiers[int(random.random() * len(identifiers))].split(':')[0] + + @exception.wrap_exception + def run_instance(self, instance_id, **_kwargs): + node = self.pick_node(instance_id, **_kwargs) + + rpc.cast('%s:%s' % (FLAGS.compute_topic, node), + {"method": "run_instance", + "args": {"instance_id" : instance_id}}) + logging.debug("Casting to node %s for instance %s" % + (node, instance_id)) + +