1818
1919//[START tpu_vm_delete]
2020
21+ import com .google .api .gax .longrunning .OperationTimedPollAlgorithm ;
22+ import com .google .api .gax .retrying .RetrySettings ;
2123import com .google .cloud .tpu .v2 .DeleteNodeRequest ;
2224import com .google .cloud .tpu .v2 .NodeName ;
2325import com .google .cloud .tpu .v2 .TpuClient ;
26+ import com .google .cloud .tpu .v2 .TpuSettings ;
2427import java .io .IOException ;
2528import java .util .concurrent .ExecutionException ;
29+ import org .threeten .bp .Duration ;
2630
2731public class DeleteTpuVm {
2832
2933 public static void main (String [] args )
3034 throws IOException , ExecutionException , InterruptedException {
3135 // TODO(developer): Replace these variables before running the sample.
36+ // Project ID or project number of the Google Cloud project you want to create a node.
3237 String projectId = "YOUR_PROJECT_ID" ;
38+ // The zone in which to create the TPU.
39+ // For more information about supported TPU types for specific zones,
40+ // see https://cloud.google.com/tpu/docs/regions-zones
3341 String zone = "europe-west4-a" ;
34- String tpuVmName = "YOUR_TPU_NAME" ;
42+ // The name for your TPU.
43+ String nodeName = "YOUR_TPY_NAME" ;
3544
36- deleteTpuVm (projectId , zone , tpuVmName );
45+ deleteTpuVm (projectId , zone , nodeName );
3746 }
3847
3948 // Deletes a TPU VM with the specified name in the given project and zone.
40- public static void deleteTpuVm (String projectId , String zone , String tpuVmName )
49+ public static void deleteTpuVm (String projectId , String zone , String nodeName )
4150 throws IOException , ExecutionException , InterruptedException {
51+ TpuSettings .Builder clientSettings =
52+ TpuSettings .newBuilder ();
53+ clientSettings
54+ .deleteNodeOperationSettings ()
55+ .setPollingAlgorithm (
56+ OperationTimedPollAlgorithm .create (
57+ RetrySettings .newBuilder ()
58+ .setInitialRetryDelay (Duration .ofMillis (5000L ))
59+ .setRetryDelayMultiplier (1.5 )
60+ .setMaxRetryDelay (Duration .ofMillis (45000L ))
61+ .setInitialRpcTimeout (Duration .ZERO )
62+ .setRpcTimeoutMultiplier (1.0 )
63+ .setMaxRpcTimeout (Duration .ZERO )
64+ .setTotalTimeout (Duration .ofHours (24L ))
65+ .build ()));
66+
4267 // Initialize client that will be used to send requests. This client only needs to be created
4368 // once, and can be reused for multiple requests.
44- try (TpuClient tpuClient = TpuClient .create ()) {
45- String nodeName = NodeName .of (projectId , zone , tpuVmName ).toString ();
69+ try (TpuClient tpuClient = TpuClient .create (clientSettings . build () )) {
70+ String name = NodeName .of (projectId , zone , nodeName ).toString ();
4671
47- DeleteNodeRequest request = DeleteNodeRequest .newBuilder ().setName (nodeName ).build ();
48- tpuClient .deleteNodeAsync (request ).get ();
72+ DeleteNodeRequest request = DeleteNodeRequest .newBuilder ().setName (name ).build ();
4973
74+ tpuClient .deleteNodeAsync (request ).get ();
5075 System .out .println ("TPU VM deleted" );
5176 }
5277 }
5378}
54- //[END tpu_vm_delete]
79+ //[END tpu_vm_delete]
0 commit comments