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.
    """
        apitools_client = self.context[commands.DATAFLOW_APITOOLS_CLIENT_KEY]
        dataflow_messages = self.context[commands.DATAFLOW_MESSAGES_MODULE_KEY]
        job_ref = job_utils.ExtractJobRef(self.context, args)

        importance_enum = (
            dataflow_messages.DataflowProjectsJobsMessagesListRequest.
            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 = dataflow_messages.DataflowProjectsJobsMessagesListRequest(
            projectId=job_ref.projectId,
            jobId=job_ref.jobId,
            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.before and time_util.Strftime(args.before),
            endTime=args.after and time_util.Strftime(args.after))

        return self._GetMessages(apitools_client, request)
Beispiel #2
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.
    """
        apitools_client = self.context[commands.DATAFLOW_APITOOLS_CLIENT_KEY]
        dataflow_messages = self.context[commands.DATAFLOW_MESSAGES_MODULE_KEY]
        job_ref = job_utils.ExtractJobRef(self.context, args.job)

        start_time = args.changed_after and time_util.Strftime(
            args.changed_after)
        request = dataflow_messages.DataflowProjectsJobsGetMetricsRequest(
            projectId=job_ref.projectId,
            jobId=job_ref.jobId,
            startTime=start_time)

        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)

        try:
            response = apitools_client.projects_jobs.GetMetrics(request)
        except exceptions.HttpError as error:
            raise dataflow_util.MakeErrorMessage(error, job_ref.jobId,
                                                 job_ref.projectId)

        return [
            self._Format(m) for m in response.metrics
            if all([pred(m) for pred in preds])
        ]