Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 977ce57

Browse files
feat: add support for placement policies (#110)
* feat: add support for placement policies feat: per-Runnable labels PiperOrigin-RevId: 532437427 Source-Link: googleapis/googleapis@288aa7f Source-Link: https://github.com/googleapis/googleapis-gen/commit/615d60f8e98ef120a79410c029b4c72448b53bde Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjE1ZDYwZjhlOThlZjEyMGE3OTQxMGMwMjliNGM3MjQ0OGI1M2JkZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent be22675 commit 977ce57

File tree

3 files changed

+115
-47
lines changed

3 files changed

+115
-47
lines changed

google/cloud/batch_v1/types/job.py

Lines changed: 94 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ class AllocationPolicy(proto.Message):
403403
reserved.
404404
network (google.cloud.batch_v1.types.AllocationPolicy.NetworkPolicy):
405405
The network policy.
406+
placement (google.cloud.batch_v1.types.AllocationPolicy.PlacementPolicy):
407+
The placement policy.
406408
"""
407409

408410
class ProvisioningModel(proto.Enum):
@@ -435,13 +437,16 @@ class LocationPolicy(proto.Message):
435437
Attributes:
436438
allowed_locations (MutableSequence[str]):
437439
A list of allowed location names represented by internal
438-
URLs. Each location can be a region or a zone. Only one
439-
region or multiple zones in one region is supported now. For
440-
example, ["regions/us-central1"] allow VMs in any zones in
441-
region us-central1. ["zones/us-central1-a",
442-
"zones/us-central1-c"] only allow VMs in zones us-central1-a
443-
and us-central1-c. All locations end up in different regions
444-
would cause errors. For example, ["regions/us-central1",
440+
URLs.
441+
442+
Each location can be a region or a zone. Only one region or
443+
multiple zones in one region is supported now. For example,
444+
["regions/us-central1"] allow VMs in any zones in region
445+
us-central1. ["zones/us-central1-a", "zones/us-central1-c"]
446+
only allow VMs in zones us-central1-a and us-central1-c.
447+
448+
All locations end up in different regions would cause
449+
errors. For example, ["regions/us-central1",
445450
"zones/us-central1-a", "zones/us-central1-b",
446451
"zones/us-west1-a"] contains 2 regions "us-central1" and
447452
"us-west1". An error is expected in this case.
@@ -455,7 +460,8 @@ class LocationPolicy(proto.Message):
455460
class Disk(proto.Message):
456461
r"""A new persistent disk or a local ssd.
457462
A VM can only have one local SSD setting but multiple local SSD
458-
partitions. https://cloud.google.com/compute/docs/disks#pdspecs.
463+
partitions. See
464+
https://cloud.google.com/compute/docs/disks#pdspecs and
459465
https://cloud.google.com/compute/docs/disks#localssds.
460466
461467
This message has `oneof`_ fields (mutually exclusive fields).
@@ -468,20 +474,24 @@ class Disk(proto.Message):
468474
Attributes:
469475
image (str):
470476
Name of a public or custom image used as the data source.
471-
For example, the following are all valid URLs: (1) Specify
472-
the image by its family name:
473-
projects/{project}/global/images/family/{image_family} (2)
474-
Specify the image version:
475-
projects/{project}/global/images/{image_version} You can
476-
also use Batch customized image in short names. The
477+
For example, the following are all valid URLs:
478+
479+
- Specify the image by its family name:
480+
projects/{project}/global/images/family/{image_family}
481+
- Specify the image version:
482+
projects/{project}/global/images/{image_version}
483+
484+
You can also use Batch customized image in short names. The
477485
following image values are supported for a boot disk:
478-
"batch-debian": use Batch Debian images. "batch-centos": use
479-
Batch CentOS images. "batch-cos": use Batch
480-
Container-Optimized images.
486+
487+
- "batch-debian": use Batch Debian images.
488+
- "batch-centos": use Batch CentOS images.
489+
- "batch-cos": use Batch Container-Optimized images.
481490
482491
This field is a member of `oneof`_ ``data_source``.
483492
snapshot (str):
484493
Name of a snapshot used as the data source.
494+
Snapshot is not supported as boot disk now.
485495
486496
This field is a member of `oneof`_ ``data_source``.
487497
type_ (str):
@@ -490,11 +500,13 @@ class Disk(proto.Message):
490500
disks and boot disks use "pd-balanced", "pd-extreme",
491501
"pd-ssd" or "pd-standard".
492502
size_gb (int):
493-
Disk size in GB. For persistent disk, this field is ignored
494-
if ``data_source`` is ``image`` or ``snapshot``. For local
495-
SSD, size_gb should be a multiple of 375GB, otherwise, the
496-
final size will be the next greater multiple of 375 GB. For
497-
boot disk, Batch will calculate the boot disk size based on
503+
Disk size in GB.
504+
505+
For persistent disk, this field is ignored if
506+
``data_source`` is ``image`` or ``snapshot``. For local SSD,
507+
size_gb should be a multiple of 375GB, otherwise, the final
508+
size will be the next greater multiple of 375 GB. For boot
509+
disk, Batch will calculate the boot disk size based on
498510
source image and task requirements if you do not speicify
499511
the size. If both this field and the boot_disk_mib field in
500512
task spec's compute_resource are defined, Batch will only
@@ -607,18 +619,20 @@ class InstancePolicy(proto.Message):
607619
machine_type (str):
608620
The Compute Engine machine type.
609621
min_cpu_platform (str):
610-
The minimum CPU platform. See
611-
``https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform``.
622+
The minimum CPU platform.
623+
See
624+
https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform.
612625
Not yet implemented.
613626
provisioning_model (google.cloud.batch_v1.types.AllocationPolicy.ProvisioningModel):
614627
The provisioning model.
615628
accelerators (MutableSequence[google.cloud.batch_v1.types.AllocationPolicy.Accelerator]):
616629
The accelerators attached to each VM
617630
instance.
618631
boot_disk (google.cloud.batch_v1.types.AllocationPolicy.Disk):
619-
Book disk to be created and attached to each
632+
Boot disk to be created and attached to each
620633
VM by this InstancePolicy. Boot disk will be
621-
deleted when the VM is deleted.
634+
deleted when the VM is deleted. Batch API now
635+
only supports booting from image.
622636
disks (MutableSequence[google.cloud.batch_v1.types.AllocationPolicy.AttachedDisk]):
623637
Non-boot disks to be attached for each VM
624638
created by this InstancePolicy. New disks will
@@ -705,21 +719,23 @@ class NetworkInterface(proto.Message):
705719
706720
Attributes:
707721
network (str):
708-
The URL of an existing network resource.
709-
You can specify the network as a full or partial
710-
URL. For example, the following are all valid
711-
URLs:
712-
https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}
713-
projects/{project}/global/networks/{network}
714-
global/networks/{network}
722+
The URL of an existing network resource. You can specify the
723+
network as a full or partial URL.
724+
725+
For example, the following are all valid URLs:
726+
727+
- https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}
728+
- projects/{project}/global/networks/{network}
729+
- global/networks/{network}
715730
subnetwork (str):
716-
The URL of an existing subnetwork resource in
717-
the network. You can specify the subnetwork as a
718-
full or partial URL. For example, the following
719-
are all valid URLs:
720-
https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork}
721-
projects/{project}/regions/{region}/subnetworks/{subnetwork}
722-
regions/{region}/subnetworks/{subnetwork}
731+
The URL of an existing subnetwork resource in the network.
732+
You can specify the subnetwork as a full or partial URL.
733+
734+
For example, the following are all valid URLs:
735+
736+
- https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork}
737+
- projects/{project}/regions/{region}/subnetworks/{subnetwork}
738+
- regions/{region}/subnetworks/{subnetwork}
723739
no_external_ip_address (bool):
724740
Default is false (with an external IP
725741
address). Required if no external public IP
@@ -762,6 +778,36 @@ class NetworkPolicy(proto.Message):
762778
message="AllocationPolicy.NetworkInterface",
763779
)
764780

