Search in sources :

Example 1 with VersionedValue

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

the class CloudstackSnitchTest method testRacks.

@Test
public void testRacks() throws IOException, ConfigurationException {
    az = "ch-gva-1";
    CloudstackSnitch snitch = new TestCloudstackSnitch();
    InetAddress local = InetAddress.getByName("127.0.0.1");
    InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
    Gossiper.instance.addSavedEndpoint(nonlocal);
    Map<ApplicationState, VersionedValue> stateMap = new EnumMap<>(ApplicationState.class);
    stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
    stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
    Gossiper.instance.getEndpointStateForEndpoint(nonlocal).addApplicationStates(stateMap);
    assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
    assertEquals("2", snitch.getRack(nonlocal));
    assertEquals("ch-gva", snitch.getDatacenter(local));
    assertEquals("1", snitch.getRack(local));
}
Also used : VersionedValue(org.apache.cassandra.gms.VersionedValue) ApplicationState(org.apache.cassandra.gms.ApplicationState) InetAddress(java.net.InetAddress) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 2 with VersionedValue

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

the class EC2SnitchTest method testRac.

@Test
public void testRac() throws IOException, ConfigurationException {
    az = "us-east-1d";
    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 = new EnumMap<>(ApplicationState.class);
    stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("us-west"));
    stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.datacenter("1a"));
    Gossiper.instance.getEndpointStateForEndpoint(nonlocal).addApplicationStates(stateMap);
    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) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 3 with VersionedValue

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

the class GoogleCloudSnitchTest method testRac.

@Test
public void testRac() throws IOException, ConfigurationException {
    az = "us-central1-a";
    GoogleCloudSnitch snitch = new TestGoogleCloudSnitch();
    InetAddress local = InetAddress.getByName("127.0.0.1");
    InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
    Gossiper.instance.addSavedEndpoint(nonlocal);
    Map<ApplicationState, VersionedValue> stateMap = new EnumMap<>(ApplicationState.class);
    stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("europe-west1"));
    stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.datacenter("a"));
    Gossiper.instance.getEndpointStateForEndpoint(nonlocal).addApplicationStates(stateMap);
    assertEquals("europe-west1", snitch.getDatacenter(nonlocal));
    assertEquals("a", snitch.getRack(nonlocal));
    assertEquals("us-central1", snitch.getDatacenter(local));
    assertEquals("a", snitch.getRack(local));
}
Also used : VersionedValue(org.apache.cassandra.gms.VersionedValue) ApplicationState(org.apache.cassandra.gms.ApplicationState) InetAddress(java.net.InetAddress) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 4 with VersionedValue

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

the class DynamicEndpointSnitch method getSeverity.

private double getSeverity(InetAddress 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 5 with VersionedValue

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

the class GossipHelper method changeGossipState.

/**
 * Changes gossip state of the `peer` on `target`
 */
public static void changeGossipState(IInvokableInstance target, IInstance peer, List<VersionedApplicationState> newState) {
    InetSocketAddress addr = peer.broadcastAddress();
    UUID hostId = peer.config().hostId();
    int netVersion = peer.getMessagingVersion();
    target.runOnInstance(() -> {
        InetAddressAndPort endpoint = toCassandraInetAddressAndPort(addr);
        StorageService storageService = StorageService.instance;
        Gossiper.runInGossipStageBlocking(() -> {
            EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
            if (state == null) {
                Gossiper.instance.initializeNodeUnsafe(endpoint, hostId, netVersion, 1);
                state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
                if (state.isAlive() && !Gossiper.instance.isDeadState(state))
                    Gossiper.instance.realMarkAlive(endpoint, state);
            }
            for (VersionedApplicationState value : newState) {
                ApplicationState as = toApplicationState(value);
                VersionedValue vv = toVersionedValue(value);
                state.addApplicationState(as, vv);
                storageService.onChange(endpoint, as, vv);
            }
        });
    });
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) InetSocketAddress(java.net.InetSocketAddress) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) ApplicationState(org.apache.cassandra.gms.ApplicationState) UUID(java.util.UUID) StorageService(org.apache.cassandra.service.StorageService)

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