Skip to content

Commit

Permalink
Merge pull request #30 from frankgh/CASSANDRA-20185
Browse files Browse the repository at this point in the history
AutoRepairServiceMBean should not use custom types for JMX methods
  • Loading branch information
jaydeepkumar1984 authored Jan 28, 2025
2 parents ed51b2c + 98fcd93 commit 95d0a5e
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 285 deletions.
54 changes: 54 additions & 0 deletions src/java/org/apache/cassandra/locator/InetAddressAndPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.net.HostAndPort;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.cassandra.io.IVersionedSerializer;
import org.apache.cassandra.io.util.DataInputPlus;
import org.apache.cassandra.io.util.DataOutputPlus;
Expand All @@ -59,6 +66,7 @@
public final class InetAddressAndPort extends InetSocketAddress implements Comparable<InetAddressAndPort>, Serializable
{
private static final long serialVersionUID = 0;
private static final Logger logger = LoggerFactory.getLogger(InetAddressAndPort.class);

//Store these here to avoid requiring DatabaseDescriptor to be loaded. DatabaseDescriptor will set
//these when it loads the config. A lot of unit tests won't end up loading DatabaseDescriptor.
Expand Down Expand Up @@ -323,6 +331,52 @@ public static void initializeDefaultPort(int port)
defaultPort = port;
}

public static List<String> stringify(Iterable<InetAddressAndPort> endpoints)
{
return stringify(endpoints, true);
}

public static List<String> stringify(Iterable<InetAddressAndPort> endpoints, boolean withPort)
{
List<String> stringEndpoints = new ArrayList<>();
for (InetAddressAndPort ep : endpoints)
{
stringEndpoints.add(ep.getHostAddress(withPort));
}
return stringEndpoints;
}

/**
* Parses a comma-separated list of hosts to a set of {@link InetAddressAndPort}
*
* @param value the comma-separated list of hosts to parse
* @param failOnError whether to fail when encountering an invalid hostname
* @return the set of parsed {@link InetAddressAndPort}
*/
public static Set<InetAddressAndPort> parseHosts(String value, boolean failOnError)
{
Set<InetAddressAndPort> hosts = new HashSet<>();
for (String host : Splitter.on(',').split(value))
{
try
{
hosts.add(InetAddressAndPort.getByName(host));
}
catch (UnknownHostException e)
{
if (failOnError)
{
throw new IllegalArgumentException("Failed to parse host: " + host, e);
}
else
{
logger.warn("Invalid ip address {} from input={}", host, value);
}
}
}
return hosts;
}

static int getDefaultPort()
{
return defaultPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;
Expand Down Expand Up @@ -104,6 +105,18 @@ public static AutoRepairState getAutoRepairState(RepairType repairType)

throw new IllegalArgumentException("Invalid repair type: " + repairType);
}

/**
* Case-insensitive parsing of the repair type string into {@link RepairType}
*
* @param repairTypeStr the repair type string
* @return the {@link RepairType} represented by the {@code repairTypeStr} string
* @throws IllegalArgumentException when the repair type string does not match any repair type
*/
public static RepairType parse(String repairTypeStr)
{
return RepairType.valueOf(LocalizeString.toUpperCaseLocalized(Objects.requireNonNull(repairTypeStr, "repairTypeStr cannot be null")));
}
}

// repair_type_overrides overrides the global_settings for a specific repair type. String used as key instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ public Map<String, String> getParameters()
{
return Collections.singletonMap(NUMBER_OF_SUBRANGES, Integer.toString(numberOfSubranges));
}
}
}
Loading

0 comments on commit 95d0a5e

Please sign in to comment.