-
Notifications
You must be signed in to change notification settings - Fork 132
docs: samples and tests for instance APIs. #2768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gcf-merge-on-green
merged 37 commits into
googleapis:main
from
arpan14:admin-instance-apis-pr
Jan 12, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
edc5bbf
fix: prevent illegal negative timeout values into thread sleep() meth…
arpan14 49a85df
Merge pull request #1 from arpan14/retryerror
arpan14 4cd497b
Fixing lint issues.
arpan14 4a6aa8e
Merge branch 'googleapis:main' into main
arpan14 b2aa09d
Merge branch 'googleapis:main' into main
arpan14 8d6d71e
Merge branch 'googleapis:main' into main
arpan14 77e6e7d
Merge branch 'googleapis:main' into main
arpan14 e8b7fad
Merge branch 'googleapis:main' into main
arpan14 8aa84e1
Merge branch 'googleapis:main' into main
arpan14 57fd405
Merge branch 'googleapis:main' into main
arpan14 1253563
Merge branch 'googleapis:main' into main
arpan14 d4f6a60
Merge branch 'googleapis:main' into main
arpan14 3efaf7c
Merge branch 'googleapis:main' into main
arpan14 f41b39f
Merge branch 'googleapis:main' into main
arpan14 82a16e9
chore: adding a few samples with auto-gen clients.
arpan14 c187621
chore: adding integration tests for samples.
arpan14 360d5db
chore: fixing the end-point for staging.
arpan14 a12fb43
chore: modified test for CreateDatabaseWithDefaultLeaderSample.
arpan14 f144f42
chore: adding sample and integration test for CreateInstanceSample.
arpan14 091414c
chore: adding license headers.
arpan14 988fd7a
chore: fix lint errors.
arpan14 922f47b
chore: rename file and add sample tags.
arpan14 0bf6f87
chore: address comments.
arpan14 396419d
Update samples/snippets/src/main/java/com/example/spanner/v2/CreateDa…
arpan14 eb997ae
chore: rewrite CreateInstanceConfigSample.
arpan14 b54bb0f
chore: rewrite instance API samples.
arpan14 fa0aa1e
chore: removed previous files and adding new integration test.
arpan14 78beaac
chore: changing instance integration tests.
arpan14 7fb407b
chore: add samples/tests for instance creation with processing units …
arpan14 c602c5b
chore:rename directory.
arpan14 be2b503
chore: minor fixes.
arpan14 335b465
chore: address comments.
arpan14 97ee485
chore: fix lint errors.
arpan14 fbf4df5
chore: fix lint errors.
arpan14 1b6a011
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] a975ecf
chore: close client resources.
arpan14 87bea00
chore: fix lint issues.
arpan14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...nippets/src/main/java/com/example/spanner/admin/generated/CreateInstanceConfigSample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2024 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.admin.generated; | ||
|
||
// [START spanner_create_instance_config] | ||
olavloite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient; | ||
import com.google.spanner.admin.instance.v1.CreateInstanceConfigRequest; | ||
import com.google.spanner.admin.instance.v1.InstanceConfig; | ||
import com.google.spanner.admin.instance.v1.InstanceConfigName; | ||
import com.google.spanner.admin.instance.v1.ProjectName; | ||
import com.google.spanner.admin.instance.v1.ReplicaInfo; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
class CreateInstanceConfigSample { | ||
|
||
static void createInstanceConfig() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String projectId = "my-project"; | ||
String baseInstanceConfigId = "nam11"; | ||
String instanceConfigId = "custom-instance-config4"; | ||
|
||
createInstanceConfig(projectId, baseInstanceConfigId, instanceConfigId); | ||
} | ||
|
||
static void createInstanceConfig( | ||
String projectId, String baseInstanceConfigId, String instanceConfigId) throws IOException { | ||
try (InstanceAdminClient instanceAdminClient = InstanceAdminClient.create()) { | ||
final InstanceConfigName baseInstanceConfigName = InstanceConfigName.of(projectId, | ||
baseInstanceConfigId); | ||
final InstanceConfig baseConfig = | ||
instanceAdminClient.getInstanceConfig(baseInstanceConfigName.toString()); | ||
final InstanceConfigName instanceConfigName = InstanceConfigName.of(projectId, | ||
instanceConfigId); | ||
/** | ||
* The replicas for the custom instance configuration must include all the replicas of the | ||
* base configuration, in addition to at least one from the list of optional replicas of the | ||
* base configuration. | ||
*/ | ||
final List<ReplicaInfo> replicas = | ||
Stream.concat(baseConfig.getReplicasList().stream(), | ||
baseConfig.getOptionalReplicasList().stream().limit(1)).collect(Collectors.toList()); | ||
final InstanceConfig instanceConfig = | ||
InstanceConfig.newBuilder().setName(instanceConfigName.toString()) | ||
.setBaseConfig(baseInstanceConfigName.toString()) | ||
.setDisplayName("Instance Configuration").addAllReplicas(replicas).build(); | ||
final CreateInstanceConfigRequest createInstanceConfigRequest = | ||
CreateInstanceConfigRequest.newBuilder().setParent(ProjectName.of(projectId).toString()) | ||
.setInstanceConfigId(instanceConfigId).setInstanceConfig(instanceConfig).build(); | ||
try { | ||
System.out.printf("Waiting for create operation for %s to complete...\n", | ||
instanceConfigName); | ||
InstanceConfig instanceConfigResult = | ||
instanceAdminClient.createInstanceConfigAsync( | ||
createInstanceConfigRequest).get(5, TimeUnit.MINUTES); | ||
System.out.printf("Created instance configuration %s\n", instanceConfigResult.getName()); | ||
} catch (ExecutionException | TimeoutException e) { | ||
System.out.printf( | ||
"Error: Creating instance configuration %s failed with error message %s\n", | ||
instanceConfig.getName(), e.getMessage()); | ||
} catch (InterruptedException e) { | ||
System.out.println( | ||
"Error: Waiting for createInstanceConfig operation to finish was interrupted"); | ||
} | ||
} | ||
} | ||
} | ||
// [END spanner_create_instance_config] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.