Skip to content

Commit d1a5d1b

Browse files
Merged changes from main
2 parents 0557a66 + 7792ddb commit d1a5d1b

File tree

43 files changed

+2241
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2241
-62
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static void createReservation(
107107

108108
// Wait for the create reservation operation to complete.
109109
Operation response =
110-
reservationsClient.insertAsync(projectId, zone, reservation).get(5, TimeUnit.MINUTES);
110+
reservationsClient.insertAsync(projectId, zone, reservation).get(7, TimeUnit.MINUTES);
111111

112112
if (response.hasError()) {
113113
System.out.println("Reservation creation failed!" + response);

compute/cloud-client/src/test/java/compute/Util.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public abstract class Util {
5757
// resources
5858
// and delete the listed resources based on the timestamp.
5959

60-
private static final int DELETION_THRESHOLD_TIME_MINUTES = 45;
60+
private static final int DELETION_THRESHOLD_TIME_MINUTES = 30;
6161
// comma separate list of zone names
6262
private static final String TEST_ZONES_NAME = "JAVA_DOCS_COMPUTE_TEST_ZONES";
6363
private static final String DEFAULT_ZONES = "us-central1-a,us-west1-a,asia-south1-a";
@@ -238,7 +238,7 @@ public static void cleanUpExistingStoragePool(
238238
throws IOException, ExecutionException, InterruptedException, TimeoutException {
239239
try (StoragePoolsClient storagePoolsClient = StoragePoolsClient.create()) {
240240
for (StoragePool storagePool : storagePoolsClient.list(projectId, zone).iterateAll()) {
241-
if (containPrefixToDeleteAndZone(projectId, prefixToDelete, zone)
241+
if (containPrefixToDeleteAndZone(storagePool, prefixToDelete, zone)
242242
&& isCreatedBeforeThresholdTime(storagePool.getCreationTimestamp())) {
243243
deleteStoragePool(projectId, zone, storagePool.getName());
244244
}
@@ -255,7 +255,7 @@ public static void deleteStoragePool(String project, String zone, String storage
255255
.setZone(zone)
256256
.setStoragePool(storagePoolName)
257257
.build();
258-
Operation operation = storagePoolsClient.deleteAsync(request).get(1, TimeUnit.MINUTES);
258+
Operation operation = storagePoolsClient.deleteAsync(request).get(3, TimeUnit.MINUTES);
259259
if (operation.hasError()) {
260260
System.out.println("StoragePool deletion failed!");
261261
throw new Error(operation.getError().toString());

compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.junit.FixMethodOrder;
3333
import org.junit.jupiter.api.AfterAll;
3434
import org.junit.jupiter.api.BeforeAll;
35+
import org.junit.jupiter.api.Disabled;
3536
import org.junit.jupiter.api.Test;
3637
import org.junit.jupiter.api.Timeout;
3738
import org.junit.runner.RunWith;
@@ -72,9 +73,9 @@ public static void cleanup()
7273
throws IOException, InterruptedException, ExecutionException, TimeoutException {
7374
// Delete all disks created for testing.
7475
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_NAME);
75-
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
76+
//DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
7677

77-
Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
78+
//Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
7879
}
7980

8081
@Test
@@ -95,6 +96,7 @@ public void stage1_CreateHyperdiskTest()
9596
Assert.assertTrue(hyperdisk.getZone().contains(ZONE));
9697
}
9798

99+
@Disabled
98100
@Test
99101
public void stage1_CreateHyperdiskStoragePoolTest()
100102
throws IOException, ExecutionException, InterruptedException, TimeoutException {
@@ -114,6 +116,7 @@ public void stage1_CreateHyperdiskStoragePoolTest()
114116
Assert.assertTrue(storagePool.getZone().contains(ZONE));
115117
}
116118

119+
@Disabled
117120
@Test
118121
public void stage2_CreateHyperdiskStoragePoolTest()
119122
throws IOException, ExecutionException, InterruptedException, TimeoutException {

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,32 @@
2323
import com.google.api.gax.rpc.NotFoundException;
2424
import com.google.cloud.compute.v1.Reservation;
2525
import compute.Util;
26+
import java.io.ByteArrayOutputStream;
2627
import java.io.IOException;
28+
import java.io.PrintStream;
2729
import java.util.List;
2830
import java.util.UUID;
2931
import java.util.concurrent.ExecutionException;
3032
import java.util.concurrent.TimeUnit;
3133
import java.util.concurrent.TimeoutException;
3234
import org.junit.Assert;
35+
import org.junit.FixMethodOrder;
3336
import org.junit.jupiter.api.AfterAll;
3437
import org.junit.jupiter.api.Assertions;
3538
import org.junit.jupiter.api.BeforeAll;
3639
import org.junit.jupiter.api.Test;
3740
import org.junit.jupiter.api.Timeout;
3841
import org.junit.runner.RunWith;
3942
import org.junit.runners.JUnit4;
43+
import org.junit.runners.MethodSorters;
4044

4145
@RunWith(JUnit4.class)
4246
@Timeout(value = 25, unit = TimeUnit.MINUTES)
43-
class CrudOperationsReservationIT {
47+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
48+
public class CrudOperationsReservationIT {
4449

4550
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
46-
private static final String ZONE = "us-central1-a";
51+
private static final String ZONE = "us-west1-a";
4752
private static String RESERVATION_NAME;
4853
private static final int NUMBER_OF_VMS = 3;
4954
static String javaVersion = System.getProperty("java.version").substring(0, 2);
@@ -64,9 +69,6 @@ public static void setUp()
6469

6570
// Cleanup existing stale resources.
6671
Util.cleanUpExistingReservations("test-reservation-" + javaVersion, PROJECT_ID, ZONE);
67-
68-
CreateReservation.createReservation(
69-
PROJECT_ID, RESERVATION_NAME, NUMBER_OF_VMS, ZONE);
7072
}
7173

7274
@AfterAll
@@ -82,8 +84,22 @@ public static void cleanup()
8284
}
8385

8486
@Test
85-
public void testGetReservation()
86-
throws IOException {
87+
public void firstCreateReservationTest()
88+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
89+
final PrintStream out = System.out;
90+
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
91+
System.setOut(new PrintStream(stdOut));
92+
CreateReservation.createReservation(
93+
PROJECT_ID, RESERVATION_NAME, NUMBER_OF_VMS, ZONE);
94+
95+
assertThat(stdOut.toString()).contains("Reservation created. Operation Status: DONE");
96+
97+
stdOut.close();
98+
System.setOut(out);
99+
}
100+
101+
@Test
102+
public void secondGetReservationTest() throws IOException {
87103
Reservation reservation = GetReservation.getReservation(
88104
PROJECT_ID, RESERVATION_NAME, ZONE);
89105

@@ -92,7 +108,7 @@ public void testGetReservation()
92108
}
93109

94110
@Test
95-
public void testListReservation() throws IOException {
111+
public void thirdListReservationTest() throws IOException {
96112
List<Reservation> reservations =
97113
ListReservations.listReservations(PROJECT_ID, ZONE);
98114

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,26 @@ public static void setUp()
9292
throws IOException, ExecutionException, InterruptedException, TimeoutException {
9393
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
9494
requireEnvVar("GOOGLE_CLOUD_PROJECT");
95+
final PrintStream out = System.out;
96+
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
97+
System.setOut(new PrintStream(stdOut));
9598

9699
// Cleanup existing stale resources.
97100
Util.cleanUpExistingInstanceTemplates("test-global-inst-temp-" + javaVersion, PROJECT_ID);
98101
Util.cleanUpExistingRegionalInstanceTemplates(
99102
"test-regional-inst-temp-" + javaVersion, PROJECT_ID, ZONE);
100-
Util.cleanUpExistingReservations("test-reserv-global-" + javaVersion, PROJECT_ID, ZONE);
101-
Util.cleanUpExistingReservations("test-reserv-regional-" + javaVersion, PROJECT_ID, ZONE);
103+
Util.cleanUpExistingReservations("test-reservation-global-" + javaVersion, PROJECT_ID, ZONE);
104+
Util.cleanUpExistingReservations("test-reservation-regional-" + javaVersion, PROJECT_ID, ZONE);
102105
Util.cleanUpExistingInstanceTemplates("test-shared-inst-temp-" + javaVersion, PROJECT_ID);
103106

104107
// Initialize the client once for all tests
105108
reservationsClient = ReservationsClient.create();
106109

107-
RESERVATION_NAME_GLOBAL = "test-reserv-global-" + javaVersion + "-"
110+
RESERVATION_NAME_GLOBAL = "test-reservation-global-" + javaVersion + "-"
108111
+ UUID.randomUUID().toString().substring(0, 8);
109-
RESERVATION_NAME_REGIONAL = "test-reserv-regional-" + javaVersion + "-"
112+
RESERVATION_NAME_REGIONAL = "test-reservation-regional-" + javaVersion + "-"
110113
+ UUID.randomUUID().toString().substring(0, 8);
111-
RESERVATION_NAME_SHARED = "test-reserv-shared-" + javaVersion + "-"
114+
RESERVATION_NAME_SHARED = "test-reservation-shared-" + javaVersion + "-"
112115
+ UUID.randomUUID().toString().substring(0, 8);
113116

114117
GLOBAL_INSTANCE_TEMPLATE_URI = String.format("projects/%s/global/instanceTemplates/%s",
@@ -125,10 +128,15 @@ public static void setUp()
125128

126129
// Create instance template with GLOBAL location.
127130
CreateInstanceTemplate.createInstanceTemplate(PROJECT_ID, GLOBAL_INSTANCE_TEMPLATE_NAME);
128-
131+
assertThat(stdOut.toString())
132+
.contains("Instance Template Operation Status " + GLOBAL_INSTANCE_TEMPLATE_NAME);
129133
// Create instance template with REGIONAL location.
130134
CreateRegionalInstanceTemplate.createRegionalInstanceTemplate(
131135
PROJECT_ID, REGION, REGIONAL_INSTANCE_TEMPLATE_NAME);
136+
assertThat(stdOut.toString()).contains("Instance Template Operation Status: DONE");
137+
138+
stdOut.close();
139+
System.setOut(out);
132140
}
133141

134142
@AfterAll
@@ -219,7 +227,6 @@ public void testCreateReservationWithRegionInstanceTemplate()
219227
@Test
220228
public void testCreateSharedReservation()
221229
throws ExecutionException, InterruptedException, TimeoutException {
222-
223230
// Mock the ReservationsClient
224231
ReservationsClient mockReservationsClient = mock(ReservationsClient.class);
225232

dataplex/snippets/src/main/java/dataplex/CreateAspectType.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public static void main(String[] args) throws Exception {
3232
String location = "MY_LOCATION";
3333
String aspectTypeId = "MY_ASPECT_TYPE_ID";
3434

35-
LocationName locationName = LocationName.of(projectId, location);
3635
AspectType.MetadataTemplate aspectField =
3736
AspectType.MetadataTemplate.newBuilder()
3837
// The name must follow regex ^(([a-zA-Z]{1})([\\w\\-_]{0,62}))$
@@ -55,15 +54,18 @@ public static void main(String[] args) throws Exception {
5554
.build())
5655
.build();
5756
List<AspectType.MetadataTemplate> aspectFields = List.of(aspectField);
58-
AspectType createdAspectType = createAspectType(locationName, aspectTypeId, aspectFields);
57+
AspectType createdAspectType =
58+
createAspectType(projectId, location, aspectTypeId, aspectFields);
5959
System.out.println("Successfully created aspect type: " + createdAspectType.getName());
6060
}
6161

6262
public static AspectType createAspectType(
63-
LocationName locationName,
63+
String projectId,
64+
String location,
6465
String aspectTypeId,
6566
List<AspectType.MetadataTemplate> aspectFields)
6667
throws Exception {
68+
LocationName locationName = LocationName.of(projectId, location);
6769
AspectType aspectType =
6870
AspectType.newBuilder()
6971
.setDescription("description of the aspect type")
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package dataplex;
18+
19+
// [START dataplex_create_entry_type]
20+
import com.google.cloud.dataplex.v1.CatalogServiceClient;
21+
import com.google.cloud.dataplex.v1.EntryType;
22+
import com.google.cloud.dataplex.v1.LocationName;
23+
24+
// Samples to create Entry Type
25+
public class CreateEntryType {
26+
27+
public static void main(String[] args) throws Exception {
28+
// TODO(developer): Replace these variables before running the sample.
29+
String projectId = "MY_PROJECT_ID";
30+
// Available locations: https://cloud.google.com/dataplex/docs/locations
31+
String location = "MY_LOCATION";
32+
String entryTypeId = "MY_ENTRY_TYPE_ID";
33+
34+
EntryType createdEntryType = createEntryType(projectId, location, entryTypeId);
35+
System.out.println("Successfully created entry type: " + createdEntryType.getName());
36+
}
37+
38+
public static EntryType createEntryType(String projectId, String location, String entryTypeId)
39+
throws Exception {
40+
LocationName locationName = LocationName.of(projectId, location);
41+
EntryType entryType =
42+
EntryType.newBuilder()
43+
.setDescription("description of the entry type")
44+
// Required aspects will need to be attached to every entry created for this entry type.
45+
// You cannot change required aspects for entry type once it is created.
46+
.addRequiredAspects(
47+
EntryType.AspectInfo.newBuilder()
48+
// Example of system aspect type.
49+
// It is also possible to specify custom aspect type.
50+
.setType("projects/dataplex-types/locations/global/aspectTypes/schema")
51+
.build())
52+
.build();
53+
54+
// Initialize client that will be used to send requests. This client only needs to be created
55+
// once, and can be reused for multiple requests. After completing all of your requests, call
56+
// the "close" method on the client to safely clean up any remaining background resources,
57+
// or use "try-with-close" statement to do this automatically.
58+
try (CatalogServiceClient client = CatalogServiceClient.create()) {
59+
return client.createEntryTypeAsync(locationName, entryType, entryTypeId).get();
60+
}
61+
}
62+
}
63+
// [END dataplex_create_entry_type]

dataplex/snippets/src/main/java/dataplex/DeleteAspectType.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ public static void main(String[] args) throws Exception {
3030
String location = "MY_LOCATION";
3131
String aspectTypeId = "MY_ASPECT_TYPE_ID";
3232

33-
AspectTypeName aspectTypeName = AspectTypeName.of(projectId, location, aspectTypeId);
34-
deleteAspectType(aspectTypeName);
33+
deleteAspectType(projectId, location, aspectTypeId);
3534
System.out.println("Successfully deleted aspect type");
3635
}
3736

38-
public static void deleteAspectType(AspectTypeName aspectTypeName) throws Exception {
37+
public static void deleteAspectType(String projectId, String location, String aspectTypeId)
38+
throws Exception {
39+
AspectTypeName aspectTypeName = AspectTypeName.of(projectId, location, aspectTypeId);
40+
3941
// Initialize client that will be used to send requests. This client only needs to be created
4042
// once, and can be reused for multiple requests. After completing all of your requests, call
4143
// the "close" method on the client to safely clean up any remaining background resources,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package dataplex;
18+
19+
// [START dataplex_delete_entry_type]
20+
import com.google.cloud.dataplex.v1.CatalogServiceClient;
21+
import com.google.cloud.dataplex.v1.EntryTypeName;
22+
23+
// Sample to delete Entry Type
24+
public class DeleteEntryType {
25+
26+
public static void main(String[] args) throws Exception {
27+
// TODO(developer): Replace these variables before running the sample.
28+
String projectId = "MY_PROJECT_ID";
29+
// Available locations: https://cloud.google.com/dataplex/docs/locations
30+
String location = "MY_LOCATION";
31+
String entryTypeId = "MY_ENTRY_TYPE_ID";
32+
33+
deleteEntryType(projectId, location, entryTypeId);
34+
System.out.println("Successfully deleted entry type");
35+
}
36+
37+
public static void deleteEntryType(String projectId, String location, String entryTypeId)
38+
throws Exception {
39+
EntryTypeName entryTypeName = EntryTypeName.of(projectId, location, entryTypeId);
40+
41+
// Initialize client that will be used to send requests. This client only needs to be created
42+
// once, and can be reused for multiple requests. After completing all of your requests, call
43+
// the "close" method on the client to safely clean up any remaining background resources,
44+
// or use "try-with-close" statement to do this automatically.
45+
try (CatalogServiceClient client = CatalogServiceClient.create()) {
46+
client.deleteEntryTypeAsync(entryTypeName).get();
47+
}
48+
}
49+
}
50+
// [END dataplex_delete_entry_type]

dataplex/snippets/src/main/java/dataplex/GetAspectType.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ public static void main(String[] args) throws IOException {
3232
String location = "MY_LOCATION";
3333
String aspectTypeId = "MY_ASPECT_TYPE_ID";
3434

35-
AspectTypeName aspectTypeName = AspectTypeName.of(projectId, location, aspectTypeId);
36-
AspectType aspectType = getAspectType(aspectTypeName);
35+
AspectType aspectType = getAspectType(projectId, location, aspectTypeId);
3736
System.out.println("Aspect type retrieved successfully: " + aspectType.getName());
3837
}
3938

40-
public static AspectType getAspectType(AspectTypeName aspectTypeName) throws IOException {
39+
public static AspectType getAspectType(String projectId, String location, String aspectTypeId)
40+
throws IOException {
41+
AspectTypeName aspectTypeName = AspectTypeName.of(projectId, location, aspectTypeId);
42+
4143
// Initialize client that will be used to send requests. This client only needs to be created
4244
// once, and can be reused for multiple requests. After completing all of your requests, call
4345
// the "close" method on the client to safely clean up any remaining background resources,

0 commit comments

Comments
 (0)