Search in sources :

Example 1 with AbstractTokenMapSupplier

use of com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier in project dynomite-cluster-checker by diegopacheco.

the class TokenMapSupplierFactory method build.

/**
 * SAMPLE
 *
 *  *  {
 *      "dc": "eu-west-1",
 *      "hostname": "ec2-52-208-92-24.eu-west-1.compute.amazonaws.com",
 *      "ip": "52.208.92.24",
 *      "rack": "dyno_sandbox--euwest1c",
 *      "token": "1383429731",
 *      "zone": "eu-west-1c"
 *  },
 *
 * @param nodes
 * @return
 */
public static TokenMapSupplier build(List<DynomiteNodeInfo> nodes) {
    StringBuilder jsonSB = new StringBuilder("[");
    int count = 0;
    final Map<String, DynomiteNodeInfo> mapNodes = new HashMap<>();
    for (DynomiteNodeInfo node : nodes) {
        mapNodes.put(node.getServer(), node);
        jsonSB.append(node.toJsonTopology());
        count++;
        if (count < nodes.size())
            jsonSB.append(" , ");
    }
    jsonSB.append(" ]\"");
    final String json = jsonSB.toString();
    TokenMapSupplier testTokenMapSupplier = new AbstractTokenMapSupplier() {

        @Override
        public String getTopologyJsonPayload(String hostname) {
            return json;
        }

        @Override
        public String getTopologyJsonPayload(Set<Host> activeHosts) {
            return json;
        }
    };
    return testTokenMapSupplier;
}
Also used : AbstractTokenMapSupplier(com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier) TokenMapSupplier(com.netflix.dyno.connectionpool.TokenMapSupplier) Set(java.util.Set) AbstractTokenMapSupplier(com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier) HashMap(java.util.HashMap) DynomiteNodeInfo(com.github.diegopacheco.dynomite.cluster.checker.parser.DynomiteNodeInfo)

Example 2 with AbstractTokenMapSupplier

use of com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier in project dynomite-cluster-checker by diegopacheco.

the class SimpleConnectionTest method toTokenMapSupplier.

private static TokenMapSupplier toTokenMapSupplier(List<DynomiteNodeInfo> nodes) {
    StringBuilder jsonSB = new StringBuilder("[");
    int count = 0;
    for (DynomiteNodeInfo node : nodes) {
        jsonSB.append(" {\"token\":\"" + node.getTokens() + "\",\"hostname\":\"" + node.getServer() + "\",\"zone\":\"" + node.getDc() + "\"} ");
        count++;
        if (count < nodes.size())
            jsonSB.append(" , ");
    }
    jsonSB.append(" ]\"");
    final String json = jsonSB.toString();
    TokenMapSupplier testTokenMapSupplier = new AbstractTokenMapSupplier() {

        @Override
        public String getTopologyJsonPayload(String hostname) {
            return json;
        }

        @Override
        public String getTopologyJsonPayload(Set<Host> activeHosts) {
            return json;
        }
    };
    return testTokenMapSupplier;
}
Also used : AbstractTokenMapSupplier(com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier) TokenMapSupplier(com.netflix.dyno.connectionpool.TokenMapSupplier) Set(java.util.Set) AbstractTokenMapSupplier(com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier) DynomiteNodeInfo(com.github.diegopacheco.dynomite.cluster.checker.parser.DynomiteNodeInfo)

Aggregations

DynomiteNodeInfo (com.github.diegopacheco.dynomite.cluster.checker.parser.DynomiteNodeInfo)2 TokenMapSupplier (com.netflix.dyno.connectionpool.TokenMapSupplier)2 AbstractTokenMapSupplier (com.netflix.dyno.connectionpool.impl.lb.AbstractTokenMapSupplier)2 Set (java.util.Set)2 HashMap (java.util.HashMap)1