use of com.google.monitoring.v3.NotificationChannel in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method createNotificationChannelExceptionTest2.
@Test
public void createNotificationChannelExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockNotificationChannelService.addException(exception);
try {
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
client.createNotificationChannel(name, notificationChannel);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.monitoring.v3.NotificationChannel in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method createNotificationChannelTest3.
@Test
public void createNotificationChannelTest3() throws Exception {
NotificationChannel expectedResponse = NotificationChannel.newBuilder().setType("type3575610").setName(NotificationChannelName.ofProjectNotificationChannelName("[PROJECT]", "[NOTIFICATION_CHANNEL]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").putAllLabels(new HashMap<String, String>()).putAllUserLabels(new HashMap<String, String>()).setEnabled(BoolValue.newBuilder().build()).setCreationRecord(MutationRecord.newBuilder().build()).addAllMutationRecords(new ArrayList<MutationRecord>()).build();
mockNotificationChannelService.addResponse(expectedResponse);
ProjectName name = ProjectName.of("[PROJECT]");
NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
NotificationChannel actualResponse = client.createNotificationChannel(name, notificationChannel);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateNotificationChannelRequest actualRequest = ((CreateNotificationChannelRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.monitoring.v3.NotificationChannel in project java-monitoring by googleapis.
the class DeleteNotificationChannelIT method setupClass.
@BeforeClass
public static void setupClass() throws IOException {
try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
String projectId = getProjectId();
NOTIFICATION_CHANNEL = NotificationChannel.newBuilder().setType("email").putLabels("email_address", "java-docs-samples-testing@google.com").build();
NotificationChannel channel = client.createNotificationChannel(ProjectName.of(projectId), NOTIFICATION_CHANNEL);
NOTIFICATION_CHANNEL_NAME = channel.getName();
}
}
use of com.google.monitoring.v3.NotificationChannel in project java-docs-samples by GoogleCloudPlatform.
the class AlertSample method restoreNotificationChannels.
private Map<String, String> restoreNotificationChannels(String projectId, List<NotificationChannel> channels, boolean isSameProject) {
Map<String, String> newChannelNames = Maps.newHashMap();
for (NotificationChannel channel : channels) {
// Update channel name if project ID is different.
boolean channelUpdated = false;
if (isSameProject) {
try {
NotificationChannel updatedChannel = notificationChannelClient.updateNotificationChannel(NOTIFICATION_CHANNEL_UPDATE_MASK, channel);
newChannelNames.put(channel.getName(), updatedChannel.getName());
channelUpdated = true;
} catch (Exception e) {
channelUpdated = false;
}
}
if (!channelUpdated) {
NotificationChannel newChannel = notificationChannelClient.createNotificationChannel(ProjectName.of(projectId), channel.toBuilder().clearName().clearVerificationStatus().build());
newChannelNames.put(channel.getName(), newChannel.getName());
}
}
return newChannelNames;
}
use of com.google.monitoring.v3.NotificationChannel in project java-docs-samples by GoogleCloudPlatform.
the class AlertSample method writePoliciesBackupFile.
private void writePoliciesBackupFile(String projectId, String filePath, List<AlertPolicy> alertPolicies, List<NotificationChannel> notificationChannels) throws IOException {
JsonObject backupContents = new JsonObject();
backupContents.add("project_id", new JsonPrimitive(projectId));
JsonArray policiesJson = new JsonArray();
for (AlertPolicy policy : alertPolicies) {
policiesJson.add(gson.toJsonTree(policy));
}
backupContents.add("policies", policiesJson);
JsonArray notificationsJson = new JsonArray();
for (NotificationChannel channel : notificationChannels) {
notificationsJson.add(gson.toJsonTree(channel));
}
backupContents.add("notification_channels", notificationsJson);
FileWriter writer = new FileWriter(filePath);
writer.write(backupContents.toString());
writer.close();
}
Aggregations