Search in sources :

Example 11 with CloudbreakEventsJson

use of com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson in project cloudbreak by hortonworks.

the class UptimeNotifierTest method notificationSendingWhenBlueprintNotNullEverythingWorkFine.

@Test
public void notificationSendingWhenBlueprintNotNullEverythingWorkFine() {
    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));
    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(GCP, 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 12 with CloudbreakEventsJson

use of com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson 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 13 with CloudbreakEventsJson

use of com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson in project cloudbreak by hortonworks.

the class CredentialService method sendCredentialNotification.

private void sendCredentialNotification(Credential credential, ResourceEvent resourceEvent) {
    CloudbreakEventsJson notification = new CloudbreakEventsJson();
    notification.setEventType(resourceEvent.name());
    notification.setEventTimestamp(new Date().getTime());
    notification.setEventMessage(resourceEvent.getMessage());
    notification.setOwner(credential.getOwner());
    notification.setAccount(credential.getAccount());
    notification.setCloud(credential.cloudPlatform());
    notificationSender.send(new Notification<>(notification));
}
Also used : CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) Date(java.util.Date)

Example 14 with CloudbreakEventsJson

use of com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson in project cloudbreak by hortonworks.

the class InteractiveCredentialCreationStatusHandler method accept.

@Override
public void accept(Event<InteractiveCredentialCreationStatus> interactiveCredentialCreationFailedEvent) {
    InteractiveCredentialCreationStatus interactiveCredentialCreationStatus = interactiveCredentialCreationFailedEvent.getData();
    String message = interactiveCredentialCreationStatus.getMessage();
    CloudbreakEventsJson notification = new CloudbreakEventsJson();
    if (interactiveCredentialCreationStatus.isError()) {
        notification.setEventType("CREDENTIAL_CREATE_FAILED");
    } else {
        notification.setEventType("INTERACTIVE_CREDENTIAL_STATUS");
    }
    notification.setEventTimestamp(new Date().getTime());
    notification.setEventMessage(message);
    notification.setOwner(interactiveCredentialCreationStatus.getCloudContext().getOwner());
    notification.setAccount(interactiveCredentialCreationStatus.getExtendedCloudCredential().getAccount());
    notification.setCloud(interactiveCredentialCreationStatus.getExtendedCloudCredential().getCloudPlatform());
    notificationSender.send(new Notification<>(notification));
}
Also used : InteractiveCredentialCreationStatus(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationStatus) CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) Date(java.util.Date)

Example 15 with CloudbreakEventsJson

use of com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson in project cloudbreak by hortonworks.

the class UptimeNotifier method sendUptime.

@Scheduled(fixedDelay = 60000)
public void sendUptime() {
    EnumSet<Status> statuses = EnumSet.complementOf(EnumSet.of(Status.DELETE_COMPLETED));
    List<Cluster> clusters = clusterRepository.findByStatuses(statuses);
    for (Cluster cluster : clusters) {
        Stack stack = stackRepository.findStackForCluster(cluster.getId());
        if (stack != null && !stack.isDeleteCompleted()) {
            Long uptime = stackUtil.getUptimeForCluster(cluster, cluster.isAvailable());
            Notification<CloudbreakEventsJson> notification = createUptimeNotification(stack, uptime);
            notificationSender.send(notification);
        }
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

CloudbreakEventsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson)16 Notification (com.sequenceiq.cloudbreak.service.notification.Notification)7 Date (java.util.Date)7 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Stack (com.sequenceiq.cloudbreak.domain.Stack)4 Test (org.junit.Test)4 StackEndpoint (com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint)1 EventEndpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)1 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)1 Status (com.sequenceiq.cloudbreak.api.model.Status)1 InteractiveCredentialCreationStatus (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationStatus)1 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)1 NotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails)1 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails)1 StructuredNotificationEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)1 HistoryEndpoint (com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1