// Path: spring-cloud-cloudfoundry-commons/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryService.java
// public class CloudFoundryService {
// 
// 	private final CloudFoundryOperations cloudFoundryOperations;
// 
// 	public CloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
// 		this.cloudFoundryOperations = cloudFoundryOperations;
// 	}
// 
// 	public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
// 		GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
// 		return this.cloudFoundryOperations.applications().get(applicationRequest).flatMapMany(applicationDetail -> {
// 			Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
// 					.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
// 			Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
// 			return generate.zipWith(ids);
// 		});
// 	}
// 
// }


import java.util.HashMap;
import java.util.List;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.applications.ApplicationDetail;
import org.cloudfoundry.operations.applications.InstanceDetail;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
/*
 * Copyright 2013-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.cloudfoundry.discovery;




/**
 *
 * Discovery Client implementation using Cloud Foundry's Native DNS based Service
 * Discovery.
 *
 * @author Toshiaki Maki
 * @see <a href="https://github.com/cloudfoundry/cf-app-sd-release">CF App Service
 * Discovery Release</a>
 * @see <a href=
 * "https://www.cloudfoundry.org/blog/polyglot-service-discovery-container-networking-cloud-foundry/">Polyglot
 * Service Discovery for Container Networking in Cloud Foundry</a>
 */
public class CloudFoundryAppServiceDiscoveryClient extends CloudFoundryDiscoveryClient {

	private static final String INTERNAL_DOMAIN = "apps.internal";

// Path: spring-cloud-cloudfoundry-commons/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryService.java
// public class CloudFoundryService {
// 
// 	private final CloudFoundryOperations cloudFoundryOperations;
// 
// 	public CloudFoundryService(CloudFoundryOperations cloudFoundryOperations) {
// 		this.cloudFoundryOperations = cloudFoundryOperations;
// 	}
// 
// 	public Flux<Tuple2<ApplicationDetail, InstanceDetail>> getApplicationInstances(String serviceId) {
// 		GetApplicationRequest applicationRequest = GetApplicationRequest.builder().name(serviceId).build();
// 		return this.cloudFoundryOperations.applications().get(applicationRequest).flatMapMany(applicationDetail -> {
// 			Flux<InstanceDetail> ids = Flux.fromStream(applicationDetail.getInstanceDetails().stream())
// 					.filter(id -> id.getState().equalsIgnoreCase("RUNNING"));
// 			Flux<ApplicationDetail> generate = Flux.generate(sink -> sink.next(applicationDetail));
// 			return generate.zipWith(ids);
// 		});
// 	}
// 
// }


// Path: spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClient.java
import java.util.HashMap;
import java.util.List;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.applications.ApplicationDetail;
import org.cloudfoundry.operations.applications.InstanceDetail;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.cloudfoundry.CloudFoundryService;

/*
 * Copyright 2013-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.cloudfoundry.discovery;




/**
 *
 * Discovery Client implementation using Cloud Foundry's Native DNS based Service
 * Discovery.
 *
 * @author Toshiaki Maki
 * @see <a href="https://github.com/cloudfoundry/cf-app-sd-release">CF App Service
 * Discovery Release</a>
 * @see <a href=
 * "https://www.cloudfoundry.org/blog/polyglot-service-discovery-container-networking-cloud-foundry/">Polyglot
 * Service Discovery for Container Networking in Cloud Foundry</a>
 */
public class CloudFoundryAppServiceDiscoveryClient extends CloudFoundryDiscoveryClient {

	private static final String INTERNAL_DOMAIN = "apps.internal";

	CloudFoundryAppServiceDiscoveryClient(CloudFoundryOperations cloudFoundryOperations, CloudFoundryService svc,