// Path: breakerbox-turbine/src/main/java/com/yammer/breakerbox/turbine/config/YamlInstanceConfiguration.java
// public class YamlInstanceConfiguration {
// 
//     @JsonUnwrapped
//     @Valid
//     private ImmutableMap<String, Cluster> clusters = ImmutableMap.of(
//             "breakerbox", Cluster.withInstances(HostAndPort.fromParts("localhost", 8080)),
//             "production", Cluster.withClusters("breakerbox"));
// 
//     @NotNull
//     private String urlSuffix = TurbineInstanceDiscovery.DEFAULT_URL_SUFFIX;
// 
//     public ImmutableMap<String, Cluster> getClusters() {
//         return clusters;
//     }
// 
//     public void setClusters(ImmutableMap<String, Cluster> clusters) {
//         this.clusters = clusters;
//     }
// 
//     public Set<Instance> getAllInstances() {
//         final ImmutableSet.Builder<Instance> builder = ImmutableSet.builder();
//         for (Map.Entry<String, Cluster> entry : clusters.entrySet()) {
//             final String clusterName = entry.getKey();
//             addCluster(builder, entry.getValue(), clusterName, ImmutableSet.of(clusterName));
//         }
//         return builder.build();
//     }
// 
//     private void addCluster(ImmutableSet.Builder<Instance> acc,
//                             Cluster cluster,
//                             String clusterName,
//                             ImmutableSet<String> visited) {
//         acc.addAll(cluster.getInstances().stream()
//                 .map(hostAndPort -> {
//                     final Instance instance = new Instance(hostAndPort.toString(), clusterName, true);
//                     instance.getAttributes().put(TurbineInstanceDiscovery.BREAKERBOX_INSTANCE_ID, hostAndPort.toString());
//                     return instance;
//                 })
//                 .collect(Collectors.toList()));
//         cluster.getClusters()
//                 .stream()
//                 .filter(name -> !visited.contains(name))
//                 .forEach(notVisitedClusterName ->
//                     addCluster(acc, clusters.get(notVisitedClusterName), clusterName,
//                         ImmutableSet.<String>builder().addAll(visited).add(notVisitedClusterName).build()));
//     }
// 
//     public String getUrlSuffix() {
//         return urlSuffix;
//     }
// 
//     public void setUrlSuffix(String urlSuffix) {
//         this.urlSuffix = urlSuffix;
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(clusters, urlSuffix);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         }
//         if (obj == null || getClass() != obj.getClass()) {
//             return false;
//         }
//         final YamlInstanceConfiguration other = (YamlInstanceConfiguration) obj;
//         return Objects.equals(this.clusters, other.clusters)
//                 && Objects.equals(this.urlSuffix, other.urlSuffix);
//     }
// 
//     @Override
//     public String toString() {
//         return "YamlInstanceConfiguration{" +
//                 "clusters=" + clusters +
//                 ", urlSuffix='" + urlSuffix + '\'' +
//                 '}';
//     }
// 
//     public static class Cluster {
//         @Valid
//         private Set<HostAndPort> instances = Collections.emptySet();
//         private Set<String> clusters = Collections.emptySet();
// 
//         public Cluster() { /* Jackson */
//         }
// 
//         public Cluster(Set<HostAndPort> instances, Set<String> clusters) {
//             this.instances = instances;
//             this.clusters = clusters;
//         }
// 
//         public Set<HostAndPort> getInstances() {
//             return instances;
//         }
// 
//         public Set<String> getClusters() {
//             return clusters;
//         }
// 
//         public void setInstances(Set<HostAndPort> instances) {
//             this.instances = instances;
//         }
// 
//         public void setClusters(Set<String> clusters) {
//             this.clusters = clusters;
//         }
// 
//         public static Cluster withInstances(HostAndPort... hostAndPorts) {
//             return new Cluster(ImmutableSet.copyOf(hostAndPorts), Collections.emptySet());
//         }
// 
//         public static Cluster withClusters(String... clusters) {
//             return new Cluster(Collections.emptySet(), ImmutableSet.copyOf(clusters));
//         }
// 
//         @Override
//         public int hashCode() {
//             return Objects.hash(instances, clusters);
//         }
// 
//         @Override
//         public boolean equals(Object obj) {
//             if (this == obj) {
//                 return true;
//             }
//             if (obj == null || getClass() != obj.getClass()) {
//                 return false;
//             }
//             final Cluster other = (Cluster) obj;
//             return Objects.equals(this.instances, other.instances)
//                     && Objects.equals(this.clusters, other.clusters);
//         }
// 
//         @Override
//         public String toString() {
//             return "Cluster{" +
//                     "instances=" + instances +
//                     ", clusters=" + clusters +
//                     '}';
//         }
//     }
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.turbine.discovery.Instance;
import com.netflix.turbine.discovery.InstanceDiscovery;
import com.yammer.breakerbox.turbine.config.YamlInstanceConfiguration;
import io.dropwizard.configuration.ConfigurationFactory;
import io.dropwizard.configuration.YamlConfigurationFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.validation.Validator;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;
package com.yammer.breakerbox.turbine;



