Class NotebookServiceClient (1.4.0)

Stay organized with collections Save and categorize content based on your preferences.
public class NotebookServiceClient implements BackgroundResource

Service Description: API v1 service for Cloud AI Platform Notebooks.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   String name = "name3373707";
   Instance response = notebookServiceClient.getInstance(name);
 }
 

Note: close() needs to be called on the NotebookServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

The surface of this class includes several types of Java methods for each of the API's methods:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of NotebookServiceSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 NotebookServiceSettings notebookServiceSettings =
     NotebookServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 NotebookServiceClient notebookServiceClient =
     NotebookServiceClient.create(notebookServiceSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 NotebookServiceSettings notebookServiceSettings =
     NotebookServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 NotebookServiceClient notebookServiceClient =
     NotebookServiceClient.create(notebookServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > NotebookServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final NotebookServiceClient create()

Constructs an instance of NotebookServiceClient with default settings.

Returns
TypeDescription
NotebookServiceClient
Exceptions
TypeDescription
IOException

create(NotebookServiceSettings settings)

public static final NotebookServiceClient create(NotebookServiceSettings settings)

Constructs an instance of NotebookServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
NameDescription
settingsNotebookServiceSettings
Returns
TypeDescription
NotebookServiceClient
Exceptions
TypeDescription
IOException

create(NotebookServiceStub stub)

public static final NotebookServiceClient create(NotebookServiceStub stub)

Constructs an instance of NotebookServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(NotebookServiceSettings).

Parameter
NameDescription
stubNotebookServiceStub
Returns
TypeDescription
NotebookServiceClient

Constructors

NotebookServiceClient(NotebookServiceSettings settings)

protected NotebookServiceClient(NotebookServiceSettings settings)

Constructs an instance of NotebookServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
NameDescription
settingsNotebookServiceSettings

NotebookServiceClient(NotebookServiceStub stub)

protected NotebookServiceClient(NotebookServiceStub stub)
Parameter
NameDescription
stubNotebookServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

createEnvironmentAsync(CreateEnvironmentRequest request)

public final OperationFuture<Environment,OperationMetadata> createEnvironmentAsync(CreateEnvironmentRequest request)

Creates a new Environment.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateEnvironmentRequest request =
       CreateEnvironmentRequest.newBuilder()
           .setParent("parent-995424086")
           .setEnvironmentId("environmentId-950205810")
           .setEnvironment(Environment.newBuilder().build())
           .build();
   Environment response = notebookServiceClient.createEnvironmentAsync(request).get();
 }
 
Parameter
NameDescription
requestCreateEnvironmentRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OperationFuture<Environment,OperationMetadata>

createEnvironmentAsync(String parent, Environment environment, String environmentId)

public final OperationFuture<Environment,OperationMetadata> createEnvironmentAsync(String parent, Environment environment, String environmentId)

Creates a new Environment.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   String parent = "parent-995424086";
   Environment environment = Environment.newBuilder().build();
   String environmentId = "environmentId-950205810";
   Environment response =
       notebookServiceClient.createEnvironmentAsync(parent, environment, environmentId).get();
 }
 
Parameters
NameDescription
parentString

Required. Format: projects/{project_id}/locations/{location}

environmentEnvironment

Required. The environment to be created.

environmentIdString

Required. User-defined unique ID of this environment. The environment_id must be 1 to 63 characters long and contain only lowercase letters, numeric characters, and dashes. The first character must be a lowercase letter and the last character cannot be a dash.

Returns
TypeDescription
OperationFuture<Environment,OperationMetadata>

createEnvironmentCallable()

public final UnaryCallable<CreateEnvironmentRequest,Operation> createEnvironmentCallable()

Creates a new Environment.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateEnvironmentRequest request =
       CreateEnvironmentRequest.newBuilder()
           .setParent("parent-995424086")
           .setEnvironmentId("environmentId-950205810")
           .setEnvironment(Environment.newBuilder().build())
           .build();
   ApiFuture<Operation> future =
       notebookServiceClient.createEnvironmentCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateEnvironmentRequest,Operation>

createEnvironmentOperationCallable()

public final OperationCallable<CreateEnvironmentRequest,Environment,OperationMetadata> createEnvironmentOperationCallable()

