Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d89cd50
feat: implementation changes to add support for
rajatbhatta Mar 24, 2022
4177d63
test: add more unit tests to Instance admin client
rajatbhatta Mar 24, 2022
a669c67
feat: add samples for create, update and deleting
rajatbhatta Mar 24, 2022
ec44bd5
chore: add test instance config to samples pom
rajatbhatta Mar 24, 2022
7fa5ef4
test: add CUD instance config integration tests
rajatbhatta Mar 24, 2022
83e1f25
feat: add proto file as reference.
rajatbhatta Mar 24, 2022
a4c1178
feat: lint the code changes, add documentation
rajatbhatta Mar 24, 2022
3ec6854
feat: minor alignment changes
rajatbhatta Mar 24, 2022
62f6988
feat: fix checkstyle violations.
rajatbhatta Mar 24, 2022
05e491b
feat: change read-only fields setters to protected.
rajatbhatta Mar 25, 2022
b09cec7
feat: change setConfigType to protected.
rajatbhatta Mar 25, 2022
2e957b5
feat: change some more method access modifiers
rajatbhatta Mar 25, 2022
813e5d5
feat: add optional fields, some design changes.
rajatbhatta Mar 30, 2022
9ed7fa2
feat: some documentation changes
rajatbhatta Mar 30, 2022
a3395ec
Merge branch 'main' into cmmr#2
rajatbhatta Mar 30, 2022
5c34085
feat: change BASE_CONFIG project name in tests.
rajatbhatta Mar 31, 2022
dd86710
feat: pom.xml changes
rajatbhatta Mar 31, 2022
9e940e7
Merge branch 'cmmr#2' of https://github.com/rajatbhatta/java-spanner …
rajatbhatta Mar 31, 2022
0a248f9
feat: add support for adding readonly replicas
rajatbhatta Mar 31, 2022
61a2048
feat: clirr changes
rajatbhatta Mar 31, 2022
1922766
feat: some refactoring
rajatbhatta Mar 31, 2022
1a1a557
feat: some method doc changes.
rajatbhatta Mar 31, 2022
46861cf
feat: incorporate review comments.
rajatbhatta Apr 1, 2022
a85e455
feat: remove samples
rajatbhatta Apr 1, 2022
ab903e7
Update pom.xml
rajatbhatta Apr 1, 2022
b76eb57
Update SampleIdGenerator.java
rajatbhatta Apr 1, 2022
614822e
Update SampleRunner.java
rajatbhatta Apr 1, 2022
c9f11ef
Update SampleTestBase.java
rajatbhatta Apr 1, 2022
8c216fd
feat: changes to InstanceConfigTest
rajatbhatta Apr 1, 2022
aa924a5
feat: changes to pom.xml
rajatbhatta Apr 1, 2022
cf72700
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/In…
rajatbhatta Apr 1, 2022
9b2eabb
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/In…
rajatbhatta Apr 1, 2022
1696035
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/In…
rajatbhatta Apr 1, 2022
e3ecd86
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/In…
rajatbhatta Apr 1, 2022
06e754c
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/In…
rajatbhatta Apr 1, 2022
4c244dc
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/In…
rajatbhatta Apr 1, 2022
ee58890
feat: make setBaseConfig protected.
rajatbhatta Apr 1, 2022
ef66169
Merge branch 'cmmr#2' of https://github.com/rajatbhatta/java-spanner …
rajatbhatta Apr 1, 2022
31c615c
feat: add method doc for addReadOnlyReplicas
rajatbhatta Apr 1, 2022
8753739
feat: incorporate review comments.
rajatbhatta Apr 4, 2022
c17ce53
feat: deprecate few constructors
rajatbhatta Apr 4, 2022
721d24c
feat: make some methods private
rajatbhatta Apr 4, 2022
1d23171
feat: move initialization to property declaration.
rajatbhatta Apr 4, 2022
7c0fbb7
feat: make InstanceConfig.Builder setters return
rajatbhatta Apr 4, 2022
3281950
feat: some doc changes
rajatbhatta Apr 4, 2022
bbb4ba9
feat: add support for ListInstanceConfigOperations
rajatbhatta May 2, 2022
96ecca3
fix: linting
rajatbhatta May 2, 2022
98d3a8c
feat: few changes
rajatbhatta May 30, 2022
2e6607b
Merge branch 'main' into cmmr#2
rajatbhatta Sep 19, 2022
1d27cd7
Update spanner_instance_admin.proto
rajatbhatta Sep 19, 2022
6029581
Update SpannerRpc.java
rajatbhatta Sep 19, 2022
503a9ac
feat: remove unnecessary parameter from
rajatbhatta Sep 21, 2022
6f73619
feat: clirr fix
rajatbhatta Sep 21, 2022
71d3e4c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Sep 21, 2022
f7d0710
feat: revert unintended sample changes
rajatbhatta Sep 21, 2022
8bfb5ad
Merge branch 'main' into cmmr#2
rajatbhatta Sep 28, 2022
b699b55
samples: add samples for CMMR Phase 2
rajatbhatta Sep 29, 2022
8041d21
Merge branch 'googleapis:main' into cmmr-samples
rajatbhatta Sep 30, 2022
4239a23
fix: print statements in samples and IT
rajatbhatta Sep 30, 2022
22ed999
fix: linting
rajatbhatta Sep 30, 2022
274346d
fix: linting
rajatbhatta Sep 30, 2022
a2a5f91
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 1, 2022
c045721
Update samples/snippets/src/main/java/com/example/spanner/CreateInsta…
rajatbhatta Oct 3, 2022
96e25db
Update samples/snippets/src/main/java/com/example/spanner/ListInstanc…
rajatbhatta Oct 3, 2022
af4ade5
incorporate review comments
rajatbhatta Oct 3, 2022
a3bb439
change print statement in sample
rajatbhatta Oct 3, 2022
8a3ec96
Merge branch 'main' into cmmr-samples
rajatbhatta Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,16 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/
| Create Database With Default Leader Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithDefaultLeaderSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithDefaultLeaderSample.java) |
| Create Database With Encryption Key | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithEncryptionKey.java) |
| Create Database With Version Retention Period Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithVersionRetentionPeriodSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateDatabaseWithVersionRetentionPeriodSample.java) |
| Create Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) |
| Create Instance Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) |
| Create Instance With Processing Units Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithProcessingUnitsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithProcessingUnitsExample.java) |
| Custom Timeout And Retry Settings Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CustomTimeoutAndRetrySettingsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CustomTimeoutAndRetrySettingsExample.java) |
| Delete Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/DeleteInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/DeleteInstanceConfigSample.java) |
| Get Commit Stats Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/GetCommitStatsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/GetCommitStatsSample.java) |
| Get Database Ddl Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/GetDatabaseDdlSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/GetDatabaseDdlSample.java) |
| Get Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/GetInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/GetInstanceConfigSample.java) |
| List Databases Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/ListDatabasesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/ListDatabasesSample.java) |
| List Instance Config Operations Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/ListInstanceConfigOperationsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/ListInstanceConfigOperationsSample.java) |
| List Instance Configs Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/ListInstanceConfigsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/ListInstanceConfigsSample.java) |
| Pg Async Query To List Async Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/PgAsyncQueryToListAsyncExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/PgAsyncQueryToListAsyncExample.java) |
| Pg Async Runner Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/PgAsyncRunnerExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/PgAsyncRunnerExample.java) |
Expand All @@ -287,6 +290,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/
| Tag Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/TagSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/TagSample.java) |
| Tracing Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/TracingSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/TracingSample.java) |
| Update Database With Default Leader Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateDatabaseWithDefaultLeaderSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateDatabaseWithDefaultLeaderSample.java) |
| Update Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateInstanceConfigSample.java) |
| Update Json Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateJsonDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateJsonDataSample.java) |
| Update Numeric Data Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/UpdateNumericDataSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/UpdateNumericDataSample.java) |

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.spanner;

