<commit_before>package org.springframework.cloud.consul.discovery;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.agent.model.Member;
import com.ecwid.consul.v1.agent.model.Self;
import com.ecwid.consul.v1.agent.model.Service;
import com.ecwid.consul.v1.catalog.model.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author <NAME>
 */
public class ConsulDiscoveryClient implements DiscoveryClient {

    @Autowired
    ApplicationContext context;

    @Autowired
    ConsulClient client;

    @Override
    public String description() {
        return "Spring Cloud Consul Discovery Client";
    }

    @Override
    public ServiceInstance getLocalServiceInstance() {
		Response<Map<String, Service>> agentServices = client.getAgentServices();
		Service service = agentServices.getValue().get(context.getId());
        if (service == null) {
            throw new IllegalStateException("Unable to locate service in consul agent: "+context.getId());
        }
        String host = "localhost";
		Response<Self> agentSelf = client.getAgentSelf();
		Member member = agentSelf.getValue().getMember();
        if (member != null) {
			if (member.getName() != null) {
                host = member.getName();
            }
        }
        return new DefaultServiceInstance(service.getId(), host, service.getPort());
    }

    @Override
    public List<ServiceInstance> getInstances(final String serviceId) {
		List<ServiceInstance> instances = new ArrayList<>();

		addInstancesToList(instances, serviceId);

        return instances;
    }

	private void addInstancesToList(List<ServiceInstance> instances, String serviceId) {
		Response<List<CatalogService>> services = client.getCatalogService(serviceId, QueryParams.DEFAULT);
		for (CatalogService service : services.getValue()) {
            instances.add(new DefaultServiceInstance(serviceId, service.getNode(), service.getServicePort()));
		}
	}

	@Override
    public List<ServiceInstance> getAllInstances() {
        List<ServiceInstance> instances = new ArrayList<>();

		Response<Map<String, List<String>>> services = client.getCatalogServices(QueryParams.DEFAULT);<commit_msg>updates to new s-c-commons stuff, remove unused class<commit_after>package org.springframework.cloud.consul.discovery;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.agent.model.Member;
import com.ecwid.consul.v1.agent.model.Self;
import com.ecwid.consul.v1.agent.model.Service;
import com.ecwid.consul.v1.catalog.model.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author <NAME>
 */
public class ConsulDiscoveryClient implements DiscoveryClient {

    @Autowired
    ApplicationContext context;

    @Autowired
    ConsulClient client;

    @Override
    public String description() {
        return "Spring Cloud Consul Discovery Client";
    }

    @Override
    public ServiceInstance getLocalServiceInstance() {
		Response<Map<String, Service>> agentServices = client.getAgentServices();
		Service service = agentServices.getValue().get(context.getId());
        if (service == null) {
            throw new IllegalStateException("Unable to locate service in consul agent: "+context.getId());
        }
        String host = "localhost";
		Response<Self> agentSelf = client.getAgentSelf();
		Member member = agentSelf.getValue().getMember();
        if (member != null) {
			if (member.getName() != null) {
                host = member.getName();
            }
        }
        return new DefaultServiceInstance(service.getId(), host, service.getPort(), false);
    }

    @Override
    public List<ServiceInstance> getInstances(final String serviceId) {
		List<ServiceInstance> instances = new ArrayList<>();

		addInstancesToList(instances, serviceId);

        return instances;
    }

	private void addInstancesToList(List<ServiceInstance> instances, String serviceId) {
		Response<List<CatalogService>> services = client.getCatalogService(serviceId, QueryParams.DEFAULT);
		for (CatalogService service : services.getValue()) {
            instances.add(new DefaultServiceInstance(serviceId, service.getNode(), service.getServicePort(), false));
		}
	}

    public List<ServiceInstance> getAllInstances() {
        List<ServiceInstance> instances = new ArrayList<>();

		Response<Map<String, List<String>>> services = client.getCatalogServices(QueryParams.DEFAULT);
{'fraction_non_alphanumeric': 0.110622009569378, 'fraction_numerical': 0.002679425837320574, 'mean_word_length': 4.2894736842105265, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2150265', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1419, 'n_words': 297}