def schedule_deletion():
    """Enqueues tasks to delete drained instance group managers."""
    for key in get_drained_instance_group_managers():
        instance_group_manager = key.get()
        if instance_group_manager:
            if instance_group_manager.url and not instance_group_manager.instances:
                utilities.enqueue_task('delete-instance-group-manager', key)
Beispiel #2
0
def schedule_deletion():
    """Enqueues tasks to delete drained instance templates."""
    for key in get_drained_instance_template_revisions():
        instance_template = key.get()
        if instance_template and instance_template.url:
            if not instance_template.active and not instance_template.drained:
                utilities.enqueue_task('delete-instance-template', key)
def schedule_resize():
    """Enqueues tasks to resize instance group managers."""
    for instance_template in models.InstanceTemplate.query():
        if instance_template.active:
            instance_template_revision = instance_template.active.get()
            if instance_template_revision:
                for instance_group_manager_key in instance_template_revision.active:
                    utilities.enqueue_task('resize-instance-group',
                                           instance_group_manager_key)
Beispiel #4
0
def schedule_drained_instance_cleanup():
  """Enqueues tasks to clean up drained instances."""
  for instance_group_manager_key in (
      instance_group_managers.get_drained_instance_group_managers()):
    instance_group_manager = instance_group_manager_key.get()
    if instance_group_manager:
      for instance_key in instance_group_manager.instances:
        instance = instance_key.get()
        if instance and not instance.cataloged:
          utilities.enqueue_task('cleanup-drained-instance', instance.key)
Beispiel #5
0
def schedule_removal():
  """Enqueues tasks to remove drained instances from the catalog."""
  for instance_group_manager_key in (
      instance_group_managers.get_drained_instance_group_managers()):
    instance_group_manager = instance_group_manager_key.get()
    if instance_group_manager:
      for instance_key in instance_group_manager.instances:
        instance = instance_key.get()
        if instance and not instance.pending_deletion:
          utilities.enqueue_task('remove-cataloged-instance', instance.key)
Beispiel #6
0
def schedule_creation():
    """Enqueues tasks to create missing instance templates."""
    # For each active InstanceTemplateRevision without a URL, schedule
    # creation of its instance template. Since we are outside a transaction
    # the InstanceTemplateRevision could be out of date and may already have
    # a task scheduled/completed. In either case it doesn't matter since
    # we make creating an instance template and updating the URL idempotent.
    for instance_template in models.InstanceTemplate.query():
        if instance_template.active:
            instance_template_revision = instance_template.active.get()
            if instance_template_revision and not instance_template_revision.url:
                utilities.enqueue_task('create-instance-template',
                                       instance_template.active)
Beispiel #7
0
def schedule_deleted_instance_cleanup():
  """Enqueues tasks to clean up deleted instances."""
  # Only delete entities for instances which were marked as deleted >10 minutes
  # ago. This is because there can be a race condition with the task queue that
  # detects new instances. At the start of the queue it may detect an instance
  # which gets deleted before it finishes, and at the end of the queue it may
  # incorrectly create an entity for that deleted instance. Since task queues
  # can take at most 10 minutes, we can avoid the race condition by deleting
  # only those entities referring to instances which were detected as having
  # been deleted >10 minutes ago. Here we use 20 minutes for safety.
  THRESHOLD = 60 * 20
  now = utils.utcnow()

  for instance in models.Instance.query():
    if instance.deleted and (now - instance.last_updated).seconds > THRESHOLD:
      utilities.enqueue_task('cleanup-deleted-instance', instance.key)
def schedule_creation():
    """Enqueues tasks to create missing instance group managers."""
    # For each active InstanceGroupManager without a URL, schedule creation
    # of its instance group manager. Since we are outside a transaction the
    # InstanceGroupManager could be out of date and may already have a task
    # scheduled/completed. In either case it doesn't matter since we make
    # creating an instance group manager and updating the URL idempotent.
    for instance_template in models.InstanceTemplate.query():
        if instance_template.active:
            instance_template_revision = instance_template.active.get()
            if instance_template_revision and instance_template_revision.url:
                for instance_group_manager_key in instance_template_revision.active:
                    instance_group_manager = instance_group_manager_key.get()
                    if instance_group_manager and not instance_group_manager.url:
                        utilities.enqueue_task('create-instance-group-manager',
                                               instance_group_manager_key)
Beispiel #9
0
def schedule_catalog():
  """Enqueues tasks to catalog instances."""
  # Only enqueue tasks for uncataloged instances not pending deletion which
  # are part of active instance group managers which are part of active
  # instance templates.
  for instance_template in models.InstanceTemplate.query():
    if instance_template.active:
      instance_template_revision = instance_template.active.get()
      if instance_template_revision:
        for instance_group_manager_key in instance_template_revision.active:
          instance_group_manager = instance_group_manager_key.get()
          if instance_group_manager:
            for instance_key in instance_group_manager.instances:
              instance = instance_key.get()
              if instance:
                if not instance.cataloged and not instance.pending_deletion:
                  utilities.enqueue_task('catalog-instance', instance.key)
Beispiel #10
0
def schedule_deleted_instance_check():
  """Enqueues tasks to check for deleted instances."""
  for instance in models.Instance.query():
    if instance.pending_deletion and not instance.deleted:
      utilities.enqueue_task('check-deleted-instance', instance.key)
Beispiel #11
0
def schedule_cataloged_instance_update():
  """Enqueues tasks to update information about cataloged instances."""
  for instance in models.Instance.query():
    if instance.cataloged and not instance.pending_deletion:
      utilities.enqueue_task('update-cataloged-instance', instance.key)
Beispiel #12
0
def schedule_pending_deletion():
    """Enqueues tasks to delete instances."""
    for instance in models.Instance.query():
        if instance.pending_deletion and not instance.deleted:
            utilities.enqueue_task('delete-instance-pending-deletion',
                                   instance.key)
Beispiel #13
0
def schedule_fetch():
    """Enqueues tasks to fetch instances."""
    for instance_group_manager in models.InstanceGroupManager.query():
        if instance_group_manager.url:
            utilities.enqueue_task('fetch-instances',
                                   instance_group_manager.key)