Example #1
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     return tasks_client.List(queue_ref, args.limit, args.page_size)
Example #2
0
 def Run(self, args):
     queues_client = queues.Queues()
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     log.warning(constants.QUEUE_MANAGEMENT_WARNING)
     queues_client.Pause(queue_ref)
     log.status.Print('Paused queue [{}].'.format(queue_ref.Name()))
Example #3
0
 def Run(self, args):
     queues_client = GetApiAdapter(self.ReleaseTrack()).queues
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     return queues_client.Get(queue_ref)
Example #4
0
 def Run(self, args):
   queues_client = GetApiAdapter(self.ReleaseTrack()).queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   log.warning(constants.QUEUE_MANAGEMENT_WARNING)
   queues_client.Resume(queue_ref)
   log.status.Print('Resumed queue [{}].'.format(queue_ref.Name()))
Example #5
0
 def Run(self, args):
   tasks_client = tasks.Tasks()
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   return tasks_client.List(queue_ref, args.limit, args.page_size)
Example #6
0
 def Run(self, args):
     tasks_client = tasks.Tasks()
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     tasks_client.Delete(task_ref)
     log.DeletedResource(task_ref.Name(), kind='task')
 def Run(self, args):
   tasks_client = tasks.Tasks()
   queue_ref = parsers.ParseQueue(args.queue)
   task_ref = parsers.ParseTask(args.task, queue_ref)
   duration = parsers.FormatLeaseDuration(args.lease_duration)
   return tasks_client.RenewLease(task_ref, args.schedule_time, duration)
Example #8
0
 def Run(self, args):
     queues_client = queues.Queues()
     queue_ref = parsers.ParseQueue(args.queue)
     return queues_client.GetIamPolicy(queue_ref)
 def Run(self, args):
     tasks_client = tasks.Tasks()
     queue_ref = parsers.ParseQueue(args.queue)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     return tasks_client.Acknowledge(task_ref, args.schedule_time)
Example #10
0
 def Run(self, args):
   queues_client = GetApiAdapter(self.ReleaseTrack()).queues
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   queues_client.Resume(queue_ref)
   log.status.Print('Resumed queue [{}].'.format(
       parsers.GetConsolePromptString(queue_ref.RelativeName())))
Example #11
0
 def testParseQueueUri(self):
     expected_self_link = (
         '{}/projects/my-project/locations/us-central1/queues/my-queue'.
         format(_SELF_LINK_PREFIX))
     actual_queue_ref = parsers.ParseQueue(expected_self_link)
     self.assertEqual(actual_queue_ref.SelfLink(), expected_self_link)
Example #12
0
 def testParseQueueId_NoProject(self):
     properties.VALUES.core.project.Set(None)
     with self.assertRaises(properties.RequiredPropertyError):
         parsers.ParseQueue('my-queue')
Example #13
0
 def Run(self, args):
   queues_client = queues.Queues()
   queue_ref = parsers.ParseQueue(args.queue)
   queues_client.Delete(queue_ref)
   log.DeletedResource(queue_ref.Name(), 'queue')
Example #14
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     tasks_client.Delete(task_ref)
     log.DeletedResource(task_ref.Name(), kind='task')
Example #15
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     return tasks_client.Get(task_ref)
Example #16
0
 def Run(self, args):
     queues_client = queues.Queues()
     queue_ref = parsers.ParseQueue(args.queue)
     queues_client.Purge(queue_ref)
     log.status.Print('Purged queue [{}].'.format(queue_ref.Name()))
Example #17
0
 def Run(self, args):
     queues_client = queues.Queues()
     queue_ref = parsers.ParseQueue(args.queue)
     log.warn(constants.QUEUE_MANAGEMENT_WARNING)
     queues_client.Resume(queue_ref)
     log.status.Print('Resumed queue [{}].'.format(queue_ref.Name()))
