@Test public void shouldDeleteIntegrationsAndDeletingAssociatedResources() { String id = "to-delete"; Integration integration = new Integration.Builder().id(id).build(); when(dataManager.fetch(Integration.class, id)).thenReturn(integration); Integration integration1 = new Integration.Builder().createFrom(integration).name("first to delete") .build(); Integration integration2 = new Integration.Builder().createFrom(integration).name("second to delete") .build(); String deploymentId1 = id + "-deploy1"; IntegrationDeployment deployment1 = new IntegrationDeployment.Builder().spec(integration1).version(1) .id(deploymentId1) .targetState(IntegrationDeploymentState.Unpublished) .stepsDone(Collections.singletonMap("deploy", "something")).build(); String deploymentId2 = id + "-deploy2"; IntegrationDeployment deployment2 = new IntegrationDeployment.Builder().spec(integration2).version(2) .id(deploymentId2) .currentState(IntegrationDeploymentState.Published).targetState(IntegrationDeploymentState.Published) .stepsDone(Collections.singletonMap("deploy", "something")).build(); Set<String> ibbIds = new HashSet<>(); for (int i = 1; i <= 2; ++i) { ibbIds.add(id + "-ibb" + i); } when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id)) .thenReturn(Stream.of(deployment1, deployment2)); when(dataManager.fetchIdsByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id)) .thenReturn(ibbIds); when(dataManager.delete(IntegrationDeployment.class, deploymentId1)).thenReturn(true); when(dataManager.delete(IntegrationDeployment.class, deploymentId2)).thenReturn(true); for (String ibbId : ibbIds) { when(dataManager.delete(IntegrationBulletinBoard.class, ibbId)).thenReturn(true); } when(dataManager.delete(Integration.class, id)).thenReturn(true); handler.delete(id); verify(dataManager).delete(Integration.class, id); verify(dataManager).delete(IntegrationDeployment.class, deploymentId1); verify(dataManager).delete(IntegrationDeployment.class, deploymentId2); for (String ibbId : ibbIds) { verify(dataManager).delete(IntegrationBulletinBoard.class, ibbId); } verify(openShiftService).delete("first to delete"); verify(openShiftService).delete("second to delete"); }
@Override public void delete(final String id) { final DataManager dataManager = getDataManager(); final Set<String> deploymentNames = dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id).map(deployment -> { String name = deployment.getSpec().getName(); String depId = deployment.getId().orElse(null); if (depId != null) { dataManager.delete(IntegrationDeployment.class, depId); } return name; }).collect(Collectors.toSet()); dataManager.fetchIdsByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id) .forEach(ibbId -> dataManager.delete(IntegrationBulletinBoard.class, ibbId)); for (final String name : deploymentNames) { try { openShiftService.delete(name); } catch (final KubernetesClientException e) { LOGGER.error("Error deleting integration deployment {}: {}", name, e.getMessage()); } } Deleter.super.delete(id); }
IntegrationHandler extends BaseHandler implements Lister<IntegrationOverview>, Getter<IntegrationOverview>,
    Creator<Integration>, Deleter<Integration>, Updater<Integration>, Validating<Integration> { @Override public void delete(final String id) { final DataManager dataManager = getDataManager(); final Set<String> deploymentNames = dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id).map(deployment -> { String name = deployment.getSpec().getName(); String depId = deployment.getId().orElse(null); if (depId != null) { dataManager.delete(IntegrationDeployment.class, depId); } return name; }).collect(Collectors.toSet()); dataManager.fetchIdsByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id) .forEach(ibbId -> dataManager.delete(IntegrationBulletinBoard.class, ibbId)); for (final String name : deploymentNames) { try { openShiftService.delete(name); } catch (final KubernetesClientException e) { LOGGER.error("Error deleting integration deployment {}: {}", name, e.getMessage()); } } Deleter.super.delete(id); } }
