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"));
}
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);
}
}
Aggregations