@Test public void testCheckIsEnvironmentDeletableWhenSdxIsEmptyButDatalakeIsNot() { when(environmentResourceDeletionService.getAttachedSdxClusterCrns(environment)).thenReturn(emptySet()); when(environmentResourceDeletionService.getDatalakeClusterNames(environment)).thenReturn(Set.of("name")); BadRequestException actual = assertThrows(BadRequestException.class, () -> environmentDeletionService.checkIsEnvironmentDeletable(environment)); assertEquals("The following Data Lake cluster(s) must be terminated before Environment deletion [name]", actual.getMessage()); }
@VisibleForTesting void checkIsEnvironmentDeletable(Environment env) { LOGGER.info("Checking if environment [name: {}] is deletable", env.getName()); Set<String> datalakes = environmentResourceDeletionService.getAttachedSdxClusterCrns(env); if (datalakes.isEmpty()) { datalakes = environmentResourceDeletionService.getDatalakeClusterNames(env); } if (!datalakes.isEmpty()) { throw new BadRequestException(String.format("The following Data Lake cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", datalakes))); } Set<String> distroXClusterNames = environmentResourceDeletionService.getAttachedDistroXClusterNames(env); if (!distroXClusterNames.isEmpty()) { throw new BadRequestException(String.format("The following Data Hub cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", distroXClusterNames))); } }
EnvironmentDeletionService { @VisibleForTesting void checkIsEnvironmentDeletable(Environment env) { LOGGER.info("Checking if environment [name: {}] is deletable", env.getName()); Set<String> datalakes = environmentResourceDeletionService.getAttachedSdxClusterCrns(env); if (datalakes.isEmpty()) { datalakes = environmentResourceDeletionService.getDatalakeClusterNames(env); } if (!datalakes.isEmpty()) { throw new BadRequestException(String.format("The following Data Lake cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", datalakes))); } Set<String> distroXClusterNames = environmentResourceDeletionService.getAttachedDistroXClusterNames(env); if (!distroXClusterNames.isEmpty()) { throw new BadRequestException(String.format("The following Data Hub cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", distroXClusterNames))); } } }
EnvironmentDeletionService { @VisibleForTesting void checkIsEnvironmentDeletable(Environment env) { LOGGER.info("Checking if environment [name: {}] is deletable", env.getName()); Set<String> datalakes = environmentResourceDeletionService.getAttachedSdxClusterCrns(env); if (datalakes.isEmpty()) { datalakes = environmentResourceDeletionService.getDatalakeClusterNames(env); } if (!datalakes.isEmpty()) { throw new BadRequestException(String.format("The following Data Lake cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", datalakes))); } Set<String> distroXClusterNames = environmentResourceDeletionService.getAttachedDistroXClusterNames(env); if (!distroXClusterNames.isEmpty()) { throw new BadRequestException(String.format("The following Data Hub cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", distroXClusterNames))); } } EnvironmentDeletionService(EnvironmentService environmentService, EnvironmentDtoConverter environmentDtoConverter,
            EnvironmentReactorFlowManager reactorFlowManager, EnvironmentResourceDeletionService environmentResourceDeletionService,
            EnvironmentJobService environmentJobService); }
EnvironmentDeletionService { @VisibleForTesting void checkIsEnvironmentDeletable(Environment env) { LOGGER.info("Checking if environment [name: {}] is deletable", env.getName()); Set<String> datalakes = environmentResourceDeletionService.getAttachedSdxClusterCrns(env); if (datalakes.isEmpty()) { datalakes = environmentResourceDeletionService.getDatalakeClusterNames(env); } if (!datalakes.isEmpty()) { throw new BadRequestException(String.format("The following Data Lake cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", datalakes))); } Set<String> distroXClusterNames = environmentResourceDeletionService.getAttachedDistroXClusterNames(env); if (!distroXClusterNames.isEmpty()) { throw new BadRequestException(String.format("The following Data Hub cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", distroXClusterNames))); } } EnvironmentDeletionService(EnvironmentService environmentService, EnvironmentDtoConverter environmentDtoConverter,
            EnvironmentReactorFlowManager reactorFlowManager, EnvironmentResourceDeletionService environmentResourceDeletionService,
            EnvironmentJobService environmentJobService); EnvironmentDto deleteByNameAndAccountId(String environmentName, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); EnvironmentDto deleteByCrnAndAccountId(String crn, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); Environment delete(Environment environment, String userCrn,
        boolean cascading, boolean forced); List<EnvironmentDto> deleteMultipleByNames(Set<String> environmentNames, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); List<EnvironmentDto> deleteMultipleByCrns(Set<String> crns, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); }
EnvironmentDeletionService { @VisibleForTesting void checkIsEnvironmentDeletable(Environment env) { LOGGER.info("Checking if environment [name: {}] is deletable", env.getName()); Set<String> datalakes = environmentResourceDeletionService.getAttachedSdxClusterCrns(env); if (datalakes.isEmpty()) { datalakes = environmentResourceDeletionService.getDatalakeClusterNames(env); } if (!datalakes.isEmpty()) { throw new BadRequestException(String.format("The following Data Lake cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", datalakes))); } Set<String> distroXClusterNames = environmentResourceDeletionService.getAttachedDistroXClusterNames(env); if (!distroXClusterNames.isEmpty()) { throw new BadRequestException(String.format("The following Data Hub cluster(s) must be terminated before Environment deletion [%s]", String.join(", ", distroXClusterNames))); } } EnvironmentDeletionService(EnvironmentService environmentService, EnvironmentDtoConverter environmentDtoConverter,
            EnvironmentReactorFlowManager reactorFlowManager, EnvironmentResourceDeletionService environmentResourceDeletionService,
            EnvironmentJobService environmentJobService); EnvironmentDto deleteByNameAndAccountId(String environmentName, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); EnvironmentDto deleteByCrnAndAccountId(String crn, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); Environment delete(Environment environment, String userCrn,
        boolean cascading, boolean forced); List<EnvironmentDto> deleteMultipleByNames(Set<String> environmentNames, String accountId, String actualUserCrn,
        boolean cascading, boolean forced); List<EnvironmentDto> deleteMultipleByCrns(Set<String> crns, String accountId, String actualUserCrn,
        boolean cascading, boolean forced);  }