Skip to content

Commit c05cf08

Browse files
Added comments
1 parent 21cb398 commit c05cf08

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compute/cloud-client/src/main/java/compute/reservation/CreateSharedReservation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public static void main(String[] args)
4242
// TODO(developer): Replace these variables before running the sample.
4343
// The ID of the project where you want to reserve resources
4444
// and where the instance template exists.
45+
// By default, no projects are allowed to create or modify shared reservations
46+
// in an organization. Add projects to the Shared Reservations Owner Projects
47+
// (compute.sharedReservationsOwnerProjects) organization policy constraint
48+
// to allow them to create and modify shared reservations.
49+
// For more information visit this page:
50+
// https://cloud.google.com/compute/docs/instances/reservations-shared#shared_reservation_constraint
4551
String projectId = "YOUR_PROJECT_ID";
4652
// Zone in which the reservation resides.
4753
String zone = "us-central1-a";
@@ -68,6 +74,10 @@ public void createSharedReservation(
6874

6975
ShareSettings shareSettings = ShareSettings.newBuilder()
7076
.setShareType(String.valueOf(ShareSettings.ShareType.SPECIFIC_PROJECTS))
77+
// The IDs of projects that can consume this reservation. You can include up to 100
78+
// consumer projects. These projects must be in the same organization as
79+
// the owner project. Don't include the owner project. By default, it is already allowed
80+
// to consume the reservation.
7181
.putProjectMap("CONSUMER_PROJECT_ID_1", ShareSettingsProjectConfig.newBuilder().build())
7282
.putProjectMap("CONSUMER_PROJECT_ID_2", ShareSettingsProjectConfig.newBuilder().build())
7383
.build();

compute/cloud-client/src/test/java/compute/reservation/ReservationIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public void testCreateSharedReservation()
253253
when(mockReservationsClient.insertAsync(PROJECT_ID, ZONE, reservation))
254254
.thenReturn(mockFuture);
255255

256-
// Mock the Operation
256+
// We should mock this operation as we don't have another project to share with.
257+
// Without mocking these test will fail.
257258
Operation mockOperation = mock(Operation.class);
258259
when(mockFuture.get(3, TimeUnit.MINUTES)).thenReturn(mockOperation);
259260
when(mockOperation.hasError()).thenReturn(false);

0 commit comments

Comments
 (0)