Skip to content

Commit

Permalink
NMS-16486: Renamed NodeMetadataCache to NodeInfoCache
Browse files Browse the repository at this point in the history
  • Loading branch information
christianpape committed Aug 29, 2024
1 parent b98302a commit 15df160
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
import org.opennms.netmgt.flows.persistence.FlowDocumentBuilder;
import org.opennms.netmgt.flows.processing.FlowBuilder;
import org.opennms.netmgt.flows.processing.impl.DocumentMangler;
import org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCacheImpl;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCacheImpl;

import com.codahale.metrics.MetricRegistry;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -169,17 +170,14 @@ public void setUp() throws MalformedURLException, ExecutionException, Interrupte
new RuleBuilder().withName("https").withSrcPort("443").withProtocol("tcp,udp").build()),
FilterService.NOOP);

final NodeMetadataCacheImpl nodeMetadataCache = new NodeMetadataCacheImpl(
final NodeInfoCache nodeInfoCache = new NodeInfoCacheImpl(
new CacheConfigBuilder()
.withName("nodeInfoCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.withExpireAfterRead(300)
.build(),
new CacheConfigBuilder()
.withName("nodeMetadataCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.build(),
true,
new MetricRegistry(),
new MockNodeDao(),
new MockIpInterfaceDao(),
Expand All @@ -189,7 +187,7 @@ public void setUp() throws MalformedURLException, ExecutionException, Interrupte
classificationEngine,
0,
new DocumentMangler(new ScriptEngineManager()),
nodeMetadataCache);
nodeInfoCache);

// The repository should be empty
assertThat(smartQueryService.getFlowCount(Collections.singletonList(new TimeRangeFilter(0, System.currentTimeMillis()))).get(), equalTo(0L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
import org.opennms.netmgt.flows.filter.api.SnmpInterfaceIdFilter;
import org.opennms.netmgt.flows.filter.api.TimeRangeFilter;
import org.opennms.netmgt.flows.processing.impl.DocumentMangler;
import org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCacheImpl;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCacheImpl;

import com.codahale.metrics.MetricRegistry;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -144,17 +145,14 @@ public void setUp() throws MalformedURLException, ExecutionException, Interrupte
new RuleBuilder().withName("http").withSrcPort("80").withProtocol("tcp,udp").build(),
new RuleBuilder().withName("https").withSrcPort("443").withProtocol("tcp,udp").build()),
FilterService.NOOP);
final NodeMetadataCacheImpl nodeMetadataCache = new NodeMetadataCacheImpl(
final NodeInfoCache nodeInfoCache = new NodeInfoCacheImpl(
new CacheConfigBuilder()
.withName("nodeInfoCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.withExpireAfterRead(300)
.build(),
new CacheConfigBuilder()
.withName("nodeMetadataCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.build(),
true,
new MetricRegistry(),
new MockNodeDao(),
new MockIpInterfaceDao(),
Expand All @@ -165,7 +163,7 @@ public void setUp() throws MalformedURLException, ExecutionException, Interrupte
classificationEngine,
0,
new DocumentMangler(new ScriptEngineManager()),
nodeMetadataCache);
nodeInfoCache);

final RawIndexInitializer initializer = new RawIndexInitializer(client, settings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
import org.opennms.netmgt.model.NetworkBuilder;
import org.opennms.netmgt.model.OnmsMetaData;
import org.opennms.netmgt.model.OnmsNode;
import org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCacheImpl;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCacheImpl;
import org.opennms.test.JUnitConfigurationEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -116,17 +117,14 @@ public void before() {
@Test
public void testSomething() throws InterruptedException {
final ClassificationEngine classificationEngine = new DefaultClassificationEngine(() -> Collections.emptyList(), FilterService.NOOP);
final NodeMetadataCacheImpl nodeMetadataCache = new NodeMetadataCacheImpl(
final NodeInfoCache nodeInfoCache = new NodeInfoCacheImpl(
new CacheConfigBuilder()
.withName("nodeInfoCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.withExpireAfterRead(300)
.build(),
new CacheConfigBuilder()
.withName("nodeMetadataCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.build(),
true,
new MetricRegistry(),
databasePopulator.getNodeDao(),
databasePopulator.getIpInterfaceDao(),
Expand All @@ -138,7 +136,7 @@ public void testSomething() throws InterruptedException {
classificationEngine,
0,
new DocumentMangler(new ScriptEngineManager()),
nodeMetadataCache);
nodeInfoCache);

final TestFlow testFlow = new TestFlow();
testFlow.setSrcAddr("1.1.1.1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.opennms.netmgt.flows.classification.ClassificationRequest;
import org.opennms.netmgt.flows.classification.persistence.api.Protocols;
import org.opennms.netmgt.flows.processing.enrichment.EnrichedFlow;
import org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCache;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -56,7 +56,7 @@ public class DocumentEnricherImpl {

private final ClassificationEngine classificationEngine;

private final NodeMetadataCache nodeMetadataCache;
private final NodeInfoCache nodeInfoCache;

private final long clockSkewCorrectionThreshold;

Expand All @@ -66,10 +66,10 @@ public DocumentEnricherImpl(final SessionUtils sessionUtils,
final ClassificationEngine classificationEngine,
final long clockSkewCorrectionThreshold,
final DocumentMangler mangler,
final NodeMetadataCache nodeMetadataCache) {
final NodeInfoCache nodeInfoCache) {
this.sessionUtils = Objects.requireNonNull(sessionUtils);
this.classificationEngine = Objects.requireNonNull(classificationEngine);
this.nodeMetadataCache = Objects.requireNonNull(nodeMetadataCache);
this.nodeInfoCache = Objects.requireNonNull(nodeInfoCache);
this.clockSkewCorrectionThreshold = clockSkewCorrectionThreshold;
this.mangler = Objects.requireNonNull(mangler);
}
Expand All @@ -91,12 +91,12 @@ public List<EnrichedFlow> enrich(final Collection<Flow> flows, final FlowSource
document.setLocation(source.getLocation());

// Node data
nodeMetadataCache.getNodeInfoFromCache(source.getLocation(), source.getSourceAddress(), source.getContextKey(), flow.getNodeIdentifier()).ifPresent(document::setExporterNodeInfo);
nodeInfoCache.getNodeInfoFromCache(source.getLocation(), source.getSourceAddress(), source.getContextKey(), flow.getNodeIdentifier()).ifPresent(document::setExporterNodeInfo);
if (flow.getDstAddr() != null) {
nodeMetadataCache.getNodeInfoFromCache(source.getLocation(), flow.getDstAddr(), null, null).ifPresent(document::setSrcNodeInfo);
nodeInfoCache.getNodeInfoFromCache(source.getLocation(), flow.getDstAddr(), null, null).ifPresent(document::setSrcNodeInfo);
}
if (flow.getSrcAddr() != null) {
nodeMetadataCache.getNodeInfoFromCache(source.getLocation(), flow.getSrcAddr(), null, null).ifPresent(document::setDstNodeInfo);
nodeInfoCache.getNodeInfoFromCache(source.getLocation(), flow.getSrcAddr(), null, null).ifPresent(document::setDstNodeInfo);
}

// Locality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</bean>

<!-- Enrichment -->
<reference id="nodeMetadataCache" interface="org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCache" availability="mandatory"/>
<reference id="nodeInfoCache" interface="org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache" availability="mandatory"/>
<reference id="interfaceToNodeCache" interface="org.opennms.netmgt.dao.api.InterfaceToNodeCache" availability="mandatory" />
<reference id="nodeDao" interface="org.opennms.netmgt.dao.api.NodeDao" availability="mandatory" />
<reference id="ipInterfaceDao" interface="org.opennms.netmgt.dao.api.IpInterfaceDao" availability="mandatory" />
Expand All @@ -70,7 +70,7 @@
<argument ref="sessionUtils" />
<argument value="${clockSkewCorrectionThreshold}" />
<argument ref="mangler" />
<argument ref="nodeMetadataCache" />
<argument ref="nodeInfoCache" />
</bean>

<bean id="interfaceMarker" class="org.opennms.netmgt.flows.processing.impl.InterfaceMarkerImpl" destroy-method="stop">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
import org.opennms.netmgt.flows.classification.persistence.api.RuleBuilder;
import org.opennms.netmgt.flows.processing.impl.DocumentEnricherImpl;
import org.opennms.netmgt.flows.processing.impl.DocumentMangler;
import org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCacheImpl;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache;
import org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCacheImpl;

import com.codahale.metrics.MetricRegistry;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -89,17 +90,14 @@ public MockDocumentEnricherFactory(final long clockSkewCorrectionThreshold) thro
new RuleBuilder().withName("http").withSrcPort("80").withProtocol("tcp,udp").build(),
new RuleBuilder().withName("https").withSrcPort("443").withProtocol("tcp,udp").build()
), FilterService.NOOP);
final NodeMetadataCacheImpl nodeMetadataCache = new NodeMetadataCacheImpl(
final NodeInfoCache nodeInfoCache = new NodeInfoCacheImpl(
new CacheConfigBuilder()
.withName("nodeInfoCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.withExpireAfterRead(300)
.build(),
new CacheConfigBuilder()
.withName("nodeMetadataCache")
.withMaximumSize(1000)
.withExpireAfterWrite(300)
.build(),
true,
new MetricRegistry(),
nodeDao,
ipInterfaceDao,
Expand All @@ -108,7 +106,7 @@ public MockDocumentEnricherFactory(final long clockSkewCorrectionThreshold) thro
enricher = new DocumentEnricherImpl(
new MockSessionUtils(), classificationEngine,
clockSkewCorrectionThreshold,
new DocumentMangler(new ScriptEngineManager()), nodeMetadataCache);
new DocumentMangler(new ScriptEngineManager()), nodeInfoCache);

// Required for mock node dao
addServiceRegistry(nodeDao);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import org.opennms.core.mate.api.ContextKey;

public interface NodeMetadataCache {
public interface NodeInfoCache {
Optional<NodeInfo> getNodeInfoFromCache(final String location, final String ipAddress, final ContextKey contextKey, final String value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opennms.core.cache.Cache;
import org.opennms.core.cache.CacheBuilder;
import org.opennms.core.cache.CacheConfig;
import org.opennms.core.cache.CacheConfigBuilder;
import org.opennms.core.mate.api.ContextKey;
import org.opennms.core.utils.InetAddressUtils;
import org.opennms.netmgt.dao.api.InterfaceToNodeCache;
Expand All @@ -52,8 +53,8 @@
import com.google.common.base.Strings;
import com.google.common.cache.CacheLoader;

public class NodeMetadataCacheImpl implements NodeMetadataCache {
private static final Logger LOG = LoggerFactory.getLogger(NodeMetadataCacheImpl.class);
public class NodeInfoCacheImpl implements NodeInfoCache {
private static final Logger LOG = LoggerFactory.getLogger(NodeInfoCacheImpl.class);

private static class NodeMetadataKey {

Expand Down Expand Up @@ -87,11 +88,18 @@ public int hashCode() {
private final Cache<InterfaceToNodeCache.Entry, Optional<NodeInfo>> nodeInfoCache;
private final Timer nodeLoadTimer;

public NodeMetadataCacheImpl(final CacheConfig nodeInfoCacheConfig, final CacheConfig nodeMetadataCacheConfig, final MetricRegistry metricRegistry, final NodeDao nodeDao, final IpInterfaceDao ipInterfaceDao, final InterfaceToNodeCache interfaceToNodeCache) {
public NodeInfoCacheImpl(final CacheConfig nodeInfoCacheConfig, final boolean nodeMetadataEnabled, final MetricRegistry metricRegistry, final NodeDao nodeDao, final IpInterfaceDao ipInterfaceDao, final InterfaceToNodeCache interfaceToNodeCache) {
this.nodeDao = Objects.requireNonNull(nodeDao);
this.ipInterfaceDao = Objects.requireNonNull(ipInterfaceDao);
this.interfaceToNodeCache = Objects.requireNonNull(interfaceToNodeCache);

final CacheConfig nodeMetadataCacheConfig = new CacheConfigBuilder()
.withName("nodeMetadataCache")
.withExpireAfterRead(nodeInfoCacheConfig.getExpireAfterRead())
.withExpireAfterWrite(nodeInfoCacheConfig.getExpireAfterWrite())
.withMaximumSize(nodeInfoCacheConfig.getMaximumSize())
.build();

this.nodeInfoCache = new CacheBuilder()
.withConfig(Objects.requireNonNull(nodeInfoCacheConfig))
.withCacheLoader(new CacheLoader<InterfaceToNodeCache.Entry, Optional<NodeInfo>>() {
Expand All @@ -102,7 +110,7 @@ public Optional<NodeInfo> load(InterfaceToNodeCache.Entry entry) {
}).build();

this.nodeMetadataCache = new CacheBuilder()
.withConfig(Objects.requireNonNull(nodeMetadataCacheConfig))
.withConfig(nodeMetadataCacheConfig)
.withCacheLoader(new CacheLoader<NodeMetadataKey, Optional<NodeInfo>>() {
@Override
public Optional<NodeInfo> load(NodeMetadataKey key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
<cm:property-placeholder id="cacheConfigProperties" persistent-id="org.opennms.features.telemetry.protocols.common" update-strategy="reload">
<cm:default-properties>
<cm:property name="nodeInfoCache.enabled" value="true" /> <!-- Set to false to disable caching -->
<cm:property name="nodeInfoCache.nodeMetadataEnabled" value="true" /> <!-- Set to false to disable caching -->
<cm:property name="nodeInfoCache.maximumSize" value="10000"/> <!-- Set value for unlimited size -->
<cm:property name="nodeInfoCache.expireAfterWrite" value="0"/> <!-- in seconds. Set to 0 to never evict elements -->
<cm:property name="nodeInfoCache.recordStats" value="true"/> <!-- Set to false to not expose cache statistics via jmx -->

<cm:property name="nodeMetadataCache.enabled" value="true" /> <!-- Set to false to disable caching -->
<cm:property name="nodeMetadataCache.maximumSize" value="10000"/> <!-- Set value for unlimited size -->
<cm:property name="nodeMetadataCache.expireAfterWrite" value="0"/> <!-- in seconds. Set to 0 to never evict elements -->
<cm:property name="nodeMetadataCache.recordStats" value="true"/> <!-- Set to false to not expose cache statistics via jmx -->
</cm:default-properties>
</cm:property-placeholder>

Expand All @@ -33,30 +29,21 @@
<property name="recordStats" value="${nodeInfoCache.recordStats}" />
</bean>

<bean id="nodeMetadataCacheConfig" class="org.opennms.core.cache.CacheConfig">
<argument value="nodeMetadataCache"/>
<property name="metricRegistry" ref="flowCacheMetricRegistry" />
<property name="enabled" value="${nodeMetadataCache.enabled}" />
<property name="maximumSize" value="${nodeMetadataCache.maximumSize}" />
<property name="expireAfterWrite" value="${nodeMetadataCache.expireAfterWrite}" />
<property name="recordStats" value="${nodeMetadataCache.recordStats}" />
</bean>

<!-- Configure references -->
<reference id="nodeDao" interface="org.opennms.netmgt.dao.api.NodeDao" availability="mandatory" />
<reference id="ipInterfaceDao" interface="org.opennms.netmgt.dao.api.IpInterfaceDao" availability="mandatory" />
<reference id="interfaceToNodeCache" interface="org.opennms.netmgt.dao.api.InterfaceToNodeCache" availability="mandatory" />

<!-- Configure NodeMetadataCache -->
<bean id="nodeMetadataCache" class="org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCacheImpl">
<!-- Configure NodeInfoCache -->
<bean id="nodeInfoCache" class="org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCacheImpl">
<argument ref="nodeInfoCacheConfig"/>
<argument ref="nodeMetadataCacheConfig"/>
<argument value="${nodeInfoCache.nodeMetadataEnabled}"/>
<argument ref="flowCacheMetricRegistry"/>
<argument ref="nodeDao"/>
<argument ref="ipInterfaceDao"/>
<argument ref="interfaceToNodeCache"/>
</bean>
<service ref="nodeMetadataCache" interface="org.opennms.netmgt.telemetry.protocols.cache.NodeMetadataCache">
<service ref="nodeInfoCache" interface="org.opennms.netmgt.telemetry.protocols.cache.NodeInfoCache">
<service-properties>
<entry key="registration.export" value="true" />
</service-properties>
Expand Down
Loading

0 comments on commit 15df160

Please sign in to comment.