From 51012ab7b56beeab3921a0a3416cb323f177e416 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Mon, 4 Mar 2024 10:40:22 -0500 Subject: [PATCH] lots of small sonar adjustments --- .../opennms/newts/aggregate/Aggregation.java | 10 +- .../aggregate/AggregationAttributesTest.java | 4 +- .../aggregate/PrimaryDataAttributesTest.java | 4 +- .../org/opennms/newts/aggregate/Utils.java | 4 +- .../newts/api/BlockingThreadPoolExecutor.java | 8 +- .../org/opennms/newts/api/AbsoluteTest.java | 4 +- .../org/opennms/newts/api/CounterTest.java | 4 +- .../org/opennms/newts/api/DeriveTest.java | 4 +- .../cassandra/search/CassandraIndexer.java | 26 +- .../cassandra/search/CassandraSearcher.java | 9 +- .../search/CassandraIndexerITCase.java | 5 +- .../EscapableResourceIdSplitterTest.java | 4 +- .../search/GuavaResourceMetadataTest.java | 4 +- .../search/SimpleResourceIdSplitterTest.java | 4 +- .../cassandra/CassandraSampleRepository.java | 7 +- .../cassandra/ConcurrentResultWrapper.java | 19 +- .../newts/persistence/cassandra/Utils.java | 4 +- .../org/opennms/newts/gsod/ExportRunner.java | 14 +- .../org/opennms/newts/gsod/FileIterable.java | 119 +++----- .../org/opennms/newts/gsod/ImportRunner.java | 260 ++++++------------ .../java/org/opennms/newts/stress/Config.java | 10 +- .../org/opennms/newts/stress/Dispatcher.java | 4 +- .../newts/graphite/GraphiteHandlerTest.java | 2 +- .../api/search/query/QueryParserTest.java | 4 +- .../opennms/newts/rest/CassandraConfig.java | 6 +- .../rest/HttpBasicAuthenticationFilter.java | 4 +- .../opennms/newts/rest/DurationParamTest.java | 4 +- .../HttpBasicAuthenticationFilterTest.java | 4 +- .../newts/rest/MeasurementsResourceTest.java | 4 +- .../newts/rest/ResultSerializationTest.java | 2 +- .../newts/rest/SamplesResourceTest.java | 12 +- .../newts/rest/TimestampParamTest.java | 4 +- 32 files changed, 212 insertions(+), 365 deletions(-) diff --git a/aggregate/src/main/java/org/opennms/newts/aggregate/Aggregation.java b/aggregate/src/main/java/org/opennms/newts/aggregate/Aggregation.java index 12ed6c1e..0b2332ef 100644 --- a/aggregate/src/main/java/org/opennms/newts/aggregate/Aggregation.java +++ b/aggregate/src/main/java/org/opennms/newts/aggregate/Aggregation.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -66,10 +66,10 @@ class Aggregation implements Iterable>, Iterator(m_timestamps.next(), m_resource) : null; + m_nextOut = m_timestamps.hasNext() ? new Row<>(m_timestamps.next(), m_resource) : null; // If the input stream contains any Samples earlier than what's relevant, iterate past them. if (m_nextOut != null) { @@ -124,7 +124,7 @@ public Row next() { return m_nextOut; } finally { - m_nextOut = m_timestamps.hasNext() ? new Row(m_timestamps.next(), m_resource) : null; + m_nextOut = m_timestamps.hasNext() ? new Row<>(m_timestamps.next(), m_resource) : null; } } @@ -160,6 +160,8 @@ public void remove() { } @Override + @SuppressWarnings("java:S4348") + // since the length is computed, it's not simple to make this re-iterable public Iterator> iterator() { return this; } diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/AggregationAttributesTest.java b/aggregate/src/test/java/org/opennms/newts/aggregate/AggregationAttributesTest.java index 2846ee13..97d93180 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/AggregationAttributesTest.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/AggregationAttributesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -17,7 +17,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.opennms.newts.aggregate.Utils.assertAttributes; import static org.opennms.newts.aggregate.Utils.mapFor; import static org.opennms.newts.api.Timestamp.fromEpochSeconds; diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataAttributesTest.java b/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataAttributesTest.java index 72b6dd7c..051d741c 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataAttributesTest.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/PrimaryDataAttributesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -16,7 +16,7 @@ package org.opennms.newts.aggregate; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.opennms.newts.aggregate.Utils.assertAttributes; import static org.opennms.newts.aggregate.Utils.mapFor; import static org.opennms.newts.api.Timestamp.fromEpochSeconds; diff --git a/aggregate/src/test/java/org/opennms/newts/aggregate/Utils.java b/aggregate/src/test/java/org/opennms/newts/aggregate/Utils.java index 93268da8..6de160e3 100644 --- a/aggregate/src/test/java/org/opennms/newts/aggregate/Utils.java +++ b/aggregate/src/test/java/org/opennms/newts/aggregate/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import java.util.Iterator; diff --git a/api/src/main/java/org/opennms/newts/api/BlockingThreadPoolExecutor.java b/api/src/main/java/org/opennms/newts/api/BlockingThreadPoolExecutor.java index 135625f9..4e4c3a57 100644 --- a/api/src/main/java/org/opennms/newts/api/BlockingThreadPoolExecutor.java +++ b/api/src/main/java/org/opennms/newts/api/BlockingThreadPoolExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -23,8 +23,6 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import com.google.common.base.Throwables; - public class BlockingThreadPoolExecutor extends ThreadPoolExecutor { @@ -46,7 +44,7 @@ public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { } } catch (InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -55,7 +53,7 @@ public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { } public BlockingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, new LinkedBlockingQueue((int)(maximumPoolSize*1.5))); + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, new LinkedBlockingQueue<>((int)(maximumPoolSize*1.5))); this.setRejectedExecutionHandler(new BlockingExecutionHandler()); } diff --git a/api/src/test/java/org/opennms/newts/api/AbsoluteTest.java b/api/src/test/java/org/opennms/newts/api/AbsoluteTest.java index 5f295440..1f170a93 100644 --- a/api/src/test/java/org/opennms/newts/api/AbsoluteTest.java +++ b/api/src/test/java/org/opennms/newts/api/AbsoluteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -18,7 +18,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; diff --git a/api/src/test/java/org/opennms/newts/api/CounterTest.java b/api/src/test/java/org/opennms/newts/api/CounterTest.java index 93f258c0..d55f8ffc 100644 --- a/api/src/test/java/org/opennms/newts/api/CounterTest.java +++ b/api/src/test/java/org/opennms/newts/api/CounterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -17,7 +17,7 @@ import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; diff --git a/api/src/test/java/org/opennms/newts/api/DeriveTest.java b/api/src/test/java/org/opennms/newts/api/DeriveTest.java index b40a4424..8ca45eba 100644 --- a/api/src/test/java/org/opennms/newts/api/DeriveTest.java +++ b/api/src/test/java/org/opennms/newts/api/DeriveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -18,7 +18,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; diff --git a/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraIndexer.java b/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraIndexer.java index 554536d0..f888ec2a 100644 --- a/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraIndexer.java +++ b/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraIndexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016, The OpenNMS Group + * Copyright 2016-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -19,7 +19,6 @@ import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.insertInto; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; -import static com.datastax.oss.driver.api.querybuilder.select.Selector.ttl; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Collection; @@ -28,7 +27,6 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; @@ -64,6 +62,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; +@SuppressWarnings("java:S4738") // we only use Guava Optional internally, it isn't passed around public class CassandraIndexer implements Indexer { private static final Logger LOG = LoggerFactory.getLogger(CassandraIndexer.class); @@ -142,9 +141,9 @@ public void update(Collection samples) { } // Order matters here; We want the cache updated only after a successful Cassandra write. - for (Context context : cacheQueue.keySet()) { - for (Map.Entry entry : cacheQueue.get(context).entrySet()) { - m_cache.merge(context, entry.getKey(), entry.getValue()); + for (final Entry> queueEntry : cacheQueue.entrySet()) { + for (final Map.Entry entry : queueEntry.getValue().entrySet()) { + m_cache.merge(queueEntry.getKey(), entry.getKey(), entry.getValue()); } } } finally { @@ -155,10 +154,11 @@ public void update(Collection samples) { } } - private List toStatements(Set generators) { - List statementsToExecute = Lists.newArrayList(); + @SuppressWarnings("rawtypes") + private List> toStatements(Set generators) { + List> statementsToExecute = Lists.newArrayList(); - Map> statementsByKey = Maps.newHashMap(); + Map>> statementsByKey = Maps.newHashMap(); for (StatementGenerator generator : generators) { BatchableStatement statement = generator.toStatement() .setConsistencyLevel(m_contextConfigurations.getWriteConsistency(generator.getContext())); @@ -170,7 +170,7 @@ private List toStatements(Set generators) { } // Group these by key - List statementsForKey = statementsByKey.get(key); + List> statementsForKey = statementsByKey.get(key); if (statementsForKey == null) { statementsForKey = Lists.newArrayList(); statementsByKey.put(key, statementsForKey); @@ -179,8 +179,8 @@ private List toStatements(Set generators) { } // Consolidate the grouped statements into batches - for (List statementsForKey: statementsByKey.values()) { - for (List partition : Lists.partition(statementsForKey, m_options.getMaxBatchSize())) { + for (List> statementsForKey: statementsByKey.values()) { + for (List> partition : Lists.partition(statementsForKey, m_options.getMaxBatchSize())) { BatchStatementBuilder builder = BatchStatement.builder(DefaultBatchType.UNLOGGED); for (BatchableStatement statement : partition) { builder.addStatement(statement); @@ -454,7 +454,7 @@ public boolean equals(Object obj) { } } - private static abstract class KeyValuePairInsert implements StatementGenerator { + private abstract static class KeyValuePairInsert implements StatementGenerator { protected final Context m_context; protected final String m_resourceId; protected final String m_field; diff --git a/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraSearcher.java b/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraSearcher.java index 1df2adf3..acdf550d 100644 --- a/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraSearcher.java +++ b/cassandra/search/src/main/java/org/opennms/newts/cassandra/search/CassandraSearcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -53,7 +53,6 @@ import com.datastax.oss.driver.api.core.cql.Row; import com.datastax.oss.driver.api.querybuilder.select.Select; import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -133,7 +132,7 @@ public SearchResults search(Context context, Query query, boolean populateMetric Resource resource = attrs.size() > 0 ? new Resource(id, Optional.of(attrs)) : new Resource(id); searchResults.addResult(resource, metrics); } catch (ExecutionException|InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } @@ -150,7 +149,7 @@ public Map getResourceAttributes(Context context, String resourc ConsistencyLevel readConsistency = m_contextConfigurations.getReadConsistency(context); return getResourceAttributesFromResults(fetchResourceAttributes(context, resourceId, readConsistency)); } catch (ExecutionException|InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -159,7 +158,7 @@ public Collection getMetricNames(Context context, String resourceId) { ConsistencyLevel readConsistency = m_contextConfigurations.getReadConsistency(context); return getMetricNamesFromResults(fetchMetricNames(context, resourceId, readConsistency)); } catch (ExecutionException|InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/CassandraIndexerITCase.java b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/CassandraIndexerITCase.java index f38be4b5..d5ee796f 100644 --- a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/CassandraIndexerITCase.java +++ b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/CassandraIndexerITCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeast; @@ -276,6 +276,7 @@ public void testCache() { } @Test + @SuppressWarnings("java:S2925") // Thread.sleep() is used to track the cache public void testCacheExpiring() throws Exception { final MetricRegistry registry = new MetricRegistry(); diff --git a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/EscapableResourceIdSplitterTest.java b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/EscapableResourceIdSplitterTest.java index 937ba128..3b89d33e 100644 --- a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/EscapableResourceIdSplitterTest.java +++ b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/EscapableResourceIdSplitterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015, The OpenNMS Group + * Copyright 2015-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -20,7 +20,7 @@ import com.google.common.collect.Lists; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; diff --git a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/GuavaResourceMetadataTest.java b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/GuavaResourceMetadataTest.java index 776312b2..195f6d76 100644 --- a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/GuavaResourceMetadataTest.java +++ b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/GuavaResourceMetadataTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -18,7 +18,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; import org.opennms.newts.api.Context; diff --git a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/SimpleResourceIdSplitterTest.java b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/SimpleResourceIdSplitterTest.java index f839624f..b0228bd8 100644 --- a/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/SimpleResourceIdSplitterTest.java +++ b/cassandra/search/src/test/java/org/opennms/newts/cassandra/search/SimpleResourceIdSplitterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015, The OpenNMS Group + * Copyright 2015-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -20,7 +20,7 @@ import com.google.common.collect.Lists; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; diff --git a/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/CassandraSampleRepository.java b/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/CassandraSampleRepository.java index 3b9a03a3..d01233ad 100644 --- a/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/CassandraSampleRepository.java +++ b/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/CassandraSampleRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2015, The OpenNMS Group + * Copyright 2015-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -29,7 +29,6 @@ import com.datastax.oss.driver.api.querybuilder.insert.RegularInsert; import com.datastax.oss.driver.api.querybuilder.select.Select; import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.common.collect.Lists; import org.opennms.newts.aggregate.IntervalGenerator; @@ -311,7 +310,7 @@ public void delete(Context context, Resource resource) { try { future.toCompletableFuture().get(); } catch (final InterruptedException | ExecutionException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } else { @@ -340,7 +339,7 @@ public void delete(Context context, Resource resource) { try { future.toCompletableFuture().get(); } catch (final InterruptedException | ExecutionException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/ConcurrentResultWrapper.java b/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/ConcurrentResultWrapper.java index 6cb9e501..695450df 100644 --- a/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/ConcurrentResultWrapper.java +++ b/cassandra/storage/src/main/java/org/opennms/newts/persistence/cassandra/ConcurrentResultWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -18,16 +18,12 @@ import java.util.Collection; import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicReference; import com.datastax.oss.driver.api.core.cql.AsyncResultSet; import com.datastax.oss.driver.api.core.cql.Row; -import com.google.common.base.Function; -import com.google.common.base.Throwables; import com.google.common.collect.Iterators; @@ -40,14 +36,11 @@ public ConcurrentResultWrapper(Collection> futur } private Iterator> getIterators(Collection> futures) { - return Iterators.transform(futures.iterator(), new Function, Iterator>() { - @Override - public Iterator apply(CompletionStage input) { - try { - return toBlockingIterator(input.toCompletableFuture().get()); - } catch (ExecutionException|InterruptedException e) { - throw Throwables.propagate(e); - } + return Iterators.transform(futures.iterator(), input -> { + try { + return toBlockingIterator(input.toCompletableFuture().get()); + } catch (ExecutionException|InterruptedException e) { + throw new RuntimeException(e); } }); } diff --git a/cassandra/storage/src/test/java/org/opennms/newts/persistence/cassandra/Utils.java b/cassandra/storage/src/test/java/org/opennms/newts/persistence/cassandra/Utils.java index f9c218ca..a57ac439 100644 --- a/cassandra/storage/src/test/java/org/opennms/newts/persistence/cassandra/Utils.java +++ b/cassandra/storage/src/test/java/org/opennms/newts/persistence/cassandra/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import java.util.Iterator; diff --git a/examples/gsod/src/main/java/org/opennms/newts/gsod/ExportRunner.java b/examples/gsod/src/main/java/org/opennms/newts/gsod/ExportRunner.java index 98eb70b4..43b22bea 100644 --- a/examples/gsod/src/main/java/org/opennms/newts/gsod/ExportRunner.java +++ b/examples/gsod/src/main/java/org/opennms/newts/gsod/ExportRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -24,6 +24,8 @@ import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; +import org.kohsuke.args4j.OptionHandlerRegistry; +import org.kohsuke.args4j.ParserProperties; import org.opennms.newts.api.Context; import org.opennms.newts.api.Resource; import org.opennms.newts.api.Results; @@ -35,15 +37,15 @@ import com.google.inject.Guice; import com.google.inject.Injector; - +@SuppressWarnings("java:S106") public class ExportRunner { static { - CmdLineParser.registerHandler(Resource.class, ResourceOptionHandler.class); + OptionHandlerRegistry.getRegistry().registerHandler(Resource.class, ResourceOptionHandler.class); } private final SampleRepository m_repository; - private final CmdLineParser m_parser = new CmdLineParser(this); + private final CmdLineParser m_parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); @Option(name = "-r", usage = "resource name to query (required)") private Resource m_resource; @@ -71,9 +73,6 @@ private void printUsage(PrintStream writer) { } private int go(String[] args) { - - m_parser.setUsageWidth(80); - try { m_parser.parseArgument(args); } @@ -103,6 +102,7 @@ private int go(String[] args) { return 0; } + @SuppressWarnings("java:S4738") private static Optional timestamp(Long arg) { if (arg == null) return Optional. absent(); return Optional.of(new Timestamp(arg, TimeUnit.MILLISECONDS)); diff --git a/examples/gsod/src/main/java/org/opennms/newts/gsod/FileIterable.java b/examples/gsod/src/main/java/org/opennms/newts/gsod/FileIterable.java index 96db13ff..2a3cb4e6 100644 --- a/examples/gsod/src/main/java/org/opennms/newts/gsod/FileIterable.java +++ b/examples/gsod/src/main/java/org/opennms/newts/gsod/FileIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -20,7 +20,6 @@ import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -31,15 +30,16 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; +import java.util.NoSuchElementException; import java.util.Stack; import java.util.zip.GZIPInputStream; import com.google.common.base.Function; -import com.google.common.base.Throwables; import com.google.common.collect.AbstractIterator; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; +@SuppressWarnings("java:S4738") public class FileIterable { private FileIterable() {} @@ -70,66 +70,7 @@ public K getKey() { } - private static KeyedIterable children(File dir, FileFilter filter) { - return new KeyedIterable<>(dir.toPath(), toPaths(dir.listFiles(filter))); - } - - private static KeyedIterable files(File dir) { - return children(dir, fileMatcher()); - } - - private static KeyedIterable subdirs(File dir) { - return children(dir, directoryMatcher()); - } - - - private static FileFilter fileMatcher() { - return new FileFilter() { - - @Override - public boolean accept(File f) { - return f.isFile(); - } - }; - } - - private static FileFilter directoryMatcher() { - return new FileFilter() { - - @Override - public boolean accept(File f) { - return f.isDirectory(); - } - }; - } - - - public static Iterable toPaths(File[] files) { - return files == null ? Collections.emptyList() : toPaths(Arrays.asList(files)); - } - - public static Iterable toPaths(Iterable files) { - return Iterables.transform(files, new Function(){ - - @Override - public Path apply(File input) { - return input.toPath(); - } - - }); - } - - public static Iterable toFiles(Iterable files) { - return Iterables.transform(files, new Function(){ - - @Override - public File apply(Path input) { - return input.toFile(); - } - - }); - } - + @SuppressWarnings("java:S1149") public static class GroupedPathIterator extends AbstractIterator> { Stack> m_dirStack; @@ -162,6 +103,29 @@ protected KeyedIterable computeNext() { return null; } + private static KeyedIterable files(final File dir) { + return children(dir, File::isFile); + } + + private static KeyedIterable subdirs(final File dir) { + return children(dir, File::isDirectory); + } + + private static KeyedIterable children(File dir, FileFilter filter) { + return new KeyedIterable<>(dir.toPath(), toPaths(dir.listFiles(filter))); + } + + public static Iterable toPaths(File[] files) { + return files == null ? Collections.emptyList() : toPaths(Arrays.asList(files)); + } + + public static Iterable toPaths(Iterable files) { + return Iterables.transform(files, File::toPath); + } + + public static Iterable toFiles(Iterable files) { + return Iterables.transform(files, Path::toFile); + } } public static FluentIterable> groupFilesByDir(final Path root) { @@ -191,7 +155,7 @@ private void fetchLine() { try { m_nextLine = m_in.readLine(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { if (m_nextLine == null) { close(); @@ -205,7 +169,7 @@ private void close() { m_in.close(); } } catch(IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { m_in = null; } @@ -221,6 +185,7 @@ public boolean hasNext() { public String next() { String line = m_nextLine; fetchLine(); + if (line == null) throw new NoSuchElementException(); return line; } @@ -239,7 +204,7 @@ public Iterator iterator() { try { return new LineIterator(new InputStreamReader(new FileInputStream(path.toFile()), StandardCharsets.UTF_8)); } catch (FileNotFoundException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; @@ -254,7 +219,7 @@ public Iterator iterator() { try { return new LineIterator(zippedFileReader(path, cs)); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; @@ -266,24 +231,12 @@ private static Reader zippedFileReader(final Path path, final Charset cs) throw return new InputStreamReader(gzipStream, cs); } - public static Function, Iterable> bind(final Function> f) { - return new Function, Iterable>() { - @Override - public Iterable apply(Iterable input) { - return Iterables.concat(Iterables.transform(input, f)); - } - }; + public static Function, Iterable> bind(final Function> f) { + return input -> Iterables.concat(Iterables.transform(input, f)); } - public static Function, Iterable> lift(final Function f) { - return new Function, Iterable>() { - - @Override - public Iterable apply(Iterable input) { - return Iterables.transform(input, f); - } - - }; + public static Function, Iterable> lift(final Function f) { + return input -> Iterables.transform(input, f); } diff --git a/examples/gsod/src/main/java/org/opennms/newts/gsod/ImportRunner.java b/examples/gsod/src/main/java/org/opennms/newts/gsod/ImportRunner.java index ca8c5b2e..a3c897db 100644 --- a/examples/gsod/src/main/java/org/opennms/newts/gsod/ImportRunner.java +++ b/examples/gsod/src/main/java/org/opennms/newts/gsod/ImportRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -55,19 +55,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Observable.Operator; -import rx.Observer; -import rx.Subscriber; -import rx.Subscription; -import rx.apache.http.ObservableHttp; -import rx.apache.http.ObservableHttpResponse; -import rx.exceptions.Exceptions; -import rx.functions.Action0; -import rx.functions.Func1; -import rx.functions.Functions; -import rx.schedulers.Schedulers; - import com.codahale.metrics.ConsoleReporter; import com.codahale.metrics.Gauge; import com.codahale.metrics.Meter; @@ -80,7 +67,19 @@ import com.google.inject.Guice; import com.google.inject.Injector; +import rx.Observable; +import rx.Observable.Operator; +import rx.Observer; +import rx.Subscriber; +import rx.Subscription; +import rx.apache.http.ObservableHttp; +import rx.apache.http.ObservableHttpResponse; +import rx.exceptions.Exceptions; +import rx.functions.Func1; +import rx.functions.Functions; +import rx.schedulers.Schedulers; +@SuppressWarnings("java:S106") public class ImportRunner { private int m_samplesPerBatch = 1000; @@ -165,14 +164,7 @@ public void execute(String... args) throws Exception { MetricRegistry metrics = new MetricRegistry(); final long start = System.currentTimeMillis(); - metrics.register("elapsed-seconds", new Gauge() { - - @Override - public Double getValue() { - return (System.currentTimeMillis() - start)/1000.0; - } - - }); + metrics.register("elapsed-seconds", (Gauge) () -> (System.currentTimeMillis() - start)/1000.0); final ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) .outputTo(System.err) @@ -207,12 +199,12 @@ public Double getValue() { .map(reportFile()) // read all the files and convert them into lines - .mergeMap(lines()) + .flatMap(lines()) // excluding the header lines .filter(exclude("YEARMODA")) // turn each line into a list of samples - .mergeMap(samples()) + .flatMap(samples()) // adjust time on samples according to arguments .map(adjustTime()) @@ -255,15 +247,12 @@ public void onError(Throwable e) { System.err.println("Error importing!"); e.printStackTrace(); try { - //latch.await(); Subscription s = subscription.get(); if (s != null) s.unsubscribe(); } catch (Exception ex) { System.err.println("Failed to close httpClient!"); ex.printStackTrace(); - } finally { - //dumpThreads(); } } @@ -277,26 +266,16 @@ public void onNext(Boolean t) { if (failed.get()) { s.unsubscribe(); } - //latch.countDown(); System.err.println("Return from Subscribe!"); latch.await(); - - //dumpThreads(); - - } private Func1 adjustTime() { - return new Func1() { - - @Override - public Sample call(Sample s) { - Timestamp oldTs = s.getTimestamp(); - Timestamp newTs = Timestamp.fromEpochMillis(m_timeoffset + Math.round(oldTs.asMillis()/m_timescaleFactor)); - return new Sample(newTs, s.getResource(), s.getName(), s.getType(), s.getValue()); - } - + return s -> { + Timestamp oldTs = s.getTimestamp(); + Timestamp newTs = Timestamp.fromEpochMillis(m_timeoffset + Math.round(oldTs.asMillis()/m_timescaleFactor)); + return new Sample(newTs, s.getResource(), s.getName(), s.getType(), s.getValue()); }; } @@ -317,17 +296,13 @@ private Observable directPoster(Observable> samples, Metri final Meter completions = metrics.meter("samples-completed"); - Func1, Boolean> insert = new Func1, Boolean>() { - - @Override - public Boolean call(List s) { - int sz = s.size(); - try (Context timerCtx = timer.time()) { - repository.insert(s); - return true; - } finally { - completions.mark(sz); - } + Func1, Boolean> insert = s -> { + int sz = s.size(); + try (final Context timerCtx = timer.time()) { + repository.insert(s); + return true; + } finally { + completions.mark(sz); } }; @@ -372,41 +347,10 @@ public boolean add(Runnable r) { 0L, TimeUnit.MILLISECONDS, workQueue); - metrics.register("active-threads", new Gauge() { - - @Override - public Integer getValue() { - return executor.getActiveCount(); - } - - }); - - metrics.register("pool-size", new Gauge() { - - @Override - public Integer getValue() { - return executor.getPoolSize(); - } - - }); - metrics.register("largest-pool-size", new Gauge() { - - @Override - public Integer getValue() { - return executor.getLargestPoolSize(); - } - - }); - - metrics.register("work-queue-size", new Gauge() { - - @Override - public Integer getValue() { - return workQueue.size(); - } - - }); - + metrics.register("active-threads", (Gauge) executor::getActiveCount); + metrics.register("pool-size", (Gauge) executor::getPoolSize); + metrics.register("largest-pool-size", (Gauge) executor::getLargestPoolSize); + metrics.register("work-queue-size", (Gauge) workQueue::size); return parMap(samples, executor, metrics, insert); } @@ -460,17 +404,12 @@ public Boolean call() throws Exception { }) .observeOn(Schedulers.io()) - .map(new Func1, Boolean>() { - - @Override - public Boolean call(ListenableFuture f) { - try { - return f.get(); - } catch (Throwable e) { - throw Exceptions.propagate(e); - } + .map(f -> { + try { + return f.get(); + } catch (Throwable e) { + throw Exceptions.propagate(e); } - }); } @@ -494,7 +433,7 @@ private Observable restPoster(Observable> samples, Metric .map(meter(metrics.meter("posts"), String.class)) // post the json to the REST server - .mergeMap(postJSON(m_restUrl, httpClient)) + .flatMap(postJSON(m_restUrl, httpClient)) // meter the responses .map(meter(metrics.meter("responses"), ObservableHttpResponse.class)) @@ -505,46 +444,31 @@ private Observable restPoster(Observable> samples, Metric // make sure every request has a successful return code .all(successful()) - .doOnCompleted(new Action0() { - - @Override - public void call() { - try { - httpClient.close(); - } catch (IOException e) { - System.err.println("Failed to close httpClient!"); - e.printStackTrace(); - } + .doOnCompleted(() -> { + try { + httpClient.close(); + } catch (IOException e) { + System.err.println("Failed to close httpClient!"); + e.printStackTrace(); } - }); } private static Func1 reportFile() { - return new Func1() { - - @Override - public Path call(Path file) { - System.err.println("Begin Processing: " + file); - return file; - } - + return file -> { + System.err.println("Begin Processing: " + file); + return file; }; } public static Func1> samples() { final LineParser parser = new LineParser(); - return new Func1>() { - - @Override - public Observable call(String line) { - try { - return Observable.from(parser.parseLine(line)); - } catch (ParseException e) { - throw propagate(e); - } + return line -> { + try { + return Observable.from(parser.parseLine(line)); + } catch (ParseException e) { + throw propagate(e); } - }; } @@ -553,42 +477,33 @@ private static boolean isNaN(Sample sample) { } public static Func1, String> toJSON() { - return new Func1, String>() { - @Override - public String call(List samples) { - JSONBuilder bldr = new JSONBuilder(); - - for(Sample sample : samples) { - if (isNaN(sample)) continue; - //System.err.println("Importing: " + sample); - bldr.newObject(); - bldr.attr("timestamp", sample.getTimestamp().asMillis()); - bldr.attr("resource", sample.getResource().getId()); - bldr.attr("name", sample.getName()); - bldr.attr("type", sample.getType().name()); - if (sample.getType() == MetricType.GAUGE) { - bldr.attr("value", sample.getValue().doubleValue()); - } else { - bldr.attr("value", sample.getValue().longValue()); - } + return samples -> { + JSONBuilder bldr = new JSONBuilder(); + + for(Sample sample : samples) { + if (isNaN(sample)) continue; + bldr.newObject(); + bldr.attr("timestamp", sample.getTimestamp().asMillis()); + bldr.attr("resource", sample.getResource().getId()); + bldr.attr("name", sample.getName()); + bldr.attr("type", sample.getType().name()); + if (sample.getType() == MetricType.GAUGE) { + bldr.attr("value", sample.getValue().doubleValue()); + } else { + bldr.attr("value", sample.getValue().longValue()); } - - return bldr.toString(); } + + return bldr.toString(); }; } private static Func1 successful() { - return new Func1() { - - @Override - public Boolean call(ObservableHttpResponse response) { - if (response.getResponse().getStatusLine().getStatusCode() >= 400) { - throw new RuntimeException("Failed to post samples: " + response.getResponse().getStatusLine()); - } - return true; + return response -> { + if (response.getResponse().getStatusLine().getStatusCode() >= 400) { + throw new RuntimeException("Failed to post samples: " + response.getResponse().getStatusLine()); } - + return true; }; } @@ -596,27 +511,17 @@ public static Func1> postJSON(final S final URI baseURI = URI.create(baseURL); - return new Func1>() { - @Override - public Observable call(String json) { - try { - return ObservableHttp.createRequest(HttpAsyncMethods.createPost(baseURI, json, ContentType.APPLICATION_JSON), httpClient).toObservable(); - } catch (UnsupportedEncodingException e) { - throw Exceptions.propagate(e); - } + return json -> { + try { + return ObservableHttp.createRequest(HttpAsyncMethods.createPost(baseURI, json, ContentType.APPLICATION_JSON), httpClient).toObservable(); + } catch (UnsupportedEncodingException e) { + throw Exceptions.propagate(e); } }; } public static Func1 exclude(final String pattern) { - return new Func1() { - - @Override - public Boolean call(String s) { - return !s.contains(pattern); - } - - }; + return s -> !s.contains(pattern); } public static Func1 meter(final Meter meter, Class clazz) { @@ -624,14 +529,9 @@ public static Func1 meter(final Meter meter, Class clazz) { } public static Func1 meter(final Meter meter, final int count, Class clazz) { - return new Func1() { - - @Override - public T call(T t) { - meter.mark(count); - return t; - } - + return t -> { + meter.mark(count); + return t; }; } diff --git a/examples/stress/src/main/java/org/opennms/newts/stress/Config.java b/examples/stress/src/main/java/org/opennms/newts/stress/Config.java index c97d67b1..2dd03949 100644 --- a/examples/stress/src/main/java/org/opennms/newts/stress/Config.java +++ b/examples/stress/src/main/java/org/opennms/newts/stress/Config.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -18,8 +18,8 @@ import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; +import org.kohsuke.args4j.OptionHandlerRegistry; import org.opennms.newts.api.Duration; import org.opennms.newts.api.Timestamp; @@ -31,8 +31,8 @@ enum Command { } static { - CmdLineParser.registerHandler(Timestamp.class, TimestampOptionHandler.class); - CmdLineParser.registerHandler(Duration.class, DurationOptionHandler.class); + OptionHandlerRegistry.getRegistry().registerHandler(Timestamp.class, TimestampOptionHandler.class); + OptionHandlerRegistry.getRegistry().registerHandler(Duration.class, DurationOptionHandler.class); } /** Number of seconds to keep Cassandra-stored samples. */ @@ -55,6 +55,7 @@ enum Command { private int m_numMetrics = 1; private Command m_command; + @SuppressWarnings("deprecation") protected void checkArgument(boolean condition, String msg, Object... msgArgs) throws CmdLineException { if (!condition) { throw new CmdLineException(null, String.format(msg, msgArgs)); @@ -62,6 +63,7 @@ protected void checkArgument(boolean condition, String msg, Object... msgArgs) t } } + @SuppressWarnings("deprecation") @Argument(required = true, metaVar = "", index = 0, usage = "The operation to run.") void setCommandArgument(String command) throws CmdLineException { try { diff --git a/examples/stress/src/main/java/org/opennms/newts/stress/Dispatcher.java b/examples/stress/src/main/java/org/opennms/newts/stress/Dispatcher.java index c81cde82..26e14bce 100644 --- a/examples/stress/src/main/java/org/opennms/newts/stress/Dispatcher.java +++ b/examples/stress/src/main/java/org/opennms/newts/stress/Dispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -43,7 +43,7 @@ abstract class Dispatcher { abstract void go() throws InterruptedException; void setupReport() { - ConsoleReporter reporter = ConsoleReporter.forRegistry(m_metricRegistry) + ConsoleReporter.forRegistry(m_metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); diff --git a/graphite/src/test/java/org/opennms/newts/graphite/GraphiteHandlerTest.java b/graphite/src/test/java/org/opennms/newts/graphite/GraphiteHandlerTest.java index 3d77c8c7..52fdce4c 100644 --- a/graphite/src/test/java/org/opennms/newts/graphite/GraphiteHandlerTest.java +++ b/graphite/src/test/java/org/opennms/newts/graphite/GraphiteHandlerTest.java @@ -2,7 +2,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.opennms.newts.graphite.GraphiteHandler.parseSample; import org.junit.Test; diff --git a/queryparser/src/test/java/org/opennms/newts/api/search/query/QueryParserTest.java b/queryparser/src/test/java/org/opennms/newts/api/search/query/QueryParserTest.java index 6c6ef02e..b339dcc0 100644 --- a/queryparser/src/test/java/org/opennms/newts/api/search/query/QueryParserTest.java +++ b/queryparser/src/test/java/org/opennms/newts/api/search/query/QueryParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -23,7 +23,7 @@ import org.opennms.newts.api.search.TermQuery; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Verifies that we can parse human readable query strings diff --git a/rest/src/main/java/org/opennms/newts/rest/CassandraConfig.java b/rest/src/main/java/org/opennms/newts/rest/CassandraConfig.java index 0e90579d..2c108ad5 100644 --- a/rest/src/main/java/org/opennms/newts/rest/CassandraConfig.java +++ b/rest/src/main/java/org/opennms/newts/rest/CassandraConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016, The OpenNMS Group + * Copyright 2016-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -70,8 +70,8 @@ public String getDatacenter() { return m_datacenter; } - public void setDatacenter(String m_datacenter) { - m_datacenter = m_datacenter; + public void setDatacenter(final String datacenter) { + m_datacenter = datacenter; } public String getKeyspace() { diff --git a/rest/src/main/java/org/opennms/newts/rest/HttpBasicAuthenticationFilter.java b/rest/src/main/java/org/opennms/newts/rest/HttpBasicAuthenticationFilter.java index b7c8f722..80bf9fdf 100644 --- a/rest/src/main/java/org/opennms/newts/rest/HttpBasicAuthenticationFilter.java +++ b/rest/src/main/java/org/opennms/newts/rest/HttpBasicAuthenticationFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015, The OpenNMS Group + * Copyright 2015-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -173,7 +173,7 @@ static Credentials fromHeader(String headerValue) { decoded = new String(Base64.decodeBase64(encoded.getBytes("UTF-8")), "UTF-8"); } catch (UnsupportedEncodingException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } matcher = s_credsPattern.matcher(decoded); diff --git a/rest/src/test/java/org/opennms/newts/rest/DurationParamTest.java b/rest/src/test/java/org/opennms/newts/rest/DurationParamTest.java index 4222eaf4..b5dddd59 100644 --- a/rest/src/test/java/org/opennms/newts/rest/DurationParamTest.java +++ b/rest/src/test/java/org/opennms/newts/rest/DurationParamTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -17,7 +17,7 @@ import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import javax.ws.rs.WebApplicationException; diff --git a/rest/src/test/java/org/opennms/newts/rest/HttpBasicAuthenticationFilterTest.java b/rest/src/test/java/org/opennms/newts/rest/HttpBasicAuthenticationFilterTest.java index f4e4f33f..6795fec0 100644 --- a/rest/src/test/java/org/opennms/newts/rest/HttpBasicAuthenticationFilterTest.java +++ b/rest/src/test/java/org/opennms/newts/rest/HttpBasicAuthenticationFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015, The OpenNMS Group + * Copyright 2015-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -16,7 +16,7 @@ package org.opennms.newts.rest; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; diff --git a/rest/src/test/java/org/opennms/newts/rest/MeasurementsResourceTest.java b/rest/src/test/java/org/opennms/newts/rest/MeasurementsResourceTest.java index 418449f1..282a4430 100644 --- a/rest/src/test/java/org/opennms/newts/rest/MeasurementsResourceTest.java +++ b/rest/src/test/java/org/opennms/newts/rest/MeasurementsResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -16,7 +16,7 @@ package org.opennms.newts.rest; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; diff --git a/rest/src/test/java/org/opennms/newts/rest/ResultSerializationTest.java b/rest/src/test/java/org/opennms/newts/rest/ResultSerializationTest.java index ef3edeeb..aa5c9933 100644 --- a/rest/src/test/java/org/opennms/newts/rest/ResultSerializationTest.java +++ b/rest/src/test/java/org/opennms/newts/rest/ResultSerializationTest.java @@ -1,7 +1,7 @@ package org.opennms.newts.rest; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.opennms.newts.api.MetricType.COUNTER; import java.util.Map; diff --git a/rest/src/test/java/org/opennms/newts/rest/SamplesResourceTest.java b/rest/src/test/java/org/opennms/newts/rest/SamplesResourceTest.java index 5355a36e..b5575cdd 100644 --- a/rest/src/test/java/org/opennms/newts/rest/SamplesResourceTest.java +++ b/rest/src/test/java/org/opennms/newts/rest/SamplesResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -17,7 +17,7 @@ import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyCollectionOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -66,10 +66,10 @@ public void testGetSamples() { when( m_repository.select( - eq(Context.DEFAULT_CONTEXT), - eq(new Resource("localhost")), - eq(Optional.of(Timestamp.fromEpochSeconds(900000000))), - eq(Optional.of(Timestamp.fromEpochSeconds(900003600)))) + Context.DEFAULT_CONTEXT, + new Resource("localhost"), + Optional.of(Timestamp.fromEpochSeconds(900000000)), + Optional.of(Timestamp.fromEpochSeconds(900003600))) ).thenReturn(results); assertThat( diff --git a/rest/src/test/java/org/opennms/newts/rest/TimestampParamTest.java b/rest/src/test/java/org/opennms/newts/rest/TimestampParamTest.java index 4f944efd..e8ba8eac 100644 --- a/rest/src/test/java/org/opennms/newts/rest/TimestampParamTest.java +++ b/rest/src/test/java/org/opennms/newts/rest/TimestampParamTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014, The OpenNMS Group + * Copyright 2014-2024, The OpenNMS Group * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain @@ -17,7 +17,7 @@ import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import javax.ws.rs.WebApplicationException;