Search in sources :

Example 1 with ServiceName

use of com.google.cloud.servicedirectory.v1.ServiceName in project java-servicedirectory by googleapis.

the class RegistrationServiceClientTest method listEndpointsTest.

@Test
public void listEndpointsTest() throws Exception {
    Endpoint responsesElement = Endpoint.newBuilder().build();
    ListEndpointsResponse expectedResponse = ListEndpointsResponse.newBuilder().setNextPageToken("").addAllEndpoints(Arrays.asList(responsesElement)).build();
    mockRegistrationService.addResponse(expectedResponse);
    ServiceName parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[NAMESPACE]", "[SERVICE]");
    ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent);
    List<Endpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getEndpointsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListEndpointsRequest actualRequest = ((ListEndpointsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListEndpointsPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListEndpointsPagedResponse) Test(org.junit.Test)

Example 2 with ServiceName

use of com.google.cloud.servicedirectory.v1.ServiceName 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 ServiceName

use of com.google.cloud.servicedirectory.v1.ServiceName in project java-servicedirectory by googleapis.

the class ServicesResolve method resolveService.

// Resolve a service.
public static void resolveService(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 (LookupServiceClient client = LookupServiceClient.create()) {
        // The service to resolve.
        ServiceName name = ServiceName.of(projectId, locationId, namespaceId, serviceId);
        // Construct the resolve request to be sent to the client.
        ResolveServiceRequest request = ResolveServiceRequest.newBuilder().setName(name.toString()).build();
        // Send the request to resolve the service.
        ResolveServiceResponse resolveResponse = client.resolveService(request);
        // Process the response.
        System.out.println("Resolved Service: " + resolveResponse.getService().getName());
        System.out.println("Endpoints found:");
        for (Endpoint endpoint : resolveResponse.getService().getEndpointsList()) {
            System.out.println(endpoint.getName() + " -- " + endpoint.getAddress() + ":" + endpoint.getPort());
        }
    }
}
Also used : ResolveServiceResponse(com.google.cloud.servicedirectory.v1.ResolveServiceResponse) Endpoint(com.google.cloud.servicedirectory.v1.Endpoint) ServiceName(com.google.cloud.servicedirectory.v1.ServiceName) ResolveServiceRequest(com.google.cloud.servicedirectory.v1.ResolveServiceRequest) LookupServiceClient(com.google.cloud.servicedirectory.v1.LookupServiceClient)

Example 4 with ServiceName

use of com.google.cloud.servicedirectory.v1.ServiceName in project java-servicedirectory by googleapis.

the class ServicesDelete method deleteService.

// Delete a service.
public static void deleteService(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 service to delete.
        ServiceName serviceName = ServiceName.of(projectId, locationId, namespaceId, serviceId);
        // Send the request to delete the service.
        client.deleteService(serviceName);
        // Log the action.
        System.out.println("Deleted Service: " + serviceName.toString());
    }
}
Also used : ServiceName(com.google.cloud.servicedirectory.v1.ServiceName) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Aggregations

ServiceName (com.google.cloud.servicedirectory.v1.ServiceName)3 Endpoint (com.google.cloud.servicedirectory.v1.Endpoint)2 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)2 LookupServiceClient (com.google.cloud.servicedirectory.v1.LookupServiceClient)1 ListEndpointsPagedResponse (com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListEndpointsPagedResponse)1 ResolveServiceRequest (com.google.cloud.servicedirectory.v1.ResolveServiceRequest)1 ResolveServiceResponse (com.google.cloud.servicedirectory.v1.ResolveServiceResponse)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1