Search in sources :

Example 1 with RegistrationServiceClient

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());
    }
}
Also used : NamespaceName(com.google.cloud.servicedirectory.v1.NamespaceName) Service(com.google.cloud.servicedirectory.v1.Service) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Example 2 with RegistrationServiceClient

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());
    }
}
Also used : Endpoint(com.google.cloud.servicedirectory.v1.Endpoint) ServiceName(com.google.cloud.servicedirectory.v1.ServiceName) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Example 3 with RegistrationServiceClient

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());
        }
    }
}
Also used : Namespace(com.google.cloud.servicedirectory.v1.Namespace) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient) LocationName(com.google.cloud.servicedirectory.v1.LocationName) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse)

Example 4 with RegistrationServiceClient

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());
    }
}
Also used : EndpointName(com.google.cloud.servicedirectory.v1.EndpointName) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Example 5 with RegistrationServiceClient

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());
    }
}
Also used : NamespaceName(com.google.cloud.servicedirectory.v1.NamespaceName) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Aggregations

RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)10 Namespace (com.google.cloud.servicedirectory.v1.Namespace)5 ListNamespacesPagedResponse (com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse)4 After (org.junit.After)3 LocationName (com.google.cloud.servicedirectory.v1.LocationName)2 NamespaceName (com.google.cloud.servicedirectory.v1.NamespaceName)2 ServiceName (com.google.cloud.servicedirectory.v1.ServiceName)2 Endpoint (com.google.cloud.servicedirectory.v1.Endpoint)1 EndpointName (com.google.cloud.servicedirectory.v1.EndpointName)1 Service (com.google.cloud.servicedirectory.v1.Service)1