781+
class PlacementPolicy(proto.Message):
782+
r"""PlacementPolicy describes a group placement policy for the
783+
VMs controlled by this AllocationPolicy.
784+
785+
Attributes:
786+
collocation (str):
787+
UNSPECIFIED vs. COLLOCATED (default
788+
UNSPECIFIED). Use COLLOCATED when you want VMs
789+
to be located close to each other for low
790+
network latency between the VMs. No placement
791+
policy will be generated when collocation is
792+
UNSPECIFIED.
793+
max_distance (int):
794+
When specified, causes the job to fail if more than
795+
max_distance logical switches are required between VMs.
796+
Batch uses the most compact possible placement of VMs even
797+
when max_distance is not specified. An explicit max_distance
798+
makes that level of compactness a strict requirement. Not
799+
yet implemented
800+
"""
801+
802+
collocation: str = proto.Field(
803+
proto.STRING,
804+
number=1,
805+
)
806+
max_distance: int = proto.Field(
807+
proto.INT64,
808+
number=2,
809+
)
810+
765811
location: LocationPolicy = proto.Field(
766812
proto.MESSAGE,
767813
number=1,
@@ -787,6 +833,11 @@ class NetworkPolicy(proto.Message):
787833
number=7,
788834
message=NetworkPolicy,
789835
)
836+
placement: PlacementPolicy = proto.Field(
837+
proto.MESSAGE,
838+
number=10,
839+
message=PlacementPolicy,
840+
)
790841

