Skip to content

Commit 9f1271c

Browse files
Merged changes from main
2 parents c2e84ff + 7792ddb commit 9f1271c

File tree

42 files changed

+2230
-55
lines changed

Some content is hidden

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

42 files changed

+2230
-55
lines changed

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,32 @@
2828
import compute.CreateInstance;
2929
import compute.DeleteInstance;
3030
import compute.Util;
31+
import java.io.ByteArrayOutputStream;
3132
import java.io.IOException;
33+
import java.io.PrintStream;
3234
import java.util.List;
3335
import java.util.UUID;
3436
import java.util.concurrent.ExecutionException;
3537
import java.util.concurrent.TimeUnit;
3638
import java.util.concurrent.TimeoutException;
3739
import org.junit.Assert;
40+
import org.junit.FixMethodOrder;
3841
import org.junit.jupiter.api.AfterAll;
3942
import org.junit.jupiter.api.Assertions;
4043
import org.junit.jupiter.api.BeforeAll;
4144
import org.junit.jupiter.api.Test;
4245
import org.junit.jupiter.api.Timeout;
4346
import org.junit.runner.RunWith;
4447
import org.junit.runners.JUnit4;
48+
import org.junit.runners.MethodSorters;
4549

4650
@RunWith(JUnit4.class)
4751
@Timeout(value = 25, unit = TimeUnit.MINUTES)
52+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
4853
public class CrudOperationsReservationIT {
4954

5055
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
51-
private static final String ZONE = "us-central1-a";
56+
private static final String ZONE = "us-west1-a";
5257
private static ReservationsClient reservationsClient;
5358
private static InstancesClient instancesClient;
5459
private static String RESERVATION_NAME;
@@ -84,8 +89,7 @@ public static void setUp()
8489
Util.cleanUpExistingReservations("test-reservation-from-vm-" + javaVersion, PROJECT_ID, ZONE);
8590

8691
CreateInstance.createInstance(PROJECT_ID, ZONE, INSTANCE_FOR_RESERVATION);
87-
CreateReservation.createReservation(
88-
PROJECT_ID, RESERVATION_NAME, NUMBER_OF_VMS, ZONE);
92+
8993
}
9094

9195
@AfterAll
@@ -109,7 +113,22 @@ public static void cleanup()
109113
}
110114

111115
@Test
112-
public void testGetReservation()
116+
public void firstCreateReservationTest()
117+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
118+
final PrintStream out = System.out;
119+
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
120+
System.setOut(new PrintStream(stdOut));
121+
CreateReservation.createReservation(
122+
PROJECT_ID, RESERVATION_NAME, NUMBER_OF_VMS, ZONE);
123+
124+
assertThat(stdOut.toString()).contains("Reservation created. Operation Status: DONE");
125+
126+
stdOut.close();
127+
System.setOut(out);
128+
}
129+
130+
@Test
131+
public void secondGetReservationTest()
113132
throws IOException {
114133
Reservation reservation = GetReservation.getReservation(
115134
PROJECT_ID, RESERVATION_NAME, ZONE);
@@ -119,7 +138,7 @@ public void testGetReservation()
119138
}
120139

121140
@Test
122-
public void testListReservation() throws IOException {
141+
public void thirdListReservationTest() throws IOException {
123142
List<Reservation> reservations =
124143
ListReservations.listReservations(PROJECT_ID, ZONE);
125144

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public static void setUp()
8383
Util.cleanUpExistingRegionalInstanceTemplates(
8484
"test-regional-inst-temp-" + javaVersion, PROJECT_ID, ZONE);
8585
Util.cleanUpExistingReservations(
86-
"test-reserv-global-" + javaVersion, PROJECT_ID, ZONE);
87-
Util.cleanUpExistingReservations("test-reserv-regional-" + javaVersion, PROJECT_ID, ZONE);
86+
"test-reservation-global-" + javaVersion, PROJECT_ID, ZONE);
87+
Util.cleanUpExistingReservations("test-reservation-regional-" + javaVersion, PROJECT_ID, ZONE);
8888

8989
// Initialize the client once for all tests
9090
reservationsClient = ReservationsClient.create();
9191

92-
RESERVATION_NAME_GLOBAL = "test-reserv-global-" + javaVersion + "-"
92+
RESERVATION_NAME_GLOBAL = "test-reservation-global-" + javaVersion + "-"
9393
+ UUID.randomUUID().toString().substring(0, 8);
94-
RESERVATION_NAME_REGIONAL = "test-reserv-regional-" + javaVersion + "-"
94+
RESERVATION_NAME_REGIONAL = "test-reservation-regional-" + javaVersion + "-"
9595
+ UUID.randomUUID().toString().substring(0, 8);
9696
GLOBAL_INSTANCE_TEMPLATE_URI = String.format("projects/%s/global/instanceTemplates/%s",
9797
PROJECT_ID, GLOBAL_INSTANCE_TEMPLATE_NAME);

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,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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_get_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.EntryTypeName;
23+
import java.io.IOException;
24+
25+
// Sample to get Entry Type
26+
public class GetEntryType {
27+
28+
public static void main(String[] args) throws IOException {
29+
// TODO(developer): Replace these variables before running the sample.
30+
String projectId = "MY_PROJECT_ID";
31+
// Available locations: https://cloud.google.com/dataplex/docs/locations
32+
String location = "MY_LOCATION";
33+
String entryTypeId = "MY_ENTRY_TYPE_ID";
34+
35+
EntryType entryType = getEntryType(projectId, location, entryTypeId);
36+
System.out.println("Entry type retrieved successfully: " + entryType.getName());
37+
}
38+
39+
public static EntryType getEntryType(String projectId, String location, String entryTypeId)
40+
throws IOException {
41+
EntryTypeName entryTypeName = EntryTypeName.of(projectId, location, entryTypeId);
42+
43+
// Initialize client that will be used to send requests. This client only needs to be created
44+
// once, and can be reused for multiple requests. After completing all of your requests, call
45+
// the "close" method on the client to safely clean up any remaining background resources,
46+
// or use "try-with-close" statement to do this automatically.
47+
try (CatalogServiceClient client = CatalogServiceClient.create()) {
48+
return client.getEntryType(entryTypeName);
49+
}
50+
}
51+
}
52+
// [END dataplex_get_entry_type]

0 commit comments

Comments
 (0)