Search in sources :

Example 1 with PrimingClient

use of org.scassandra.http.client.PrimingClient in project java-driver by datastax.

the class ClusterInitTest method primePeerRows.

private void primePeerRows(Scassandra scassandra, List<FakeHost> otherHosts) throws UnknownHostException {
    PrimingClient primingClient = PrimingClient.builder().withHost(ipOfNode(1)).withPort(scassandra.getAdminPort()).build();
    List<Map<String, ?>> rows = Lists.newArrayListWithCapacity(5);
    int i = 0;
    for (FakeHost otherHost : otherHosts) {
        InetAddress address = InetAddress.getByName(otherHost.address);
        rows.add(ImmutableMap.<String, Object>builder().put("peer", address).put("rpc_address", address).put("data_center", "datacenter1").put("rack", "rack1").put("release_version", ProtocolVersion.NEWEST_SUPPORTED.minCassandraVersion().toString()).put("tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i++))).put("host_id", UUID.randomUUID()).build());
    }
    primingClient.prime(PrimingRequest.queryBuilder().withQuery("SELECT * FROM system.peers").withThen(then().withRows(rows).withColumnTypes(ScassandraCluster.SELECT_PEERS)).build());
}
Also used : PrimingClient(org.scassandra.http.client.PrimingClient) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) InetAddress(java.net.InetAddress)

Example 2 with PrimingClient

use of org.scassandra.http.client.PrimingClient in project java-driver by datastax.

the class ScassandraCluster method primeMetadata.

private void primeMetadata(Scassandra node) {
    PrimingClient client = node.primingClient();
    int nodeCount = 0;
    ImmutableList.Builder<Map<String, ?>> rows = ImmutableList.builder();
    for (Integer dc : new TreeSet<Integer>(dcNodeMap.keySet())) {
        List<Scassandra> nodesInDc = dcNodeMap.get(dc);
        List<Long> tokens = getTokensForDC(dc);
        for (int n = 0; n < nodesInDc.size(); n++) {
            String address = ipPrefix + ++nodeCount;
            Scassandra peer = nodesInDc.get(n);
            String query;
            Map<String, Object> row;
            org.scassandra.http.client.types.ColumnMetadata[] metadata;
            if (node == peer) {
                // prime system.local.
                metadata = SELECT_LOCAL;
                query = "SELECT * FROM system.local WHERE key='local'";
                row = Maps.newHashMap();
                addPeerInfo(row, dc, n + 1, "key", "local");
                addPeerInfo(row, dc, n + 1, "bootstrapped", "COMPLETED");
                addPeerInfo(row, dc, n + 1, "broadcast_address", address);
                addPeerInfo(row, dc, n + 1, "cluster_name", "scassandra");
                addPeerInfo(row, dc, n + 1, "cql_version", "3.2.0");
                addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc));
                addPeerInfo(row, dc, n + 1, "listen_address", getPeerInfo(dc, n + 1, "listen_address", address));
                addPeerInfo(row, dc, n + 1, "partitioner", "org.apache.cassandra.dht.Murmur3Partitioner");
                addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1"));
                addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", cassandraVersion));
                addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n)));
                addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
                addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
                addPeerInfo(row, dc, n + 1, "graph", false);
                // These columns might not always be present, we don't have to specify them in the scassandra
                // column metadata as it will default them to text columns.
                addPeerInfoIfExists(row, dc, n + 1, "dse_version");
                addPeerInfoIfExists(row, dc, n + 1, "workload");
            } else {
                // prime system.peers.
                query = "SELECT * FROM system.peers WHERE peer='" + address + "'";
                metadata = SELECT_PEERS;
                row = Maps.newHashMap();
                addPeerInfo(row, dc, n + 1, "peer", address);
                addPeerInfo(row, dc, n + 1, "rpc_address", address);
                addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc));
                addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1"));
                addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", cassandraVersion));
                addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n))));
                addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
                addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
                addPeerInfo(row, dc, n + 1, "graph", false);
                addPeerInfoIfExists(row, dc, n + 1, "listen_address");
                addPeerInfoIfExists(row, dc, n + 1, "dse_version");
                addPeerInfoIfExists(row, dc, n + 1, "workload");
                rows.add(row);
            }
            client.prime(PrimingRequest.queryBuilder().withQuery(query).withThen(then().withColumnTypes(metadata).withRows(Collections.<Map<String, ?>>singletonList(row)).build()).build());
        }
    }
    client.prime(PrimingRequest.queryBuilder().withQuery("SELECT * FROM system.peers").withThen(then().withColumnTypes(SELECT_PEERS).withRows(rows.build()).build()).build());
    // Needed to ensure cluster_name matches what we expect on connection.
    Map<String, Object> clusterNameRow = ImmutableMap.<String, Object>builder().put("cluster_name", "scassandra").build();
    client.prime(PrimingRequest.queryBuilder().withQuery("select cluster_name from system.local").withThen(then().withColumnTypes(SELECT_CLUSTER_NAME).withRows(Collections.<Map<String, ?>>singletonList(clusterNameRow)).build()).build());
    client.prime(PrimingRequest.queryBuilder().withQuery(keyspaceQuery).withThen(then().withColumnTypes(keyspaceColumnTypes).withRows(keyspaceRows).build()).build());
}
Also used : PrimingClient(org.scassandra.http.client.PrimingClient) TreeSet(java.util.TreeSet) Scassandra(org.scassandra.Scassandra) Map(java.util.Map)

Aggregations

Map (java.util.Map)2 PrimingClient (org.scassandra.http.client.PrimingClient)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 InetAddress (java.net.InetAddress)1 TreeSet (java.util.TreeSet)1 Scassandra (org.scassandra.Scassandra)1