791842

792843
class TaskGroup(proto.Message):
@@ -804,10 +855,11 @@ class TaskGroup(proto.Message):
804855
task spec.
805856
task_count (int):
806857
Number of Tasks in the TaskGroup.
807-
default is 1
858+
Default is 1.
808859
parallelism (int):
809860
Max number of tasks that can run in parallel. Default to
810-
min(task_count, 1000).
861+
min(task_count, 1000). Field parallelism must be 1 if the
862+
scheduling_policy is IN_ORDER.
811863
task_environments (MutableSequence[google.cloud.batch_v1.types.Environment]):
812864
An array of environment variable mappings, which are passed
813865
to Tasks with matching indices. If task_environments is used

google/cloud/batch_v1/types/task.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class State(proto.Enum):
138138
139139
Values:
140140
STATE_UNSPECIFIED (0):
141-
unknown state
141+
Unknown state.
142142
PENDING (1):
143143
The Task is created and waiting for
144144
resources.
@@ -150,13 +150,17 @@ class State(proto.Enum):
150150
The Task has failed.
151151
SUCCEEDED (5):
152152
The Task has succeeded.
153+
UNEXECUTED (6):
154+
The Task has not been executed when the Job
155+
finishes.
153156
"""
154157
STATE_UNSPECIFIED = 0
155158
PENDING = 1
156159
ASSIGNED = 2
157160
RUNNING = 3
158161
FAILED = 4
159162
SUCCEEDED = 5
163+
UNEXECUTED = 6
160164

161165
state: State = proto.Field(
162166
proto.ENUM,
@@ -222,6 +226,8 @@ class Runnable(proto.Message):
222226
TaskGroup).
223227
timeout (google.protobuf.duration_pb2.Duration):
224228
Timeout for this Runnable.
229+
labels (MutableMapping[str, str]):
230+
Labels for this Runnable.
225231
"""
226232

227233
class Container(proto.Message):
@@ -247,10 +253,11 @@ class Container(proto.Message):
247253
the "docker run" command when running this
248254
container, e.g. "--network host".
249255
block_external_network (bool):
250-
If set to true, external network access to
251-
and from container will be blocked. The
252-
container will use the default internal network
253-
'goog-internal'.
256+
If set to true, external network access to and from
257+
container will be blocked, containers that are with
258+
block_external_network as true can still communicate with
259+
each other, network cannot be specified in the
260+
``container.options`` field.
254261
username (str):
255262
Optional username for logging in to a docker registry. If
256263
username matches ``projects/*/secrets/*/versions/*`` then
@@ -399,6 +406,11 @@ class Barrier(proto.Message):
399406
number=8,
400407
message=duration_pb2.Duration,
401408
)
409+
labels: MutableMapping[str, str] = proto.MapField(
410+
proto.STRING,
411+
proto.STRING,
412+
number=9,
413+
)
402414

403415

404416
class TaskSpec(proto.Message):

tests/unit/gapic/batch_v1/test_batch_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,7 @@ def test_create_job_rest(request_type):
25492549
},
25502550
},
25512551
"timeout": {"seconds": 751, "nanos": 543},
2552+
"labels": {},
25522553
}
25532554
],
25542555
"compute_resource": {
@@ -2640,6 +2641,7 @@ def test_create_job_rest(request_type):
26402641
}
26412642
]
26422643
},
2644+
"placement": {"collocation": "collocation_value", "max_distance": 1264},
26432645
},
26442646
"labels": {},
26452647
"status": {
@@ -2896,6 +2898,7 @@ def test_create_job_rest_bad_request(
28962898
},
28972899
},
28982900
"timeout": {"seconds": 751, "nanos": 543},
2901+
"labels": {},
28992902
}
29002903
],
29012904
"compute_resource": {
@@ -2987,6 +2990,7 @@ def test_create_job_rest_bad_request(
29872990
}
29882991
]
29892992
},
2993+
"placement": {"collocation": "collocation_value", "max_distance": 1264},
29902994
},
29912995
"labels": {},
29922996
"status": {

0 commit comments

Comments
 (0)