Skip to content

Commit ccfd268

Browse files
Fixed empty lines and tests, deleted cleanup method
1 parent 736c1fd commit ccfd268

File tree

11 files changed

+20
-132
lines changed

11 files changed

+20
-132
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,10 @@ public static QueuedResource createQueuedResourceWithNetwork(
127127
.setQueuedResource(queuedResource)
128128
.setQueuedResourceId(queuedResourceId)
129129
.build();
130-
131-
QueuedResource response = tpuClient.createQueuedResourceAsync(request).get();
132130
// You can wait until TPU Node is READY,
133131
// and check its status using getTpuVm() from "tpu_vm_get" sample.
134-
System.out.println("Queued Resource created: " + queuedResourceId);
135-
return response;
132+
133+
return tpuClient.createQueuedResourceAsync(request).get();
136134
}
137135
}
138136
}

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/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 & 1 deletion
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
}

tpu/src/main/java/tpu/StartTpuVm.java

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

4141
startTpuVm(projectId, zone, nodeName);
4242
}

tpu/src/main/java/tpu/StopTpuVm.java

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

4141
stopTpuVm(projectId, zone, nodeName);
4242
}

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

Lines changed: 10 additions & 6 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,7 +33,7 @@
3333

3434
@RunWith(JUnit4.class)
3535
@Timeout(value = 6, unit = TimeUnit.MINUTES)
36-
public class CreateQueuedResourceWithNetworkIT {
36+
public class QueuedResourceIT {
3737

3838
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
3939
private static final String ZONE = "europe-west4-a";
@@ -46,11 +46,15 @@ public class CreateQueuedResourceWithNetworkIT {
4646
+ UUID.randomUUID().toString().substring(0, 8);
4747
private static final String NETWORK_NAME = "default";
4848

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

52-
// Cleanup existing stale resources.
53-
Util.cleanUpExistingQueuedResources("queued-resource-network-", PROJECT_ID, ZONE);
54+
@BeforeAll
55+
public static void setUp() {
56+
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
57+
requireEnvVar("GOOGLE_CLOUD_PROJECT");
5458
}
5559

5660
@AfterAll

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
public class TpuVmIT {
4646
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
4747
private static final String ZONE = "us-south1-a";
48-
static String javaVersion = System.getProperty("java.version").substring(0, 2);
49-
private static final String NODE_NAME = "test-tpu-" + javaVersion + "-"
50-
+ UUID.randomUUID().toString().substring(0, 8);
48+
private static final String NODE_NAME = "test-tpu-" + UUID.randomUUID();
5149
private static final String TPU_TYPE = "v5litepod-1";
5250
private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.12.1";
5351
private static final String NODE_PATH_NAME =
@@ -59,13 +57,9 @@ public static void requireEnvVar(String envVarName) {
5957
}
6058

6159
@BeforeAll
62-
public static void setUp()
63-
throws IOException, ExecutionException, InterruptedException {
60+
public static void setUp() {
6461
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
6562
requireEnvVar("GOOGLE_CLOUD_PROJECT");
66-
67-
// Cleanup existing stale resources.
68-
Util.cleanUpExistingTpu("test-tpu-" + javaVersion, PROJECT_ID, ZONE);
6963
}
7064

7165
@AfterAll
@@ -81,7 +75,6 @@ public static void cleanup() throws Exception {
8175
@Test
8276
@Order(1)
8377
public void testCreateTpuVm() throws IOException, ExecutionException, InterruptedException {
84-
8578
Node node = CreateTpuVm.createTpuVm(
8679
PROJECT_ID, ZONE, NODE_NAME, TPU_TYPE, TPU_SOFTWARE_VERSION);
8780

0 commit comments

Comments
 (0)