Search in sources :

Example 1 with ServiceEventData

use of com.sequenceiq.cloudbreak.audit.model.ServiceEventData in project cloudbreak by hortonworks.

the class AuditServiceTest method testAuditServiceEvent.

@Test
public void testAuditServiceEvent() {
    String auditMessage = "audit service message";
    underTest.auditAutoscaleServiceEvent(ScalingStatus.SUCCESS, auditMessage, "clusterCrn", "user-account", System.currentTimeMillis());
    ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
    verify(auditClient, times(1)).createAuditEvent(captor.capture());
    AuditEvent auditEvent = captor.getValue();
    assertEquals("user-account", auditEvent.getAccountId());
    assertEquals(AUTOSCALE_DATAHUB_CLUSTER, auditEvent.getEventName());
    assertEquals(Crn.Service.DATAHUB, auditEvent.getEventSource());
    assertEquals(Crn.Service.DATAHUB.getName(), ((ActorService) auditEvent.getActor()).getActorServiceName());
    ServiceEventData serviceEventData = (ServiceEventData) auditEvent.getEventData();
    assertNotNull("Event Data should be intialized", serviceEventData.getEventDetails());
    assertTrue("Time stamp should be intialized", serviceEventData.getEventDetails().contains("timestamp"));
}
Also used : ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Test(org.junit.Test)

Example 2 with ServiceEventData

use of com.sequenceiq.cloudbreak.audit.model.ServiceEventData in project cloudbreak by hortonworks.

the class AuditService method auditAutoscaleServiceEvent.

@Async
public void auditAutoscaleServiceEvent(ScalingStatus scalingStatus, String auditMessage, String clusterCrn, String accountId, Long timestamp) {
    AuditEvent event = null;
    try {
        Map<String, Object> eventDetails = new HashMap<>();
        eventDetails.put(CLUSTER_CRN, clusterCrn);
        eventDetails.put(TIMESTAMP, timestamp);
        eventDetails.put(AUTOSCALE_ACTION, auditMessage);
        eventDetails.put(AUTOSCALE_TRIGGER_STATUS, scalingStatus);
        ServiceEventData serviceEventData = ServiceEventData.builder().withEventDetails(new Json(eventDetails).getValue()).withVersion(periscopeVersion).build();
        event = AuditEvent.builder().withAccountId(accountId).withEventData(serviceEventData).withEventName(AuditEventName.AUTOSCALE_DATAHUB_CLUSTER).withEventSource(Crn.Service.DATAHUB).withActor(ActorService.builder().withActorServiceName(Crn.Service.DATAHUB.getName()).build()).build();
        auditClient.createAuditEvent(event);
    } catch (Exception ex) {
        LOGGER.warn("Service Audit event creation failed, error : '{}', event : '{}'", ex.getMessage(), event, ex);
    }
}
Also used : HashMap(java.util.HashMap) ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Json(com.sequenceiq.periscope.model.json.Json) Async(org.springframework.scheduling.annotation.Async)

Aggregations

AuditEvent (com.sequenceiq.cloudbreak.audit.model.AuditEvent)2 ServiceEventData (com.sequenceiq.cloudbreak.audit.model.ServiceEventData)2 Json (com.sequenceiq.periscope.model.json.Json)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Async (org.springframework.scheduling.annotation.Async)1