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 String format(String project, String notificationChannel) { return newBuilder() .setProject(project) .setNotificationChannel(notificationChannel) .build() .toString(); }
/** * 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); }
/** * 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); }
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]
/** * 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); }
/** * 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); }