// [START spanner_create_instance_config]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.spanner.InstanceAdminClient;
import com.google.cloud.spanner.InstanceConfig;
import com.google.cloud.spanner.InstanceConfigId;
import com.google.cloud.spanner.InstanceConfigInfo;
import com.google.cloud.spanner.ReplicaInfo;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.common.collect.ImmutableList;
import com.google.spanner.admin.instance.v1.CreateInstanceConfigMetadata;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

class CreateInstanceConfigSample {
static void createInstanceConfig() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
String baseInstanceConfig = "my-base-instance-config";
String instanceConfigId = "custom-instance-config4";
createInstanceConfig(projectId, baseInstanceConfig, instanceConfigId);
}

static void createInstanceConfig(
String projectId, String baseInstanceConfig, String instanceConfigId) {
try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
final InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
final InstanceConfig baseConfig = instanceAdminClient.getInstanceConfig(baseInstanceConfig);
List<ReplicaInfo> readOnlyReplicas =
ImmutableList.of(baseConfig.getOptionalReplicas().get(0));
InstanceConfigInfo instanceConfigInfo =
InstanceConfig.newBuilder(InstanceConfigId.of(projectId, instanceConfigId), baseConfig)
.setDisplayName(instanceConfigId)
.addReadOnlyReplicas(readOnlyReplicas)
.build();
final OperationFuture<InstanceConfig, CreateInstanceConfigMetadata> operation =
instanceAdminClient.createInstanceConfig(instanceConfigInfo);
try {
System.out.printf("Waiting for create operation for %s to complete...\n", instanceConfigId);
InstanceConfig instanceConfig = operation.get(5, TimeUnit.MINUTES);
System.out.printf("Created instance configuration %s\n", instanceConfig.getId());
} catch (ExecutionException | TimeoutException e) {
System.out.printf(
"Error: Creating instance configuration %s failed with error message %s\n",
instanceConfigInfo.getId(), e.getMessage());
} catch (InterruptedException e) {
System.out.println(
"Error: Waiting for createInstanceConfig operation to finish was interrupted");
}
}
}
}
// [END spanner_create_instance_config]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.spanner;

