use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.
the class BaseLegacyStructuredFlowEventFactory method createStructuredNotificationEvent.
public StructuredNotificationEvent createStructuredNotificationEvent(Stack stack, String notificationType, String message, String instanceGroupName) {
Long stackId = stack.getId();
NotificationDetails notificationDetails = new NotificationDetails();
notificationDetails.setNotificationType(notificationType);
notificationDetails.setNotification(message);
notificationDetails.setStackId(stackId);
String stackName = stack.getName();
String userName = stack.getCreator().getUserName();
String userId = stack.getCreator().getUserId();
try {
notificationDetails.setCloud(stack.cloudPlatform());
notificationDetails.setRegion(stack.getRegion());
notificationDetails.setAvailabiltyZone(stack.getAvailabilityZone());
notificationDetails.setStackName(stack.getDisplayName());
notificationDetails.setStackStatus(stack.getStatus().name());
notificationDetails.setNodeCount(stack.getNotDeletedInstanceMetaDataSet().size());
Cluster cluster = stack.getCluster();
notificationDetails.setInstanceGroup(instanceGroupName);
if (cluster != null) {
notificationDetails.setClusterId(cluster.getId());
notificationDetails.setClusterName(cluster.getName());
notificationDetails.setClusterStatus(stack.getStatus().name());
Blueprint blueprint = cluster.getBlueprint();
if (blueprint != null) {
notificationDetails.setBlueprintId(blueprint.getId());
notificationDetails.setBlueprintName(blueprint.getStackName());
}
}
} catch (AccessDeniedException e) {
LOGGER.info("Access denied in structured notification event creation, user: {}, stack: {}", userName, stackId, e);
}
String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), NOTIFICATION, resourceType, stackId, stackName, nodeConfig.getInstanceUUID(), cbVersion, stack.getWorkspace().getId(), userId, userName, stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
return new StructuredNotificationEvent(operationDetails, notificationDetails);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.
the class BaseLegacyStructuredFlowEventFactory method createStucturedFlowEvent.
@Override
public StructuredFlowEvent createStucturedFlowEvent(Long stackId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
Stack stack = stackService.getByIdWithTransaction(stackId);
String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, stackId, stack.getName(), nodeConfig.getId(), cbVersion, stack.getWorkspace().getId(), stack.getCreator().getUserId(), stack.getCreator().getUserName(), stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
StackDetails stackDetails = null;
ClusterDetails clusterDetails = null;
BlueprintDetails blueprintDetails = null;
if (detailed) {
stackDetails = stackToStackDetailsConverter.convert(stack);
Cluster cluster = stack.getCluster();
if (cluster != null) {
clusterDetails = clusterToClusterDetailsConverter.convert(cluster);
blueprintDetails = getIfNotNull(cluster.getBlueprint(), blueprintToBlueprintDetailsConverter::convert);
}
}
StructuredFlowEvent event = new StructuredFlowEvent(operationDetails, flowDetails, stackDetails, clusterDetails, blueprintDetails);
if (exception != null) {
event.setException(ExceptionUtils.getStackTrace(exception));
}
return event;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.
the class DistroxStopStartScaleDurationAssertions method getTimestampForEvent.
private long getTimestampForEvent(List<StructuredNotificationEvent> structuredNotificationEvents, String message) {
OperationDetails latestEvent = structuredNotificationEvents.stream().filter(events -> StringUtils.containsIgnoreCase(events.getNotificationDetails().getNotification(), message)).map(StructuredEvent::getOperation).max(Comparator.comparing(OperationDetails::getTimestamp)).orElseThrow(() -> new TestFailException(String.format("Cannot find Structured Event for '%s' message!", message)));
long latestEventTimestamp = latestEvent.getTimestamp();
LOGGER.info(String.format("[%s] event time '%s'.", message, LocalDateTime.ofInstant(Instant.ofEpochMilli(latestEventTimestamp), ZoneId.systemDefault())));
return latestEventTimestamp;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.
the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackNotFound.
@Test
public void testRequestParametersWhenStackNotFound() {
StructuredRestCallEvent event = new StructuredRestCallEvent();
OperationDetails operation = new OperationDetails();
operation.setResourceName("name");
operation.setWorkspaceId(123L);
event.setOperation(operation);
RestCallDetails restCall = new RestCallDetails();
event.setRestCall(restCall);
RestRequestDetails restRequest = new RestRequestDetails();
restCall.setRestRequest(restRequest);
Map<String, Object> params = new HashMap<>();
when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.empty());
Map<String, Object> actual = underTest.requestParameters(event);
Assertions.assertEquals(0, actual.size());
}
use of com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails in project cloudbreak by hortonworks.
the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundButNotScaling.
@Test
public void testRequestParametersWhenStackFoundButNotScaling() {
StructuredRestCallEvent event = new StructuredRestCallEvent();
OperationDetails operation = new OperationDetails();
operation.setResourceName("name");
operation.setWorkspaceId(123L);
event.setOperation(operation);
RestCallDetails restCall = new RestCallDetails();
event.setRestCall(restCall);
RestRequestDetails restRequest = new RestRequestDetails();
restRequest.setMethod("POST");
restCall.setRestRequest(restRequest);
Stack stack = new Stack();
Map<String, Object> params = new HashMap<>();
when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
Map<String, Object> actual = underTest.requestParameters(event);
Assertions.assertEquals(0, actual.size());
}
Aggregations