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

Commit be22675

Browse files
feat: support order_by in ListJobs and ListTasks requests (#108)
* fix: override HTTP URLs for LRO cancel/delete operations PiperOrigin-RevId: 532357846 Source-Link: googleapis/googleapis@5cfe30b Source-Link: https://github.com/googleapis/googleapis-gen/commit/0e1e293ad959be26640d593b978cab7fba7ced97 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMGUxZTI5M2FkOTU5YmUyNjY0MGQ1OTNiOTc4Y2FiN2ZiYTdjZWQ5NyJ9 * 🦉 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 3681dd2 commit be22675

File tree

7 files changed

+146
-54
lines changed

7 files changed

+146
-54
lines changed

google/cloud/batch_v1alpha/types/batch.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class ListJobsRequest(proto.Message):
163163
Parent path.
164164
filter (str):
165165
List filter.
166+
order_by (str):
167+
Sort results. Supported are "name", "name desc",
168+
"create_time", "create_time desc", and "".
166169
page_size (int):
167170
Page size.
168171
page_token (str):
@@ -177,6 +180,10 @@ class ListJobsRequest(proto.Message):
177180
proto.STRING,
178181
number=4,
179182
)
183+
order_by: str = proto.Field(
184+
proto.STRING,
185+
number=5,
186+
)
180187
page_size: int = proto.Field(
181188
proto.INT32,
182189
number=2,
@@ -230,6 +237,9 @@ class ListTasksRequest(proto.Message):
230237
Task filter, null filter matches all Tasks.
231238
Filter string should be of the format
232239
State=TaskStatus.State e.g. State=RUNNING
240+
order_by (str):
241+
Sort results. Supported are "name", "name desc",
242+
"create_time", "create_time desc", and "".
233243
page_size (int):
234244
Page size.
235245
page_token (str):
@@ -244,6 +254,10 @@ class ListTasksRequest(proto.Message):
244254
proto.STRING,
245255
number=2,
246256
)
257+
order_by: str = proto.Field(
258+
proto.STRING,
259+
number=5,
260+
)
247261
page_size: int = proto.Field(
248262
proto.INT32,
249263
number=3,

google/cloud/batch_v1alpha/types/job.py

Lines changed: 108 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ class AllocationPolicy(proto.Message):
515515
reserved.
516516
network (google.cloud.batch_v1alpha.types.AllocationPolicy.NetworkPolicy):
517517
The network policy.
518+
placement (google.cloud.batch_v1alpha.types.AllocationPolicy.PlacementPolicy):
519+
The placement policy.
518520
"""
519521

520522
class ProvisioningModel(proto.Enum):
@@ -547,13 +549,16 @@ class LocationPolicy(proto.Message):
547549
Attributes:
548550
allowed_locations (MutableSequence[str]):
549551
A list of allowed location names represented by internal
550-
URLs. Each location can be a region or a zone. Only one
551-
region or multiple zones in one region is supported now. For
552-
example, ["regions/us-central1"] allow VMs in any zones in
553-
region us-central1. ["zones/us-central1-a",
554-
"zones/us-central1-c"] only allow VMs in zones us-central1-a
555-
and us-central1-c. All locations end up in different regions
556-
would cause errors. For example, ["regions/us-central1",
552+
URLs.
553+
554+
Each location can be a region or a zone. Only one region or
555+
multiple zones in one region is supported now. For example,
556+
["regions/us-central1"] allow VMs in any zones in region
557+
us-central1. ["zones/us-central1-a", "zones/us-central1-c"]
558+
only allow VMs in zones us-central1-a and us-central1-c.
559+
560+
All locations end up in different regions would cause
561+
errors. For example, ["regions/us-central1",
557562
"zones/us-central1-a", "zones/us-central1-b",
558563
"zones/us-west1-a"] contains 2 regions "us-central1" and
559564
"us-west1". An error is expected in this case.
@@ -574,7 +579,8 @@ class LocationPolicy(proto.Message):
574579
class Disk(proto.Message):
575580
r"""A new persistent disk or a local ssd.
576581
A VM can only have one local SSD setting but multiple local SSD
577-
partitions. https://cloud.google.com/compute/docs/disks#pdspecs.
582+
partitions. See
583+
https://cloud.google.com/compute/docs/disks#pdspecs and
578584
https://cloud.google.com/compute/docs/disks#localssds.
579585
580586
This message has `oneof`_ fields (mutually exclusive fields).
@@ -587,20 +593,24 @@ class Disk(proto.Message):
587593
Attributes:
588594
image (str):
589595
Name of a public or custom image used as the data source.
590-
For example, the following are all valid URLs: (1) Specify
591-
the image by its family name:
592-
projects/{project}/global/images/family/{image_family} (2)
593-
Specify the image version:
594-
projects/{project}/global/images/{image_version} You can
595-
also use Batch customized image in short names. The
596+
For example, the following are all valid URLs:
597+
598+
- Specify the image by its family name:
599+
projects/{project}/global/images/family/{image_family}
600+
- Specify the image version:
601+
projects/{project}/global/images/{image_version}
602+
603+
You can also use Batch customized image in short names. The
596604
following image values are supported for a boot disk:
597-
"batch-debian": use Batch Debian images. "batch-centos": use
598-
Batch CentOS images. "batch-cos": use Batch
599-
Container-Optimized images.
605+
606+
- "batch-debian": use Batch Debian images.
607+
- "batch-centos": use Batch CentOS images.
608+
- "batch-cos": use Batch Container-Optimized images.
600609
601610
This field is a member of `oneof`_ ``data_source``.
602611
snapshot (str):
603612
Name of a snapshot used as the data source.
613+
Snapshot is not supported as boot disk now.
604614
605615
This field is a member of `oneof`_ ``data_source``.
606616
type_ (str):
@@ -609,11 +619,13 @@ class Disk(proto.Message):
609619
disks and boot disks use "pd-balanced", "pd-extreme",
610620
"pd-ssd" or "pd-standard".
611621
size_gb (int):
612-
Disk size in GB. For persistent disk, this field is ignored
613-
if ``data_source`` is ``image`` or ``snapshot``. For local
614-
SSD, size_gb should be a multiple of 375GB, otherwise, the
615-
final size will be the next greater multiple of 375 GB. For
616-
boot disk, Batch will calculate the boot disk size based on
622+
Disk size in GB.
623+
624+
For persistent disk, this field is ignored if
625+
``data_source`` is ``image`` or ``snapshot``. For local SSD,
626+
size_gb should be a multiple of 375GB, otherwise, the final
627+
size will be the next greater multiple of 375 GB. For boot
628+
disk, Batch will calculate the boot disk size based on
617629
source image and task requirements if you do not speicify
618630
the size. If both this field and the boot_disk_mib field in
619631
task spec's compute_resource are defined, Batch will only
@@ -728,25 +740,29 @@ class InstancePolicy(proto.Message):
728740
machine_type (str):
729741
The Compute Engine machine type.
730742
min_cpu_platform (str):
731-
The minimum CPU platform. See
732-
``https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform``.
743+
The minimum CPU platform.
744+
See
745+
https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform.
733746
Not yet implemented.
734747
provisioning_model (google.cloud.batch_v1alpha.types.AllocationPolicy.ProvisioningModel):
735748
The provisioning model.
736749
accelerators (MutableSequence[google.cloud.batch_v1alpha.types.AllocationPolicy.Accelerator]):
737750
The accelerators attached to each VM
738751
instance.
739752
boot_disk (google.cloud.batch_v1alpha.types.AllocationPolicy.Disk):
740-
Book disk to be created and attached to each
753+
Boot disk to be created and attached to each
741754
VM by this InstancePolicy. Boot disk will be
742-
deleted when the VM is deleted.
755+
deleted when the VM is deleted. Batch API now
756+
only supports booting from image.
743757
disks (MutableSequence[google.cloud.batch_v1alpha.types.AllocationPolicy.AttachedDisk]):
744758
Non-boot disks to be attached for each VM
745759
created by this InstancePolicy. New disks will
746760
be deleted when the VM is deleted.
747761
reservation (str):
748-
If specified, VMs will be allocated only
749-
inside the matching reservation.
762+
If specified, VMs will consume only the
763+
specified reservation. If not specified
764+
(default), VMs will consume any applicable
765+
reservation.
750766
"""
751767

752768
allowed_machine_types: MutableSequence[str] = proto.RepeatedField(
@@ -837,21 +853,23 @@ class NetworkInterface(proto.Message):
837853
838854
Attributes:
839855
network (str):
840-
The URL of an existing network resource.
841-
You can specify the network as a full or partial
842-
URL. For example, the following are all valid
843-
URLs:
844-
https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}
845-
projects/{project}/global/networks/{network}
846-
global/networks/{network}
856+
The URL of an existing network resource. You can specify the
857+
network as a full or partial URL.
858+
859+
For example, the following are all valid URLs:
860+
861+
- https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}
862+
- projects/{project}/global/networks/{network}
863+
- global/networks/{network}
847864
subnetwork (str):
848-
The URL of an existing subnetwork resource in
849-
the network. You can specify the subnetwork as a
850-
full or partial URL. For example, the following
851-
are all valid URLs:
852-
https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork}
853-
projects/{project}/regions/{region}/subnetworks/{subnetwork}
854-
regions/{region}/subnetworks/{subnetwork}
865+
The URL of an existing subnetwork resource in the network.
866+
You can specify the subnetwork as a full or partial URL.
867+
868+
For example, the following are all valid URLs:
869+
870+
- https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetwork}
871+
- projects/{project}/regions/{region}/subnetworks/{subnetwork}
872+
- regions/{region}/subnetworks/{subnetwork}
855873
no_external_ip_address (bool):
856874
Default is false (with an external IP
857875
address). Required if no external public IP
@@ -894,6 +912,36 @@ class NetworkPolicy(proto.Message):
894912
message="AllocationPolicy.NetworkInterface",
895913
)
896914

915+
class PlacementPolicy(proto.Message):
916+
r"""PlacementPolicy describes a group placement policy for the
917+
VMs controlled by this AllocationPolicy.
918+
919+
Attributes:
920+
collocation (str):
921+
UNSPECIFIED vs. COLLOCATED (default
922+
UNSPECIFIED). Use COLLOCATED when you want VMs
923+
to be located close to each other for low
924+
network latency between the VMs. No placement
925+
policy will be generated when collocation is
926+
UNSPECIFIED.
927+
max_distance (int):
928+
When specified, causes the job to fail if more than
929+
max_distance logical switches are required between VMs.
930+
Batch uses the most compact possible placement of VMs even
931+
when max_distance is not specified. An explicit max_distance
932+
makes that level of compactness a strict requirement. Not
933+
yet implemented
934+
"""
935+
936+
collocation: str = proto.Field(
937+
proto.STRING,
938+
number=1,
939+
)
940+
max_distance: int = proto.Field(
941+
proto.INT64,
942+
number=2,
943+
)
944+
897945
location: LocationPolicy = proto.Field(
898946
proto.MESSAGE,
899947
number=1,
@@ -937,6 +985,11 @@ class NetworkPolicy(proto.Message):
937985
number=7,
938986
message=NetworkPolicy,
939987
)
988+
placement: PlacementPolicy = proto.Field(
989+
proto.MESSAGE,
990+
number=10,
991+
message=PlacementPolicy,
992+
)
940993

941994

942995
class TaskGroup(proto.Message):
@@ -954,12 +1007,14 @@ class TaskGroup(proto.Message):
9541007
task spec.
9551008
task_count (int):
9561009
Number of Tasks in the TaskGroup.
957-
default is 1
1010+
Default is 1.
9581011
parallelism (int):
9591012
Max number of tasks that can run in parallel. Default to
960-
min(task_count, 1000).
1013+
min(task_count, 1000). Field parallelism must be 1 if the
1014+
scheduling_policy is IN_ORDER.
9611015
scheduling_policy (google.cloud.batch_v1alpha.types.TaskGroup.SchedulingPolicy):
962-
Scheduling policy for Tasks in the TaskGroup.
1016+
Scheduling policy for Tasks in the TaskGroup. The default
1017+
value is AS_SOON_AS_POSSIBLE.
9631018
allocation_policy (google.cloud.batch_v1alpha.types.AllocationPolicy):
9641019
Compute resource allocation for the
9651020
TaskGroup. If specified, it overrides resources
@@ -1011,9 +1066,17 @@ class SchedulingPolicy(proto.Enum):
10111066
Unspecified.
10121067
AS_SOON_AS_POSSIBLE (1):
10131068
Run Tasks as soon as resources are available.
1069+
1070+
Tasks might be executed in parallel depending on parallelism
1071+
and task_count values.
1072+
IN_ORDER (2):
1073+
Run Tasks sequentially with increased task
1074+
index.
1075+
Not yet implemented.
10141076
"""
10151077
SCHEDULING_POLICY_UNSPECIFIED = 0
10161078
AS_SOON_AS_POSSIBLE = 1
1079+
IN_ORDER = 2
10171080

10181081
name: str = proto.Field(
10191082
proto.STRING,

google/cloud/batch_v1alpha/types/task.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class State(proto.Enum):
148148
149149
Values:
150150
STATE_UNSPECIFIED (0):
151-
unknown state
151+
Unknown state.
152152
PENDING (1):
153153
The Task is created and waiting for
154154
resources.
@@ -160,13 +160,17 @@ class State(proto.Enum):
160160
The Task has failed.
161161
SUCCEEDED (5):
162162
The Task has succeeded.
163+
UNEXECUTED (6):
164+
The Task has not been executed when the Job
165+
finishes.
163166
"""
164167
STATE_UNSPECIFIED = 0
165168
PENDING = 1
166169
ASSIGNED = 2
167170
RUNNING = 3
168171
FAILED = 4
169172
SUCCEEDED = 5
173+
UNEXECUTED = 6
170174

171175
state: State = proto.Field(
172176
proto.ENUM,
@@ -279,10 +283,11 @@ class Container(proto.Message):
279283
the "docker run" command when running this
280284
container, e.g. "--network host".
281285
block_external_network (bool):
282-
If set to true, external network access to
283-
and from container will be blocked. The
284-
container will use the default internal network
285-
'goog-internal'.
286+
If set to true, external network access to and from
287+
container will be blocked, containers that are with
288+
block_external_network as true can still communicate with
289+
each other, network cannot be specified in the
290+
``container.options`` field.
286291
username (str):
287292
Optional username for logging in to a docker registry. If
288293
username matches ``projects/*/secrets/*/versions/*`` then

samples/generated_samples/snippet_metadata_google.cloud.batch.v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-batch",
11-
"version": "0.10.0"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

samples/generated_samples/snippet_metadata_google.cloud.batch.v1alpha.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-batch",
11-
"version": "0.10.0"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

scripts/fixup_batch_v1alpha_keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class batchCallTransformer(cst.CSTTransformer):
4343
'delete_job': ('name', 'reason', 'request_id', ),
4444
'get_job': ('name', ),
4545
'get_task': ('name', ),
46-
'list_jobs': ('parent', 'filter', 'page_size', 'page_token', ),
47-
'list_tasks': ('parent', 'filter', 'page_size', 'page_token', ),
46+
'list_jobs': ('parent', 'filter', 'order_by', 'page_size', 'page_token', ),
47+
'list_tasks': ('parent', 'filter', 'order_by', 'page_size', 'page_token', ),
4848
}
4949

5050
def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:

0 commit comments

Comments
 (0)