Skip to content

Commit d0ca1da

Browse files
Fixed empty lines and tests, deleted cleanup method
1 parent 435dcd5 commit d0ca1da

11 files changed

+26
-151
lines changed

tpu/src/main/java/tpu/CreateQueuedResourceWithNetwork.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ public static QueuedResource createQueuedResourceWithNetwork(
128128
.setQueuedResourceId(queuedResourceId)
129129
.build();
130130

131-
QueuedResource response = tpuClient.createQueuedResourceAsync(request).get();
132131
// You can wait until TPU Node is READY,
133132
// and check its status using getTpuVm() from "tpu_vm_get" sample.
134-
System.out.println("Queued Resource created: " + queuedResourceId);
135-
return response;
133+
134+
return tpuClient.createQueuedResourceAsync(request).get();
136135
}
137136
}
138137
}

tpu/src/main/java/tpu/CreateTpuVm.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void main(String[] args)
3939
// see https://cloud.google.com/tpu/docs/regions-zones
4040
String zone = "europe-west4-a";
4141
// The name for your TPU.
42-
String nodeName = "YOUR_TPY_NAME";
42+
String nodeName = "YOUR_TPU_NAME";
4343
// The accelerator type that specifies the version and size of the Cloud TPU you want to create.
4444
// For more information about supported accelerator types for each TPU version,
4545
// see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
@@ -90,9 +90,7 @@ public static Node createTpuVm(
9090
.setNode(tpuVm)
9191
.build();
9292

93-
Node response = tpuClient.createNodeAsync(request).get();
94-
System.out.printf("TPU VM created: %s\n", response.getName());
95-
return response;
93+
return tpuClient.createNodeAsync(request).get();
9694
}
9795
}
9896
}

tpu/src/main/java/tpu/CreateTpuWithTopologyFlag.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void main(String[] args)
4141
// see https://cloud.google.com/tpu/docs/regions-zones
4242
String zone = "europe-west4-a";
4343
// The name for your TPU.
44-
String nodeName = "YOUR_TPY_NAME";
44+
String nodeName = "YOUR_TPU_NAME";
4545
// The version of the Cloud TPU you want to create.
4646
// Available options: TYPE_UNSPECIFIED = 0, V2 = 2, V3 = 4, V4 = 7
4747
Type tpuVersion = AcceleratorConfig.Type.V2;
@@ -101,9 +101,7 @@ public static Node createTpuWithTopologyFlag(String projectId, String zone, Stri
101101
.setNode(tpuVm)
102102
.build();
103103

104-
Node response = tpuClient.createNodeAsync(request).get();
105-
System.out.printf("TPU VM created: %s\n", response.getName());
106-
return response;
104+
return tpuClient.createNodeAsync(request).get();
107105
}
108106
}
109107
}

tpu/src/main/java/tpu/DeleteForceQueuedResource.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package tpu;
1818

1919
//[START tpu_queued_resources_delete_force]
20-
2120
import com.google.api.gax.retrying.RetrySettings;
2221
import com.google.api.gax.rpc.UnknownException;
2322
import com.google.cloud.tpu.v2alpha1.DeleteQueuedResourceRequest;

tpu/src/main/java/tpu/DeleteTpuVm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void main(String[] args)
3939
// see https://cloud.google.com/tpu/docs/regions-zones
4040
String zone = "europe-west4-a";
4141
// The name for your TPU.
42-
String nodeName = "YOUR_TPY_NAME";
42+
String nodeName = "YOUR_TPU_NAME";
4343

4444
deleteTpuVm(projectId, zone, nodeName);
4545
}

tpu/src/main/java/tpu/GetQueuedResource.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package tpu;
1818

1919
//[START tpu_queued_resources_get]
20-
2120
import com.google.cloud.tpu.v2alpha1.GetQueuedResourceRequest;
2221
import com.google.cloud.tpu.v2alpha1.QueuedResource;
2322
import com.google.cloud.tpu.v2alpha1.TpuClient;

