Skip to content

Commit

Permalink
Better abstract caller in DE control interface
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Apr 16, 2013
1 parent ddb1774 commit 821ae61
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
6 changes: 2 additions & 4 deletions epu/decisionengine/impls/phantom.py
Expand Up @@ -143,19 +143,17 @@ def _launch_one(self, control, uniquekv=None):
self._next_launch_attempt, self.decide_count)
else:

owner = control.domain.owner
launch_id, instance_ids = control.launch(self.available_types[0],
self.available_sites[0], self.available_allocations[0],
extravars=uniquekv, caller=owner)
extravars=uniquekv)
if len(instance_ids) != 1:
raise Exception("Could not retrieve instance ID after launch")
log.info("Phantom Launched an instance ('%s'). decide count %d, next_attempt %d", instance_ids[
0], self.decide_count, self._next_launch_attempt)
self._next_launch_attempt = 0

def _destroy_one(self, control, instanceid):
owner = control.domain.owner
control.destroy_instances([instanceid], caller=owner)
control.destroy_instances([instanceid])
log.info("Destroyed an instance ('%s')", instanceid)

def reconfigure(self, control, newconf):
Expand Down
5 changes: 2 additions & 3 deletions epu/decisionengine/impls/phantom_multi.py
Expand Up @@ -59,7 +59,7 @@ def decide(self, control, state):
to_kill_array = healthy_instances[0:new_vms]
instance_id_a = [i.instance_id for i in to_kill_array]
log.info("Destroying an instances %s for %s" % (str(instance_id_a), control.domain.owner))
control.destroy_instances(instance_id_a, caller=control.domain.owner)
control.destroy_instances(instance_id_a)
return

if new_vms == 0:
Expand All @@ -78,8 +78,7 @@ def decide(self, control, state):
log.debug("PhantomMultiNSite start new VMs")
for i in range(new_vms):
(launch_ids, instance_ids) = control.launch(self.dt_name,
self.sitename, self.instance_type,
caller=control.domain.owner)
self.sitename, self.instance_type)
log.debug("PhantomMultiNSite launched %s %s" % (str(launch_ids), str(instance_ids)))

def _check_for_delay(self, unhealthy_instances):
Expand Down
6 changes: 2 additions & 4 deletions epu/decisionengine/impls/sensor.py
Expand Up @@ -301,7 +301,6 @@ def decide(self, control, state):
self.decide_count += 1

def _launch_one(self, control, extravars=None):
owner = control.domain.owner

if not self.iaas_site:
raise Exception("No IaaS site configuration")
Expand All @@ -310,7 +309,7 @@ def _launch_one(self, control, extravars=None):
if not self.deployable_type:
raise Exception("No deployable type configuration")
launch_id, instance_ids = control.launch(self.deployable_type,
self.iaas_site, self.iaas_allocation, extravars=extravars, caller=owner)
self.iaas_site, self.iaas_allocation, extravars=extravars)
if len(instance_ids) != 1:
raise Exception("Could not retrieve instance ID after launch")
if extravars:
Expand All @@ -319,8 +318,7 @@ def _launch_one(self, control, extravars=None):
log.info("Launched an instance ('%s')", instance_ids[0])

def _destroy_one(self, control, instanceid):
owner = control.domain.owner
control.destroy_instances([instanceid], caller=owner)
control.destroy_instances([instanceid])
log.info("Destroyed an instance ('%s')" % instanceid)

def reconfigure(self, control, newconf):
Expand Down
6 changes: 2 additions & 4 deletions epu/decisionengine/impls/simplest.py
Expand Up @@ -113,17 +113,15 @@ def decide(self, control, state):
self._set_state(all_instances, -1, health_not_checked=control.health_not_checked)

def _launch_one(self, control, uniquekv=None):
owner = control.domain.owner
launch_id, instance_ids = control.launch(self.available_types[0],
self.available_sites[0], self.available_allocations[0],
extravars=uniquekv, caller=owner)
extravars=uniquekv)
if len(instance_ids) != 1:
raise Exception("Could not retrieve instance ID after launch")
log.info("Launched an instance ('%s')", instance_ids[0])

def _destroy_one(self, control, instanceid):
owner = control.domain.owner
control.destroy_instances([instanceid], caller=owner)
control.destroy_instances([instanceid])
log.info("Destroyed an instance ('%s')" % instanceid)

def reconfigure(self, control, newconf):
Expand Down
9 changes: 5 additions & 4 deletions epu/epumanagement/decider.py
Expand Up @@ -380,7 +380,7 @@ def _shutdown_domain(self, domain):
log.debug("terminating %s", instance_id_s)
c = self.controls[domain.key]
try:
c.destroy_instances(instance_id_s, caller=domain.owner)
c.destroy_instances(instance_id_s)
except Exception:
log.exception("Error destroying instances")
else:
Expand Down Expand Up @@ -434,7 +434,6 @@ def _new_engine(self, domain):
class ControllerCoreControl(Control):
def __init__(self, provisioner_client, domain, prov_vars, controller_name, health_not_checked=True):
super(ControllerCoreControl, self).__init__()
self.sleep_seconds = 5.0 # TODO: ignored for now on a per-engine basis
self.provisioner = provisioner_client
self.domain = domain
self.controller_name = controller_name
Expand Down Expand Up @@ -464,7 +463,7 @@ def configure(self, parameters):
self.prov_vars = parameters[PROVISIONER_VARS_KEY]
log.info("Configured with new provisioner vars:\n%s", self.prov_vars)

def launch(self, deployable_type_id, site, allocation, count=1, extravars=None, caller=None):
def launch(self, deployable_type_id, site, allocation, count=1, extravars=None):
"""
Choose instance IDs for each instance desired, a launch ID and send
appropriate message to Provisioner.
Expand Down Expand Up @@ -508,6 +507,7 @@ def launch(self, deployable_type_id, site, allocation, count=1, extravars=None,
vars_send['heartbeat_dest'] = self.controller_name

subscribers = (self.controller_name,)
caller = self.domain.owner

self.provisioner.provision(launch_id, new_instance_id_list,
deployable_type_id, subscribers, site=site,
Expand All @@ -518,7 +518,7 @@ def launch(self, deployable_type_id, site, allocation, count=1, extravars=None,
cei_events.event("controller", "new_launch", extra=extradict)
return launch_id, new_instance_id_list

def destroy_instances(self, instance_list, caller=None):
def destroy_instances(self, instance_list):
"""Terminate particular instances.
Control API method, see the decision engine implementer's guide.
Expand All @@ -528,5 +528,6 @@ def destroy_instances(self, instance_list, caller=None):
@exception Exception illegal input/unknown ID(s)
@exception Exception message not sent
"""
caller = self.domain.owner
self.provisioner.terminate_nodes(instance_list, caller=caller)

0 comments on commit 821ae61

Please sign in to comment.