This repository was archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
samples: add code snippets for Service Directory. #28
Merged
chingor13
merged 14 commits into
googleapis:master
from
makk94:add-servicedirectory-snippets
Apr 15, 2020
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c238cc5
Add code snippets for Service Directory.
98d371f
inline some stuff in EndpointsCreate snippet.
207ed6b
chore: update libraries-bom to 4.4.0 (#26)
yoshi-automation 6fdee70
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 34007b0
deps: update dependency org.threeten:threetenbp to v1.4.3 (#14)
renovate-bot 21c8e5a
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot 46ce0fc
deps: update core dependencies (#1)
renovate-bot 3dd8ec2
chore: release 0.1.1 (#23)
release-please[bot] a5ea611
chore(deps): update dependency com.google.cloud:google-cloud-serviced…
renovate-bot 5c99182
chore: release 0.1.2-SNAPSHOT (#33)
release-please[bot] 53862d1
build(deps): update dependency com.google.cloud:google-cloud-shared-c…
renovate-bot dedd57d
Fix type in README.
aa2efb9
Add clarifying comments. Add some configuration in ServicesCreate
8f2256a
Merge branch 'master' into add-servicedirectory-snippets
makk94 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Service Directory | ||
|
|
||
| [Service Directory](https://cloud.google.com/service-directory/) is a platform | ||
| for discovering, publishing, and connecting services. It offers customers a | ||
| single place to register and discover their services in a consistent and | ||
| reliable way, regardless of their environment. These sample Java applications | ||
| demonstrate how to access the Service Directory API using the Google Java API | ||
| Client Libraries. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ### Enable the API | ||
|
|
||
| You must enable the Service Directory API for your project in order to use these | ||
| samples. You can do so | ||
| [here](https://console.cloud.google.com/flows/enableapi?apiid=servicedirectory.googleapis.com&_ga=2.140387959.57242806.1585772225-360187285.1585772225). | ||
|
|
||
| ### Set Environment Variables | ||
|
|
||
| You must set your project ID in order to run the tests | ||
|
|
||
| `$ export GOOGLE_CLOUD_PROJECT=<your-project-id-here>` | ||
|
|
||
| ### Grant Permissions | ||
|
|
||
| You must ensure that the | ||
| [user account or service account](https://cloud.google.com/iam/docs/service-accounts#differences_between_a_service_account_and_a_user_account) | ||
| you used to authorize your gcloud session has the proper permissions to edit | ||
| Service Directory resources for your project. In the Cloud Console under IAM, | ||
| add the `Service Directory Admin` role to the project whose service account | ||
| you're using to test. | ||
|
|
||
| More information can be found in the | ||
| [Authentication docs](https://cloud.google.com/docs/authentication/production). | ||
|
|
||
| ## Quickstart | ||
|
|
||
| Install [Maven](https://maven.apache.org/). | ||
|
|
||
| Build your project with: | ||
|
|
||
| mvn clean package -DskipTests | ||
|
|
||
| You can run all tests with: | ||
|
|
||
| mvn clean verify |
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
66 changes: 66 additions & 0 deletions
66
samples/snippets/src/main/java/com/example/servicedirectory/EndpointsCreate.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,66 @@ | ||
| /* | ||
| * Copyright 2020 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.servicedirectory; | ||
|
|
||
| // [START servicedirectory_create_endpoint] | ||
|
|
||
| import com.google.cloud.servicedirectory.v1beta1.Endpoint; | ||
| import com.google.cloud.servicedirectory.v1beta1.RegistrationServiceClient; | ||
| import com.google.cloud.servicedirectory.v1beta1.ServiceName; | ||
| import java.io.IOException; | ||
|
|
||
| public class EndpointsCreate { | ||
|
|
||
| public static void createEndpoint() throws IOException { | ||
| // TODO(developer): Replace these variables before running the sample. | ||
| // These variables should refer to an existing Service Directory service. | ||
| String projectId = "your-project-id"; | ||
| String locationId = "your-region"; | ||
| String namespaceId = "your-namespace"; | ||
| String serviceId = "your-service"; | ||
| // This is user-created; must be unique within the service above. | ||
| String endpointId = "your-endpoint"; | ||
nnegrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| createEndpoint(projectId, locationId, namespaceId, serviceId, endpointId); | ||
| } | ||
|
|
||
| // Create a new endpoint. | ||
| public static void createEndpoint( | ||
| String projectId, String locationId, String namespaceId, String serviceId, String endpointId) | ||
| throws IOException { | ||
| // Initialize client that will be used to send requests. This client only needs to be created | ||
| // once, and can be reused for multiple requests. After completing all of your requests, call | ||
| // the "close" method on the client to safely clean up any remaining background resources. | ||
| try (RegistrationServiceClient client = RegistrationServiceClient.create()) { | ||
|
|
||
| // The service to create the endpoint in. | ||
| ServiceName parent = ServiceName.of(projectId, locationId, namespaceId, serviceId); | ||
|
|
||
| // The endpoint to create, with fields filled in. | ||
| // Optionally set an IP address and port for the endpoint. | ||
| Endpoint endpoint = Endpoint.newBuilder().setAddress("10.0.0.1").setPort(443).build(); | ||
|
|
||
| // Send the request to create the endpoint. | ||
| Endpoint createdEndpoint = client.createEndpoint(parent, endpoint, endpointId); | ||
|
|
||
| // Process the response. | ||
| System.out.println("Created Endpoint: " + createdEndpoint.getName()); | ||
| System.out.println("IP Address: " + createdEndpoint.getAddress()); | ||
| System.out.println("Port: " + createdEndpoint.getPort()); | ||
| } | ||
| } | ||
| } | ||
| // [END servicedirectory_create_endpoint] | ||
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.