def testExtractJobRefsTwo(self):
     job_utils.ArgsForJobRefs(self.parser, nargs='+')
     jobs = job_utils.ExtractJobRefs(
         self.ParseArgs('%s %s' % (JOB_1_ID, JOB_2_ID)))
     self.assertEqual(2, len(jobs))
     self.AssertJobRef(jobs[0], JOB_1_ID)
     self.AssertJobRef(jobs[1], JOB_2_ID)
 def testExtractJobRefsTwoWithRegion(self):
     job_utils.ArgsForJobRefs(self.parser, nargs='+')
     jobs = job_utils.ExtractJobRefs(
         self.ParseArgs('--region=%s %s %s' % (REGION, JOB_1_ID, JOB_2_ID)))
     self.assertEqual(2, len(jobs))
     self.AssertJobRef(jobs[0], JOB_1_ID, location=REGION)
     self.AssertJobRef(jobs[1], JOB_2_ID, location=REGION)
    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(args.jobs):
            try:
                apis.Jobs.Cancel(job_ref.jobId)
                log.status.Print('Cancelled job [{0}]'.format(job_ref.jobId))
            except exceptions.HttpException as error:
                log.status.Print('Failed to cancel job [{0}]: {1}'.format(
                    job_ref.jobId, error.payload.status_message))
Exemple #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.
    """
        for job_ref in job_utils.ExtractJobRefs(args):
            try:
                apis.Jobs.Drain(job_ref.jobId,
                                project_id=job_ref.projectId,
                                region_id=job_ref.location)
                log.status.Print('Started draining job [{0}]'.format(
                    job_ref.jobId))
            except exceptions.HttpException as error:
                log.status.Print('Failed to drain job [{0}]: {1}'.format(
                    job_ref.jobId, error.payload.status_message))
Exemple #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.
    """
        for job_ref in job_utils.ExtractJobRefs(args):
            try:
                apis.Jobs.Cancel(job_ref.jobId,
                                 project_id=job_ref.projectId,
                                 region_id=job_ref.location)
                log.status.Print('Cancelled job [{0}]'.format(job_ref.jobId))
            except exceptions.HttpException as error:
                log.status.Print(
                    "Failed to cancel job [{0}]: {1} Please ensure you have permission "
                    "to access the job and the `--region` flag, {2}, matches the job\'s"
                    " region.".format(job_ref.jobId,
                                      error.payload.status_message,
                                      job_ref.location))
 def testExtractJobRefsOne(self):
     job_utils.ArgsForJobRefs(self.parser, nargs='+')
     jobs = job_utils.ExtractJobRefs(self.parser.parse_args([JOB_1_ID]))
     self.assertEqual(1, len(jobs))
     self.AssertJobRef(jobs[0], JOB_1_ID)
 def testExtractJobRefsNoneOptional(self):
     job_utils.ArgsForJobRefs(self.parser, nargs='*')
     self.assertEqual([],
                      job_utils.ExtractJobRefs(self.parser.parse_args([])))