Search in sources :

Example 1 with NamespaceName

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

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

the class RegistrationServiceClientTest method listServicesTest.

@Test
public void listServicesTest() throws Exception {
    Service responsesElement = Service.newBuilder().build();
    ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
    mockRegistrationService.addResponse(expectedResponse);
    NamespaceName parent = NamespaceName.of("[PROJECT]", "[LOCATION]", "[NAMESPACE]");
    ListServicesPagedResponse pagedListResponse = client.listServices(parent);
    List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListServicesPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListServicesPagedResponse) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Example 3 with NamespaceName

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

NamespaceName (com.google.cloud.servicedirectory.v1.NamespaceName)2 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)2 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)1 ListServicesPagedResponse (com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListServicesPagedResponse)1 Service (com.google.cloud.servicedirectory.v1.Service)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1