Search in sources :

Example 1 with UpdateUptimeCheckConfigRequest

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

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 2 with UpdateUptimeCheckConfigRequest

use of com.google.monitoring.v3.UpdateUptimeCheckConfigRequest 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 3 with UpdateUptimeCheckConfigRequest

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

the class UptimeCheckServiceClientTest method updateUptimeCheckConfigTest.

@Test
public void updateUptimeCheckConfigTest() 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);
    UptimeCheckConfig uptimeCheckConfig = UptimeCheckConfig.newBuilder().build();
    UptimeCheckConfig actualResponse = client.updateUptimeCheckConfig(uptimeCheckConfig);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockUptimeCheckService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateUptimeCheckConfigRequest actualRequest = ((UpdateUptimeCheckConfigRequest) actualRequests.get(0));
    Assert.assertEquals(uptimeCheckConfig, actualRequest.getUptimeCheckConfig());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateUptimeCheckConfigRequest(com.google.monitoring.v3.UpdateUptimeCheckConfigRequest) ArrayList(java.util.ArrayList) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) Test(org.junit.Test)

Aggregations

UpdateUptimeCheckConfigRequest (com.google.monitoring.v3.UpdateUptimeCheckConfigRequest)3 UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)3 UptimeCheckServiceClient (com.google.cloud.monitoring.v3.UptimeCheckServiceClient)2 IOException (java.io.IOException)2 ParseException (org.apache.commons.cli.ParseException)2 AbstractMessage (com.google.protobuf.AbstractMessage)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1