public class YamlInstanceDiscovery implements InstanceDiscovery {
    private static final Logger LOGGER = LoggerFactory.getLogger(YamlInstanceDiscovery.class);
    private final Path path;
// Path: breakerbox-turbine/src/main/java/com/yammer/breakerbox/turbine/config/YamlInstanceConfiguration.java
// public class YamlInstanceConfiguration {
// 
//     @JsonUnwrapped
//     @Valid
//     private ImmutableMap<String, Cluster> clusters = ImmutableMap.of(
//             "breakerbox", Cluster.withInstances(HostAndPort.fromParts("localhost", 8080)),
//             "production", Cluster.withClusters("breakerbox"));
// 
//     @NotNull
//     private String urlSuffix = TurbineInstanceDiscovery.DEFAULT_URL_SUFFIX;
// 
//     public ImmutableMap<String, Cluster> getClusters() {
//         return clusters;
//     }
// 
//     public void setClusters(ImmutableMap<String, Cluster> clusters) {
//         this.clusters = clusters;
//     }
// 
//     public Set<Instance> getAllInstances() {
//         final ImmutableSet.Builder<Instance> builder = ImmutableSet.builder();
//         for (Map.Entry<String, Cluster> entry : clusters.entrySet()) {
//             final String clusterName = entry.getKey();
//             addCluster(builder, entry.getValue(), clusterName, ImmutableSet.of(clusterName));
//         }
//         return builder.build();
//     }
// 
//     private void addCluster(ImmutableSet.Builder<Instance> acc,
//                             Cluster cluster,
//                             String clusterName,
//                             ImmutableSet<String> visited) {
//         acc.addAll(cluster.getInstances().stream()
//                 .map(hostAndPort -> {
//                     final Instance instance = new Instance(hostAndPort.toString(), clusterName, true);
//                     instance.getAttributes().put(TurbineInstanceDiscovery.BREAKERBOX_INSTANCE_ID, hostAndPort.toString());
//                     return instance;
//                 })
//                 .collect(Collectors.toList()));
//         cluster.getClusters()
//                 .stream()
//                 .filter(name -> !visited.contains(name))
//                 .forEach(notVisitedClusterName ->
//                     addCluster(acc, clusters.get(notVisitedClusterName), clusterName,
//                         ImmutableSet.<String>builder().addAll(visited).add(notVisitedClusterName).build()));
//     }
// 
//     public String getUrlSuffix() {
//         return urlSuffix;
//     }
// 
//     public void setUrlSuffix(String urlSuffix) {
//         this.urlSuffix = urlSuffix;
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(clusters, urlSuffix);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         }
//         if (obj == null || getClass() != obj.getClass()) {
//             return false;
//         }
//         final YamlInstanceConfiguration other = (YamlInstanceConfiguration) obj;
//         return Objects.equals(this.clusters, other.clusters)
//                 && Objects.equals(this.urlSuffix, other.urlSuffix);
//     }
// 
//     @Override
//     public String toString() {
//         return "YamlInstanceConfiguration{" +
//                 "clusters=" + clusters +
//                 ", urlSuffix='" + urlSuffix + '\'' +
//                 '}';
//     }
// 
//     public static class Cluster {
//         @Valid
//         private Set<HostAndPort> instances = Collections.emptySet();
//         private Set<String> clusters = Collections.emptySet();
// 
//         public Cluster() { /* Jackson */
//         }
// 
//         public Cluster(Set<HostAndPort> instances, Set<String> clusters) {
//             this.instances = instances;
//             this.clusters = clusters;
//         }
// 
//         public Set<HostAndPort> getInstances() {
//             return instances;
//         }
// 
//         public Set<String> getClusters() {
//             return clusters;
//         }
// 
//         public void setInstances(Set<HostAndPort> instances) {
//             this.instances = instances;
//         }
// 
//         public void setClusters(Set<String> clusters) {
//             this.clusters = clusters;
//         }
// 
//         public static Cluster withInstances(HostAndPort... hostAndPorts) {
//             return new Cluster(ImmutableSet.copyOf(hostAndPorts), Collections.emptySet());
//         }
// 
//         public static Cluster withClusters(String... clusters) {
//             return new Cluster(Collections.emptySet(), ImmutableSet.copyOf(clusters));
//         }
// 
//         @Override
//         public int hashCode() {
//             return Objects.hash(instances, clusters);
//         }
// 
//         @Override
//         public boolean equals(Object obj) {
//             if (this == obj) {
//                 return true;
//             }
//             if (obj == null || getClass() != obj.getClass()) {
//                 return false;
//             }
//             final Cluster other = (Cluster) obj;
//             return Objects.equals(this.instances, other.instances)
//                     && Objects.equals(this.clusters, other.clusters);
//         }
// 
//         @Override
//         public String toString() {
//             return "Cluster{" +
//                     "instances=" + instances +
//                     ", clusters=" + clusters +
//                     '}';
//         }
//     }
// }


// Path: breakerbox-turbine/src/main/java/com/yammer/breakerbox/turbine/YamlInstanceDiscovery.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.turbine.discovery.Instance;
import com.netflix.turbine.discovery.InstanceDiscovery;
import com.yammer.breakerbox.turbine.config.YamlInstanceConfiguration;
import io.dropwizard.configuration.ConfigurationFactory;
import io.dropwizard.configuration.YamlConfigurationFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.validation.Validator;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

package com.yammer.breakerbox.turbine;



public class YamlInstanceDiscovery implements InstanceDiscovery {
    private static final Logger LOGGER = LoggerFactory.getLogger(YamlInstanceDiscovery.class);
    private final Path path;
    private final ConfigurationFactory<YamlInstanceConfiguration> configurationFactory;