예제 #1
0
    def delete(self, entity_version=None, force_delete=False):
        """
        Delete the job

        :param entity_version: the entity version of the job, for concurrency control.
            If entity_version is provided,  start will use the provided value,
            and raise an exception if version is wrong.
            if entity_version is not provided, start will query job runtime to
            get config version and retry until version is correct.
        :param force_delete: force delete a job.  If set to true, it will force
            a delete of the job even if it is running.The job will be first
            stopped and deleted. This step cannot be undone, and the job cannot
            be re-created (with same uuid) till the delete is complete.
        """
        job_entity_version = (
            entity_version
            or self.entity_version
            or self.get_status().version.value
        )

        while True:
            request = stateless_svc.DeleteJobRequest(
                job_id=v1alpha_peloton.JobID(value=self.job_id),
                version=v1alpha_peloton.EntityVersion(
                    value=job_entity_version
                ),
                force=force_delete,
            )
            try:
                self.client.stateless_svc.DeleteJob(
                    request,
                    metadata=self.client.jobmgr_metadata,
                    timeout=self.config.rpc_timeout_sec,
                )
            except grpc.RpcError as e:
                # if entity version is incorrect, get entity version from job status
                # and try again.
                if (
                    e.code() == grpc.StatusCode.ABORTED
                    and INVALID_ENTITY_VERSION_ERR_MESSAGE in e.details()
                    and entity_version is None
                ):
                    job_entity_version = (
                        entity_version or self.get_status().version.value
                    )
                    continue
                raise
            break
        log.info("job %s deleted", self.job_id)
예제 #2
0
 def wait_for_jobmgr_available(self):
     """
     utility method to wait for job manger leader to come up.
     good practice to check before all write apis
     """
     attempts = 0
     while attempts < self.config.max_retry_attempts:
         try:
             request = stateless_svc.DeleteJobRequest(
                 job_id=v1alpha_peloton.JobID(value=self.job_id),
                 version=v1alpha_peloton.EntityVersion(
                     value="dummy-entity-version"),
             )
             self.client.stateless_svc.DeleteJob(
                 request,
                 metadata=self.client.jobmgr_metadata,
                 timeout=self.config.rpc_timeout_sec,
             )
         except grpc.RpcError as e:
             if e.code() != grpc.StatusCode.UNAVAILABLE:
                 break
         log.info("waiting for job manager leader")
         time.sleep(self.config.sleep_time_sec)
         attempts += 1