Search in sources :

Example 1 with InboundMessageHandlers

use of org.apache.cassandra.net.InboundMessageHandlers in project cassandra by apache.

the class InternodeInboundTable method data.

@Override
public DataSet data(DecoratedKey partitionKey) {
    ByteBuffer[] addressAndPortBytes = ((CompositeType) metadata().partitionKeyType).split(partitionKey.getKey());
    InetAddress address = InetAddressType.instance.compose(addressAndPortBytes[0]);
    int port = Int32Type.instance.compose(addressAndPortBytes[1]);
    InetAddressAndPort addressAndPort = InetAddressAndPort.getByAddressOverrideDefaults(address, port);
    SimpleDataSet result = new SimpleDataSet(metadata());
    InboundMessageHandlers handlers = MessagingService.instance().messageHandlers.get(addressAndPort);
    if (null != handlers)
        addRow(result, addressAndPort, handlers);
    return result;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) CompositeType(org.apache.cassandra.db.marshal.CompositeType)

Example 2 with InboundMessageHandlers

use of org.apache.cassandra.net.InboundMessageHandlers in project cassandra by apache.

the class InternodeEncryptionEnforcementTest method testConnectionsAreAcceptedWithValidConfig.

@Test
public void testConnectionsAreAcceptedWithValidConfig() throws Throwable {
    Cluster.Builder builder = builder().withNodes(2).withConfig(c -> {
        c.with(Feature.NETWORK);
        c.with(Feature.NATIVE_PROTOCOL);
        HashMap<String, Object> encryption = new HashMap<>();
        encryption.put("keystore", "test/conf/cassandra_ssl_test.keystore");
        encryption.put("keystore_password", "cassandra");
        encryption.put("truststore", "test/conf/cassandra_ssl_test.truststore");
        encryption.put("truststore_password", "cassandra");
        encryption.put("internode_encryption", "dc");
        c.set("server_encryption_options", encryption);
    }).withNodeIdTopology(ImmutableMap.of(1, NetworkTopology.dcAndRack("dc1", "r1a"), 2, NetworkTopology.dcAndRack("dc2", "r2a")));
    try (Cluster cluster = builder.start()) {
        openConnections(cluster);
        /*
             * instance (1) should connect to instance (2) without any issues;
             * instance (2) should connect to instance (1) without any issues.
             */
        SerializableRunnable runnable = () -> {
            InboundMessageHandlers inbound = getOnlyElement(MessagingService.instance().messageHandlers.values());
            assertTrue(inbound.count() > 0);
            OutboundConnections outbound = getOnlyElement(MessagingService.instance().channelManagers.values());
            assertTrue(outbound.small.isConnected() || outbound.large.isConnected() || outbound.urgent.isConnected());
        };
        cluster.get(1).runOnInstance(runnable);
        cluster.get(2).runOnInstance(runnable);
    }
}
Also used : MessagingService(org.apache.cassandra.net.MessagingService) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableMap(com.google.common.collect.ImmutableMap) SerializableRunnable(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) OutboundConnections(org.apache.cassandra.net.OutboundConnections) Assert.assertThat(org.junit.Assert.assertThat) Assert.assertFalse(org.junit.Assert.assertFalse) Cluster(org.apache.cassandra.distributed.Cluster) Assert.fail(org.junit.Assert.fail) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) OutboundConnections(org.apache.cassandra.net.OutboundConnections) HashMap(java.util.HashMap) SerializableRunnable(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable) Cluster(org.apache.cassandra.distributed.Cluster) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) Test(org.junit.Test)

Example 3 with InboundMessageHandlers

use of org.apache.cassandra.net.InboundMessageHandlers in project cassandra by apache.

the class InternodeEncryptionEnforcementTest method testConnectionsAreRejectedWithInvalidConfig.

@Test
public void testConnectionsAreRejectedWithInvalidConfig() throws Throwable {
    Cluster.Builder builder = builder().withNodes(2).withConfig(c -> {
        c.with(Feature.NETWORK);
        c.with(Feature.NATIVE_PROTOCOL);
        if (c.num() == 1) {
            HashMap<String, Object> encryption = new HashMap<>();
            encryption.put("keystore", "test/conf/cassandra_ssl_test.keystore");
            encryption.put("keystore_password", "cassandra");
            encryption.put("truststore", "test/conf/cassandra_ssl_test.truststore");
            encryption.put("truststore_password", "cassandra");
            encryption.put("internode_encryption", "dc");
            c.set("server_encryption_options", encryption);
        }
    }).withNodeIdTopology(ImmutableMap.of(1, NetworkTopology.dcAndRack("dc1", "r1a"), 2, NetworkTopology.dcAndRack("dc2", "r2a")));
    try (Cluster cluster = builder.start()) {
        try {
            openConnections(cluster);
            fail("Instances should not be able to connect, much less complete a schema change.");
        } catch (RuntimeException ise) {
            assertThat(ise.getMessage(), containsString("agreement not reached"));
        }
        /*
             * instance (1) won't connect to (2), since (2) won't have a TLS listener;
             * instance (2) won't connect to (1), since inbound check will reject
             * the unencrypted connection attempt;
             *
             * without the patch, instance (2) *CAN* connect to (1), without encryption,
             * despite being in a different dc.
             */
        cluster.get(1).runOnInstance(() -> {
            InboundMessageHandlers inbound = getOnlyElement(MessagingService.instance().messageHandlers.values());
            assertEquals(0, inbound.count());
            OutboundConnections outbound = getOnlyElement(MessagingService.instance().channelManagers.values());
            assertFalse(outbound.small.isConnected() || outbound.large.isConnected() || outbound.urgent.isConnected());
        });
        cluster.get(2).runOnInstance(() -> {
            assertTrue(MessagingService.instance().messageHandlers.isEmpty());
            OutboundConnections outbound = getOnlyElement(MessagingService.instance().channelManagers.values());
            assertFalse(outbound.small.isConnected() || outbound.large.isConnected() || outbound.urgent.isConnected());
        });
    }
}
Also used : MessagingService(org.apache.cassandra.net.MessagingService) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableMap(com.google.common.collect.ImmutableMap) SerializableRunnable(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) OutboundConnections(org.apache.cassandra.net.OutboundConnections) Assert.assertThat(org.junit.Assert.assertThat) Assert.assertFalse(org.junit.Assert.assertFalse) Cluster(org.apache.cassandra.distributed.Cluster) Assert.fail(org.junit.Assert.fail) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) OutboundConnections(org.apache.cassandra.net.OutboundConnections) HashMap(java.util.HashMap) Cluster(org.apache.cassandra.distributed.Cluster) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) Test(org.junit.Test)

Aggregations

InboundMessageHandlers (org.apache.cassandra.net.InboundMessageHandlers)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 HashMap (java.util.HashMap)2 Cluster (org.apache.cassandra.distributed.Cluster)2 Feature (org.apache.cassandra.distributed.api.Feature)2 SerializableRunnable (org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable)2 NetworkTopology (org.apache.cassandra.distributed.shared.NetworkTopology)2 MessagingService (org.apache.cassandra.net.MessagingService)2 OutboundConnections (org.apache.cassandra.net.OutboundConnections)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertThat (org.junit.Assert.assertThat)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Assert.fail (org.junit.Assert.fail)2 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 CompositeType (org.apache.cassandra.db.marshal.CompositeType)1