Search in sources :

Example 1 with MonitoredResourceDescriptorName

use of com.google.monitoring.v3.MonitoredResourceDescriptorName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method getMonitoredResourceDescriptorExceptionTest.

@Test
@SuppressWarnings("all")
public void getMonitoredResourceDescriptorExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricService.addException(exception);
    try {
        MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
        client.getMonitoredResourceDescriptor(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : MonitoredResourceDescriptorName(com.google.monitoring.v3.MonitoredResourceDescriptorName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 2 with MonitoredResourceDescriptorName

use of com.google.monitoring.v3.MonitoredResourceDescriptorName in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method describeMonitoredResources.

/**
 * Gets full information for a monitored resource.
 *
 * @param type The resource type
 */
void describeMonitoredResources(String type) throws IOException {
    // [START monitoring_get_descriptor]
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    final MetricServiceClient client = MetricServiceClient.create();
    MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of(projectId, type);
    MonitoredResourceDescriptor response = client.getMonitoredResourceDescriptor(name);
    System.out.println("Printing monitored resource descriptor: ");
    System.out.println(response);
// [END monitoring_get_descriptor]
}
Also used : MonitoredResourceDescriptorName(com.google.monitoring.v3.MonitoredResourceDescriptorName) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor)

Example 3 with MonitoredResourceDescriptorName

use of com.google.monitoring.v3.MonitoredResourceDescriptorName in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method getMonitoredResourceDescriptorTest.

@Test
@SuppressWarnings("all")
public void getMonitoredResourceDescriptorTest() {
    String name2 = "name2-1052831874";
    String type = "type3575610";
    String displayName = "displayName1615086568";
    String description = "description-1724546052";
    MonitoredResourceDescriptor expectedResponse = MonitoredResourceDescriptor.newBuilder().setName(name2).setType(type).setDisplayName(displayName).setDescription(description).build();
    mockMetricService.addResponse(expectedResponse);
    MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
    MonitoredResourceDescriptor actualResponse = client.getMonitoredResourceDescriptor(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetMonitoredResourceDescriptorRequest actualRequest = (GetMonitoredResourceDescriptorRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsMonitoredResourceDescriptorName());
}
Also used : MonitoredResourceDescriptorName(com.google.monitoring.v3.MonitoredResourceDescriptorName) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) GetMonitoredResourceDescriptorRequest(com.google.monitoring.v3.GetMonitoredResourceDescriptorRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

MonitoredResourceDescriptorName (com.google.monitoring.v3.MonitoredResourceDescriptorName)3 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)2 Test (org.junit.Test)2 ApiException (com.google.api.gax.grpc.ApiException)1 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)1 GetMonitoredResourceDescriptorRequest (com.google.monitoring.v3.GetMonitoredResourceDescriptorRequest)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1