IntegrationHandler extends BaseHandler implements Lister<IntegrationOverview>, Getter<IntegrationOverview>,
    Creator<Integration>, Deleter<Integration>, Updater<Integration>, Validating<Integration> { @Override public void delete(final String id) { final DataManager dataManager = getDataManager(); final Set<String> deploymentNames = dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id).map(deployment -> { String name = deployment.getSpec().getName(); String depId = deployment.getId().orElse(null); if (depId != null) { dataManager.delete(IntegrationDeployment.class, depId); } return name; }).collect(Collectors.toSet()); dataManager.fetchIdsByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id) .forEach(ibbId -> dataManager.delete(IntegrationBulletinBoard.class, ibbId)); for (final String name : deploymentNames) { try { openShiftService.delete(name); } catch (final KubernetesClientException e) { LOGGER.error("Error deleting integration deployment {}: {}", name, e.getMessage()); } } Deleter.super.delete(id); } IntegrationHandler(final DataManager dataMgr, final OpenShiftService openShiftService,
                              final Validator validator, final Inspectors inspectors,
                              final EncryptionComponent encryptionSupport, final APIGenerator apiGenerator,
                              final IntegrationOverviewHelper integrationOverviewHelper); }
IntegrationHandler extends BaseHandler implements Lister<IntegrationOverview>, Getter<IntegrationOverview>,
    Creator<Integration>, Deleter<Integration>, Updater<Integration>, Validating<Integration> { @Override public void delete(final String id) { final DataManager dataManager = getDataManager(); final Set<String> deploymentNames = dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id).map(deployment -> { String name = deployment.getSpec().getName(); String depId = deployment.getId().orElse(null); if (depId != null) { dataManager.delete(IntegrationDeployment.class, depId); } return name; }).collect(Collectors.toSet()); dataManager.fetchIdsByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id) .forEach(ibbId -> dataManager.delete(IntegrationBulletinBoard.class, ibbId)); for (final String name : deploymentNames) { try { openShiftService.delete(name); } catch (final KubernetesClientException e) { LOGGER.error("Error deleting integration deployment {}: {}", name, e.getMessage()); } } Deleter.super.delete(id); } IntegrationHandler(final DataManager dataMgr, final OpenShiftService openShiftService,
                              final Validator validator, final Inspectors inspectors,
                              final EncryptionComponent encryptionSupport, final APIGenerator apiGenerator,
                              final IntegrationOverviewHelper integrationOverviewHelper); @Override Integration create(@Context final SecurityContext sec, final Integration integration); @Override void delete(final String id); @Override IntegrationOverview get(final String id); @POST @Produces(MediaType.APPLICATION_JSON) @Path(value = "/filters/options") FilterOptions getFilterOptions(final DataShape dataShape); @GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/filters/options") FilterOptions getGlobalFilterOptions(); Integration getIntegration(final String id); @GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/{id}/overview") IntegrationOverview getOverview(@PathParam("id") final String id); @Override Validator getValidator(); @Override ListResult<IntegrationOverview> list(int page, int perPage); @Override Kind resourceKind(); @Override void update(final String id, final Integration integration); }
IntegrationHandler extends BaseHandler implements Lister<IntegrationOverview>, Getter<IntegrationOverview>,
    Creator<Integration>, Deleter<Integration>, Updater<Integration>, Validating<Integration> { @Override public void delete(final String id) { final DataManager dataManager = getDataManager(); final Set<String> deploymentNames = dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id).map(deployment -> { String name = deployment.getSpec().getName(); String depId = deployment.getId().orElse(null); if (depId != null) { dataManager.delete(IntegrationDeployment.class, depId); } return name; }).collect(Collectors.toSet()); dataManager.fetchIdsByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id) .forEach(ibbId -> dataManager.delete(IntegrationBulletinBoard.class, ibbId)); for (final String name : deploymentNames) { try { openShiftService.delete(name); } catch (final KubernetesClientException e) { LOGGER.error("Error deleting integration deployment {}: {}", name, e.getMessage()); } } Deleter.super.delete(id); } IntegrationHandler(final DataManager dataMgr, final OpenShiftService openShiftService,
                              final Validator validator, final Inspectors inspectors,
                              final EncryptionComponent encryptionSupport, final APIGenerator apiGenerator,
                              final IntegrationOverviewHelper integrationOverviewHelper); @Override Integration create(@Context final SecurityContext sec, final Integration integration); @Override void delete(final String id); @Override IntegrationOverview get(final String id); @POST @Produces(MediaType.APPLICATION_JSON) @Path(value = "/filters/options") FilterOptions getFilterOptions(final DataShape dataShape); @GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/filters/options") FilterOptions getGlobalFilterOptions(); Integration getIntegration(final String id); @GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/{id}/overview") IntegrationOverview getOverview(@PathParam("id") final String id); @Override Validator getValidator(); @Override ListResult<IntegrationOverview> list(int page, int perPage); @Override Kind resourceKind(); @Override void update(final String id, final Integration integration);  }