Search in sources :

Example 6 with Notification

use of com.sequenceiq.cloudbreak.service.notification.Notification in project cloudbreak by hortonworks.

the class UptimeNotifierTest method notificationSendingWhenCredentialNullEverythingWorkFine.

@Test
public void notificationSendingWhenCredentialNullEverythingWorkFine() {
    doNothing().when(notificationSender).send(any(Notification.class));
    List<Cluster> clusters = TestUtil.generateCluster(1);
    when(clusterRepository.findByStatuses(any())).thenReturn(Collections.singletonList(clusters.get(0)));
    Stack stack2 = TestUtil.stack();
    stack2.setCluster(clusters.get(0));
    stack2.setCredential(null);
    when(stackRepository.findStackForCluster(anyLong())).thenReturn(stack2);
    underTest.sendUptime();
    ArgumentCaptor<Notification> argument2 = ArgumentCaptor.forClass(Notification.class);
    verify(notificationSender).send(argument2.capture());
    Notification<CloudbreakEventsJson> notification = argument2.getValue();
    assertEquals("null", notification.getNotification().getCloud());
    assertEquals("multi-node-yarn", notification.getNotification().getBlueprintName());
    assertEquals(Long.valueOf(1), notification.getNotification().getBlueprintId());
    verify(notificationSender, times(1)).send(any(Notification.class));
}
Also used : CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Notification(com.sequenceiq.cloudbreak.service.notification.Notification) Stack(com.sequenceiq.cloudbreak.domain.Stack) Test(org.junit.Test)

Example 7 with Notification

use of com.sequenceiq.cloudbreak.service.notification.Notification in project cloudbreak by hortonworks.

the class UptimeNotifier method createUptimeNotification.

private Notification<CloudbreakEventsJson> createUptimeNotification(Stack stack, Long uptime) {
    CloudbreakEventsJson notification = new CloudbreakEventsJson();
    notification.setOwner(stack.getOwner());
    notification.setAccount(stack.getAccount());
    notification.setStackId(stack.getId());
    notification.setEventType(UPTIME_NOTIFICATION);
    notification.setEventMessage(String.valueOf(uptime));
    if (stack.getCredential() == null) {
        notification.setCloud("null");
    } else {
        notification.setCloud(stack.getCredential().cloudPlatform());
    }
    if (stack.getCluster() == null || stack.getCluster().getBlueprint() == null) {
        notification.setBlueprintId(null);
        notification.setBlueprintName("null");
    } else {
        notification.setBlueprintId(stack.getCluster().getBlueprint().getId());
        notification.setBlueprintName(stack.getCluster().getBlueprint().getAmbariName());
        notification.setClusterName(stack.getCluster().getName());
        notification.setClusterId(stack.getCluster().getId());
    }
    return new Notification<>(notification);
}
Also used : CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) Notification(com.sequenceiq.cloudbreak.service.notification.Notification)

Aggregations

CloudbreakEventsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson)7 Notification (com.sequenceiq.cloudbreak.service.notification.Notification)7 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 Date (java.util.Date)3 Test (org.junit.Test)3