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;
}
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);
}
}
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());
});
}
}
Aggregations