// Path: agathon-manager/src/main/java/com/brighttag/agathon/model/CassandraInstance.java
// public class CassandraInstance {
// 
//   private final int id;
//   private final String datacenter;
//   private final String rack;
//   private final String hostname;
//   private final String publicIpAddress;
//   private final @Nullable String fullyQualifiedDomainName;
// 
//   private CassandraInstance(
//       @JsonProperty("id") int id, @JsonProperty("datacenter") String dataCenter,
//       @JsonProperty("rack") String rack, @JsonProperty("hostname") String hostName,
//       @JsonProperty("publicIpAddress") String publicIpAddress,
//       @JsonProperty("fullyQualifiedDomainName") String fullyQualifiedDomainName) {
//     this(new Builder()
//         .id(id)
//         .dataCenter(dataCenter)
//         .rack(rack)
//         .hostName(hostName)
//         .publicIpAddress(publicIpAddress)
//         .fullyQualifiedDomainName(fullyQualifiedDomainName));
//   }
// 
//   private CassandraInstance(Builder builder) {
//     this.id = builder.id;
//     this.datacenter = builder.datacenter;
//     this.rack = builder.rack;
//     this.hostname = builder.hostname;
//     this.publicIpAddress = builder.publicIpAddress;
//     this.fullyQualifiedDomainName = builder.fullyQualifiedDomainName;
//   }
// 
//   public @Min(1) int getId() {
//     return id;
//   }
// 
//   public @NotEmpty String getDataCenter() {
//     return datacenter;
//   }
// 
//   public @NotEmpty String getRack() {
//     return rack;
//   }
// 
//   public @NotEmpty String getHostName() {
//     return hostname;
//   }
// 
//   public @NotEmpty String getPublicIpAddress() {
//     return publicIpAddress;
//   }
// 
//   public @Nullable String getFullyQualifiedDomainName() {
//     return fullyQualifiedDomainName;
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(significantAttributes());
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (obj == null) {
//       return false;
//     } else if (obj == this) {
//       return true;
//     } else if (!getClass().isAssignableFrom(obj.getClass())) {
//       return false;
//     }
//     return Arrays.equals(significantAttributes(), getClass().cast(obj).significantAttributes());
//   }
// 
//   @Override
//   public String toString() {
//     return Objects.toStringHelper(this)
//         .add("id", id)
//         .add("datacenter", datacenter)
//         .add("rack", rack)
//         .add("hostname", hostname)
//         .add("publicIpAddress", publicIpAddress)
//         .add("fullyQualifiedDomainName", fullyQualifiedDomainName)
//         .toString();
//   }
// 
//   Object[] significantAttributes() {
//     return new Object[] { id, datacenter, rack, hostname, publicIpAddress, fullyQualifiedDomainName };
//   }
// 
//   /**
//    * Fluent builder for {@link CassandraInstance}s.
//    *
//    * @author codyaray
//    * @since 5/12/12
//    */
//   public static class Builder {
// 
//     private int id;
//     private String datacenter;
//     private String rack;
//     private String hostname;
//     private String publicIpAddress;
//     private @Nullable String fullyQualifiedDomainName;
// 
//     public Builder id(int id) {
//       this.id = id;
//       return this;
//     }
// 
//     public Builder dataCenter(String dataCenter) {
//       this.datacenter = dataCenter;
//       return this;
//     }
// 
//     public Builder rack(String rack) {
//       this.rack = rack;
//       return this;
//     }
// 
//     public Builder hostName(String hostName) {
//       this.hostname = hostName;
//       return this;
//     }
// 
//     public Builder publicIpAddress(String publicIpAddress) {
//       this.publicIpAddress = publicIpAddress;
//       return this;
//     }
// 
//     public Builder fullyQualifiedDomainName(@Nullable String fullyQualifiedDomainName) {
//       this.fullyQualifiedDomainName = fullyQualifiedDomainName;
//       return this;
//     }
// 
//     public CassandraInstance build() {
//       return new CassandraInstance(this);
//     }
// 
//   }
// 
// }


import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nullable;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.brighttag.agathon.dao.CassandraInstanceDao;
import com.brighttag.agathon.model.CassandraInstance;

  @VisibleForTesting MemoryCassandraInstanceDao(
      ConcurrentMap<String, Map<Integer, CassandraInstance>> rings) {
    this.rings = rings;
  }

  @Override
  public ImmutableSet<CassandraInstance> findAll(String ring) {
    ImmutableSet<CassandraInstance> instances = ImmutableSet.of();
    if (rings.containsKey(ring)) {
      instances = ImmutableSet.copyOf(rings.get(ring).values());
    }
    LOG.info("Returning instances: {}", instances);
    return instances;
  }

  @Override
  public @Nullable CassandraInstance findById(String ring, int id) {
    CassandraInstance instance = null;
    if (rings.containsKey(ring)) {
      instance = rings.get(ring).get(id);
    }
    LOG.info("Returning instance: {}", instance);
    return instance;
  }

  @Override
  public void save(String ringName, CassandraInstance instance) {
    LOG.info("Saving instance: {}", instance);
    if (!rings.containsKey(ringName)) {
// Path: agathon-manager/src/main/java/com/brighttag/agathon/model/CassandraInstance.java
// public class CassandraInstance {
// 
//   private final int id;
//   private final String datacenter;
//   private final String rack;
//   private final String hostname;
//   private final String publicIpAddress;
//   private final @Nullable String fullyQualifiedDomainName;
// 
//   private CassandraInstance(
//       @JsonProperty("id") int id, @JsonProperty("datacenter") String dataCenter,
//       @JsonProperty("rack") String rack, @JsonProperty("hostname") String hostName,
//       @JsonProperty("publicIpAddress") String publicIpAddress,
//       @JsonProperty("fullyQualifiedDomainName") String fullyQualifiedDomainName) {
//     this(new Builder()
//         .id(id)
//         .dataCenter(dataCenter)
//         .rack(rack)
//         .hostName(hostName)
//         .publicIpAddress(publicIpAddress)
//         .fullyQualifiedDomainName(fullyQualifiedDomainName));
//   }
// 
//   private CassandraInstance(Builder builder) {
//     this.id = builder.id;
//     this.datacenter = builder.datacenter;
//     this.rack = builder.rack;
//     this.hostname = builder.hostname;
//     this.publicIpAddress = builder.publicIpAddress;
//     this.fullyQualifiedDomainName = builder.fullyQualifiedDomainName;
//   }
// 
//   public @Min(1) int getId() {
//     return id;
//   }
// 
//   public @NotEmpty String getDataCenter() {
//     return datacenter;
//   }
// 
//   public @NotEmpty String getRack() {
//     return rack;
//   }
// 
//   public @NotEmpty String getHostName() {
//     return hostname;
//   }
// 
//   public @NotEmpty String getPublicIpAddress() {
//     return publicIpAddress;
//   }
// 
//   public @Nullable String getFullyQualifiedDomainName() {
//     return fullyQualifiedDomainName;
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(significantAttributes());
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (obj == null) {
//       return false;
//     } else if (obj == this) {
//       return true;
//     } else if (!getClass().isAssignableFrom(obj.getClass())) {
//       return false;
//     }
//     return Arrays.equals(significantAttributes(), getClass().cast(obj).significantAttributes());
//   }
// 
//   @Override
//   public String toString() {
//     return Objects.toStringHelper(this)
//         .add("id", id)
//         .add("datacenter", datacenter)
//         .add("rack", rack)
//         .add("hostname", hostname)
//         .add("publicIpAddress", publicIpAddress)
//         .add("fullyQualifiedDomainName", fullyQualifiedDomainName)
//         .toString();
//   }
// 
//   Object[] significantAttributes() {
//     return new Object[] { id, datacenter, rack, hostname, publicIpAddress, fullyQualifiedDomainName };
//   }
// 
//   /**
//    * Fluent builder for {@link CassandraInstance}s.
//    *
//    * @author codyaray
//    * @since 5/12/12
//    */
//   public static class Builder {
// 
//     private int id;
//     private String datacenter;
//     private String rack;
//     private String hostname;
//     private String publicIpAddress;
//     private @Nullable String fullyQualifiedDomainName;
// 
//     public Builder id(int id) {
//       this.id = id;
//       return this;
//     }
// 
//     public Builder dataCenter(String dataCenter) {
//       this.datacenter = dataCenter;
//       return this;
//     }
// 
//     public Builder rack(String rack) {
//       this.rack = rack;
//       return this;
//     }
// 
//     public Builder hostName(String hostName) {
//       this.hostname = hostName;
//       return this;
//     }
// 
//     public Builder publicIpAddress(String publicIpAddress) {
//       this.publicIpAddress = publicIpAddress;
//       return this;
//     }
// 
//     public Builder fullyQualifiedDomainName(@Nullable String fullyQualifiedDomainName) {
//       this.fullyQualifiedDomainName = fullyQualifiedDomainName;
//       return this;
//     }
// 
//     public CassandraInstance build() {
//       return new CassandraInstance(this);
//     }
// 
//   }
// 
// }


// Path: agathon-manager/src/main/java/com/brighttag/agathon/dao/memory/MemoryCassandraInstanceDao.java
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nullable;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.brighttag.agathon.dao.CassandraInstanceDao;
import com.brighttag.agathon.model.CassandraInstance;


  @VisibleForTesting MemoryCassandraInstanceDao(
      ConcurrentMap<String, Map<Integer, CassandraInstance>> rings) {
    this.rings = rings;
  }

  @Override
  public ImmutableSet<CassandraInstance> findAll(String ring) {
    ImmutableSet<CassandraInstance> instances = ImmutableSet.of();
    if (rings.containsKey(ring)) {
      instances = ImmutableSet.copyOf(rings.get(ring).values());
    }
    LOG.info("Returning instances: {}", instances);
    return instances;
  }

  @Override
  public @Nullable CassandraInstance findById(String ring, int id) {
    CassandraInstance instance = null;
    if (rings.containsKey(ring)) {
      instance = rings.get(ring).get(id);
    }
    LOG.info("Returning instance: {}", instance);
    return instance;
  }

  @Override
  public void save(String ringName, CassandraInstance instance) {
    LOG.info("Saving instance: {}", instance);
    if (!rings.containsKey(ringName)) {
      rings.put(ringName, Maps.<Integer, CassandraInstance>newHashMap());