Example #18
0
 def Run(self, args):
     tasks_client = tasks.Tasks()
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     return tasks_client.Get(task_ref)
def DeployQueuesYamlFile(tasks_api,
                         config,
                         all_queues_in_db_dict,
                         ct_api_version=base.ReleaseTrack.BETA):
    """Perform a deployment based on the parsed 'queue.yaml' file.

  Args:
    tasks_api: api_lib.tasks.<Alpha|Beta|GA>ApiAdapter, Cloud Tasks API needed
      for doing queue based operations.
    config: A yaml_parsing.ConfigYamlInfo object for the parsed YAML file we
      are going to process.
    all_queues_in_db_dict: A dictionary with queue names as keys and
      corresponding apis.cloudtasks.<ver>.cloudtasks_<ver>_messages.Queue
      objects as values
    ct_api_version: The Cloud Tasks API version we want to use.

  Returns:
    A list of responses received from the Cloud Tasks APIs representing queue
    states for every call made to modify the attributes of a queue.
  """
    class _PlaceholderQueueRef:
        """A placeholder class to simulate queue_ref resource objects used in CT APIs.

    This class simulates the behaviour of the resource object returned by
    tasks.parsers.ParseQueue(...) function. We use this placeholder class
    instead of creating an actual resource instance because otherwise it takes
    roughly 2 minutes to create resource instances for a 1000 queues.

    Attributes:
      _relative_path: A string representing the full path for a queue in the
        format: 'projects/<project>/locations/<location>/queues/<queue>'
    """
        def __init__(self, relative_path):
            """Initializes the instance and sets the relative path."""
            self._relative_path = relative_path

        def RelativeName(self):
            """Gets the string representing the full path for a queue.

      This is the only function we are currently using in CT APIs for the
      queue_ref resource object.

      Returns:
        A string representing the full path for a queue in the following
        format: 'projects/<project>/locations/<location>/queues/<queue>'
      """
            return self._relative_path

    queue_yaml = config.parsed
    queues_client = tasks_api.queues
    queues_not_present_in_yaml = set(all_queues_in_db_dict.keys())

    # Just need to create one real instance of queue_ref. After that we can
    # create placeholder queue_ref objects based on this instance.
    queue_ref = parsers.ParseQueue('a')
    queue_ref_stub = queue_ref.RelativeName()[:-1]

    # Get the arg values that we need to fill up for each queue using CT APIs
    # pylint: disable=protected-access
    task_args = flags._PushQueueFlags(release_track=ct_api_version)
    # TODO(b/169069379) Remove max_burst_size when/if API is exposed via `gcloud
    # tasks queues` CLI invocation.
    task_args.append(base.Argument('--max_burst_size', type=int, help=''))
    expected_args = []
    for task_flag in task_args:
        new_arg = task_flag.args[0][2:].replace('-', '_')
        expected_args.extend((new_arg, 'clear_{}'.format(new_arg)))

    responses = []
    for queue in queue_yaml.queue:
        if queue.name in queues_not_present_in_yaml:
            queues_not_present_in_yaml.remove(queue.name)

        queue_ref = _PlaceholderQueueRef('{}{}'.format(queue_ref_stub,
                                                       queue.name))
        cur_queue_object = all_queues_in_db_dict.get(queue.name, None)
        cloud_task_args = _PopulateCloudTasksArgs(queue, cur_queue_object,
                                                  expected_args)

        rate_to_set = cloud_task_args.GetValue('max_dispatches_per_second')
        if (cur_queue_object
                and (rate_to_set or queue.mode == constants.PULL_QUEUE)
                and cur_queue_object.state in (cur_queue_object.state.DISABLED,
                                               cur_queue_object.state.PAUSED)):
            # Resume queue if it exists, was previously disabled/paused and the
            # new rate > 0
            queues_client.Resume(queue_ref)
        elif (cur_queue_object and not rate_to_set
              and cur_queue_object.state == cur_queue_object.state.RUNNING
              and queue.mode in (None, constants.PUSH_QUEUE)):
            queues_client.Pause(queue_ref)

        if not _AnyUpdatableFields(cloud_task_args):
            # Queue attributes in DB == Queue attributes in YAML
            continue

        queue_config = parsers.ParseCreateOrUpdateQueueArgs(
            cloud_task_args,
            # Deliberately hardcoding push queues because we want to be able to
            # modify all attributes even for pull queues.
            constants.PUSH_QUEUE,
            tasks_api.messages,
            release_track=ct_api_version)
        updated_fields = parsers.GetSpecifiedFieldsMask(
            cloud_task_args,
            constants.PUSH_QUEUE,
            release_track=ct_api_version)
        app_engine_routing_override = (
            queue_config.appEngineHttpQueue.appEngineRoutingOverride
            if queue_config.appEngineHttpQueue is not None else None)
        response = queues_client.Patch(
            queue_ref,
            updated_fields,
            retry_config=queue_config.retryConfig,
            rate_limits=queue_config.rateLimits,
            app_engine_routing_override=app_engine_routing_override,
            queue_type=queue_config.type)
        responses.append(response)

        if (not cur_queue_object and not rate_to_set
                and queue.mode == constants.PUSH_QUEUE):
            # Pause queue if its a new push-queue and rate is zero.
            queues_client.Pause(queue_ref)

    for queue_name in queues_not_present_in_yaml:
        queue = all_queues_in_db_dict[queue_name]
        if queue.state in (queue.state.PAUSED, queue.state.DISABLED):
            continue
        queue_ref = _PlaceholderQueueRef('{}{}'.format(queue_ref_stub,
                                                       queue_name))
        queues_client.Pause(queue_ref)
    return responses
 def Run(self, args):
   tasks_client = tasks.Tasks()
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   task_ref = parsers.ParseTask(args.task, queue_ref)
   return tasks_client.CancelLease(task_ref, args.schedule_time)
Example #21
0
 def Run(self, args):
     tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     task_ref = parsers.ParseTask(args.task, queue_ref)
     tasks_client.Acknowledge(task_ref, args.schedule_time)
Example #22
0
 def Run(self, args):
     queues_client = queues.Queues()
     queue_ref = parsers.ParseQueue(args.queue, args.location)
     return queues_client.Get(queue_ref)
Example #23
0
 def Run(self, args):
   tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
   queue_ref = parsers.ParseQueue(args.queue, args.location)
   task_ref = parsers.ParseTask(args.task, queue_ref)
   duration = parsers.FormatLeaseDuration(args.lease_duration)
   return tasks_client.RenewLease(task_ref, args.schedule_time, duration)