@Test public void test_enroller_bind_applications_bound_to_other_service_but_not_itself() throws Exception { when(spaceEnrollerConfigRepository.findOne(eq(SERVICE_ID))).thenReturn(spaceEnrollerConfig); when(spaceEnrollerConfig.getExcludeFromAutoEnrollment()).thenReturn(null); when(applicationRepository.findAll()).thenReturn(remoteApplicationIds.stream() .filter(remoteApplicationId -> !remoteApplicationId.equals(APP_ID)) .map(remoteApplicationId -> BeanGenerator.createAppInfoLinkedToService(remoteApplicationId, SERVICE_ID + "-other")) .collect(Collectors.toList())); when(cloudFoundryApi.listAliveApplications(eq(SPACE_ID), eq(null))) .thenReturn(remoteApplicationIds.stream() .map(applicationId -> ApplicationIdentity.builder() .guid(applicationId) .name(applicationId) .build()) .collect(Collectors.toList())); spaceEnroller.run(); verify(spaceEnroller, times(1)).rescheduleWithDefaultPeriod(); verify(cloudFoundryApi, times(1)) .bindApplications(anyString(), argThat(anyListOfSize(remoteApplicationIds.size() - 1))); }
@Override public void run() { SpaceEnrollerConfig serviceInstance = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (serviceInstance != null) { try { Set<String> watchedOrIgnoredApplications = new HashSet<>(); applicationRepository.findAll() .forEach(applicationInfo -> { if (!applicationInfo.getEnrollmentState().isCandidate(spaceEnrollerConfigId)) { watchedOrIgnoredApplications.add(applicationInfo.getUuid()); } }); log.debug("{} known applications (already enrolled, or blacklisted)", watchedOrIgnoredApplications.size()); List<ApplicationIdentity> applicationIdentities = cloudFoundryApi .listAliveApplications(serviceInstance.getSpaceId(), serviceInstance.getExcludeFromAutoEnrollment()); List<ApplicationIdentity> newApplications = applicationIdentities.stream() .filter(application -> deployment == null || !deployment.getApplicationId().equals(application.getGuid())) .filter(application -> !(watchedOrIgnoredApplications.contains(application.getGuid()))) .collect(Collectors.toList()); if (!newApplications.isEmpty()) { log.debug("{} - new applications", newApplications.size()); cloudFoundryApi.bindApplications(serviceInstance.getId(), newApplications); } else { log.debug("No new started app to bind (all live apps are already enrolled or filtered out by regexp)"); } } catch (CloudFoundryException c) { log.error("cloudfoundry error", c); } rescheduleWithDefaultPeriod(); } else { log.debug("service has been removed. Cancelling task"); stopTask(); } }
SpaceEnroller extends AbstractPeriodicTask { @Override public void run() { SpaceEnrollerConfig serviceInstance = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (serviceInstance != null) { try { Set<String> watchedOrIgnoredApplications = new HashSet<>(); applicationRepository.findAll() .forEach(applicationInfo -> { if (!applicationInfo.getEnrollmentState().isCandidate(spaceEnrollerConfigId)) { watchedOrIgnoredApplications.add(applicationInfo.getUuid()); } }); log.debug("{} known applications (already enrolled, or blacklisted)", watchedOrIgnoredApplications.size()); List<ApplicationIdentity> applicationIdentities = cloudFoundryApi .listAliveApplications(serviceInstance.getSpaceId(), serviceInstance.getExcludeFromAutoEnrollment()); List<ApplicationIdentity> newApplications = applicationIdentities.stream() .filter(application -> deployment == null || !deployment.getApplicationId().equals(application.getGuid())) .filter(application -> !(watchedOrIgnoredApplications.contains(application.getGuid()))) .collect(Collectors.toList()); if (!newApplications.isEmpty()) { log.debug("{} - new applications", newApplications.size()); cloudFoundryApi.bindApplications(serviceInstance.getId(), newApplications); } else { log.debug("No new started app to bind (all live apps are already enrolled or filtered out by regexp)"); } } catch (CloudFoundryException c) { log.error("cloudfoundry error", c); } rescheduleWithDefaultPeriod(); } else { log.debug("service has been removed. Cancelling task"); stopTask(); } } }
SpaceEnroller extends AbstractPeriodicTask { @Override public void run() { SpaceEnrollerConfig serviceInstance = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (serviceInstance != null) { try { Set<String> watchedOrIgnoredApplications = new HashSet<>(); applicationRepository.findAll() .forEach(applicationInfo -> { if (!applicationInfo.getEnrollmentState().isCandidate(spaceEnrollerConfigId)) { watchedOrIgnoredApplications.add(applicationInfo.getUuid()); } }); log.debug("{} known applications (already enrolled, or blacklisted)", watchedOrIgnoredApplications.size()); List<ApplicationIdentity> applicationIdentities = cloudFoundryApi .listAliveApplications(serviceInstance.getSpaceId(), serviceInstance.getExcludeFromAutoEnrollment()); List<ApplicationIdentity> newApplications = applicationIdentities.stream() .filter(application -> deployment == null || !deployment.getApplicationId().equals(application.getGuid())) .filter(application -> !(watchedOrIgnoredApplications.contains(application.getGuid()))) .collect(Collectors.toList()); if (!newApplications.isEmpty()) { log.debug("{} - new applications", newApplications.size()); cloudFoundryApi.bindApplications(serviceInstance.getId(), newApplications); } else { log.debug("No new started app to bind (all live apps are already enrolled or filtered out by regexp)"); } } catch (CloudFoundryException c) { log.error("cloudfoundry error", c); } rescheduleWithDefaultPeriod(); } else { log.debug("service has been removed. Cancelling task"); stopTask(); } } @Builder  SpaceEnroller(Clock clock,
                  Duration period,
                  String spaceEnrollerConfigId,
                  CloudFoundryApiService cloudFoundryApi,
                  SpaceEnrollerConfigRepository spaceEnrollerConfigRepository,
                  ApplicationRepository applicationRepository,
                  DeployedApplicationConfig.Deployment deployment); }