Creates a new Environment.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateEnvironmentRequest request =
       CreateEnvironmentRequest.newBuilder()
           .setParent("parent-995424086")
           .setEnvironmentId("environmentId-950205810")
           .setEnvironment(Environment.newBuilder().build())
           .build();
   OperationFuture<Environment, OperationMetadata> future =
       notebookServiceClient.createEnvironmentOperationCallable().futureCall(request);
   // Do something.
   Environment response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<CreateEnvironmentRequest,Environment,OperationMetadata>

createExecutionAsync(CreateExecutionRequest request)

public final OperationFuture<Execution,OperationMetadata> createExecutionAsync(CreateExecutionRequest request)

Creates a new Execution in a given project and location.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateExecutionRequest request =
       CreateExecutionRequest.newBuilder()
           .setParent(ExecutionName.of("[PROJECT]", "[LOCATION]", "[EXECUTION]").toString())
           .setExecutionId("executionId-454906285")
           .setExecution(Execution.newBuilder().build())
           .build();
   Execution response = notebookServiceClient.createExecutionAsync(request).get();
 }
 
Parameter
NameDescription
requestCreateExecutionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OperationFuture<Execution,OperationMetadata>

createExecutionAsync(ExecutionName parent, Execution execution, String executionId)

public final OperationFuture<Execution,OperationMetadata> createExecutionAsync(ExecutionName parent, Execution execution, String executionId)

Creates a new Execution in a given project and location.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   ExecutionName parent = ExecutionName.of("[PROJECT]", "[LOCATION]", "[EXECUTION]");
   Execution execution = Execution.newBuilder().build();
   String executionId = "executionId-454906285";
   Execution response =
       notebookServiceClient.createExecutionAsync(parent, execution, executionId).get();
 }
 
Parameters
NameDescription
parentExecutionName

Required. Format: parent=projects/{project_id}/locations/{location}

executionExecution

Required. The execution to be created.

executionIdString

Required. User-defined unique ID of this execution.

Returns
TypeDescription
OperationFuture<Execution,OperationMetadata>

createExecutionAsync(String parent, Execution execution, String executionId)

public final OperationFuture<Execution,OperationMetadata> createExecutionAsync(String parent, Execution execution, String executionId)

Creates a new Execution in a given project and location.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   String parent = ExecutionName.of("[PROJECT]", "[LOCATION]", "[EXECUTION]").toString();
   Execution execution = Execution.newBuilder().build();
   String executionId = "executionId-454906285";
   Execution response =
       notebookServiceClient.createExecutionAsync(parent, execution, executionId).get();
 }
 
Parameters
NameDescription
parentString

Required. Format: parent=projects/{project_id}/locations/{location}

executionExecution

Required. The execution to be created.

executionIdString

Required. User-defined unique ID of this execution.

Returns
TypeDescription
OperationFuture<Execution,OperationMetadata>

createExecutionCallable()

public final UnaryCallable<CreateExecutionRequest,Operation> createExecutionCallable()

Creates a new Execution in a given project and location.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateExecutionRequest request =
       CreateExecutionRequest.newBuilder()
           .setParent(ExecutionName.of("[PROJECT]", "[LOCATION]", "[EXECUTION]").toString())
           .setExecutionId("executionId-454906285")
           .setExecution(Execution.newBuilder().build())
           .build();
   ApiFuture<Operation> future =
       notebookServiceClient.createExecutionCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateExecutionRequest,Operation>

createExecutionOperationCallable()

public final OperationCallable<CreateExecutionRequest,Execution,OperationMetadata> createExecutionOperationCallable()

Creates a new Execution in a given project and location.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateExecutionRequest request =
       CreateExecutionRequest.newBuilder()
           .setParent(ExecutionName.of("[PROJECT]", "[LOCATION]", "[EXECUTION]").toString())
           .setExecutionId("executionId-454906285")
           .setExecution(Execution.newBuilder().build())
           .build();
   OperationFuture<Execution, OperationMetadata> future =
       notebookServiceClient.createExecutionOperationCallable().futureCall(request);
   // Do something.
   Execution response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<CreateExecutionRequest,Execution,OperationMetadata>

createInstanceAsync(CreateInstanceRequest request)

public final OperationFuture<Instance,OperationMetadata> createInstanceAsync(CreateInstanceRequest request)

Creates a new Instance in a given project and location.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (NotebookServiceClient notebookServiceClient = NotebookServiceClient.create()) {
   CreateInstanceRequest request =
       CreateInstanceRequest.newBuilder()
           .setParent("parent-99