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());
}
}
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()));
}
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());
}
}
Aggregations