Search in sources :

Example 11 with UptimeCheckConfig

use of com.google.monitoring.v3.UptimeCheckConfig in project java-monitoring by googleapis.

the class UptimeCheckServiceClientTest method createUptimeCheckConfigExceptionTest2.

@Test
public void createUptimeCheckConfigExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockUptimeCheckService.addException(exception);
    try {
        OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
        UptimeCheckConfig uptimeCheckConfig = UptimeCheckConfig.newBuilder().build();
        client.createUptimeCheckConfig(parent, uptimeCheckConfig);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : OrganizationName(com.google.monitoring.v3.OrganizationName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) Test(org.junit.Test)

Example 12 with UptimeCheckConfig

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

the class UptimeSample method updateUptimeCheck.

// [END monitoring_uptime_check_create]]
// [START monitoring_uptime_check_update]]
private static void updateUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
    String fullCheckName = UptimeCheckConfigName.format(projectId, displayName);
    UpdateUptimeCheckConfigRequest request = UpdateUptimeCheckConfigRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("http_check.path")).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setName(fullCheckName).setMonitoredResource(MonitoredResource.newBuilder().setType("uptime_url").putLabels("host", hostName)).setHttpCheck(HttpCheck.newBuilder().setPath(pathName).setPort(80)).setTimeout(Duration.newBuilder().setSeconds(10)).setPeriod(Duration.newBuilder().setSeconds(300))).build();
    try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
        UptimeCheckConfig config = client.updateUptimeCheckConfig(request);
        System.out.println("Uptime check updated: \n" + config.toString());
    } catch (Exception e) {
        usage("Exception updating uptime check: " + e.toString());
        throw e;
    }
}
Also used : UpdateUptimeCheckConfigRequest(com.google.monitoring.v3.UpdateUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 13 with UptimeCheckConfig

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

the class UptimeSample method createUptimeCheck.

// [START monitoring_uptime_check_create]]
private static void createUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
    CreateUptimeCheckConfigRequest request = CreateUptimeCheckConfigRequest.newBuilder().setParent(ProjectName.format(projectId)).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setDisplayName(displayName).setMonitoredResource(MonitoredResource.newBuilder().setType("uptime_url").putLabels("host", hostName)).setHttpCheck(HttpCheck.newBuilder().setPath(pathName).setPort(80)).setTimeout(Duration.newBuilder().setSeconds(10)).setPeriod(Duration.newBuilder().setSeconds(300))).build();
    try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
        UptimeCheckConfig config = client.createUptimeCheckConfig(request);
        System.out.println("Uptime check created: " + config.getDisplayName());
    } catch (Exception e) {
        usage("Exception creating uptime check: " + e.toString());
        throw e;
    }
}
Also used : CreateUptimeCheckConfigRequest(com.google.monitoring.v3.CreateUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 14 with UptimeCheckConfig

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

the class UptimeSample method getUptimeCheckConfig.

// [END monitoring_uptime_check_list_ips]]
// [START monitoring_uptime_check_get]]
private static void getUptimeCheckConfig(String projectId, String checkName) throws IOException {
    try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
        String fullCheckName = UptimeCheckConfigName.format(projectId, checkName);
        UptimeCheckConfig config = client.getUptimeCheckConfig(fullCheckName);
        if (config != null) {
            System.out.println(config.toString());
        } else {
            System.out.println("No uptime check config found with name " + checkName + " in project " + projectId);
        }
    } catch (Exception e) {
        usage("Exception getting uptime check: " + e.toString());
        throw e;
    }
}
Also used : UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 15 with UptimeCheckConfig

use of com.google.monitoring.v3.UptimeCheckConfig in project java-monitoring by googleapis.

the class UptimeCheckServiceClientTest method createUptimeCheckConfigTest4.

@Test
public void createUptimeCheckConfigTest4() throws Exception {
    UptimeCheckConfig expectedResponse = UptimeCheckConfig.newBuilder().setName(UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").toString()).setDisplayName("displayName1714148973").setPeriod(Duration.newBuilder().build()).setTimeout(Duration.newBuilder().build()).addAllContentMatchers(new ArrayList<UptimeCheckConfig.ContentMatcher>()).addAllSelectedRegions(new ArrayList<UptimeCheckRegion>()).setIsInternal(true).addAllInternalCheckers(new ArrayList<InternalChecker>()).build();
    mockUptimeCheckService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    UptimeCheckConfig uptimeCheckConfig = UptimeCheckConfig.newBuilder().build();
    UptimeCheckConfig actualResponse = client.createUptimeCheckConfig(parent, uptimeCheckConfig);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockUptimeCheckService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateUptimeCheckConfigRequest actualRequest = ((CreateUptimeCheckConfigRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(uptimeCheckConfig, actualRequest.getUptimeCheckConfig());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CreateUptimeCheckConfigRequest(com.google.monitoring.v3.CreateUptimeCheckConfigRequest) ArrayList(java.util.ArrayList) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) Test(org.junit.Test)

Aggregations

UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)22 Test (org.junit.Test)16 AbstractMessage (com.google.protobuf.AbstractMessage)11 ArrayList (java.util.ArrayList)7 UptimeCheckServiceClient (com.google.cloud.monitoring.v3.UptimeCheckServiceClient)6 CreateUptimeCheckConfigRequest (com.google.monitoring.v3.CreateUptimeCheckConfigRequest)6 IOException (java.io.IOException)6 ParseException (org.apache.commons.cli.ParseException)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 ListUptimeCheckConfigsPagedResponse (com.google.cloud.monitoring.v3.UptimeCheckServiceClient.ListUptimeCheckConfigsPagedResponse)4 ListUptimeCheckConfigsRequest (com.google.monitoring.v3.ListUptimeCheckConfigsRequest)4 ListUptimeCheckConfigsResponse (com.google.monitoring.v3.ListUptimeCheckConfigsResponse)4 FolderName (com.google.monitoring.v3.FolderName)3 OrganizationName (com.google.monitoring.v3.OrganizationName)3 ProjectName (com.google.monitoring.v3.ProjectName)3 UpdateUptimeCheckConfigRequest (com.google.monitoring.v3.UpdateUptimeCheckConfigRequest)3 GetUptimeCheckConfigRequest (com.google.monitoring.v3.GetUptimeCheckConfigRequest)2 UptimeCheckServiceSettings (com.google.cloud.monitoring.v3.UptimeCheckServiceSettings)1 UptimeCheckConfigName (com.google.monitoring.v3.UptimeCheckConfigName)1