SpaceEnroller extends AbstractPeriodicTask { @Override public void run() { SpaceEnrollerConfig serviceInstance = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (serviceInstance != null) { try { Set<String> watchedOrIgnoredApplications = new HashSet<>(); applicationRepository.findAll() .forEach(applicationInfo -> { if (!applicationInfo.getEnrollmentState().isCandidate(spaceEnrollerConfigId)) { watchedOrIgnoredApplications.add(applicationInfo.getUuid()); } }); log.debug("{} known applications (already enrolled, or blacklisted)", watchedOrIgnoredApplications.size()); List<ApplicationIdentity> applicationIdentities = cloudFoundryApi .listAliveApplications(serviceInstance.getSpaceId(), serviceInstance.getExcludeFromAutoEnrollment()); List<ApplicationIdentity> newApplications = applicationIdentities.stream() .filter(application -> deployment == null || !deployment.getApplicationId().equals(application.getGuid())) .filter(application -> !(watchedOrIgnoredApplications.contains(application.getGuid()))) .collect(Collectors.toList()); if (!newApplications.isEmpty()) { log.debug("{} - new applications", newApplications.size()); cloudFoundryApi.bindApplications(serviceInstance.getId(), newApplications); } else { log.debug("No new started app to bind (all live apps are already enrolled or filtered out by regexp)"); } } catch (CloudFoundryException c) { log.error("cloudfoundry error", c); } rescheduleWithDefaultPeriod(); } else { log.debug("service has been removed. Cancelling task"); stopTask(); } } @Builder  SpaceEnroller(Clock clock,
                  Duration period,
                  String spaceEnrollerConfigId,
                  CloudFoundryApiService cloudFoundryApi,
                  SpaceEnrollerConfigRepository spaceEnrollerConfigRepository,
                  ApplicationRepository applicationRepository,
                  DeployedApplicationConfig.Deployment deployment); @Override void run(); }
SpaceEnroller extends AbstractPeriodicTask { @Override public void run() { SpaceEnrollerConfig serviceInstance = spaceEnrollerConfigRepository.findOne(spaceEnrollerConfigId); if (serviceInstance != null) { try { Set<String> watchedOrIgnoredApplications = new HashSet<>(); applicationRepository.findAll() .forEach(applicationInfo -> { if (!applicationInfo.getEnrollmentState().isCandidate(spaceEnrollerConfigId)) { watchedOrIgnoredApplications.add(applicationInfo.getUuid()); } }); log.debug("{} known applications (already enrolled, or blacklisted)", watchedOrIgnoredApplications.size()); List<ApplicationIdentity> applicationIdentities = cloudFoundryApi .listAliveApplications(serviceInstance.getSpaceId(), serviceInstance.getExcludeFromAutoEnrollment()); List<ApplicationIdentity> newApplications = applicationIdentities.stream() .filter(application -> deployment == null || !deployment.getApplicationId().equals(application.getGuid())) .filter(application -> !(watchedOrIgnoredApplications.contains(application.getGuid()))) .collect(Collectors.toList()); if (!newApplications.isEmpty()) { log.debug("{} - new applications", newApplications.size()); cloudFoundryApi.bindApplications(serviceInstance.getId(), newApplications); } else { log.debug("No new started app to bind (all live apps are already enrolled or filtered out by regexp)"); } } catch (CloudFoundryException c) { log.error("cloudfoundry error", c); } rescheduleWithDefaultPeriod(); } else { log.debug("service has been removed. Cancelling task"); stopTask(); } } @Builder  SpaceEnroller(Clock clock,
                  Duration period,
                  String spaceEnrollerConfigId,
                  CloudFoundryApiService cloudFoundryApi,
                  SpaceEnrollerConfigRepository spaceEnrollerConfigRepository,
                  ApplicationRepository applicationRepository,
                  DeployedApplicationConfig.Deployment deployment); @Override void run();  }