Search in sources :

Example 6 with ServiceName

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

Example 7 with ServiceName

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ServiceName(com.google.monitoring.v3.ServiceName) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) GetServiceRequest(com.google.monitoring.v3.GetServiceRequest) Test(org.junit.Test)

Example 8 with ServiceName

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()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) ServiceName(com.google.monitoring.v3.ServiceName) DeleteServiceRequest(com.google.monitoring.v3.DeleteServiceRequest) Test(org.junit.Test)

Example 9 with ServiceName

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ServiceName(com.google.monitoring.v3.ServiceName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 10 with ServiceName

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ServiceName(com.google.monitoring.v3.ServiceName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

ServiceName (com.google.monitoring.v3.ServiceName)8 Test (org.junit.Test)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 ServiceName (com.google.cloud.servicedirectory.v1.ServiceName)3 ServiceLevelObjective (com.google.monitoring.v3.ServiceLevelObjective)3 Endpoint (com.google.cloud.servicedirectory.v1.Endpoint)2 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)2 DeleteServiceRequest (com.google.monitoring.v3.DeleteServiceRequest)2 HashMap (java.util.HashMap)2 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)1 ListServiceLevelObjectivesPagedResponse (com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServiceLevelObjectivesPagedResponse)1 LookupServiceClient (com.google.cloud.servicedirectory.v1.LookupServiceClient)1 ResolveServiceRequest (com.google.cloud.servicedirectory.v1.ResolveServiceRequest)1 ResolveServiceResponse (com.google.cloud.servicedirectory.v1.ResolveServiceResponse)1 CreateServiceLevelObjectiveRequest (com.google.monitoring.v3.CreateServiceLevelObjectiveRequest)1 GetServiceRequest (com.google.monitoring.v3.GetServiceRequest)1 ListServiceLevelObjectivesRequest (com.google.monitoring.v3.ListServiceLevelObjectivesRequest)1 ListServiceLevelObjectivesResponse (com.google.monitoring.v3.ListServiceLevelObjectivesResponse)1