class EmrHelperServiceImpl implements EmrHelperService {

    void updateEmrClusterDefinitionWithValidInstanceFleetSubnets(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterDefinition emrClusterDefinition,
        AwsParamsDto awsParamsDto)
    {
        // Get total count of instances this definition will attempt to create
        Integer instanceFleetMinimumIpAvailableFilter = emrClusterDefinition.getInstanceFleetMinimumIpAvailableFilter();

        if (instanceFleetMinimumIpAvailableFilter == null || instanceFleetMinimumIpAvailableFilter == 0)
        {
            return;
        }

        // Get the subnet information
        // Makes AWS EC2 call DescribeSubnets

        List<Subnet> subnets = emrPricingHelper.getSubnets(emrClusterDefinition, awsParamsDto);

        List<String> validSubnetIds =
            subnets.stream().filter(subnet -> subnet.getAvailableIpAddressCount() >= instanceFleetMinimumIpAvailableFilter).map(Subnet::getSubnetId)
                .collect(Collectors.toList());

        String contextInfo = String.format("namespace=\"%s\" emrClusterDefinitionName=\"%s\" emrClusterName=\"%s\" " +
                "instanceFleetMinimumIpAvailableFilter=%s subnetAvailableIpAddressCounts=%s validSubnetIds=%s", emrClusterAlternateKeyDto.getNamespace(),
            emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName(), instanceFleetMinimumIpAvailableFilter,
            jsonHelper.objectToJson(subnets.stream().collect(Collectors.toMap(Subnet::getSubnetId, Subnet::getAvailableIpAddressCount))),
            validSubnetIds.toString());

        LOGGER.info("Current IP availability: {}", contextInfo);

        if (validSubnetIds.isEmpty())
        {
            throw new IllegalArgumentException(
                "Specified subnets do not have enough available IP addresses required for the instance fleet. " + "Current IP availability: " + contextInfo);
        }

        // Pass list of valid subnet ids back to EMR cluster definition
        emrClusterDefinition.setSubnetId(String.join(",", validSubnetIds));
    }

}