@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()); }
@Override public Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent) { Map<String, Object> params = legacyRestCommonService.addClusterCrnAndNameIfPresent(structuredEvent); OperationDetails operation = structuredEvent.getOperation(); Optional<Stack> stack = stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId()); AuditEventName auditEventName = auditEventName(structuredEvent); if (stack.isPresent() && auditEventName == AuditEventName.RESIZE_DATAHUB_CLUSTER) { Json json = new Json(structuredEvent.getRestCall().getRestRequest().getBody()); String group = json.getValue("group"); HostGroup hostGroup = hostGroupService.getByClusterIdAndNameWithRecipes(stack.get().getCluster().getId(), group); Integer desiredCount = json.getValue("desiredCount"); Integer originalNodeCount = hostGroup.getInstanceGroup().getNodeCount(); params.put("desiredCount", desiredCount); params.put("originalCount", originalNodeCount); params.put("hostGroup", group); } return params; }
DatahubRestResourceAuditEventConverter implements RestResourceAuditEventConverter { @Override public Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent) { Map<String, Object> params = legacyRestCommonService.addClusterCrnAndNameIfPresent(structuredEvent); OperationDetails operation = structuredEvent.getOperation(); Optional<Stack> stack = stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId()); AuditEventName auditEventName = auditEventName(structuredEvent); if (stack.isPresent() && auditEventName == AuditEventName.RESIZE_DATAHUB_CLUSTER) { Json json = new Json(structuredEvent.getRestCall().getRestRequest().getBody()); String group = json.getValue("group"); HostGroup hostGroup = hostGroupService.getByClusterIdAndNameWithRecipes(stack.get().getCluster().getId(), group); Integer desiredCount = json.getValue("desiredCount"); Integer originalNodeCount = hostGroup.getInstanceGroup().getNodeCount(); params.put("desiredCount", desiredCount); params.put("originalCount", originalNodeCount); params.put("hostGroup", group); } return params; } }
DatahubRestResourceAuditEventConverter implements RestResourceAuditEventConverter { @Override public Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent) { Map<String, Object> params = legacyRestCommonService.addClusterCrnAndNameIfPresent(structuredEvent); OperationDetails operation = structuredEvent.getOperation(); Optional<Stack> stack = stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId()); AuditEventName auditEventName = auditEventName(structuredEvent); if (stack.isPresent() && auditEventName == AuditEventName.RESIZE_DATAHUB_CLUSTER) { Json json = new Json(structuredEvent.getRestCall().getRestRequest().getBody()); String group = json.getValue("group"); HostGroup hostGroup = hostGroupService.getByClusterIdAndNameWithRecipes(stack.get().getCluster().getId(), group); Integer desiredCount = json.getValue("desiredCount"); Integer originalNodeCount = hostGroup.getInstanceGroup().getNodeCount(); params.put("desiredCount", desiredCount); params.put("originalCount", originalNodeCount); params.put("hostGroup", group); } return params; }  }
DatahubRestResourceAuditEventConverter implements RestResourceAuditEventConverter { @Override public Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent) { Map<String, Object> params = legacyRestCommonService.addClusterCrnAndNameIfPresent(structuredEvent); OperationDetails operation = structuredEvent.getOperation(); Optional<Stack> stack = stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId()); AuditEventName auditEventName = auditEventName(structuredEvent); if (stack.isPresent() && auditEventName == AuditEventName.RESIZE_DATAHUB_CLUSTER) { Json json = new Json(structuredEvent.getRestCall().getRestRequest().getBody()); String group = json.getValue("group"); HostGroup hostGroup = hostGroupService.getByClusterIdAndNameWithRecipes(stack.get().getCluster().getId(), group); Integer desiredCount = json.getValue("desiredCount"); Integer originalNodeCount = hostGroup.getInstanceGroup().getNodeCount(); params.put("desiredCount", desiredCount); params.put("originalCount", originalNodeCount); params.put("hostGroup", group); } return params; }  @Override AuditEventName auditEventName(StructuredRestCallEvent structuredEvent); @Override boolean shouldAudit(StructuredRestCallEvent structuredRestCallEvent); @Override Crn.Service eventSource(StructuredRestCallEvent structuredEvent); @Override Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent); }
DatahubRestResourceAuditEventConverter implements RestResourceAuditEventConverter { @Override public Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent) { Map<String, Object> params = legacyRestCommonService.addClusterCrnAndNameIfPresent(structuredEvent); OperationDetails operation = structuredEvent.getOperation(); Optional<Stack> stack = stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId()); AuditEventName auditEventName = auditEventName(structuredEvent); if (stack.isPresent() && auditEventName == AuditEventName.RESIZE_DATAHUB_CLUSTER) { Json json = new Json(structuredEvent.getRestCall().getRestRequest().getBody()); String group = json.getValue("group"); HostGroup hostGroup = hostGroupService.getByClusterIdAndNameWithRecipes(stack.get().getCluster().getId(), group); Integer desiredCount = json.getValue("desiredCount"); Integer originalNodeCount = hostGroup.getInstanceGroup().getNodeCount(); params.put("desiredCount", desiredCount); params.put("originalCount", originalNodeCount); params.put("hostGroup", group); } return params; }  @Override AuditEventName auditEventName(StructuredRestCallEvent structuredEvent); @Override boolean shouldAudit(StructuredRestCallEvent structuredRestCallEvent); @Override Crn.Service eventSource(StructuredRestCallEvent structuredEvent); @Override Map<String, Object> requestParameters(StructuredRestCallEvent structuredEvent);  }