예제 #1
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: all the arguments that were provided to this command invocation.

    Returns:
      None on success, or a string containing the error message.
    """
    job_ref = job_utils.ExtractJobRef(args.job)

    start_time = args.changed_after and time_util.Strftime(args.changed_after)

    preds = []
    if not args.tentative and args.hide_committed:
      raise calliope_exceptions.ToolException(
          'Cannot exclude both tentative and committed metrics.')
    elif not args.tentative and not args.hide_committed:
      preds.append(lambda m: self._GetContextValue(m, 'tentative') != 'true')
    elif args.tentative and args.hide_committed:
      preds.append(lambda m: self._GetContextValue(m, 'tentative') == 'true')

    preds.append(lambda m: self._FilterBySource(m, args.source))
    preds.append(lambda m: self._FilterByTransform(m, args.transform))

    if args.changed_after:
      preds.append(
          lambda m: time_util.ParseTimeArg(m.updateTime) > args.changed_after)

    response = apis.Metrics.Get(job_ref.jobId, job_ref.projectId, start_time)

    return [self._Format(m) for m in response.metrics
            if all([pred(m) for pred in preds])]
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: all the arguments that were provided to this command invocation.

    Returns:
      None on success, or a string containing the error message.
    """
        job_ref = job_utils.ExtractJobRef(args)

        importance_enum = (
            apis.Messages.LIST_REQUEST.MinimumImportanceValueValuesEnum)
        importance_map = {
            'debug': importance_enum.JOB_MESSAGE_DEBUG,
            'detailed': importance_enum.JOB_MESSAGE_DETAILED,
            'error': importance_enum.JOB_MESSAGE_ERROR,
            'warning': importance_enum.JOB_MESSAGE_WARNING,
        }

        request = apis.Messages.LIST_REQUEST(
            projectId=job_ref.projectId,
            jobId=job_ref.jobId,
            location=job_ref.location,
            minimumImportance=(args.importance
                               and importance_map[args.importance]),

            # Note: It if both are present, startTime > endTime, because we will
            # return messages with actual time [endTime, startTime).
            startTime=args.after and time_util.Strftime(args.after),
            endTime=args.before and time_util.Strftime(args.before))

        return dataflow_util.YieldFromList(job_id=job_ref.jobId,
                                           project_id=job_ref.projectId,
                                           region_id=job_ref.location,
                                           service=apis.Messages.GetService(),
                                           request=request,
                                           batch_size=args.limit,
                                           batch_size_attribute='pageSize',
                                           field='jobMessages')