tpu/src/main/java/tpu/GetTpuVm.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void main(String[] args) throws IOException {
3434
// see https://cloud.google.com/tpu/docs/regions-zones
3535
String zone = "europe-west4-a";
3636
// The name for your TPU.
37-
String nodeName = "YOUR_TPY_NAME";
37+
String nodeName = "YOUR_TPU_NAME";
3838

3939
getTpuVm(projectId, zone, nodeName);
4040
}
@@ -46,7 +46,6 @@ public static Node getTpuVm(String projectId, String zone, String nodeName)
4646
// once, and can be reused for multiple requests.
4747
try (TpuClient tpuClient = TpuClient.create()) {
4848
String name = NodeName.of(projectId, zone, nodeName).toString();
49-
5049
GetNodeRequest request = GetNodeRequest.newBuilder().setName(name).build();
5150

5251
return tpuClient.getNode(request);

tpu/src/test/java/tpu/CreateTpuWithTopologyFlagIT.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
public class CreateTpuWithTopologyFlagIT {
4242
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
4343
private static final String ZONE = "europe-west4-a";
44-
static String javaVersion = System.getProperty("java.version").substring(0, 2);
45-
private static final String NODE_NAME = "test-tpu-topology-" + javaVersion + "-"
46-
+ UUID.randomUUID().toString().substring(0, 8);
44+
private static final String NODE_NAME = "test-tpu-topology-" + UUID.randomUUID();
4745
private static final Type ACCELERATOR_TYPE = AcceleratorConfig.Type.V2;
4846
private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.14.1";
4947
private static final String TOPOLOGY = "2x2";
@@ -54,20 +52,15 @@ public static void requireEnvVar(String envVarName) {
5452
}
5553

5654
@BeforeAll
57-
public static void setUp()
58-
throws IOException, ExecutionException, InterruptedException {
55+
public static void setUp() {
5956
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
6057
requireEnvVar("GOOGLE_CLOUD_PROJECT");
61-
62-
// Cleanup existing stale resources.
63-
Util.cleanUpExistingTpu("test-tpu-topology-" + javaVersion, PROJECT_ID, ZONE);
6458
}
6559

6660
@AfterAll
6761
public static void cleanup() throws Exception {
6862
DeleteTpuVm.deleteTpuVm(PROJECT_ID, ZONE, NODE_NAME);
6963

70-
// Test that TPUs is deleted
7164
Assertions.assertThrows(
7265
NotFoundException.class,
7366
() -> GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME));

tpu/src/test/java/tpu/CreateQueuedResourceWithNetworkIT.java renamed to tpu/src/test/java/tpu/QueuedResourceIT.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
package tpu;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static com.google.common.truth.Truth.assertWithMessage;
2021

2122
import com.google.api.gax.rpc.NotFoundException;
2223
import com.google.cloud.tpu.v2alpha1.QueuedResource;
23-
import java.io.IOException;
2424
import java.util.UUID;
2525
import java.util.concurrent.TimeUnit;
2626
import org.junit.Test;
@@ -33,24 +33,24 @@
3333

3434
@RunWith(JUnit4.class)
3535
@Timeout(value = 6, unit = TimeUnit.MINUTES)
36-
public class CreateQueuedResourceWithNetworkIT {
37-
36+
public class QueuedResourceIT {
3837
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
3938
private static final String ZONE = "europe-west4-a";
40-
static String javaVersion = System.getProperty("java.version").substring(0, 2);
41-
private static final String NODE_NAME = "test-tpu-queued-resource-network-" + javaVersion + "-"
42-
+ UUID.randomUUID().toString().substring(0, 8);
39+
private static final String NODE_NAME = "test-tpu-queued-resource-network-" + UUID.randomUUID();
4340
private static final String TPU_TYPE = "v2-8";
4441
private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.14.1";
45-
private static final String QUEUED_RESOURCE_NAME = "queued-resource-network-" + javaVersion + "-"
46-
+ UUID.randomUUID().toString().substring(0, 8);
42+
private static final String QUEUED_RESOURCE_NAME = "queued-resource-network-" + UUID.randomUUID();
4743
private static final String NETWORK_NAME = "default";
4844

49-
@BeforeAll
50-
public static void setUp() throws IOException {
45+
public static void requireEnvVar(String envVarName) {
46+
assertWithMessage(String.format("Missing environment variable '%s' ", envVarName))
47+
.that(System.getenv(envVarName)).isNotEmpty();
48+
}
5149

52-
// Cleanup existing stale resources.
53-
Util.cleanUpExistingQueuedResources("queued-resource-network-", PROJECT_ID, ZONE);
50+
@BeforeAll
51+
public static void setUp() {
52+
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
53+
requireEnvVar("GOOGLE_CLOUD_PROJECT");
5454
}
5555

5656
@AfterAll

tpu/src/test/java/tpu/TpuVmIT.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@
3939

4040
@RunWith(JUnit4.class)
4141
@Timeout(value = 15, unit = TimeUnit.MINUTES)
42-
@TestMethodOrder(MethodOrderer. OrderAnnotation. class)
42+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
4343
public class TpuVmIT {
4444
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
4545
private static final String ZONE = "us-central1-c";
46-
static String javaVersion = System.getProperty("java.version").substring(0, 2);
47-
private static final String NODE_NAME = "test-tpu-" + javaVersion + "-"
48-
+ UUID.randomUUID().toString().substring(0, 8);
46+
private static final String NODE_NAME = "test-tpu-" + UUID.randomUUID();
4947
private static final String TPU_TYPE = "v2-8";
5048
private static final String TPU_SOFTWARE_VERSION = "tpu-vm-base";
5149
private static final String NODE_PATH_NAME =
@@ -57,20 +55,16 @@ public static void requireEnvVar(String envVarName) {
5755
}
5856

5957
@BeforeAll
60-
public static void setUp()
61-
throws IOException, ExecutionException, InterruptedException {
58+
public static void setUp() {
6259
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
6360
requireEnvVar("GOOGLE_CLOUD_PROJECT");
64-
65-
// Cleanup existing stale resources.
66-
Util.cleanUpExistingTpu("test-tpu-" + javaVersion, PROJECT_ID, ZONE);
6761
}
6862

6963
@AfterAll
7064
public static void cleanup() throws Exception {
7165
DeleteTpuVm.deleteTpuVm(PROJECT_ID, ZONE, NODE_NAME);
7266

73-
// Test that TPUs is deleted
67+
// Test that TPUs are deleted
7468
Assertions.assertThrows(
7569
NotFoundException.class,
7670
() -> GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME));
@@ -79,7 +73,6 @@ public static void cleanup() throws Exception {
7973
@Test
8074
@Order(1)
8175
public void testCreateTpuVm() throws IOException, ExecutionException, InterruptedException {
82-
8376
Node node = CreateTpuVm.createTpuVm(
8477
PROJECT_ID, ZONE, NODE_NAME, TPU_TYPE, TPU_SOFTWARE_VERSION);
8578

0 commit comments

Comments
 (0)