diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultJmxConnectionProvider.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultJmxConnectionProvider.java index 1ca7f3c6e..57cf02896 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultJmxConnectionProvider.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultJmxConnectionProvider.java @@ -100,7 +100,7 @@ private String[] convertCredentials(final Supplier jmxSecu Credentials credentials = jmxSecurity.get().getJmxCredentials(); if (!credentials.isEnabled()) { - return null; + return new String[0]; } return new String[] { credentials.getUsername(), credentials.getPassword() diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java index a4c48917e..441f88985 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java @@ -108,7 +108,6 @@ public ECChronosInternals(final Config configuration, .build(); myTableRepairMetricsImpl = TableRepairMetricsImpl.builder() - .withTableStorageStates(myTableStorageStatesImpl) .withMeterRegistry(meterRegistry) .build(); @@ -213,9 +212,8 @@ public final void close() myCassandraMetrics.close(); } - private static class NoOpRepairMetrics implements TableRepairMetrics + private static final class NoOpRepairMetrics implements TableRepairMetrics { - @Override public void repairState(final TableReference tableReference, final int repairedRanges, @@ -252,7 +250,7 @@ public void repairSession(final TableReference tableReference, } } - private static class NoOpTableStorageState implements TableStorageStates + private static final class NoOpTableStorageState implements TableStorageStates { @Override public long getDataSize(final TableReference tableReference) diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ReloadingCertificateHandler.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ReloadingCertificateHandler.java index fce80d57e..1e12ea4ca 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ReloadingCertificateHandler.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ReloadingCertificateHandler.java @@ -158,11 +158,7 @@ CqlTLSConfig getTlsConfig() boolean sameConfig(final CqlTLSConfig newTLSConfig) throws IOException, NoSuchAlgorithmException { - if (!myTlsConfig.equals(newTLSConfig)) - { - return false; - } - return checksumSame(newTLSConfig); + return myTlsConfig.equals(newTLSConfig) && checksumSame(newTLSConfig); } private boolean checksumSame(final CqlTLSConfig newTLSConfig) throws IOException, NoSuchAlgorithmException diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/ConfigurationHelper.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/ConfigurationHelper.java index d88716d17..1c6cf657a 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/ConfigurationHelper.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/ConfigurationHelper.java @@ -85,7 +85,7 @@ private T getConfiguration(final File configurationFile, final Class claz } return config; } - catch (IOException e) + catch (IOException e) // NOPMD { throw new ConfigurationException("Unable to load configuration file " + configurationFile, e); } @@ -105,7 +105,7 @@ private T getConfiguration(final InputStream configurationFile, } return config; } - catch (IOException e) + catch (IOException e) // NOPMD { throw new ConfigurationException("Unable to load configuration file from classpath", e); } diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/Connection.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/Connection.java index 57f40be3f..5faf9a5de 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/Connection.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/Connection.java @@ -96,7 +96,7 @@ public final void setProvider(final Class providerClass) throws NoS * If the getDeclaredConstructor method was not found. */ @JsonProperty("certificateHandler") - public void setCertificateHandler(final Class certificateHandlerClass) + public final void setCertificateHandler(final Class certificateHandlerClass) throws NoSuchMethodException { certificateHandlerClass.getDeclaredConstructor(expectedCertHandlerConstructor()); diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/security/CqlTLSConfig.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/security/CqlTLSConfig.java index 71a24a7a3..f7c5fa683 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/security/CqlTLSConfig.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/security/CqlTLSConfig.java @@ -190,7 +190,7 @@ public final String[] getProtocols() { if (myProtocol == null) { - return null; + return new String[0]; } return myProtocol.split(","); } diff --git a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java index 9c0cbce91..0cc65d64f 100644 --- a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java +++ b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java @@ -50,7 +50,8 @@ public class DataCenterAwarePolicy extends DefaultLoadBalancingPolicy { private static final Logger LOG = LoggerFactory.getLogger(DataCenterAwarePolicy.class); - private final ConcurrentMap> myPerDcLiveNodes = new ConcurrentHashMap<>(); + private final ConcurrentMap> myPerDcLiveNodes = // NOPMD + new ConcurrentHashMap<>(); private final AtomicInteger myIndex = new AtomicInteger(); public DataCenterAwarePolicy(final DriverContext context, final String profileName) @@ -64,7 +65,7 @@ public final void init(final Map nodes, final DistanceReporter dista super.init(nodes, distanceReporter); LOG.info("Using provided data-center name '{}' for DataCenterAwareLoadBalancingPolicy", getLocalDatacenter()); - ArrayList notInLocalDC = new ArrayList<>(); + List notInLocalDC = new ArrayList<>(); for (Node node : nodes.values()) { @@ -75,7 +76,7 @@ public final void init(final Map nodes, final DistanceReporter dista notInLocalDC.add(String.format("%s (%s)", node, dc)); } - CopyOnWriteArrayList nodeList = myPerDcLiveNodes.get(dc); + CopyOnWriteArrayList nodeList = myPerDcLiveNodes.get(dc); // NOPMD if (nodeList == null) { myPerDcLiveNodes.put(dc, new CopyOnWriteArrayList<>(Collections.singletonList(node))); @@ -172,7 +173,7 @@ public NodeDistance distance(final Node node, final String dataCenter) return NodeDistance.LOCAL; } - CopyOnWriteArrayList dcNodes = myPerDcLiveNodes.get(dc); + CopyOnWriteArrayList dcNodes = myPerDcLiveNodes.get(dc); // NOPMD if (dcNodes == null) { return NodeDistance.IGNORED; @@ -183,7 +184,7 @@ public NodeDistance distance(final Node node, final String dataCenter) private Queue getFallbackQueryPlan(final String dataCenter) { - CopyOnWriteArrayList localLiveNodes = myPerDcLiveNodes.get(dataCenter); + CopyOnWriteArrayList localLiveNodes = myPerDcLiveNodes.get(dataCenter); // NOPMD final List nodes = localLiveNodes == null ? Collections.emptyList() : cloneList(localLiveNodes); final int startIndex = myIndex.getAndIncrement(); int index = startIndex; @@ -203,7 +204,7 @@ private Queue getFallbackQueryPlan(final String dataCenter) } @SuppressWarnings ("unchecked") - private static CopyOnWriteArrayList cloneList(final CopyOnWriteArrayList list) + private static CopyOnWriteArrayList cloneList(final CopyOnWriteArrayList list) // NOPMD { return (CopyOnWriteArrayList) list.clone(); } @@ -219,10 +220,10 @@ private void markAsUp(final Node node) { String dc = getDc(node); - CopyOnWriteArrayList dcNodes = myPerDcLiveNodes.get(dc); + CopyOnWriteArrayList dcNodes = myPerDcLiveNodes.get(dc); // NOPMD if (dcNodes == null) { - CopyOnWriteArrayList newMap = new CopyOnWriteArrayList<>(Collections.singletonList(node)); + CopyOnWriteArrayList newMap = new CopyOnWriteArrayList<>(Collections.singletonList(node)); // NOPMD dcNodes = myPerDcLiveNodes.putIfAbsent(dc, newMap); // If we've successfully put our new node, we're good, otherwise we've been beaten so continue if (dcNodes == null) @@ -242,7 +243,7 @@ public final void onDown(final Node node) private void markAsDown(final Node node) { - CopyOnWriteArrayList dcNodes = myPerDcLiveNodes.get(getDc(node)); + CopyOnWriteArrayList dcNodes = myPerDcLiveNodes.get(getDc(node)); // NOPMD if (dcNodes != null) { dcNodes.remove(node); @@ -272,7 +273,7 @@ public final void onRemove(final Node node) /** * Only for test purposes. */ - ConcurrentMap> getPerDcLiveNodes() + ConcurrentMap> getPerDcLiveNodes() // NOPMD { return myPerDcLiveNodes; } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/HostStatesImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/HostStatesImpl.java index 1197f9fe0..f0b1f2e97 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/HostStatesImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/HostStatesImpl.java @@ -17,6 +17,7 @@ import java.io.Closeable; import java.io.IOException; import java.net.InetAddress; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -38,7 +39,7 @@ public final class HostStatesImpl implements HostStates, Closeable private static final long DEFAULT_REFRESH_INTERVAL_IN_MS = TimeUnit.SECONDS.toMillis(10); - private final ConcurrentHashMap myHostStates = new ConcurrentHashMap<>(); + private final Map myHostStates = new ConcurrentHashMap<>(); private final Object myRefreshLock = new Object(); private final long myRefreshIntervalInMs; diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/JmxProxyFactoryImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/JmxProxyFactoryImpl.java index c9509480e..90e231f16 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/JmxProxyFactoryImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/JmxProxyFactoryImpl.java @@ -41,8 +41,7 @@ /** * A factory creating JMX proxies to Cassandra. */ -@SuppressWarnings("FinalClass") -public class JmxProxyFactoryImpl implements JmxProxyFactory +public final class JmxProxyFactoryImpl implements JmxProxyFactory { private static final Logger LOG = LoggerFactory.getLogger(JmxProxyFactoryImpl.class); diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/TableStorageStatesImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/TableStorageStatesImpl.java index 532f8da58..3b44b48bd 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/TableStorageStatesImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/TableStorageStatesImpl.java @@ -38,7 +38,7 @@ public final class TableStorageStatesImpl implements TableStorageStates, Closeab private static final long DEFAULT_UPDATE_DELAY_IN_MS = TimeUnit.SECONDS.toMillis(60); - private final AtomicReference> myTableSizes = new AtomicReference<>(); + private final AtomicReference> myTableSizes = new AtomicReference<>(); private final ScheduledExecutorService myScheduledExecutorService; private final ReplicatedTableProvider myReplicatedTableProvider; @@ -60,7 +60,7 @@ private TableStorageStatesImpl(final Builder builder) @Override public long getDataSize(final TableReference tableReference) { - ImmutableMap dataSizes = myTableSizes.get(); + Map dataSizes = myTableSizes.get(); if (dataSizes != null && dataSizes.containsKey(tableReference)) { @@ -73,7 +73,7 @@ public long getDataSize(final TableReference tableReference) @Override public long getDataSize() { - ImmutableMap dataSizes = myTableSizes.get(); + Map dataSizes = myTableSizes.get(); if (dataSizes != null) { @@ -160,7 +160,7 @@ void updateTableStates() } } - private ImmutableMap getTableSizes(final JmxProxy jmxProxy) + private Map getTableSizes(final JmxProxy jmxProxy) { Map dataSizes = new HashMap<>(); diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TableRepairMetricsImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TableRepairMetricsImpl.java index 0f6d84ae1..49569f9d6 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TableRepairMetricsImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TableRepairMetricsImpl.java @@ -24,6 +24,7 @@ import io.micrometer.core.instrument.Timer; import java.io.Closeable; +import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -49,16 +50,13 @@ interface Clock } @VisibleForTesting - static Clock clock = () -> System.currentTimeMillis(); + static Clock clock = () -> System.currentTimeMillis(); // NOPMD - private final ConcurrentHashMap myTableGauges = new ConcurrentHashMap<>(); - private final TableStorageStates myTableStorageStates; + private final Map myTableGauges = new ConcurrentHashMap<>(); private final MeterRegistry myMeterRegistry; private TableRepairMetricsImpl(final Builder builder) { - myTableStorageStates = Preconditions.checkNotNull(builder.myTableStorageStates, - "Table storage states cannot be null"); myMeterRegistry = Preconditions.checkNotNull(builder.myMeterRegistry, "Meter registry cannot be null"); } @@ -153,18 +151,20 @@ public static Builder builder() public static class Builder { - private TableStorageStates myTableStorageStates; private MeterRegistry myMeterRegistry; /** * Build with table storage states. * + * @deprecated + * This is not used anymore, calling this method is a NoOP + * * @param tableStorageStates Table storage states * @return Builder */ + @Deprecated public Builder withTableStorageStates(final TableStorageStates tableStorageStates) { - myTableStorageStates = tableStorageStates; return this; } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/CombinedRepairResourceFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/CombinedRepairResourceFactory.java index d9fbc6abd..d262fae08 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/CombinedRepairResourceFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/CombinedRepairResourceFactory.java @@ -25,7 +25,7 @@ */ public class CombinedRepairResourceFactory implements RepairResourceFactory { - private final ImmutableSet myRepairResourceFactories; + private final Set myRepairResourceFactories; /** * Constructor. diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/OngoingJob.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/OngoingJob.java index cddfef1ec..459a6611a 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/OngoingJob.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/OngoingJob.java @@ -26,10 +26,8 @@ import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; -import com.google.common.collect.ImmutableSet; -@SuppressWarnings("FinalClass") -public class OngoingJob +public final class OngoingJob { public enum Status { @@ -39,7 +37,7 @@ public enum Status private final UUID myJobId; private final UUID myHostId; private final TableReference myTableReference; - private final Map> myTokens; + private final Map> myTokens; private final Set myRepairedTokens; private final OnDemandStatus myOnDemandStatus; private final ReplicationState myReplicationState; @@ -112,7 +110,7 @@ public void finishRanges(final Set ranges) myOnDemandStatus.updateJob(myJobId, myRepairedTokens); } - public Map> getTokens() + public Map> getTokens() { return myTokens; } @@ -127,11 +125,11 @@ public boolean hasTopologyChanged() public void startClusterWideJob(final RepairOptions.RepairType repairType) { - Map> allTokenRanges = myReplicationState + Map> allTokenRanges = myReplicationState .getTokenRanges(myTableReference); Map> repairedRangesPerNode = new HashMap<>(); Map> remainingRangesPerNode = new HashMap<>(); - for (Map.Entry> range : allTokenRanges.entrySet()) + for (Map.Entry> range : allTokenRanges.entrySet()) { LongTokenRange rangeForNodes = range.getKey(); Set nodes = range.getValue(); diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairConfiguration.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairConfiguration.java index 94e2d4110..69c3ca298 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairConfiguration.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairConfiguration.java @@ -22,8 +22,7 @@ /** * Configuration options for table repairs. */ -@SuppressWarnings("FinalClass") -public class RepairConfiguration +public final class RepairConfiguration { public static final double NO_UNWIND = 0.0d; public static final long FULL_REPAIR_SIZE = Long.MAX_VALUE; diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairLockFactoryImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairLockFactoryImpl.java index 65f7e82c6..93e64eab0 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairLockFactoryImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairLockFactoryImpl.java @@ -124,27 +124,21 @@ private LockFactory.DistributedLock getLockForRepairResource( String dataCenter = repairResource.getDataCenter(); String resource = repairResource.getResourceName(LOCKS_PER_RESOURCE); - try - { - myLock = lockFactory.tryLock(dataCenter, resource, priority, metadata); - if (myLock != null) - { - return myLock; - } + myLock = lockFactory.tryLock(dataCenter, resource, priority, metadata); - String msg = String.format("Lock resources exhausted for %s", repairResource); - LOG.warn(msg); - throw new LockException(msg); - } - catch (LockException e) + if (myLock != null) { - LOG.debug("Lock ({} in datacenter {}) got error {}", - resource, - dataCenter, - e.getMessage()); - throw e; + return myLock; } + + String msg = String.format("Lock resources exhausted for %s", repairResource); + LOG.warn(msg); + LOG.debug("Lock ({} in datacenter {}) got error {}", + resource, + dataCenter, + msg); + throw new LockException(msg); } static class TemporaryLockHolder implements AutoCloseable diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairTask.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairTask.java index bc2996e19..3a7248f11 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairTask.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/RepairTask.java @@ -363,7 +363,7 @@ public enum ProgressEventType NOTIFICATION } - private class HangPreventingTask implements Runnable + private final class HangPreventingTask implements Runnable { private static final int MAX_CHECKS = 3; private static final String NORMAL_STATUS = "NORMAL"; diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/ScheduledRepairJob.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/ScheduledRepairJob.java index 5b31fc356..546e3cc5c 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/ScheduledRepairJob.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/ScheduledRepairJob.java @@ -67,7 +67,7 @@ public ScheduledRepairJob(final Configuration configuration, final UUID id, fina * Get the table reference for this job. * @return Table reference */ - public TableReference getTableReference() + public final TableReference getTableReference() { return myTableReference; } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/VnodeOnDemandRepairJob.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/VnodeOnDemandRepairJob.java index 41e470a04..b2ece0bad 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/VnodeOnDemandRepairJob.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/VnodeOnDemandRepairJob.java @@ -28,7 +28,6 @@ import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,12 +66,12 @@ private VnodeOnDemandRepairJob(final Builder builder) } private Map> createRepairTasks( - final Map> tokenRanges, + final Map> tokenRanges, final Set repairedTokens) { Map> taskMap = new ConcurrentHashMap<>(); List vnodeRepairStates = new ArrayList<>(); - Map> remainingTokenRanges; + Map> remainingTokenRanges; if (repairedTokens.isEmpty()) { @@ -84,10 +83,10 @@ private Map> createRepairTasks( repairedTokens.iterator().forEachRemaining(remainingTokenRanges::remove); } - for (Map.Entry> entry : remainingTokenRanges.entrySet()) + for (Map.Entry> entry : remainingTokenRanges.entrySet()) { LongTokenRange longTokenRange = entry.getKey(); - ImmutableSet replicas = entry.getValue(); + Set replicas = entry.getValue(); vnodeRepairStates.add(new VnodeRepairState(longTokenRange, replicas, -1)); } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/EccRepairHistory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/EccRepairHistory.java index 8ff1d2f91..068319d8e 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/EccRepairHistory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/EccRepairHistory.java @@ -31,7 +31,6 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.AbstractIterator; -import com.google.common.collect.ImmutableSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,7 +122,7 @@ public RepairSession newSession(final TableReference tableReference, { Preconditions.checkArgument(participants.contains(localNode), "Local node must be part of repair"); - ImmutableSet nodes = replicationState.getNodes(tableReference, range); + Set nodes = replicationState.getNodes(tableReference, range); if (nodes == null || !nodes.equals(participants)) { return new NoOpRepairSession(); diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateImpl.java index 919b73e30..fa200db93 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateImpl.java @@ -236,7 +236,7 @@ private boolean replicasAreRepairable(final VnodeRepairState vnodeRepairState) * @return boolean */ @VisibleForTesting - boolean isRepairNeeded(final long lastRepairedAt, final long estimatedRepairTime, final long now) + final boolean isRepairNeeded(final long lastRepairedAt, final long estimatedRepairTime, final long now) { return lastRepairedAt + (myRepairConfiguration.getRepairIntervalInMs() - estimatedRepairTime) <= now; } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateSnapshot.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateSnapshot.java index 9f0a9f520..b78b8aed0 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateSnapshot.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/RepairStateSnapshot.java @@ -29,13 +29,12 @@ *
  • If there is a repair available - {@link #canRepair()}
  • * */ -@SuppressWarnings("FinalClass") -public class RepairStateSnapshot +public final class RepairStateSnapshot { private final boolean canRepair; private final long myLastCompletedAt; private final long myCreatedAt; - private final ImmutableList myReplicaRepairGroup; + private final List myReplicaRepairGroup; private final VnodeRepairStates myVnodeRepairStates; private final long myEstimatedRepairTime; @@ -124,7 +123,7 @@ public static class Builder { private Long myLastCompletedAt; private long myCreatedAt = System.currentTimeMillis(); - private ImmutableList myReplicaRepairGroup; + private List myReplicaRepairGroup; private VnodeRepairStates myVnodeRepairStates; /** diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicaRepairGroup.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicaRepairGroup.java index 66d8f3c9e..e528900e4 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicaRepairGroup.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicaRepairGroup.java @@ -16,10 +16,9 @@ import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import java.util.Iterator; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -28,8 +27,8 @@ */ public class ReplicaRepairGroup implements Iterable { - private final ImmutableSet myReplicas; - private final ImmutableList myVnodes; + private final Set myReplicas; + private final List myVnodes; private final long myLastCompletedAt; /** @@ -39,7 +38,7 @@ public class ReplicaRepairGroup implements Iterable * @param vnodes The token ranges. * @param lastCompletedAt last repair completed */ - public ReplicaRepairGroup(final ImmutableSet replicas, final ImmutableList vnodes, + public ReplicaRepairGroup(final Set replicas, final List vnodes, final long lastCompletedAt) { myReplicas = replicas; diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationState.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationState.java index f16780db6..e3dcefc8d 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationState.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationState.java @@ -15,11 +15,11 @@ package com.ericsson.bss.cassandra.ecchronos.core.repair.state; import java.util.Map; +import java.util.Set; import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; -import com.google.common.collect.ImmutableSet; /** * Replication state interface used to retrieve mappings between token range to responsible nodes. @@ -36,7 +36,7 @@ public interface ReplicationState * @param tokenRange The token range to get nodes for. * @return The responsible nodes or null if either the token range does not exist or is intersecting two ranges. */ - ImmutableSet getNodes(TableReference tableReference, LongTokenRange tokenRange); + Set getNodes(TableReference tableReference, LongTokenRange tokenRange); /** * Get the nodes that are a replica for the provided table that have ranges in common with the local node. @@ -44,7 +44,7 @@ public interface ReplicationState * @param tableReference The table to fetch replicas for. * @return The replicas for the table */ - ImmutableSet getReplicas(TableReference tableReference); + Set getReplicas(TableReference tableReference); /** * Get the nodes that are responsible for the provided token range, check clusterwide. @@ -54,7 +54,7 @@ public interface ReplicationState * @param tokenRange The token range to get nodes for. * @return The responsible nodes or null if either the token range does not exist or is intersecting two ranges. */ - ImmutableSet getNodesClusterWide(TableReference tableReference, LongTokenRange tokenRange); + Set getNodesClusterWide(TableReference tableReference, LongTokenRange tokenRange); /** * Get a map of the current replication state for the provided table. @@ -63,7 +63,7 @@ public interface ReplicationState * The table used to calculate the proper replication. * @return The map consisting of token -> responsible nodes. */ - Map> getTokenRangeToReplicas(TableReference tableReference); + Map> getTokenRangeToReplicas(TableReference tableReference); - Map> getTokenRanges(TableReference tableReference); + Map> getTokenRanges(TableReference tableReference); } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationStateImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationStateImpl.java index 9545cf428..bcfdc168e 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationStateImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/ReplicationStateImpl.java @@ -47,9 +47,9 @@ public class ReplicationStateImpl implements ReplicationState { private static final Logger LOG = LoggerFactory.getLogger(ReplicationStateImpl.class); - private static final Map>> + private static final Map>> KEYSPACE_REPLICATION_CACHE = new ConcurrentHashMap<>(); - private static final Map>> + private static final Map>> CLUSTER_WIDE_KEYSPACE_REPLICATION_CACHE = new ConcurrentHashMap<>(); private final NodeResolver myNodeResolver; @@ -67,11 +67,11 @@ public ReplicationStateImpl(final NodeResolver nodeResolver, final CqlSession se * {@inheritDoc} */ @Override - public ImmutableSet getNodes(final TableReference tableReference, final LongTokenRange tokenRange) + public Set getNodes(final TableReference tableReference, final LongTokenRange tokenRange) { String keyspace = tableReference.getKeyspace(); - ImmutableMap> replication = maybeRenew(keyspace); + Map> replication = maybeRenew(keyspace); return getNodes(replication, tokenRange); } @@ -79,11 +79,11 @@ public ImmutableSet getNodes(final TableReference tableReference, fi * {@inheritDoc} */ @Override - public ImmutableSet getReplicas(final TableReference tableReference) + public Set getReplicas(final TableReference tableReference) { - Map> tokens = getTokenRangeToReplicas(tableReference); + Map> tokens = getTokenRangeToReplicas(tableReference); Set allReplicas = new HashSet<>(); - for (ImmutableSet replicas : tokens.values()) + for (Set replicas : tokens.values()) { allReplicas.addAll(replicas); } @@ -94,23 +94,23 @@ public ImmutableSet getReplicas(final TableReference tableReference) * {@inheritDoc} */ @Override - public ImmutableSet getNodesClusterWide(final TableReference tableReference, + public Set getNodesClusterWide(final TableReference tableReference, final LongTokenRange tokenRange) { String keyspace = tableReference.getKeyspace(); - ImmutableMap> replication = maybeRenewClusterWide(keyspace); + Map> replication = maybeRenewClusterWide(keyspace); return getNodes(replication, tokenRange); } - private ImmutableSet getNodes(final ImmutableMap> replication, + private Set getNodes(final Map> replication, final LongTokenRange tokenRange) { - ImmutableSet nodes = replication.get(tokenRange); + Set nodes = replication.get(tokenRange); if (nodes == null) { - for (Map.Entry> entry : replication.entrySet()) + for (Map.Entry> entry : replication.entrySet()) { if (entry.getKey().isCovering(tokenRange)) { @@ -131,15 +131,15 @@ private ImmutableSet getNodes(final ImmutableMap> getTokenRangeToReplicas(final TableReference tableReference) + public Map> getTokenRangeToReplicas(final TableReference tableReference) { String keyspace = tableReference.getKeyspace(); return maybeRenew(keyspace); } - private ImmutableMap> maybeRenew(final String keyspace) + private Map> maybeRenew(final String keyspace) { - ImmutableMap> replication = buildTokenMap(keyspace, false); + Map> replication = buildTokenMap(keyspace, false); return KEYSPACE_REPLICATION_CACHE.compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); } @@ -151,25 +151,25 @@ private ImmutableMap> maybeRenew(final * @return Nodes and their ranges */ @Override - public Map> getTokenRanges(final TableReference tableReference) + public Map> getTokenRanges(final TableReference tableReference) { String keyspace = tableReference.getKeyspace(); return maybeRenewClusterWide(keyspace); } - private ImmutableMap> maybeRenewClusterWide(final String keyspace) + private Map> maybeRenewClusterWide(final String keyspace) { - ImmutableMap> replication = buildTokenMap(keyspace, true); + Map> replication = buildTokenMap(keyspace, true); return CLUSTER_WIDE_KEYSPACE_REPLICATION_CACHE .compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); } - private ImmutableMap> buildTokenMap(final String keyspace, + private Map> buildTokenMap(final String keyspace, final boolean clusterWide) { - ImmutableMap.Builder> replicationBuilder = ImmutableMap.builder(); - Map, ImmutableSet> replicaCache = new HashMap<>(); + ImmutableMap.Builder> replicationBuilder = ImmutableMap.builder(); + Map, Set> replicaCache = new HashMap<>(); Metadata metadata = mySession.getMetadata(); Optional tokenMap = metadata.getTokenMap(); if (!tokenMap.isPresent()) @@ -189,7 +189,7 @@ private ImmutableMap> buildTokenMap(fin for (TokenRange tokenRange : tokenRanges) { LongTokenRange longTokenRange = convert(tokenRange); - ImmutableSet replicas + Set replicas = replicaCache.computeIfAbsent(tokenMap.get().getReplicas(keyspaceName, tokenRange), this::convert); replicationBuilder.put(longTokenRange, replicas); @@ -198,7 +198,7 @@ private ImmutableMap> buildTokenMap(fin return replicationBuilder.build(); } - private ImmutableSet convert(final Set nodes) + private Set convert(final Set nodes) { ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); for (Node node : nodes) diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/SubRangeRepairStates.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/SubRangeRepairStates.java index 76100cd4c..1f7f37de9 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/SubRangeRepairStates.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/SubRangeRepairStates.java @@ -24,7 +24,7 @@ public final class SubRangeRepairStates implements VnodeRepairStates // CPD-OFF { - private final ImmutableList myVnodeRepairStatuses; + private final List myVnodeRepairStatuses; private SubRangeRepairStates(final SubRangeRepairStates.Builder builder) { @@ -92,7 +92,7 @@ public int hashCode() public static class Builder implements VnodeRepairStates.Builder { - private final ImmutableList myVnodeRepairStatesBase; + private final List myVnodeRepairStatesBase; private final Map myActualVnodeRepairStates = new HashMap<>(); public Builder(final Collection vnodeRepairStates) @@ -154,22 +154,12 @@ else if (partialVnodeIsNewer(baseVnode, newVnode)) // Partial vnode private boolean shouldReplace(final VnodeRepairState baseVnode, final VnodeRepairState newVnode) { - if (!baseVnode.isSameVnode(newVnode)) - { - return false; - } - - return isNewer(baseVnode, newVnode); + return baseVnode.isSameVnode(newVnode) && isNewer(baseVnode, newVnode); } private boolean partialVnodeIsNewer(final VnodeRepairState baseVnode, final VnodeRepairState newVnode) { - if (!baseVnode.getReplicas().equals(newVnode.getReplicas())) - { - return false; - } - - return isNewer(baseVnode, newVnode); + return baseVnode.getReplicas().equals(newVnode.getReplicas()) && isNewer(baseVnode, newVnode); } private boolean isNewer(final VnodeRepairState baseVnode, final VnodeRepairState newVnode) diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairGroupFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairGroupFactory.java index cd7a2f324..b5609afa4 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairGroupFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairGroupFactory.java @@ -17,7 +17,6 @@ import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Comparator; @@ -53,7 +52,7 @@ public List generateReplicaRepairGroups(final List replicas = vnodeRepairState.getReplicas(); + Set replicas = vnodeRepairState.getReplicas(); if (countedReplicaGroups.add(replicas)) { diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairState.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairState.java index af1162745..1ce25d3c7 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairState.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairState.java @@ -16,9 +16,9 @@ import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; -import com.google.common.collect.ImmutableSet; import java.util.Objects; +import java.util.Set; /** * A class representing the repair state of a single vnode. @@ -28,7 +28,7 @@ public class VnodeRepairState public static final long UNREPAIRED = -1L; private final LongTokenRange myTokenRange; - private final ImmutableSet myReplicas; + private final Set myReplicas; private final long myStartedAt; private final long myFinishedAt; private final long myRepairTime; @@ -41,7 +41,7 @@ public class VnodeRepairState * @param startedAt Started at timetamp. */ public VnodeRepairState(final LongTokenRange tokenRange, - final ImmutableSet replicas, + final Set replicas, final long startedAt) { this(tokenRange, replicas, startedAt, UNREPAIRED); @@ -57,7 +57,7 @@ public VnodeRepairState(final LongTokenRange tokenRange, * @param repairTime Repair time. */ public VnodeRepairState(final LongTokenRange tokenRange, - final ImmutableSet replicas, + final Set replicas, final long startedAt, final long finishedAt, final long repairTime) @@ -78,7 +78,7 @@ public VnodeRepairState(final LongTokenRange tokenRange, * @param finishedAt Finished at timestamp. */ public VnodeRepairState(final LongTokenRange tokenRange, - final ImmutableSet replicas, + final Set replicas, final long startedAt, final long finishedAt) { @@ -112,7 +112,7 @@ public LongTokenRange getTokenRange() * * @return The nodes */ - public ImmutableSet getReplicas() + public Set getReplicas() { return myReplicas; } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStateFactoryImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStateFactoryImpl.java index bff391829..10197b172 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStateFactoryImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStateFactoryImpl.java @@ -17,7 +17,6 @@ import com.ericsson.bss.cassandra.ecchronos.core.utils.LongTokenRange; import com.ericsson.bss.cassandra.ecchronos.core.utils.DriverNode; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; -import com.google.common.collect.ImmutableSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +54,7 @@ public VnodeRepairStateFactoryImpl(final ReplicationState replicationState, public VnodeRepairStates calculateNewState(final TableReference tableReference, final RepairStateSnapshot previous, final long iterateToTime) { - Map> tokenRangeToReplicaMap + Map> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); long lastRepairedAt = previousLastRepairedAt(previous, tokenRangeToReplicaMap); @@ -86,7 +85,7 @@ public VnodeRepairStates calculateState(final TableReference tableReference, final long to, final long from) { - Map> tokenRangeToReplicaMap + Map> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); Iterator repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, to, from, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); @@ -102,7 +101,7 @@ public VnodeRepairStates calculateClusterWideState(final TableReference tableRef final long to, final long from) { - Map> tokenRanges = myReplicationState.getTokenRanges(tableReference); + Map> tokenRanges = myReplicationState.getTokenRanges(tableReference); Set allNodes = new HashSet<>(); tokenRanges.values().forEach(n -> allNodes.addAll(n)); List allRepairEntries = new ArrayList<>(); @@ -122,15 +121,15 @@ public VnodeRepairStates calculateClusterWideState(final TableReference tableRef private VnodeRepairStates generateVnodeRepairStates(final long lastRepairedAt, final RepairStateSnapshot previous, final Iterator repairEntryIterator, - final Map> + final Map> tokenRangeToReplicaMap) { List vnodeRepairStatesBase = new ArrayList<>(); - for (Map.Entry> entry : tokenRangeToReplicaMap.entrySet()) + for (Map.Entry> entry : tokenRangeToReplicaMap.entrySet()) { LongTokenRange longTokenRange = entry.getKey(); - ImmutableSet replicas = entry.getValue(); + Set replicas = entry.getValue(); vnodeRepairStatesBase.add(new VnodeRepairState(longTokenRange, replicas, lastRepairedAt)); } @@ -153,7 +152,7 @@ private VnodeRepairStates generateVnodeRepairStates(final long lastRepairedAt, { RepairEntry repairEntry = repairEntryIterator.next(); LongTokenRange longTokenRange = repairEntry.getRange(); - ImmutableSet replicas = getReplicasForRange(longTokenRange, tokenRangeToReplicaMap); + Set replicas = getReplicasForRange(longTokenRange, tokenRangeToReplicaMap); VnodeRepairState vnodeRepairState = new VnodeRepairState(longTokenRange, replicas, repairEntry.getStartedAt(), repairEntry.getFinishedAt()); @@ -165,7 +164,7 @@ private VnodeRepairStates generateVnodeRepairStates(final long lastRepairedAt, } private long previousLastRepairedAt(final RepairStateSnapshot previous, - final Map> tokenToReplicaMap) + final Map> tokenToReplicaMap) { if (previous == null) { @@ -194,7 +193,7 @@ private long previousLastRepairedAt(final RepairStateSnapshot previous, } private boolean acceptRepairEntries(final RepairEntry repairEntry, - final Map> tokenRangeToReplicaMap) + final Map> tokenRangeToReplicaMap) { if (RepairStatus.SUCCESS != repairEntry.getStatus()) { @@ -204,7 +203,7 @@ private boolean acceptRepairEntries(final RepairEntry repairEntry, LongTokenRange repairedRange = repairEntry.getRange(); - ImmutableSet nodes = getReplicasForRange(repairedRange, tokenRangeToReplicaMap); + Set nodes = getReplicasForRange(repairedRange, tokenRangeToReplicaMap); if (nodes == null) { LOG.trace("Ignoring entry {}, replicas not present in tokenRangeToReplicas", repairEntry); @@ -220,14 +219,14 @@ private boolean acceptRepairEntries(final RepairEntry repairEntry, return true; } - private ImmutableSet getReplicasForRange(final LongTokenRange range, - final Map> + private Set getReplicasForRange(final LongTokenRange range, + final Map> tokenRangeToReplicaMap) { - ImmutableSet nodes = tokenRangeToReplicaMap.get(range); + Set nodes = tokenRangeToReplicaMap.get(range); if (nodes == null && useSubRanges) { - for (Map.Entry> vnode : tokenRangeToReplicaMap.entrySet()) + for (Map.Entry> vnode : tokenRangeToReplicaMap.entrySet()) { if (vnode.getKey().isCovering(range)) { diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStatesImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStatesImpl.java index f7cfbeebb..6a18f245b 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStatesImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/VnodeRepairStatesImpl.java @@ -19,12 +19,13 @@ import java.util.Collection; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Objects; public final class VnodeRepairStatesImpl implements VnodeRepairStates // CPD-OFF { - private final ImmutableList myVnodeRepairStatuses; + private final List myVnodeRepairStatuses; private VnodeRepairStatesImpl(final Builder builder) { diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduleManagerImpl.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduleManagerImpl.java index 65a531488..84b089b05 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduleManagerImpl.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduleManagerImpl.java @@ -150,7 +150,7 @@ private Long validateJob(final ScheduledJob job) *

    * Retrieves a job from the queue and tries to run it provided that it's possible to get the required locks. */ - private class JobRunTask implements Runnable + private final class JobRunTask implements Runnable { @Override public void run() @@ -215,7 +215,7 @@ private boolean tryRunTasks(final ScheduledJob next) private boolean tryRunTask(final ScheduledJob job, final ScheduledTask task) { LOG.debug("Trying to acquire lock for {}", task); - try (LockFactory.DistributedLock lock = task.getLock(myLockFactory)) + try (LockFactory.DistributedLock lock = task.getLock(myLockFactory)) // NOPMD { boolean successful = runTask(task); job.postExecute(successful, task); diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduledJobQueue.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduledJobQueue.java index 2186f3ee3..324485551 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduledJobQueue.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/scheduling/ScheduledJobQueue.java @@ -14,11 +14,13 @@ */ package com.ericsson.bss.cassandra.ecchronos.core.scheduling; -import java.util.Collection; import java.util.Comparator; +import java.util.Queue; +import java.util.Map; import java.util.EnumMap; -import java.util.Iterator; import java.util.PriorityQueue; +import java.util.Collection; +import java.util.Iterator; import com.google.common.collect.AbstractIterator; import org.slf4j.Logger; @@ -40,7 +42,7 @@ public class ScheduledJobQueue implements Iterable private final Comparator myComparator; - private final EnumMap> myJobQueues + private final Map> myJobQueues = new EnumMap<>(ScheduledJob.Priority.class); /** @@ -107,7 +109,7 @@ final int size() { int size = 0; - for (PriorityQueue queue : myJobQueues.values()) + for (Queue queue : myJobQueues.values()) { size += queue.size(); } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LongTokenRange.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LongTokenRange.java index f7034588e..0ea564c60 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LongTokenRange.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LongTokenRange.java @@ -125,11 +125,7 @@ public final boolean equals(final Object o) LongTokenRange that = (LongTokenRange) o; - if (start != that.start) - { - return false; - } - return end == that.end; + return start == that.start && end == that.end; } @Override diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestMetricInspector.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestMetricInspector.java index 790bf0669..871fc301d 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestMetricInspector.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestMetricInspector.java @@ -43,8 +43,6 @@ public class TestMetricInspector private static final String TEST_TABLE1 = "test_table1"; private static final String TEST_TABLE2 = "test_table2"; - @Mock - private TableStorageStates myTableStorageStates; private MeterRegistry myMeterRegistry; private TableRepairMetricsImpl myTableRepairMetricsImpl; private MetricInspector myMetricInspector; @@ -62,7 +60,6 @@ public void init() compositeMeterRegistry.add(new SimpleMeterRegistry()); myMeterRegistry = compositeMeterRegistry; myTableRepairMetricsImpl = TableRepairMetricsImpl.builder() - .withTableStorageStates(myTableStorageStates) .withMeterRegistry(myMeterRegistry) .build(); myMetricInspector = new MetricInspector(myMeterRegistry, 1, 1, 5000); } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestTableRepairMetricsImpl.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestTableRepairMetricsImpl.java index 9a3e0bdcd..2d4b38a59 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestTableRepairMetricsImpl.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/metrics/TestTableRepairMetricsImpl.java @@ -41,9 +41,6 @@ public class TestTableRepairMetricsImpl private static final String TEST_TABLE1 = "test_table1"; private static final String TEST_TABLE2 = "test_table2"; - @Mock - private TableStorageStates myTableStorageStates; - private TableRepairMetricsImpl myTableRepairMetricsImpl; private MeterRegistry myMeterRegistry; @@ -56,7 +53,6 @@ public void init() compositeMeterRegistry.add(new SimpleMeterRegistry()); myMeterRegistry = compositeMeterRegistry; myTableRepairMetricsImpl = TableRepairMetricsImpl.builder() - .withTableStorageStates(myTableStorageStates) .withMeterRegistry(myMeterRegistry) .build(); } @@ -73,7 +69,6 @@ public void testBuildWithNullTableStorageStates() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> TableRepairMetricsImpl.builder() - .withTableStorageStates(null) .build()); } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOnDemandStatus.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOnDemandStatus.java index 86ed5afc1..223f7df87 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOnDemandStatus.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOnDemandStatus.java @@ -283,7 +283,7 @@ public void testGetAllClusterWideJobs() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -320,7 +320,7 @@ public void testGetOngoingJobsWithNewJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -347,7 +347,7 @@ public void testGetOngoingJobsWithNewTable() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -368,7 +368,7 @@ public void testGetOngoingJobsWithUpdatedJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -398,7 +398,7 @@ public void testGetOngoingJobsWithFinishedJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -422,7 +422,7 @@ public void testGetOngoingJobsWithFailedJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -456,7 +456,7 @@ public void testGetAllJobsWithNewJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -483,7 +483,7 @@ public void testGetAllJobsWithNewTable() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -504,7 +504,7 @@ public void testGetAllJobsWithUpdatedJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -534,7 +534,7 @@ public void testGetAllJobsWithFinishedJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); @@ -565,7 +565,7 @@ public void testGetAllJobsWithFailedJob() UUID jobId = UUID.randomUUID(); int hashValue = 1; TableReference tableReference = myTableReferenceFactory.forTable(KEYSPACE_NAME, TEST_TABLE_NAME); - Map> tokenMap = new HashMap<>(); + Map> tokenMap = new HashMap<>(); when(myReplicationState.getTokenRangeToReplicas(tableReference)).thenReturn(tokenMap); onDemandStatus.addNewJob(jobId, tableReference, hashValue, RepairOptions.RepairType.VNODE); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOngoingJob.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOngoingJob.java index 3dd4da4af..551486b2f 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOngoingJob.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestOngoingJob.java @@ -48,7 +48,7 @@ public class TestOngoingJob private static final String keyspaceName = "keyspace"; private static final String tableName = "table"; - private final Map> myTokenMap = new HashMap<>(); + private final Map> myTokenMap = new HashMap<>(); @Mock private OnDemandStatus myOnDemandStatus; @@ -354,31 +354,31 @@ public void testHasTopologyChangedWithChangedTopologyAfterRestart() @Test public void testStartClusterWideJob() { - Map> thisNodeTokenMap = new HashMap<>(); + Map> thisNodeTokenMap = new HashMap<>(); DriverNode node1 = mock(DriverNode.class); DriverNode node2 = mock(DriverNode.class); DriverNode node3 = mock(DriverNode.class); DriverNode node4 = mock(DriverNode.class); LongTokenRange range1 = new LongTokenRange(1, 2); - ImmutableSet range1Replicas = ImmutableSet.of(node1, node2, node3); + Set range1Replicas = ImmutableSet.of(node1, node2, node3); LongTokenRange range2 = new LongTokenRange(2, 3); - ImmutableSet range2Replicas = ImmutableSet.of(node1, node2, node3); + Set range2Replicas = ImmutableSet.of(node1, node2, node3); LongTokenRange range3 = new LongTokenRange(3, 4); - ImmutableSet range3Replicas = ImmutableSet.of(node2, node1, node3); + Set range3Replicas = ImmutableSet.of(node2, node1, node3); LongTokenRange range4 = new LongTokenRange(4, 5); - ImmutableSet range4Replicas = ImmutableSet.of(node2, node1, node3); + Set range4Replicas = ImmutableSet.of(node2, node1, node3); LongTokenRange range5 = new LongTokenRange(5, 6); - ImmutableSet range5Replicas = ImmutableSet.of(node3, node2, node1); + Set range5Replicas = ImmutableSet.of(node3, node2, node1); LongTokenRange range6 = new LongTokenRange(6, 7); - ImmutableSet range6Replicas = ImmutableSet.of(node2, node3, node4); + Set range6Replicas = ImmutableSet.of(node2, node3, node4); LongTokenRange range7 = new LongTokenRange(7, 8); - ImmutableSet range7Replicas = ImmutableSet.of(node2, node3, node4); + Set range7Replicas = ImmutableSet.of(node2, node3, node4); LongTokenRange range8 = new LongTokenRange(8, 9); - ImmutableSet range8Replicas = ImmutableSet.of(node3, node2, node4); + Set range8Replicas = ImmutableSet.of(node3, node2, node4); LongTokenRange range9 = new LongTokenRange(9, 10); - ImmutableSet range9Replicas = ImmutableSet.of(node4, node3, node2); + Set range9Replicas = ImmutableSet.of(node4, node3, node2); thisNodeTokenMap.put(range1, range1Replicas); thisNodeTokenMap.put(range2, range2Replicas); @@ -386,7 +386,7 @@ public void testStartClusterWideJob() thisNodeTokenMap.put(range4, range4Replicas); thisNodeTokenMap.put(range5, range5Replicas); - Map> allTokenMap = new HashMap<>(); + Map> allTokenMap = new HashMap<>(); allTokenMap.put(range1, range1Replicas); allTokenMap.put(range2, range2Replicas); allTokenMap.put(range3, range3Replicas); @@ -438,7 +438,7 @@ public void testStartClusterWideJob() repairedRangesNode4.add(range7); repairedRangesNode4.add(range8); //Node4 is replica to node2 and node3 - Map> node4TokenMap = new HashMap<>(); + Map> node4TokenMap = new HashMap<>(); node4TokenMap.put(range6, range6Replicas); node4TokenMap.put(range7, range7Replicas); node4TokenMap.put(range8, range8Replicas); @@ -450,7 +450,7 @@ public void testStartClusterWideJob() @Test public void testStartIncrementalClusterWideJob() { - Map> thisNodeTokenMap = new HashMap<>(); + Map> thisNodeTokenMap = new HashMap<>(); DriverNode node1 = mock(DriverNode.class); DriverNode node2 = mock(DriverNode.class); UUID node2Id = UUID.randomUUID(); @@ -463,24 +463,24 @@ public void testStartIncrementalClusterWideJob() when(node4.getId()).thenReturn(node4Id); LongTokenRange range1 = new LongTokenRange(1, 2); - ImmutableSet range1Replicas = ImmutableSet.of(node1, node2, node3); + Set range1Replicas = ImmutableSet.of(node1, node2, node3); LongTokenRange range2 = new LongTokenRange(2, 3); - ImmutableSet range2Replicas = ImmutableSet.of(node1, node2, node3); + Set range2Replicas = ImmutableSet.of(node1, node2, node3); LongTokenRange range3 = new LongTokenRange(3, 4); - ImmutableSet range3Replicas = ImmutableSet.of(node2, node1, node3); + Set range3Replicas = ImmutableSet.of(node2, node1, node3); LongTokenRange range4 = new LongTokenRange(4, 5); - ImmutableSet range4Replicas = ImmutableSet.of(node2, node1, node3); + Set range4Replicas = ImmutableSet.of(node2, node1, node3); LongTokenRange range5 = new LongTokenRange(5, 6); - ImmutableSet range5Replicas = ImmutableSet.of(node3, node2, node1); + Set range5Replicas = ImmutableSet.of(node3, node2, node1); LongTokenRange range6 = new LongTokenRange(6, 7); - ImmutableSet range6Replicas = ImmutableSet.of(node2, node3, node4); + Set range6Replicas = ImmutableSet.of(node2, node3, node4); LongTokenRange range7 = new LongTokenRange(7, 8); - ImmutableSet range7Replicas = ImmutableSet.of(node2, node3, node4); + Set range7Replicas = ImmutableSet.of(node2, node3, node4); LongTokenRange range8 = new LongTokenRange(8, 9); - ImmutableSet range8Replicas = ImmutableSet.of(node3, node2, node4); + Set range8Replicas = ImmutableSet.of(node3, node2, node4); LongTokenRange range9 = new LongTokenRange(9, 10); - ImmutableSet range9Replicas = ImmutableSet.of(node4, node3, node2); + Set range9Replicas = ImmutableSet.of(node4, node3, node2); thisNodeTokenMap.put(range1, range1Replicas); thisNodeTokenMap.put(range2, range2Replicas); @@ -488,7 +488,7 @@ public void testStartIncrementalClusterWideJob() thisNodeTokenMap.put(range4, range4Replicas); thisNodeTokenMap.put(range5, range5Replicas); - Map> allTokenMap = new HashMap<>(); + Map> allTokenMap = new HashMap<>(); allTokenMap.put(range1, range1Replicas); allTokenMap.put(range2, range2Replicas); allTokenMap.put(range3, range3Replicas); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestVnodeOnDemandRepairJob.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestVnodeOnDemandRepairJob.java index d210afa65..2f392f1f4 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestVnodeOnDemandRepairJob.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestVnodeOnDemandRepairJob.java @@ -179,7 +179,7 @@ private VnodeOnDemandRepairJob createVnodeOnDemandRepairJob(int repairedTokenPer { LongTokenRange range1 = new LongTokenRange(1, 2); LongTokenRange range2 = new LongTokenRange(1, 3); - Map> tokenRangeToReplicas = new HashMap<>(); + Map> tokenRangeToReplicas = new HashMap<>(); tokenRangeToReplicas.put(range1, ImmutableSet.of(mockReplica1, mockReplica2, mockReplica3)); tokenRangeToReplicas.put(range2, @@ -211,7 +211,7 @@ private VnodeOnDemandRepairJob createRestartedOnDemandRepairJob() { LongTokenRange range1 = new LongTokenRange(1, 2); LongTokenRange range2 = new LongTokenRange(1, 3); - Map> tokenRangeToReplicas = new HashMap<>(); + Map> tokenRangeToReplicas = new HashMap<>(); tokenRangeToReplicas.put(range1, ImmutableSet.of(mockReplica1, mockReplica2, mockReplica3)); tokenRangeToReplicas.put(range2, diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestReplicationStateImpl.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestReplicationStateImpl.java index 409fa5789..2c983e78c 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestReplicationStateImpl.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestReplicationStateImpl.java @@ -36,6 +36,7 @@ import java.net.InetSocketAddress; import java.util.Map; import java.util.Optional; +import java.util.Set; import static com.ericsson.bss.cassandra.ecchronos.core.MockTableReferenceFactory.tableReference; import static org.assertj.core.api.Assertions.assertThat; @@ -122,7 +123,7 @@ public void testGetTokenRangeToReplicaSingleToken() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( + Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( tableReference); assertThat(tokenRangeToReplicas.keySet()).containsExactlyInAnyOrder(range1); @@ -148,7 +149,7 @@ public void testGetTokenRangeToReplica() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( + Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( tableReference); assertThat(tokenRangeToReplicas.keySet()).containsExactlyInAnyOrder(range1, range2); @@ -174,7 +175,7 @@ public void testGetReplicas() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - ImmutableSet replicas = replicationState.getReplicas(tableReference); + Set replicas = replicationState.getReplicas(tableReference); assertThat(replicas).containsExactlyInAnyOrder(mockNode1, mockNode2, mockNode3); } @@ -196,7 +197,7 @@ public void testGetTokenRangeToReplicaSetReuse() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( + Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( tableReference); assertThat(tokenRangeToReplicas.keySet()).containsExactlyInAnyOrder(range1, range2); @@ -221,7 +222,7 @@ public void testGetTokenRangeToReplicaMapReuse() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( + Map> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas( tableReference); assertThat(tokenRangeToReplicas.keySet()).containsExactlyInAnyOrder(range1); @@ -246,7 +247,7 @@ public void testGetNodesForSubRange() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - ImmutableSet nodes = replicationState.getNodes(tableReference, subRange); + Set nodes = replicationState.getNodes(tableReference, subRange); assertThat(nodes).containsExactlyInAnyOrder(mockNode1, mockNode2, mockNode3); } @@ -303,7 +304,7 @@ public void testGetNodesClusterWideForSubRange() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - ImmutableSet nodes = replicationState.getNodesClusterWide(tableReference, subRange); + Set nodes = replicationState.getNodesClusterWide(tableReference, subRange); assertThat(nodes).containsExactlyInAnyOrder(mockNode1, mockNode2, mockNode3); } @@ -373,7 +374,7 @@ public void testGetTokenRanges() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - Map> tokenRanges = replicationState.getTokenRanges(tableReference); + Map> tokenRanges = replicationState.getTokenRanges(tableReference); assertThat(tokenRanges.keySet()).containsExactlyInAnyOrder(range1, range2, range3, range4); assertThat(tokenRanges.get(range1)).containsExactlyInAnyOrder(mockNode1, mockNode2, mockNode3); @@ -396,7 +397,7 @@ public void testGetTokenRangesReuse() throws Exception ReplicationState replicationState = new ReplicationStateImpl(mockNodeResolver, mockSession, mockReplica1); - Map> tokenRanges = replicationState.getTokenRanges(tableReference); + Map> tokenRanges = replicationState.getTokenRanges(tableReference); assertThat(tokenRanges.keySet()).containsExactlyInAnyOrder(range1); assertThat(tokenRanges.get(range1)).containsExactlyInAnyOrder(mockNode1, mockNode2, mockNode3); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestVnodeRepairStateFactoryImpl.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestVnodeRepairStateFactoryImpl.java index b71dc332b..406663794 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestVnodeRepairStateFactoryImpl.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/state/TestVnodeRepairStateFactoryImpl.java @@ -23,17 +23,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -57,7 +47,7 @@ public class TestVnodeRepairStateFactoryImpl @Mock private ReplicationState mockReplicationState; - private Map> tokenToNodeMap = new TreeMap<>( + private Map> tokenToNodeMap = new TreeMap<>( Comparator.comparingLong(l -> l.start)); private RepairHistoryProvider repairHistoryProvider = new MockedRepairHistoryProvider(TABLE_REFERENCE); @@ -437,7 +427,7 @@ public void testWithHistoryAndPreviousOnlyIteratesOverDiff() throws UnknownHostE withRange(longTokenRange2, node1, node2); ImmutableSet replicas = ImmutableSet.of(node1, node2); - Map> tokenToHostMap = new HashMap<>(); + Map> tokenToHostMap = new HashMap<>(); tokenToHostMap.put(longTokenRange1, replicas); tokenToHostMap.put(longTokenRange2, replicas); @@ -508,23 +498,23 @@ private VnodeRepairStates vnodeRepairStates(VnodeRepairState... states) private void withSubRangeSuccessfulRepairHistory(LongTokenRange range, long startedAt, long finishedAt) { - ImmutableSet replicas = getKnownReplicasForSubRange(range); + Set replicas = getKnownReplicasForSubRange(range); withRepairHistory(range, startedAt, finishedAt, replicas, "SUCCESS"); } private void withSuccessfulRepairHistory(LongTokenRange range, long startedAt, long finishedAt) { - ImmutableSet replicas = getKnownReplicas(range); + Set replicas = getKnownReplicas(range); withRepairHistory(range, startedAt, finishedAt, replicas, "SUCCESS"); } private void withFailedRepairHistory(LongTokenRange range, long startedAt) { - ImmutableSet replicas = getKnownReplicas(range); + Set replicas = getKnownReplicas(range); withRepairHistory(range, startedAt, VnodeRepairState.UNREPAIRED, replicas, "FAILED"); } - private void withRepairHistory(LongTokenRange range, long startedAt, long finishedAt, ImmutableSet replicas, String status) + private void withRepairHistory(LongTokenRange range, long startedAt, long finishedAt, Set replicas, String status) { RepairEntry repairEntry = new RepairEntry(range, startedAt, finishedAt, replicas, status); repairHistory.add(repairEntry); @@ -555,9 +545,9 @@ private VnodeRepairState newSubRangeState(LongTokenRange range, long startedAt, return new VnodeRepairState(range, getKnownReplicasForSubRange(range), startedAt, finishedAt); } - private ImmutableSet getKnownReplicasForSubRange(LongTokenRange range) + private Set getKnownReplicasForSubRange(LongTokenRange range) { - ImmutableSet replicas = tokenToNodeMap.get(range); + Set replicas = tokenToNodeMap.get(range); if (replicas == null) { for (LongTokenRange vnode : tokenToNodeMap.keySet()) @@ -575,9 +565,9 @@ private ImmutableSet getKnownReplicasForSubRange(LongTokenRange rang return replicas; } - private ImmutableSet getKnownReplicas(LongTokenRange range) + private Set getKnownReplicas(LongTokenRange range) { - ImmutableSet replicas = tokenToNodeMap.get(range); + Set replicas = tokenToNodeMap.get(range); assertThat(replicas).isNotNull(); return replicas; } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/utils/TestStatusLogger.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/utils/TestStatusLogger.java index c5c32c2e1..209b82d53 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/utils/TestStatusLogger.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/utils/TestStatusLogger.java @@ -43,8 +43,7 @@ public class TestStatusLogger private static final String TEST_KEYSPACE = "test_keyspace"; private static final String TEST_TABLE1 = "test_table1"; private static final String TEST_TABLE2 = "test_table2"; - @Mock - private TableStorageStates myTableStorageStates; + private MeterRegistry myMeterRegistry; private TableRepairMetricsImpl myTableRepairMetricsImpl; @@ -64,7 +63,6 @@ public void init() compositeMeterRegistry.add(new SimpleMeterRegistry()); myMeterRegistry = compositeMeterRegistry; myTableRepairMetricsImpl = TableRepairMetricsImpl.builder() - .withTableStorageStates(myTableStorageStates) .withMeterRegistry(myMeterRegistry) .build(); } diff --git a/pmd-rules.xml b/pmd-rules.xml index 5858cf92b..00fdce9bb 100644 --- a/pmd-rules.xml +++ b/pmd-rules.xml @@ -33,6 +33,7 @@ + @@ -49,4 +50,16 @@ + + + + + + + + + + + +