mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-5.0' into trunk
This commit is contained in:
commit
d40e4ecc09
|
|
@ -524,7 +524,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.cassandra</groupId>
|
<groupId>org.apache.cassandra</groupId>
|
||||||
<artifactId>dtest-api</artifactId>
|
<artifactId>dtest-api</artifactId>
|
||||||
<version>0.0.17</version>
|
<version>0.0.18</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,7 @@ Merged from 4.1:
|
||||||
* Enforce CQL message size limit on multiframe messages (CASSANDRA-20052)
|
* Enforce CQL message size limit on multiframe messages (CASSANDRA-20052)
|
||||||
* Fix race condition in DecayingEstimatedHistogramReservoir during rescale (CASSANDRA-19365)
|
* Fix race condition in DecayingEstimatedHistogramReservoir during rescale (CASSANDRA-19365)
|
||||||
Merged from 4.0:
|
Merged from 4.0:
|
||||||
|
* Updated dtest-api to 0.0.18 and removed JMX-related classes that now live in the dtest-api (CASSANDRA-20884)
|
||||||
* Fixed incorrect error message constant for keyspace name length validation (CASSANDRA-20915)
|
* Fixed incorrect error message constant for keyspace name length validation (CASSANDRA-20915)
|
||||||
* Prevent too long table names not fitting file names (CASSANDRA-20389)
|
* Prevent too long table names not fitting file names (CASSANDRA-20389)
|
||||||
* Update Jackson to 2.19.2 (CASSANDRA-20848)
|
* Update Jackson to 2.19.2 (CASSANDRA-20848)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.utils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to override the local address the JMX client calculates when trying to connect,
|
|
||||||
* which can otherwise be influenced by the system property "java.rmi.server.hostname" in strange and
|
|
||||||
* unpredictable ways.
|
|
||||||
*/
|
|
||||||
public class RMIClientSocketFactoryImpl implements Serializable, RMICloseableClientSocketFactory
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 955153017775496366L;
|
|
||||||
List<Socket> sockets = new ArrayList<>();
|
|
||||||
private final InetAddress localAddress;
|
|
||||||
|
|
||||||
public RMIClientSocketFactoryImpl(InetAddress localAddress)
|
|
||||||
{
|
|
||||||
this.localAddress = localAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Socket createSocket(String host, int port) throws IOException
|
|
||||||
{
|
|
||||||
Socket socket = new Socket(localAddress, port);
|
|
||||||
sockets.add(socket);
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
for (Socket socket: sockets)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
catch (IOException ignored)
|
|
||||||
{
|
|
||||||
// intentionally ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
RMIClientSocketFactoryImpl that = (RMIClientSocketFactoryImpl) o;
|
|
||||||
return Objects.equals(localAddress, that.localAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hash(localAddress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.utils;
|
|
||||||
|
|
||||||
import java.rmi.server.RMIClientSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This represents closeable RMI Client Socket factory. It extends {@link AutoCloseable} and can be used with
|
|
||||||
* {@code try-with-resources}.
|
|
||||||
*/
|
|
||||||
public interface RMICloseableClientSocketFactory extends RMIClientSocketFactory, AutoCloseable
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.utils;
|
|
||||||
|
|
||||||
import java.rmi.server.RMIServerSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This represents closeable RMI Server Socket factory. It extends {@link AutoCloseable} and can be used with
|
|
||||||
* {@code try-with-resources}.
|
|
||||||
*/
|
|
||||||
public interface RMICloseableServerSocketFactory extends RMIServerSocketFactory, AutoCloseable
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
@ -228,12 +228,6 @@ public abstract class AbstractCluster<I extends IInstance> implements ICluster<I
|
||||||
withSharedClasses(SHARED_PREDICATE);
|
withSharedClasses(SHARED_PREDICATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private B self()
|
|
||||||
{
|
|
||||||
return (B) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public B withNodeProvisionStrategy(INodeProvisionStrategy.Factory nodeProvisionStrategy)
|
public B withNodeProvisionStrategy(INodeProvisionStrategy.Factory nodeProvisionStrategy)
|
||||||
{
|
{
|
||||||
this.nodeProvisionStrategy = nodeProvisionStrategy;
|
this.nodeProvisionStrategy = nodeProvisionStrategy;
|
||||||
|
|
@ -618,7 +612,7 @@ public abstract class AbstractCluster<I extends IInstance> implements ICluster<I
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
InstanceConfig createInstanceConfig(int nodeNum)
|
public InstanceConfig createInstanceConfig(int nodeNum)
|
||||||
{
|
{
|
||||||
INodeProvisionStrategy provisionStrategy = nodeProvisionStrategy.create(subnet, portMap);
|
INodeProvisionStrategy provisionStrategy = nodeProvisionStrategy.create(subnet, portMap);
|
||||||
Collection<String> tokens = tokenSupplier.tokens(nodeNum);
|
Collection<String> tokens = tokenSupplier.tokens(nodeNum);
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.distributed.impl;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.net.ServerSocketFactory;
|
|
||||||
|
|
||||||
import org.apache.cassandra.utils.RMICloseableServerSocketFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to keep track of RMI servers created during a cluster creation so we can
|
|
||||||
* later close the sockets, which would otherwise be left with a thread running waiting for
|
|
||||||
* connections that would never show up as the server was otherwise closed.
|
|
||||||
*/
|
|
||||||
class CollectingRMIServerSocketFactoryImpl implements RMICloseableServerSocketFactory
|
|
||||||
{
|
|
||||||
private final InetAddress bindAddress;
|
|
||||||
List<ServerSocket> sockets = new ArrayList<>();
|
|
||||||
|
|
||||||
public CollectingRMIServerSocketFactoryImpl(InetAddress bindAddress)
|
|
||||||
{
|
|
||||||
this.bindAddress = bindAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServerSocket createServerSocket(int pPort) throws IOException
|
|
||||||
{
|
|
||||||
ServerSocket result = ServerSocketFactory.getDefault().createServerSocket(pPort, 0, bindAddress);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
result.setReuseAddress(true);
|
|
||||||
}
|
|
||||||
catch (SocketException e)
|
|
||||||
{
|
|
||||||
result.close();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
sockets.add(result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
for (ServerSocket socket : sockets)
|
|
||||||
{
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
CollectingRMIServerSocketFactoryImpl that = (CollectingRMIServerSocketFactoryImpl) o;
|
|
||||||
return Objects.equals(bindAddress, that.bindAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hash(bindAddress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,150 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.distributed.impl;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.SSLSocket;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
import org.apache.cassandra.utils.RMICloseableServerSocketFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to keep track of SSL based RMI servers created during a cluster creation to
|
|
||||||
* later close the sockets, which would otherwise be left with a thread running waiting for
|
|
||||||
* connections that would never show up as the server was otherwise closed.
|
|
||||||
*/
|
|
||||||
class CollectingSslRMIServerSocketFactoryImpl implements RMICloseableServerSocketFactory
|
|
||||||
{
|
|
||||||
private final InetAddress bindAddress;
|
|
||||||
private final String[] enabledCipherSuites;
|
|
||||||
private final String[] enabledProtocols;
|
|
||||||
private final boolean needClientAuth;
|
|
||||||
private final SSLSocketFactory sslSocketFactory;
|
|
||||||
List<ServerSocket> sockets = new ArrayList<>();
|
|
||||||
|
|
||||||
public CollectingSslRMIServerSocketFactoryImpl(InetAddress bindAddress, String[] enabledCipherSuites,
|
|
||||||
String[] enabledProtocols, boolean needClientAuth, SSLContext sslContext)
|
|
||||||
{
|
|
||||||
this.bindAddress = bindAddress;
|
|
||||||
this.enabledCipherSuites = enabledCipherSuites;
|
|
||||||
this.enabledProtocols = enabledProtocols;
|
|
||||||
this.needClientAuth = needClientAuth;
|
|
||||||
this.sslSocketFactory = sslContext.getSocketFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getEnabledCipherSuites()
|
|
||||||
{
|
|
||||||
return enabledCipherSuites;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getEnabledProtocols()
|
|
||||||
{
|
|
||||||
return enabledProtocols;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNeedClientAuth()
|
|
||||||
{
|
|
||||||
return needClientAuth;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServerSocket createServerSocket(int pPort) throws IOException
|
|
||||||
{
|
|
||||||
ServerSocket result = createSslServerSocket(pPort);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
result.setReuseAddress(true);
|
|
||||||
}
|
|
||||||
catch (SocketException e)
|
|
||||||
{
|
|
||||||
result.close();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
sockets.add(result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServerSocket createSslServerSocket(int pPort) throws IOException
|
|
||||||
{
|
|
||||||
return new ServerSocket(pPort, 0, bindAddress)
|
|
||||||
{
|
|
||||||
public Socket accept() throws IOException
|
|
||||||
{
|
|
||||||
Socket socket = super.accept();
|
|
||||||
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
|
|
||||||
socket, socket.getInetAddress().getHostName(),
|
|
||||||
socket.getPort(), true);
|
|
||||||
sslSocket.setUseClientMode(false);
|
|
||||||
if (enabledCipherSuites != null)
|
|
||||||
{
|
|
||||||
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
|
|
||||||
}
|
|
||||||
if (enabledProtocols != null)
|
|
||||||
{
|
|
||||||
sslSocket.setEnabledProtocols(enabledProtocols);
|
|
||||||
}
|
|
||||||
sslSocket.setNeedClientAuth(needClientAuth);
|
|
||||||
return sslSocket;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
for (ServerSocket socket : sockets)
|
|
||||||
{
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
CollectingSslRMIServerSocketFactoryImpl that = (CollectingSslRMIServerSocketFactoryImpl) o;
|
|
||||||
return Objects.equals(bindAddress, that.bindAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hash(bindAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SSLSocketFactory defaultSSLSocketFactory = null;
|
|
||||||
|
|
||||||
private static synchronized SSLSocketFactory getDefaultSSLSocketFactory()
|
|
||||||
{
|
|
||||||
if (defaultSSLSocketFactory == null)
|
|
||||||
defaultSSLSocketFactory =
|
|
||||||
(SSLSocketFactory) SSLSocketFactory.getDefault();
|
|
||||||
return defaultSSLSocketFactory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -33,17 +33,18 @@ import javax.management.remote.rmi.RMIConnectorServer;
|
||||||
import javax.management.remote.rmi.RMIJRMPServerImpl;
|
import javax.management.remote.rmi.RMIJRMPServerImpl;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import org.apache.cassandra.config.EncryptionOptions;
|
import org.apache.cassandra.config.EncryptionOptions;
|
||||||
import org.apache.cassandra.config.JMXServerOptions;
|
import org.apache.cassandra.config.JMXServerOptions;
|
||||||
import org.apache.cassandra.distributed.api.IInstance;
|
import org.apache.cassandra.distributed.api.IInstance;
|
||||||
import org.apache.cassandra.distributed.api.IInstanceConfig;
|
import org.apache.cassandra.distributed.api.IInstanceConfig;
|
||||||
|
import org.apache.cassandra.distributed.shared.jmx.RMICloseableClientSocketFactory;
|
||||||
|
import org.apache.cassandra.distributed.shared.jmx.RMICloseableServerSocketFactory;
|
||||||
import org.apache.cassandra.distributed.shared.JMXUtil;
|
import org.apache.cassandra.distributed.shared.JMXUtil;
|
||||||
import org.apache.cassandra.utils.JMXServerUtils;
|
import org.apache.cassandra.utils.JMXServerUtils;
|
||||||
import org.apache.cassandra.utils.MBeanWrapper;
|
import org.apache.cassandra.utils.MBeanWrapper;
|
||||||
import org.apache.cassandra.utils.RMICloseableClientSocketFactory;
|
|
||||||
import org.apache.cassandra.utils.RMICloseableServerSocketFactory;
|
|
||||||
import sun.rmi.transport.tcp.TCPEndpoint;
|
import sun.rmi.transport.tcp.TCPEndpoint;
|
||||||
|
|
||||||
import static org.apache.cassandra.config.CassandraRelevantProperties.JAVA_RMI_DGC_LEASE_VALUE_IN_JVM_DTEST;
|
import static org.apache.cassandra.config.CassandraRelevantProperties.JAVA_RMI_DGC_LEASE_VALUE_IN_JVM_DTEST;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ import javax.net.ssl.SSLContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.apache.cassandra.utils.RMIClientSocketFactoryImpl;
|
import org.apache.cassandra.distributed.shared.jmx.CollectingRMIServerSocketFactoryImpl;
|
||||||
|
import org.apache.cassandra.distributed.shared.jmx.CollectingSslRMIServerSocketFactoryImpl;
|
||||||
|
import org.apache.cassandra.distributed.shared.jmx.RMIClientSocketFactoryImpl;
|
||||||
|
import org.apache.cassandra.distributed.shared.jmx.RMISslClientSocketFactoryImpl;
|
||||||
import org.apache.cassandra.utils.jmx.AbstractJmxSocketFactory;
|
import org.apache.cassandra.utils.jmx.AbstractJmxSocketFactory;
|
||||||
|
|
||||||
import static javax.management.remote.rmi.RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE;
|
import static javax.management.remote.rmi.RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE;
|
||||||
|
|
|
||||||
|
|
@ -1,131 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.distributed.impl;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import javax.net.SocketFactory;
|
|
||||||
import javax.net.ssl.SSLSocket;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
|
|
||||||
import org.apache.cassandra.utils.RMICloseableClientSocketFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@code RMIClientSocketFactory} for testing SSL based JMX clients.
|
|
||||||
* This class is used to override the local address the JMX client calculates when trying to connect,
|
|
||||||
* which can otherwise be influenced by the system property "java.rmi.server.hostname" in strange and
|
|
||||||
* unpredictable ways.
|
|
||||||
*/
|
|
||||||
public class RMISslClientSocketFactoryImpl implements Serializable, RMICloseableClientSocketFactory
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 9054380061905145241L;
|
|
||||||
private static final Pattern COMMA_SPLITTER = Pattern.compile(",");
|
|
||||||
private static final List<Socket> sockets = new ArrayList<>();
|
|
||||||
private final InetAddress localAddress;
|
|
||||||
private final String[] enabledCipherSuites;
|
|
||||||
private final String[] enabledProtocols;
|
|
||||||
|
|
||||||
public RMISslClientSocketFactoryImpl(InetAddress localAddress, String enabledCipherSuites, String enabledProtocls)
|
|
||||||
{
|
|
||||||
this.localAddress = localAddress;
|
|
||||||
this.enabledCipherSuites = splitCommaSeparatedString(enabledCipherSuites);
|
|
||||||
this.enabledProtocols = splitCommaSeparatedString(enabledProtocls);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Socket createSocket(String host, int port) throws IOException
|
|
||||||
{
|
|
||||||
Socket socket = createSslSocket(port);
|
|
||||||
sockets.add(socket);
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Socket createSslSocket(int port) throws IOException
|
|
||||||
{
|
|
||||||
final SocketFactory sslSocketFactory = SSLSocketFactory.getDefault();
|
|
||||||
final SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(localAddress, port);
|
|
||||||
if (enabledCipherSuites != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e)
|
|
||||||
{
|
|
||||||
throw new IOException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (enabledProtocols != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sslSocket.setEnabledProtocols(enabledProtocols);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e)
|
|
||||||
{
|
|
||||||
throw new IOException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sslSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
for (Socket socket : sockets)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
catch (IOException ignored)
|
|
||||||
{
|
|
||||||
// intentionally ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
RMISslClientSocketFactoryImpl that = (RMISslClientSocketFactoryImpl) o;
|
|
||||||
return Objects.equals(localAddress, that.localAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Objects.hash(localAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] splitCommaSeparatedString(String stringToSplit)
|
|
||||||
{
|
|
||||||
if (stringToSplit == null)
|
|
||||||
return null;
|
|
||||||
return COMMA_SPLITTER.split(stringToSplit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue