use of com.google.monitoring.v3.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());
}
}
use of com.google.monitoring.v3.ServiceName in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method getServiceTest.
@Test
public void getServiceTest() throws Exception {
Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
mockServiceMonitoringService.addResponse(expectedResponse);
ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
Service actualResponse = client.getService(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetServiceRequest actualRequest = ((GetServiceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.ServiceName in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method deleteServiceTest.
@Test
public void deleteServiceTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockServiceMonitoringService.addResponse(expectedResponse);
ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
client.deleteService(name);
List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteServiceRequest actualRequest = ((DeleteServiceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.ServiceName in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method listServiceLevelObjectivesExceptionTest.
@Test
public void listServiceLevelObjectivesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
client.listServiceLevelObjectives(parent);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.ServiceName in project java-monitoring by googleapis.
the class ServiceMonitoringServiceClientTest method deleteServiceExceptionTest.
@Test
public void deleteServiceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockServiceMonitoringService.addException(exception);
try {
ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
client.deleteService(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations