Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [cloudbuild] Add routing information in Cloud Build GRPC clients #9635

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions java-cloudbuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ If you are using Maven without the BOM, add this to your dependencies:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-build</artifactId>
<version>3.23.0</version>
<version>3.22.0</version>
</dependency>
```

If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-build:3.23.0'
implementation 'com.google.cloud:google-cloud-build:3.22.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-build" % "3.23.0"
libraryDependencies += "com.google.cloud" % "google-cloud-build" % "3.22.0"
```
<!-- {x-version-update-end} -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,9 @@ public final UnaryCallable<CancelBuildRequest, Build> cancelBuildCallable() {
* <p>For builds that specify `StorageSource`:
*
* <ul>
* <li>If the original build pulled source from Google Cloud Storage without specifying the
* generation of the object, the new build will use the current object, which may be
* different from the original build source.
* <li>If the original build pulled source from Cloud Storage without specifying the generation
* of the object, the new build will use the current object, which may be different from the
* original build source.
* <li>If the original build pulled source from Cloud Storage and specified the generation of
* the object, the new build will attempt to use the same object, which may or may not be
* available depending on the bucket's lifecycle management settings.
Expand Down Expand Up @@ -794,9 +794,9 @@ public final OperationFuture<Build, BuildOperationMetadata> retryBuildAsync(
* <p>For builds that specify `StorageSource`:
*
* <ul>
* <li>If the original build pulled source from Google Cloud Storage without specifying the
* generation of the object, the new build will use the current object, which may be
* different from the original build source.
* <li>If the original build pulled source from Cloud Storage without specifying the generation
* of the object, the new build will use the current object, which may be different from the
* original build source.
* <li>If the original build pulled source from Cloud Storage and specified the generation of
* the object, the new build will attempt to use the same object, which may or may not be
* available depending on the bucket's lifecycle management settings.
Expand Down Expand Up @@ -855,9 +855,9 @@ public final OperationFuture<Build, BuildOperationMetadata> retryBuildAsync(
* <p>For builds that specify `StorageSource`:
*
* <ul>
* <li>If the original build pulled source from Google Cloud Storage without specifying the
* generation of the object, the new build will use the current object, which may be
* different from the original build source.
* <li>If the original build pulled source from Cloud Storage without specifying the generation
* of the object, the new build will use the current object, which may be different from the
* original build source.
* <li>If the original build pulled source from Cloud Storage and specified the generation of
* the object, the new build will attempt to use the same object, which may or may not be
* available depending on the bucket's lifecycle management settings.
Expand Down Expand Up @@ -916,9 +916,9 @@ public final OperationFuture<Build, BuildOperationMetadata> retryBuildAsync(
* <p>For builds that specify `StorageSource`:
*
* <ul>
* <li>If the original build pulled source from Google Cloud Storage without specifying the
* generation of the object, the new build will use the current object, which may be
* different from the original build source.
* <li>If the original build pulled source from Cloud Storage without specifying the generation
* of the object, the new build will use the current object, which may be different from the
* original build source.
* <li>If the original build pulled source from Cloud Storage and specified the generation of
* the object, the new build will attempt to use the same object, which may or may not be
* available depending on the bucket's lifecycle management settings.
Expand Down Expand Up @@ -1622,6 +1622,11 @@ public final UnaryCallable<UpdateBuildTriggerRequest, BuildTrigger> updateBuildT
/**
* Runs a `BuildTrigger` at a particular source revision.
*
* <p>To run a regional or global trigger, use the POST request that includes the location
* endpoint in the path (ex. v1/projects/{projectId}/locations/{region}/triggers/{triggerId}:run).
* The POST request that does not include the location endpoint in the path can only be used when
* running global triggers.
*
* <p>Sample code:
*
* <pre>{@code
Expand All @@ -1640,7 +1645,8 @@ public final UnaryCallable<UpdateBuildTriggerRequest, BuildTrigger> updateBuildT
*
* @param projectId Required. ID of the project.
* @param triggerId Required. ID of the trigger.
* @param source Source to build against this trigger.
* @param source Source to build against this trigger. Branch and tag names cannot consist of
* regular expressions.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Build, BuildOperationMetadata> runBuildTriggerAsync(
Expand All @@ -1658,6 +1664,11 @@ public final OperationFuture<Build, BuildOperationMetadata> runBuildTriggerAsync
/**
* Runs a `BuildTrigger` at a particular source revision.
*
* <p>To run a regional or global trigger, use the POST request that includes the location
* endpoint in the path (ex. v1/projects/{projectId}/locations/{region}/triggers/{triggerId}:run).
* The POST request that does not include the location endpoint in the path can only be used when
* running global triggers.
*
* <p>Sample code:
*
* <pre>{@code
Expand Down Expand Up @@ -1690,6 +1701,11 @@ public final OperationFuture<Build, BuildOperationMetadata> runBuildTriggerAsync
/**
* Runs a `BuildTrigger` at a particular source revision.
*
* <p>To run a regional or global trigger, use the POST request that includes the location
* endpoint in the path (ex. v1/projects/{projectId}/locations/{region}/triggers/{triggerId}:run).
* The POST request that does not include the location endpoint in the path can only be used when
* running global triggers.
*
* <p>Sample code:
*
* <pre>{@code
Expand Down Expand Up @@ -1722,6 +1738,11 @@ public final OperationFuture<Build, BuildOperationMetadata> runBuildTriggerAsync
/**
* Runs a `BuildTrigger` at a particular source revision.
*
* <p>To run a regional or global trigger, use the POST request that includes the location
* endpoint in the path (ex. v1/projects/{projectId}/locations/{region}/triggers/{triggerId}:run).
* The POST request that does not include the location endpoint in the path can only be used when
* running global triggers.
*
* <p>Sample code:
*
* <pre>{@code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.RequestParamsBuilder;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.api.pathtemplate.PathTemplate;
import com.google.cloudbuild.v1.ApproveBuildRequest;
import com.google.cloudbuild.v1.Build;
import com.google.cloudbuild.v1.BuildOperationMetadata;
Expand Down Expand Up @@ -294,6 +295,41 @@ public class GrpcCloudBuildStub extends CloudBuildStub {
private final GrpcOperationsStub operationsStub;
private final GrpcStubCallableFactory callableFactory;

private static final PathTemplate CREATE_BUILD_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}");
private static final PathTemplate GET_BUILD_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/builds/*");
private static final PathTemplate LIST_BUILDS_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}");
private static final PathTemplate CANCEL_BUILD_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/builds/*");
private static final PathTemplate RETRY_BUILD_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/builds/*");
private static final PathTemplate APPROVE_BUILD_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/builds/*");
private static final PathTemplate CREATE_BUILD_TRIGGER_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}");
private static final PathTemplate GET_BUILD_TRIGGER_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/triggers/*");
private static final PathTemplate LIST_BUILD_TRIGGERS_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}");
private static final PathTemplate DELETE_BUILD_TRIGGER_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/triggers/*");
private static final PathTemplate UPDATE_BUILD_TRIGGER_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/triggers/*");
private static final PathTemplate RUN_BUILD_TRIGGER_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/triggers/*");
private static final PathTemplate CREATE_WORKER_POOL_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}");
private static final PathTemplate GET_WORKER_POOL_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/workerPools/*");
private static final PathTemplate DELETE_WORKER_POOL_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/workerPools/*");
private static final PathTemplate UPDATE_WORKER_POOL_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}/workerPools/*");
private static final PathTemplate LIST_WORKER_POOLS_0_PATH_TEMPLATE =
PathTemplate.create("projects/*/locations/{location=*}");

public static final GrpcCloudBuildStub create(CloudBuildStubSettings settings)
throws IOException {
return new GrpcCloudBuildStub(settings, ClientContext.create(settings));
Expand Down Expand Up @@ -338,8 +374,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(request.getParent(), "location", CREATE_BUILD_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -349,9 +384,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("id", String.valueOf(request.getId()));
builder.add("name", String.valueOf(request.getName()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(request.getName(), "location", GET_BUILD_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -361,8 +394,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(request.getParent(), "location", LIST_BUILDS_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -372,9 +404,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("id", String.valueOf(request.getId()));
builder.add("name", String.valueOf(request.getName()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(request.getName(), "location", CANCEL_BUILD_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -384,9 +414,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("id", String.valueOf(request.getId()));
builder.add("name", String.valueOf(request.getName()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(request.getName(), "location", RETRY_BUILD_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -396,7 +424,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
builder.add(request.getName(), "location", APPROVE_BUILD_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -406,8 +434,8 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(
request.getParent(), "location", CREATE_BUILD_TRIGGER_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -417,9 +445,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add("trigger_id", String.valueOf(request.getTriggerId()));
builder.add(request.getName(), "location", GET_BUILD_TRIGGER_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -430,8 +456,8 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(
request.getParent(), "location", LIST_BUILD_TRIGGERS_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -441,9 +467,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add("trigger_id", String.valueOf(request.getTriggerId()));
builder.add(request.getName(), "location", DELETE_BUILD_TRIGGER_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -453,11 +477,12 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add(
"trigger.resource_name",
String.valueOf(request.getTrigger().getResourceName()));
builder.add("trigger_id", String.valueOf(request.getTriggerId()));
if (request.getTrigger() != null) {
builder.add(
request.getTrigger().getResourceName(),
"location",
UPDATE_BUILD_TRIGGER_0_PATH_TEMPLATE);
}
return builder.build();
})
.build();
Expand All @@ -467,9 +492,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
builder.add("project_id", String.valueOf(request.getProjectId()));
builder.add("trigger_id", String.valueOf(request.getTriggerId()));
builder.add(request.getName(), "location", RUN_BUILD_TRIGGER_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -493,7 +516,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
builder.add(request.getParent(), "location", CREATE_WORKER_POOL_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -503,7 +526,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
builder.add(request.getName(), "location", GET_WORKER_POOL_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -513,7 +536,7 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
builder.add(request.getName(), "location", DELETE_WORKER_POOL_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand All @@ -523,8 +546,12 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add(
"worker_pool.name", String.valueOf(request.getWorkerPool().getName()));
if (request.getWorkerPool() != null) {
builder.add(
request.getWorkerPool().getName(),
"location",
UPDATE_WORKER_POOL_0_PATH_TEMPLATE);
}
return builder.build();
})
.build();
Expand All @@ -535,7 +562,8 @@ protected GrpcCloudBuildStub(
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
builder.add(
request.getParent(), "location", LIST_WORKER_POOLS_0_PATH_TEMPLATE);
return builder.build();
})
.build();
Expand Down
Loading
Loading