@@ -319,7 +319,7 @@ def cancel(self) -> None:
319319 getattr (self .api_client , self ._cancel_method )(name = self .resource_name )
320320
321321
322- class BatchPredictionJob (_Job ):
322+ class BatchPredictionJob (_Job , base . PreviewMixin ):
323323
324324 _resource_noun = "batchPredictionJobs"
325325 _getter_method = "get_batch_prediction_job"
@@ -329,6 +329,9 @@ class BatchPredictionJob(_Job):
329329 _job_type = "batch-predictions"
330330 _parse_resource_name_method = "parse_batch_prediction_job_path"
331331 _format_resource_name_method = "batch_prediction_job_path"
332+ _preview_class = (
333+ "google.cloud.aiplatform.aiplatform.preview.jobs.BatchPredictionJob"
334+ )
332335
333336 def __init__ (
334337 self ,
@@ -949,6 +952,9 @@ def _submit_impl(
949952 ] = None ,
950953 analysis_instance_schema_uri : Optional [str ] = None ,
951954 service_account : Optional [str ] = None ,
955+ reservation_affinity_type : Optional [str ] = None ,
956+ reservation_affinity_key : Optional [str ] = None ,
957+ reservation_affinity_values : Optional [Sequence [str ]] = None ,
952958 wait_for_completion : bool = False ,
953959 ) -> "BatchPredictionJob" :
954960 """Create a batch prediction job.
@@ -1136,6 +1142,18 @@ def _submit_impl(
11361142 service_account (str):
11371143 Optional. Specifies the service account for workload run-as account.
11381144 Users submitting jobs must have act-as permission on this run-as account.
1145+ reservation_affinity_type (str):
1146+ Optional. The type of reservation affinity.
1147+ One of NO_RESERVATION, ANY_RESERVATION, SPECIFIC_RESERVATION,
1148+ SPECIFIC_THEN_ANY_RESERVATION, SPECIFIC_THEN_NO_RESERVATION
1149+ reservation_affinity_key (str):
1150+ Optional. Corresponds to the label key of a reservation resource.
1151+ To target a SPECIFIC_RESERVATION by name, use `compute.googleapis.com/reservation-name` as the key
1152+ and specify the name of your reservation as its value.
1153+ reservation_affinity_values (List[str]):
1154+ Optional. Corresponds to the label values of a reservation resource.
1155+ This must be the full resource name of the reservation.
1156+ Format: 'projects/{project_id_or_number}/zones/{zone}/reservations/{reservation_name}'
11391157 wait_for_completion (bool):
11401158 Whether to wait for the job completion.
11411159 Returns:
@@ -1268,6 +1286,13 @@ def _submit_impl(
12681286 machine_spec .accelerator_type = accelerator_type
12691287 machine_spec .accelerator_count = accelerator_count
12701288
1289+ if reservation_affinity_type :
1290+ machine_spec .reservation_affinity = utils .get_reservation_affinity (
1291+ reservation_affinity_type ,
1292+ reservation_affinity_key ,
1293+ reservation_affinity_values ,
1294+ )
1295+
12711296 dedicated_resources = gca_machine_resources_compat .BatchDedicatedResources ()
12721297
12731298 dedicated_resources .machine_spec = machine_spec
0 commit comments