// [START spanner_delete_instance_config]
import com.google.cloud.spanner.InstanceAdminClient;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.spanner.SpannerOptions;

class DeleteInstanceConfigSample {
static void deleteInstanceConfig() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
String instanceConfigId = "custom-user-config";
deleteInstanceConfig(projectId, instanceConfigId);
}

static void deleteInstanceConfig(String projectId, String instanceConfigId) {
try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
final InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
try {
System.out.printf("Deleting %s...\n", instanceConfigId);
instanceAdminClient.deleteInstanceConfig(instanceConfigId);
System.out.printf("Deleted instance configuration %s\n", instanceConfigId);
} catch (SpannerException e) {
System.out.printf(
"Error: Deleting instance configuration %s failed with error message: %s\n",
instanceConfigId, e.getMessage());
}
}
}
}
// [END spanner_delete_instance_config]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.spanner;

// [START spanner_list_instance_config_operations]
import com.google.cloud.spanner.InstanceAdminClient;
import com.google.cloud.spanner.Options;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.longrunning.Operation;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.spanner.admin.instance.v1.CreateInstanceConfigMetadata;

public class ListInstanceConfigOperationsSample {
static void listInstanceConfigOperations() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
listInstanceConfigOperations(projectId);
}

static void listInstanceConfigOperations(String projectId) {
try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
final InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();

try {
System.out.printf(
"Getting list of instance config operations for project %s...\n",
projectId);
final Iterable<Operation> instanceConfigOperations =
instanceAdminClient
.listInstanceConfigOperations(
Options.filter(
"(metadata.@type=type.googleapis.com/"
+ "google.spanner.admin.instance.v1.CreateInstanceConfigMetadata)"))
.iterateAll();
for (Operation operation : instanceConfigOperations) {
CreateInstanceConfigMetadata metadata =
operation.getMetadata().unpack(CreateInstanceConfigMetadata.class);
System.out.printf(
"Create instance config operation for %s is %d%% completed.\n",
metadata.getInstanceConfig().getName(), metadata.getProgress().getProgressPercent());
}
} catch (InvalidProtocolBufferException e) {
System.out.printf(
"Error: Listing instance config operations failed with error message %s\n",
e.getMessage());
}
}
}
}
// [END spanner_list_instance_config_operations]
Loading