@Test public void test_list_alive_applications() throws CloudFoundryException { final String returnedApplication = "application-returned"; final String ignoredApplication = "application-ignored"; final String stoppedApplicationId = "application-stopped"; Pattern excludePattern = Pattern.compile("^(?:(?!" + returnedApplication + ").)*$"); ApplicationsV2 applications = mock(ApplicationsV2.class); when(cfClient.applicationsV2()).thenReturn(applications); when(applications.list(any(ListApplicationsRequest.class))) .thenReturn(Mono.just(ListApplicationsResponse.builder() .resource(ApplicationResource.builder() .metadata(Metadata.builder() .id(returnedApplication) .build()) .entity(ApplicationEntity.builder() .name(returnedApplication) .build()) .build()) .resource(ApplicationResource.builder() .metadata(Metadata.builder() .id(ignoredApplication) .build()) .entity(ApplicationEntity.builder() .name(ignoredApplication) .build()) .build()) .resource(ApplicationResource.builder() .metadata(Metadata.builder() .id(stoppedApplicationId) .build()) .entity(ApplicationEntity.builder() .name(stoppedApplicationId) .build()) .build()) .build())); when(applications.instances(any(ApplicationInstancesRequest.class))) .then(invocation -> { ApplicationInstancesRequest request = (ApplicationInstancesRequest) invocation.getArguments()[0]; if (request.getApplicationId().equals(stoppedApplicationId)) { return Mono.error(new org.cloudfoundry.client.v2.ClientV2Exception( null, CloudFoundryApi.CF_INSTANCES_ERROR, "", "")); } else { return Mono.just(ApplicationInstancesResponse.builder() .instance("1", ApplicationInstanceInfo.builder() .state("RUNNING") .build()) .build()); } }); List<ApplicationIdentity> result = cloudFoundryApi .listAliveApplications("space-id", excludePattern); assertNotNull(result); assertEquals(1, result.size()); assertEquals(returnedApplication, result.get(0).getGuid()); }
@Override public List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames) throws CloudFoundryException { log.debug("listAliveApplications from space_guid {} excluding the ones with name matching {}" , spaceUuid, excludeNames); try { return Mono.just(spaceUuid) .flatMapMany(spaceId -> this.cfClient .applicationsV2() .list(ListApplicationsRequest.builder() .spaceId(spaceUuid) .build())) .flatMap(listApplicationsResponse -> Flux.fromIterable(listApplicationsResponse.getResources())) .filter(applicationResource -> excludeNames == null || !excludeNames.matcher(applicationResource.getEntity().getName()).matches()) .flatMap(applicationResource -> Mono.zip(Mono.just(applicationResource), getApplicationInstances(applicationResource.getMetadata().getId()))) .filter(tuple -> !tuple.getT2().getInstances().isEmpty()) .map(tuple -> ApplicationIdentity.builder() .guid(tuple.getT1().getMetadata().getId()) .name(tuple.getT1().getEntity().getName()) .build()) .collect(ArrayList<ApplicationIdentity>::new, ArrayList::add) .block(Config.CF_API_TIMEOUT); } catch (RuntimeException r) { throw new CloudFoundryException("failed listing applications from space_id: " + spaceUuid, r); } }
CloudFoundryApi implements CloudFoundryApiService { @Override public List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames) throws CloudFoundryException { log.debug("listAliveApplications from space_guid {} excluding the ones with name matching {}" , spaceUuid, excludeNames); try { return Mono.just(spaceUuid) .flatMapMany(spaceId -> this.cfClient .applicationsV2() .list(ListApplicationsRequest.builder() .spaceId(spaceUuid) .build())) .flatMap(listApplicationsResponse -> Flux.fromIterable(listApplicationsResponse.getResources())) .filter(applicationResource -> excludeNames == null || !excludeNames.matcher(applicationResource.getEntity().getName()).matches()) .flatMap(applicationResource -> Mono.zip(Mono.just(applicationResource), getApplicationInstances(applicationResource.getMetadata().getId()))) .filter(tuple -> !tuple.getT2().getInstances().isEmpty()) .map(tuple -> ApplicationIdentity.builder() .guid(tuple.getT1().getMetadata().getId()) .name(tuple.getT1().getEntity().getName()) .build()) .collect(ArrayList<ApplicationIdentity>::new, ArrayList::add) .block(Config.CF_API_TIMEOUT); } catch (RuntimeException r) { throw new CloudFoundryException("failed listing applications from space_id: " + spaceUuid, r); } } }
CloudFoundryApi implements CloudFoundryApiService { @Override public List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames) throws CloudFoundryException { log.debug("listAliveApplications from space_guid {} excluding the ones with name matching {}" , spaceUuid, excludeNames); try { return Mono.just(spaceUuid) .flatMapMany(spaceId -> this.cfClient .applicationsV2() .list(ListApplicationsRequest.builder() .spaceId(spaceUuid) .build())) .flatMap(listApplicationsResponse -> Flux.fromIterable(listApplicationsResponse.getResources())) .filter(applicationResource -> excludeNames == null || !excludeNames.matcher(applicationResource.getEntity().getName()).matches()) .flatMap(applicationResource -> Mono.zip(Mono.just(applicationResource), getApplicationInstances(applicationResource.getMetadata().getId()))) .filter(tuple -> !tuple.getT2().getInstances().isEmpty()) .map(tuple -> ApplicationIdentity.builder() .guid(tuple.getT1().getMetadata().getId()) .name(tuple.getT1().getEntity().getName()) .build()) .collect(ArrayList<ApplicationIdentity>::new, ArrayList::add) .block(Config.CF_API_TIMEOUT); } catch (RuntimeException r) { throw new CloudFoundryException("failed listing applications from space_id: " + spaceUuid, r); } }  }
CloudFoundryApi implements CloudFoundryApiService { @Override public List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames) throws CloudFoundryException { log.debug("listAliveApplications from space_guid {} excluding the ones with name matching {}" , spaceUuid, excludeNames); try { return Mono.just(spaceUuid) .flatMapMany(spaceId -> this.cfClient .applicationsV2() .list(ListApplicationsRequest.builder() .spaceId(spaceUuid) .build())) .flatMap(listApplicationsResponse -> Flux.fromIterable(listApplicationsResponse.getResources())) .filter(applicationResource -> excludeNames == null || !excludeNames.matcher(applicationResource.getEntity().getName()).matches()) .flatMap(applicationResource -> Mono.zip(Mono.just(applicationResource), getApplicationInstances(applicationResource.getMetadata().getId()))) .filter(tuple -> !tuple.getT2().getInstances().isEmpty()) .map(tuple -> ApplicationIdentity.builder() .guid(tuple.getT1().getMetadata().getId()) .name(tuple.getT1().getEntity().getName()) .build()) .collect(ArrayList<ApplicationIdentity>::new, ArrayList::add) .block(Config.CF_API_TIMEOUT); } catch (RuntimeException r) { throw new CloudFoundryException("failed listing applications from space_id: " + spaceUuid, r); } }  @Override void bindApplications(String serviceInstanceId, List<ApplicationIdentity> applications); void bindRoutes(String serviceInstanceId, List<String> routeIds); @Override ApplicationActivity getApplicationActivity(String appUid); Instant getInstantFromLogMessageTimestamp(Long logMessageTimestamp); @Override String getApplicationState(String applicationUuid); @Override String getHost(String routeId); @Override boolean isAppRunning(String appUid); @Override List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames); @Override List<String> listApplicationRoutes(String applicationUuid); @Override List<String> listRouteApplications(String routeUuid); @Override boolean startApplication(String applicationUuid); @Override boolean stopApplication(String applicationUuid); @Override void unbind(String bindingId); boolean isValidOrganization(String organizationGuid); }
CloudFoundryApi implements CloudFoundryApiService { @Override public List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames) throws CloudFoundryException { log.debug("listAliveApplications from space_guid {} excluding the ones with name matching {}" , spaceUuid, excludeNames); try { return Mono.just(spaceUuid) .flatMapMany(spaceId -> this.cfClient .applicationsV2() .list(ListApplicationsRequest.builder() .spaceId(spaceUuid) .build())) .flatMap(listApplicationsResponse -> Flux.fromIterable(listApplicationsResponse.getResources())) .filter(applicationResource -> excludeNames == null || !excludeNames.matcher(applicationResource.getEntity().getName()).matches()) .flatMap(applicationResource -> Mono.zip(Mono.just(applicationResource), getApplicationInstances(applicationResource.getMetadata().getId()))) .filter(tuple -> !tuple.getT2().getInstances().isEmpty()) .map(tuple -> ApplicationIdentity.builder() .guid(tuple.getT1().getMetadata().getId()) .name(tuple.getT1().getEntity().getName()) .build()) .collect(ArrayList<ApplicationIdentity>::new, ArrayList::add) .block(Config.CF_API_TIMEOUT); } catch (RuntimeException r) { throw new CloudFoundryException("failed listing applications from space_id: " + spaceUuid, r); } }  @Override void bindApplications(String serviceInstanceId, List<ApplicationIdentity> applications); void bindRoutes(String serviceInstanceId, List<String> routeIds); @Override ApplicationActivity getApplicationActivity(String appUid); Instant getInstantFromLogMessageTimestamp(Long logMessageTimestamp); @Override String getApplicationState(String applicationUuid); @Override String getHost(String routeId); @Override boolean isAppRunning(String appUid); @Override List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames); @Override List<String> listApplicationRoutes(String applicationUuid); @Override List<String> listRouteApplications(String routeUuid); @Override boolean startApplication(String applicationUuid); @Override boolean stopApplication(String applicationUuid); @Override void unbind(String bindingId); boolean isValidOrganization(String organizationGuid);  }