Skip to content
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

samples: migrate code from googleapis/java-servicedirectory #7399

Merged
merged 93 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
1e6d8d0
chore: updated grpc code output, add samples scaffold (#12)
yoshi-automation Mar 19, 2020
3e05846
chore(deps): update dependency com.google.cloud:libraries-bom to v4.3…
renovate-bot Mar 23, 2020
1a6fb34
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Mar 25, 2020
a97a4a1
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Mar 30, 2020
a6f42e2
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 1, 2020
446254b
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 6, 2020
7b2da1c
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 6, 2020
e63e9cd
chore(deps): update dependency com.google.cloud:libraries-bom to v5 (…
renovate-bot Apr 14, 2020
f6663ec
chore(deps): update dependency com.google.cloud:libraries-bom to v5.1…
renovate-bot Apr 14, 2020
02b4f20
samples: add code snippets for Service Directory. (#28)
makk94 Apr 15, 2020
9357ec6
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 16, 2020
f962423
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 17, 2020
3642549
chore(deps): update dependency com.google.cloud:libraries-bom to v5.2…
renovate-bot Apr 23, 2020
c8e45d4
chore(deps): update dependency com.google.cloud:libraries-bom to v5.3…
renovate-bot Apr 28, 2020
c211505
chore(deps): update dependency com.google.cloud:libraries-bom to v5.4…
renovate-bot May 19, 2020
721eca4
chore(deps): update dependency com.google.cloud:libraries-bom to v5.5…
renovate-bot May 29, 2020
5c761e0
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 10, 2020
f3a04bd
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
renovate-bot Jun 10, 2020
b38edf6
chore(deps): update dependency com.google.cloud:libraries-bom to v6 (…
renovate-bot Jun 16, 2020
908be5c
chore(deps): update dependency com.google.cloud:libraries-bom to v7 (…
renovate-bot Jun 17, 2020
2faa0a3
chore(deps): update dependency com.google.cloud:libraries-bom to v7.0…
renovate-bot Jun 22, 2020
67d3566
chore(deps): update dependency com.google.cloud:libraries-bom to v8 (…
renovate-bot Jun 26, 2020
9a889b9
samples: add quickstart (#82)
Jun 30, 2020
b45054e
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…
renovate-bot Jul 16, 2020
4c5a37e
chore(deps): update dependency com.google.cloud:libraries-bom to v9 (…
renovate-bot Aug 14, 2020
621928a
chore(deps): update dependency com.google.cloud:libraries-bom to v9.1.0
renovate-bot Aug 17, 2020
d1aa1dc
chore(deps): update dependency com.google.cloud:libraries-bom to v10 …
renovate-bot Sep 22, 2020
cdde6cb
chore(deps): update dependency com.google.cloud:libraries-bom to v11 …
renovate-bot Sep 24, 2020
633a34e
chore(deps): update dependency com.google.cloud:libraries-bom to v12 …
renovate-bot Oct 6, 2020
e4cb8ad
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Oct 9, 2020
4026a8a
test(deps): update dependency junit:junit to v4.13.1
renovate-bot Oct 12, 2020
5b9f57a
chore(deps): update dependency com.google.cloud:libraries-bom to v12.…
renovate-bot Oct 15, 2020
24a913b
chore(deps): update dependency com.google.cloud:libraries-bom to v13 …
renovate-bot Oct 20, 2020
0c58085
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 21, 2020
da09272
test(deps): update dependency com.google.truth:truth to v1.1 (#189)
renovate-bot Oct 22, 2020
bf8ac80
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 23, 2020
1db4c7c
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 26, 2020
dc1201e
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 30, 2020
f5e12f7
chore(deps): update dependency com.google.cloud:libraries-bom to v14 …
renovate-bot Nov 4, 2020
4cf9383
chore(deps): update dependency com.google.cloud:libraries-bom to v15 …
renovate-bot Nov 5, 2020
b01a48b
chore(deps): update dependency com.google.cloud:libraries-bom to v15.…
renovate-bot Nov 12, 2020
5fa54ad
chore(deps): update dependency com.google.cloud:libraries-bom to v16 …
renovate-bot Nov 19, 2020
df669d4
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Dec 15, 2020
c5dc245
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 7, 2021
4db2e5e
test(deps): update dependency com.google.truth:truth to v1.1.2 (#281)
renovate-bot Jan 25, 2021
6c5c8f4
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 26, 2021
1089df2
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Feb 10, 2021
4f051d7
feat: update java samples to v1 (#274)
katiehochberg Feb 10, 2021
b4cdb58
test(deps): update dependency junit:junit to v4.13.2 (#298)
renovate-bot Feb 16, 2021
3d99509
chore(deps): update dependency com.google.cloud:libraries-bom to v17 …
renovate-bot Feb 24, 2021
058a0af
chore(deps): update dependency com.google.cloud:libraries-bom to v18 …
renovate-bot Feb 25, 2021
1cde3f3
chore(deps): update dependency com.google.cloud:libraries-bom to v18.…
renovate-bot Mar 3, 2021
e13cb71
chore(deps): update dependency com.google.cloud:libraries-bom to v19 …
renovate-bot Mar 4, 2021
9ad5c3d
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot Mar 24, 2021
5f5dabc
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 9, 2021
18c5a82
chore(deps): update dependency com.google.cloud:libraries-bom to v20 …
renovate-bot Apr 12, 2021
dca989d
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 19, 2021
2308505
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 29, 2021
4ff585d
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 13, 2021
1fc3ab7
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 17, 2021
2448d69
test(deps): update dependency com.google.truth:truth to v1.1.3 (#412)
renovate-bot May 26, 2021
e9ecebe
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 31, 2021
5c5b169
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 7, 2021
6d2d72d
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 7, 2021
5d72b23
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 23, 2021
5bdf422
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 9, 2021
08cfe5a
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 27, 2021
7b97be2
chore(deps): update dependency com.google.cloud:libraries-bom to v21 …
renovate-bot Aug 19, 2021
9eb2c57
chore(deps): update dependency com.google.cloud:libraries-bom to v22 …
renovate-bot Aug 27, 2021
917764a
chore(deps): update dependency com.google.cloud:libraries-bom to v23 …
renovate-bot Sep 13, 2021
5156a0d
chore(deps): update dependency com.google.cloud:libraries-bom to v23.…
renovate-bot Oct 1, 2021
0d0d072
chore(deps): update dependency com.google.cloud:libraries-bom to v24 …
renovate-bot Oct 27, 2021
7109dd3
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Dec 6, 2021
e06708c
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 8, 2021
35ca506
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 28, 2021
900fd64
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 7, 2022
7117063
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 18, 2022
7618f33
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Feb 8, 2022
4250409
chore(deps): update dependency com.google.cloud:libraries-bom to v25 …
renovate-bot Mar 14, 2022
b452517
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 1, 2022
7fcccd3
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 27, 2022
ae9bd88
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot May 16, 2022
bad17df
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Jun 6, 2022
7190982
chore(deps): update dependency com.google.cloud:libraries-bom to v26 …
renovate-bot Jul 11, 2022
93d0fc9
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 16, 2022
c7f727c
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 31, 2022
c9feef9
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Sep 20, 2022
c02cdf6
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Oct 7, 2022
c5b2a6e
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Nov 8, 2022
fb2baf6
Merge remote-tracking branch 'migration/main' into java-servicedirect…
Shabirmean Nov 9, 2022
93df18a
chore: remove redundant snippets subdirectory
Shabirmean Nov 9, 2022
6367e60
test: use a region other than us-central1
Shabirmean Nov 9, 2022
18db1f8
chore: update maven groupId and artifact url
Shabirmean Nov 10, 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
46 changes: 46 additions & 0 deletions servicedirectory/README.md
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
73 changes: 73 additions & 0 deletions servicedirectory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright 2020 Google Inc.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.servicedirectory</groupId>
<artifactId>servicedirectory-snippets</artifactId>
<packaging>jar</packaging>
<name>Google Service Directory Snippets</name>
<url>https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/servicedirectory</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.2.0</version>
</parent>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<!-- [START servicedirectory_install_with_bom] -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-servicedirectory</artifactId>
</dependency>
<!-- [END servicedirectory_install_with_bom] -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
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.v1.Endpoint;
import com.google.cloud.servicedirectory.v1.RegistrationServiceClient;
import com.google.cloud.servicedirectory.v1.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";
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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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_delete_endpoint]

import com.google.cloud.servicedirectory.v1.EndpointName;
import com.google.cloud.servicedirectory.v1.RegistrationServiceClient;
import java.io.IOException;

public class EndpointsDelete {

public static void deleteEndpoint() throws IOException {
// TODO(developer): Replace these variables before running the sample.
// These variables should refer to an existing Service Directory endpoint.
String projectId = "your-project-id";
String locationId = "your-region";
String namespaceId = "your-namespace";
String serviceId = "your-service";
String endpointId = "your-endpoint";
deleteEndpoint(projectId, locationId, namespaceId, serviceId, endpointId);
}

// Delete an endpoint.
public static void deleteEndpoint(
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 endpoint to delete.
EndpointName endpointName =
EndpointName.of(projectId, locationId, namespaceId, serviceId, endpointId);

// Send the request to delete the endpoint.
client.deleteEndpoint(endpointName);

// Log the action.
System.out.println("Deleted Endpoint: " + endpointName.toString());
}
}
}
// [END servicedirectory_delete_endpoint]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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_namespace]

import com.google.cloud.servicedirectory.v1.LocationName;
import com.google.cloud.servicedirectory.v1.Namespace;
import com.google.cloud.servicedirectory.v1.RegistrationServiceClient;
import java.io.IOException;

public class NamespacesCreate {

public static void createNamespace() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-region";
// This is user-created; must be unique within the project/region above.
String namespaceId = "your-namespace";
createNamespace(projectId, locationId, namespaceId);
}

// Create a new namespace.
public static void createNamespace(String projectId, String locationId, String namespaceId)
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 project and location to create the namespace in.
LocationName parent = LocationName.of(projectId, locationId);

// The namespace object to create. Here, we use the default instance.
Namespace namespace = Namespace.newBuilder().build();

// Send the request to create the namespace.
Namespace createdNamespace = client.createNamespace(parent, namespace, namespaceId);

// Process the response.
System.out.println("Created Namespace: " + createdNamespace.getName());
}
}
}
// [END servicedirectory_create_namespace]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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_delete_namespace]

import com.google.cloud.servicedirectory.v1.NamespaceName;
import com.google.cloud.servicedirectory.v1.RegistrationServiceClient;
import java.io.IOException;

public class NamespacesDelete {

public static void deleteNamespace() throws IOException {
// TODO(developer): Replace these variables before running the sample.
// These variables should refer to an existing Service Directory namespace.
String projectId = "your-project-id";
String locationId = "your-region";
String namespaceId = "your-namespace";
deleteNamespace(projectId, locationId, namespaceId);
}

// Delete a namespace.
public static void deleteNamespace(String projectId, String locationId, String namespaceId)
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 namespace to delete.
NamespaceName namespaceName = NamespaceName.of(projectId, locationId, namespaceId);

// Send the request to delete the namespace.
client.deleteNamespace(namespaceName);

// Log the action.
System.out.println("Deleted Namespace: " + namespaceName.toString());
}
}
}
// [END servicedirectory_delete_namespace]
Loading