Search in sources :

Example 6 with VersionedValue

use of org.apache.cassandra.gms.VersionedValue in project cassandra by apache.

the class DynamicEndpointSnitch method getSeverity.

private double getSeverity(InetAddressAndPort endpoint) {
    EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
    if (state == null)
        return 0.0;
    VersionedValue event = state.getApplicationState(ApplicationState.SEVERITY);
    if (event == null)
        return 0.0;
    return Double.parseDouble(event.value);
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue)

Example 7 with VersionedValue

use of org.apache.cassandra.gms.VersionedValue in project cassandra by apache.

the class Utils method currentToken.

static Token currentToken() {
    EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(getBroadcastAddressAndPort());
    VersionedValue value = epState.getApplicationState(ApplicationState.TOKENS);
    try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(value.toBytes()))) {
        return TokenSerializer.deserialize(getPartitioner(), in).iterator().next();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 8 with VersionedValue

use of org.apache.cassandra.gms.VersionedValue in project eiger by wlloyd.

the class EC2SnitchTest method testRac.

@Test
public void testRac() throws IOException, ConfigurationException {
    Ec2Snitch snitch = new TestEC2Snitch();
    InetAddress local = InetAddress.getByName("127.0.0.1");
    InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
    Gossiper.instance.addSavedEndpoint(nonlocal);
    Map<ApplicationState, VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
    stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("us-west"));
    stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.datacenter("1a"));
    assertEquals("us-west", snitch.getDatacenter(nonlocal));
    assertEquals("1a", snitch.getRack(nonlocal));
    assertEquals("us-east", snitch.getDatacenter(local));
    assertEquals("1d", snitch.getRack(local));
}
Also used : VersionedValue(org.apache.cassandra.gms.VersionedValue) ApplicationState(org.apache.cassandra.gms.ApplicationState) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

VersionedValue (org.apache.cassandra.gms.VersionedValue)8 ApplicationState (org.apache.cassandra.gms.ApplicationState)5 InetAddress (java.net.InetAddress)4 EndpointState (org.apache.cassandra.gms.EndpointState)4 Test (org.junit.Test)4 EnumMap (java.util.EnumMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 DistributedTestSnitch.toCassandraInetAddressAndPort (org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort)1 VersionedApplicationState (org.apache.cassandra.distributed.shared.VersionedApplicationState)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 StorageService (org.apache.cassandra.service.StorageService)1