public static NotificationChannelName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "NotificationChannelName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("notification_channel")); }
public static List<String> toStringList(List<NotificationChannelName> values) { List<String> list = new ArrayList<String>(values.size()); for (NotificationChannelName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public static List<NotificationChannelName> parseList(List<String> formattedStrings) { List<NotificationChannelName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
public static String format(String project, String notificationChannel) { return newBuilder() .setProject(project) .setNotificationChannel(notificationChannel) .build() .toString(); }
@Test @SuppressWarnings("all") public void deleteNotificationChannelTest() { Empty expectedResponse = Empty.newBuilder().build(); mockNotificationChannelService.addResponse(expectedResponse); NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); boolean force = false; client.deleteNotificationChannel(name, force); List<GeneratedMessageV3> actualRequests = mockNotificationChannelService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteNotificationChannelRequest actualRequest = (DeleteNotificationChannelRequest) actualRequests.get(0); Assert.assertEquals(name, NotificationChannelName.parse(actualRequest.getName())); Assert.assertEquals(force, actualRequest.getForce()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
private static void replaceChannels(String projectId, String alertPolicyId, String[] channelIds) throws IOException { AlertPolicy.Builder policyBuilder = AlertPolicy .newBuilder() .setName(AlertPolicyName.of(projectId, alertPolicyId).toString()); for (String channelId : channelIds) { policyBuilder.addNotificationChannels( NotificationChannelName.of(projectId, channelId).toString()); } try (AlertPolicyServiceClient client = AlertPolicyServiceClient.create()) { AlertPolicy result = client.updateAlertPolicy( FieldMask.newBuilder().addPaths("notification_channels").build(), policyBuilder.build()); System.out.println(String.format("Updated %s", result.getName())); } } // [END monitoring_alert_replace_channels]
public NotificationChannelName build() { return new NotificationChannelName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
public static NotificationChannelName of(String project, String notificationChannel) { return newBuilder().setProject(project).setNotificationChannel(notificationChannel).build(); }
@Test @SuppressWarnings("all") public void getNotificationChannelTest() { String type = "type3575610"; String name2 = "name2-1052831874"; String displayName = "displayName1615086568"; String description = "description-1724546052"; NotificationChannel expectedResponse = NotificationChannel.newBuilder() .setType(type) .setName(name2) .setDisplayName(displayName) .setDescription(description) .build(); mockNotificationChannelService.addResponse(expectedResponse); NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); NotificationChannel actualResponse = client.getNotificationChannel(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockNotificationChannelService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetNotificationChannelRequest actualRequest = (GetNotificationChannelRequest) actualRequests.get(0); Assert.assertEquals(name, NotificationChannelName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * Gets a single notification channel. The channel includes the relevant configuration details * with which the channel was created. However, the response may truncate or omit passwords, API * keys, or other private key matter and thus the response may not be 100% identical to the * information that was supplied in the call to the create method. * * <p>Sample code: * * <pre><code> * try (NotificationChannelServiceClient notificationChannelServiceClient = NotificationChannelServiceClient.create()) { * NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); * NotificationChannel response = notificationChannelServiceClient.getNotificationChannel(name); * } * </code></pre> * * @param name The channel for which to execute the request. The format is * `projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final NotificationChannel getNotificationChannel(NotificationChannelName name) { GetNotificationChannelRequest request = GetNotificationChannelRequest.newBuilder() .setName(name == null ? null : name.toString()) .build(); return getNotificationChannel(request); }
@Test @SuppressWarnings("all") public void getNotificationChannelExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockNotificationChannelService.addException(exception); try { NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); client.getNotificationChannel(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
/** * Deletes a notification channel. * * <p>Sample code: * * <pre><code> * try (NotificationChannelServiceClient notificationChannelServiceClient = NotificationChannelServiceClient.create()) { * NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); * boolean force = false; * notificationChannelServiceClient.deleteNotificationChannel(name, force); * } * </code></pre> * * @param name The channel for which to execute the request. The format is * `projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]`. * @param force If true, the notification channel will be deleted regardless of its use in alert * policies (the policies will be updated to remove the channel). If false, channels that are * still referenced by an existing alerting policy will fail to be deleted in a delete * operation. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void deleteNotificationChannel(NotificationChannelName name, boolean force) { DeleteNotificationChannelRequest request = DeleteNotificationChannelRequest.newBuilder() .setName(name == null ? null : name.toString()) .setForce(force) .build(); deleteNotificationChannel(request); }
@Test @SuppressWarnings("all") public void deleteNotificationChannelExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockNotificationChannelService.addException(exception); try { NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); boolean force = false; client.deleteNotificationChannel(name, force); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }
/** * Gets a single notification channel. The channel includes the relevant configuration details * with which the channel was created. However, the response may truncate or omit passwords, API * keys, or other private key matter and thus the response may not be 100% identical to the * information that was supplied in the call to the create method. * * <p>Sample code: * * <pre><code> * try (NotificationChannelServiceClient notificationChannelServiceClient = NotificationChannelServiceClient.create()) { * NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); * NotificationChannel response = notificationChannelServiceClient.getNotificationChannel(name); * } * </code></pre> * * @param name The channel for which to execute the request. The format is * `projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final NotificationChannel getNotificationChannel(NotificationChannelName name) { GetNotificationChannelRequest request = GetNotificationChannelRequest.newBuilder() .setName(name == null ? null : name.toString()) .build(); return getNotificationChannel(request); }
/** * Demonstrates deleting a notification channel by name. * @param channelName Name of the notification channel to delete. */ // [START monitoring_alert_delete_channel] static void deleteNotificationChannel(String channelName) throws IOException { String projectId = System.getProperty("projectId"); try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) { NotificationChannelName name = NotificationChannelName.of(projectId, channelName); client.deleteNotificationChannel(channelName, false); System.out.println("Deleted notification channel " + channelName); } } // [END monitoring_alert_delete_channel]
/** * Deletes a notification channel. * * <p>Sample code: * * <pre><code> * try (NotificationChannelServiceClient notificationChannelServiceClient = NotificationChannelServiceClient.create()) { * NotificationChannelName name = NotificationChannelName.of("[PROJECT]", "[NOTIFICATION_CHANNEL]"); * boolean force = false; * notificationChannelServiceClient.deleteNotificationChannel(name, force); * } * </code></pre> * * @param name The channel for which to execute the request. The format is * `projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]`. * @param force If true, the notification channel will be deleted regardless of its use in alert * policies (the policies will be updated to remove the channel). If false, channels that are * still referenced by an existing alerting policy will fail to be deleted in a delete * operation. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void deleteNotificationChannel(NotificationChannelName name, boolean force) { DeleteNotificationChannelRequest request = DeleteNotificationChannelRequest.newBuilder() .setName(name == null ? null : name.toString()) .setForce(force) .build(); deleteNotificationChannel(request); }