Skip to content

Commit

Permalink
test for existence of the newly config variables for backward compati…
Browse files Browse the repository at this point in the history
…bility.
  • Loading branch information
Xiaolin Charlene Zang committed Sep 15, 2017
1 parent d896b36 commit 7805577
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion jobQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ def getNextPendingJobReuse(self, target_id=None):
# the limit for pool is not reached yet
if self.preallocator.freePoolSize(job.vm.name) == 0 and \
self.preallocator.poolSize(job.vm.name) < Config.POOL_SIZE:
self.preallocator.incrementPoolSize(job.vm, Config.POOL_ALLOC_INCREMENT)
increment = 1
if hasattr(Config, 'POOL_ALLOC_INCREMENT') and Config.POOL_ALLOC_INCREMENT:
increment = Config.POOL_ALLOC_INCREMENT
self.preallocator.incrementPoolSize(job.vm, increment)

# If the job hasn't been assigned to a worker yet, see if there
# is a free VM
Expand Down
6 changes: 2 additions & 4 deletions preallocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def decrementPoolSize(self, vm):
Called by worker to shrink the pool, after returning a vm to free pool
"""

if not (Config.POOL_SIZE_LOW_WATER_MARK and vm.name in self.machines.keys()):
if not (hasattr(Config, 'POOL_SIZE_LOW_WATER_MARK') and
Config.POOL_SIZE_LOW_WATER_MARK and vm.name in self.machines.keys()):
return

delta = self.freePoolSize(vm.name) - Config.POOL_SIZE_LOW_WATER_MARK
Expand All @@ -61,9 +62,6 @@ def incrementPoolSize(self, vm, delta):
Called by jobQueue to create the pool and allcoate given number of vms
"""

if not delta: # POOL_ALLOC_INCREMENT may not be defined in Config
delta = 1

self.lock.acquire()
if vm.name not in self.machines.keys():
self.machines.set(vm.name, [[], TangoQueue(vm.name)])
Expand Down
10 changes: 6 additions & 4 deletions vmms/ec2SSH.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ def __init__(self, accessKeyId=None, accessKey=None):
# When an instance is terminated, it's detached.
self.asg = None
self.auto_scaling_group = None
if config.Config.EC2_AUTO_SCALING_GROUP_NAME:
self.auto_scaling_group_name = None
if hasattr(config.Config, 'EC2_AUTO_SCALING_GROUP_NAME') and config.Config.EC2_AUTO_SCALING_GROUP_NAME:
self.asg = boto3.client("autoscaling", config.Config.EC2_REGION)
groups = self.asg.describe_auto_scaling_groups(AutoScalingGroupNames=[config.Config.EC2_AUTO_SCALING_GROUP_NAME])
if len(groups['AutoScalingGroups']) == 1:
self.auto_scaling_group = groups['AutoScalingGroups'][0]
self.log.info("Use aws auto scaling group %s" % config.Config.EC2_AUTO_SCALING_GROUP_NAME)
self.auto_scaling_group_name = config.Config.EC2_AUTO_SCALING_GROUP_NAME
self.log.info("Use aws auto scaling group %s" % self.auto_scaling_group_name)

instances = self.asg.describe_auto_scaling_instances()['AutoScalingInstances']
else:
Expand Down Expand Up @@ -323,7 +325,7 @@ def initializeVM(self, vm):

if self.auto_scaling_group:
self.asg.attach_instances(InstanceIds=[newInstance.id],
AutoScalingGroupName=config.Config.EC2_AUTO_SCALING_GROUP_NAME)
AutoScalingGroupName=self.auto_scaling_group_name)
self.log.info("attach new instance %s to auto scaling group" % newInstance.id)

# Save domain and id ssigned by EC2 in vm object
Expand Down Expand Up @@ -507,7 +509,7 @@ def destroyVM(self, vm):
MaxRecords=1)
if len(response['AutoScalingInstances']) == 1:
self.asg.detach_instances(InstanceIds=[vm.ec2_id],
AutoScalingGroupName=config.Config.EC2_AUTO_SCALING_GROUP_NAME,
AutoScalingGroupName=self.auto_scaling_group_name,
ShouldDecrementDesiredCapacity=True)
self.log.info("detach instance %s %s from auto scaling group" % (vm.ec2_id, vm.name))
else:
Expand Down

0 comments on commit 7805577

Please sign in to comment.