def Run(self, args): """Runs the command. Args: args: The arguments that were provided to this command invocation. Returns: A Job message. """ job_ref = job_utils.ExtractJobRef(args) job = apis.Jobs.Get( job_id=job_ref.jobId, project_id=job_ref.projectId, region_id=job_ref.location, view=apis.Jobs.GET_REQUEST.ViewValueValuesEnum.JOB_VIEW_ALL) # Extract the basic display information for the job shown_job = job_display.DisplayInfo(job) if args.environment: shown_job.environment = job.environment if args.steps: shown_job.steps = [ self._PrettyStep(step) for step in step_json.ExtractSteps(job) ] return shown_job
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): """Runs the command. Args: args: The arguments that were provided to this command invocation. Returns: A Job message. """ job_ref = job_utils.ExtractJobRef(args.job) job = apis.Jobs.Get( job_id=job_ref.jobId, project_id=job_ref.projectId, view=apis.Jobs.GET_REQUEST.ViewValueValuesEnum.JOB_VIEW_ALL) # Extract the basic display information for the job shown_job = job_display.DisplayInfo(job) # TODO(b/36057351): "Prettify" the environment, etc, since it includes # JSON as a string in some of the fields. if args.environment: shown_job.environment = job.environment if args.steps: shown_job.steps = [ self._PrettyStep(step) for step in step_json.ExtractSteps(job) ] return shown_job
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. """ job_ref = job_utils.ExtractJobRef(args) try: apis.Jobs.ResumeUnsupportedSDK( job_ref.jobId, "unsupported_sdk_temporary_override_token=" + args.token, project_id=job_ref.projectId, region_id=job_ref.location) log.status.Print( "Resuming job running on unsupported SDK version [{0}]. " "This job may be cancelled in the future. For more " "details, see https://cloud.google.com/dataflow/docs/" "support/sdk-version-support-status.".format(job_ref.jobId)) except exceptions.HttpException as error: log.status.Print(( "Failed to resume job [{0}]: {1} Please ensure you have permission " "to access the job, the `--region` flag, {2}, is correct for the " "job and the `--token` flag, {3}, corresponds to the job." ).format(job_ref.jobId, error.payload.status_message, job_ref.location, args.token))
def Run(self, args): """Runs the command. Args: args: The arguments that were provided to this command invocation. Returns: A Job message. """ job_ref = job_utils.ExtractJobRef(args.job) return apis.Jobs.Get(job_ref.jobId, job_ref.projectId, args.full)
def Run(self, args): """Runs the command. Args: args: The arguments that were provided to this command invocation. Returns: A Job message. """ request = job_utils.ExtractJobRef(args.job).Request() request.view = args.full return apis.Jobs.Get(request.jobId, request.projectId, request.view)
def Run(self, args): """Runs the command. Args: args: All the arguments that were provided to this command invocation. Returns: An iterator over the steps in the given job. """ job_ref = job_utils.ExtractJobRef(args) return step_json.ExtractSteps( apis.Jobs.Get( job_ref.jobId, project_id=job_ref.projectId, region_id=job_ref.location, view=apis.Jobs.GET_REQUEST.ViewValueValuesEnum.JOB_VIEW_ALL))
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: List of metric values. Raises: exceptions.InvalidExclusionException: If the excluded metrics are not valid. """ job_ref = job_utils.ExtractJobRef(args) start_time = args.changed_after and times.FormatDateTime( args.changed_after) preds = [] if not args.tentative and args.hide_committed: raise exceptions.InvalidExclusionException( '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: times.ParseDateTime(m.updateTime) > args. changed_after) response = apis.Metrics.Get(job_ref.jobId, project_id=job_ref.projectId, region_id=job_ref.location, start_time=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')
def testExtractJobRefsNoneButHasRegion(self): job_utils.ArgsForJobRefs(self.parser, nargs='+') with self.AssertRaisesArgumentErrorMatches( 'argument JOB_ID [JOB_ID ...]: Must be specified.'): job_utils.ExtractJobRef( self.parser.parse_args(['--region=%s' % (REGION)]))
def testExtractJobRefsNone(self): job_utils.ArgsForJobRefs(self.parser, nargs='+') with self.AssertRaisesArgumentErrorMatches( 'argument JOB_ID [JOB_ID ...]: Must be specified.'): job_utils.ExtractJobRef(self.parser.parse_args([]))
def testExtractJobRefMissingRequiredArgButHasRegion(self): with self.AssertRaisesArgumentErrorMatches( 'argument JOB_ID: Must be specified.'): job_utils.ExtractJobRef( self.parser.parse_args(['--region=%s' % (REGION)]))
def testExtractJobRefAndRegion(self): self.AssertJobRef(job_utils.ExtractJobRef( self.parser.parse_args(['--region=%s' % REGION, JOB_1_ID])), job_id=JOB_1_ID, location=REGION)
def testExtractJobRef(self): self.AssertJobRef(job_utils.ExtractJobRef(self.ParseArgs(JOB_1_ID)), job_id=JOB_1_ID)