use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient in project java-servicedirectory by googleapis.
the class ServicesCreate method createService.
// Create a new service.
public static void createService(String projectId, String locationId, String namespaceId, String serviceId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
// The namespace to create the service in.
NamespaceName parent = NamespaceName.of(projectId, locationId, namespaceId);
// The service object to create.
// Optionally add some annotations for the service.
Service service = Service.newBuilder().putAnnotations("protocol", "tcp").build();
// Send the request to create the namespace.
Service createdService = client.createService(parent, service, serviceId);
// Process the response.
System.out.println("Created Service: " + createdService.getName());
System.out.println("Annotations: " + createdService.getAnnotations());
}
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient in project java-servicedirectory by googleapis.
the class EndpointsCreate method createEndpoint.
// Create a new endpoint.
public static void createEndpoint(String projectId, String locationId, String namespaceId, String serviceId, String endpointId) throws IOException {
// 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());
}
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient in project java-servicedirectory by googleapis.
the class Quickstart method quickstart.
public static void quickstart(String projectId, String locationId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
// The project and location that hold the namespace to list.
LocationName parent = LocationName.of(projectId, locationId);
// Call the API.
ListNamespacesPagedResponse response = client.listNamespaces(parent);
// Iterate over each namespace and print its name.
System.out.println("Namespaces:");
for (Namespace namespace : response.iterateAll()) {
System.out.println(namespace.getName());
}
}
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient in project java-servicedirectory by googleapis.
the class EndpointsDelete method deleteEndpoint.
// Delete an endpoint.
public static void deleteEndpoint(String projectId, String locationId, String namespaceId, String serviceId, String endpointId) throws IOException {
// 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());
}
}
use of com.google.cloud.servicedirectory.v1.RegistrationServiceClient in project java-servicedirectory by googleapis.
the class NamespacesDelete method deleteNamespace.
// Delete a namespace.
public static void deleteNamespace(String projectId, String locationId, String namespaceId) throws IOException {
// 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());
}
}
Aggregations