Beispiel #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.
    """
        drained = []
        failed = []
        output_stream = log.status.GetConsoleWriterStream()
        for job_ref in job_utils.ExtractJobRefs(self.context, args):
            output_stream.flush()
            try:
                output_stream.write(
                    'Starting drain for job \'{0}\' ... '.format(
                        job_ref.jobId))
                self._DrainJob(job_ref)
                output_stream.write('Success\n')
                drained.append(job_ref.jobId)
            except exceptions.HttpError as error:
                reason = dataflow_util.GetErrorMessage(error)
                output_stream.write('Failure: {0}\n'.format(reason))
                failed.append(job_ref.jobId)
        if drained:
            log.status.Print('Started draining jobs: [{0}]'.format(
                ','.join(drained)))
        if failed:
            log.status.Print('Failed to start draining jobs: [{0}]'.format(
                ','.join(failed)))
  def Run(self, args):
    """Runs the command.

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

    Returns:
      An iterator over Job messages.
    """
    job_refs = job_utils.ExtractJobRefs(self.context, args)
    filter_pred = _JobFilter(self.context, args)

    if job_refs and not filter_pred.AlwaysTrue():
      raise calliope_exceptions.ToolException(
          'Cannot specify both job IDs and job filters.')

    jobs = []
    if job_refs:
      view = job_utils.JOB_VIEW_SUMMARY
      jobs = [job_utils.GetJob(self.context, job_ref, view=view)
              for job_ref in job_refs]
    else:
      project_id = properties.VALUES.core.project.Get(required=True)
      jobs = self._JobSummariesForProject(project_id, filter_pred)

    dataflow_messages = self.context[commands.DATAFLOW_MESSAGES_MODULE_KEY]
    return [job_display.DisplayInfo(job, dataflow_messages) for job in jobs]
Beispiel #3
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.
    """
        for job_ref in job_utils.ExtractJobRefs(self.context, args.jobs):
            try:
                self._CancelJob(job_ref)
                log.status.Print('Cancelled job [{0}]'.format(job_ref.jobId))
            except exceptions.HttpError as error:
                log.status.Print('Failed to cancel job [{0}]: {1}'.format(
                    job_ref.jobId, dataflow_util.GetErrorMessage(error)))
Beispiel #4
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:
      A pair of lists indicating the jobs that were successfully cancelled and
      those that failed to be cancelled.
    """
        for job_ref in job_utils.ExtractJobRefs(self.context, args):
            self._CancelJob(job_ref)
        return None
Beispiel #5
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.
    """
        output_stream = log.status.GetConsoleWriterStream()
        for job_ref in job_utils.ExtractJobRefs(self.context, args.jobs):
            output_stream.flush()
            try:
                self._DrainJob(job_ref)
                log.status.Print('Started draining job [{0}]'.format(
                    job_ref.jobId))
            except exceptions.HttpError as error:
                log.status.Print('Failed to drain job [{0}]: {1}'.format(
                    job_ref.jobId, dataflow_util.GetErrorMessage(error)))