Search in sources :

Example 1 with ResourceMetadata

use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.

the class RedisResourceMetadataCacheIT method canGetEntriesWithPrefix.

@Test
public void canGetEntriesWithPrefix() {
    Context ctx = Context.DEFAULT_CONTEXT;
    RedisResourceMetadataCache cache = new RedisResourceMetadataCache(REDIS_HOSTNAME, REDIS_PORT, 8, m_registry, new EscapableResourceIdSplitter());
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a").isEmpty());
    Resource resource = new Resource("a:b:c");
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    cache.merge(ctx, resource, resourceMetadata);
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b:c").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b:c:d").isEmpty());
}
Also used : Context(org.opennms.newts.api.Context) EscapableResourceIdSplitter(org.opennms.newts.cassandra.search.EscapableResourceIdSplitter) Resource(org.opennms.newts.api.Resource) ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata) Test(org.junit.Test)

Example 2 with ResourceMetadata

use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.

the class GuavaSearchableResourceMetadataCacheTest method getResourceIdsWithPrefixPerftTest.

@Test
@Ignore
public void getResourceIdsWithPrefixPerftTest() {
    long numResourceIdsToCache = 200000;
    long numSearches = 1000;
    Context ctx = Context.DEFAULT_CONTEXT;
    GuavaSearchableResourceMetadataCache cache = new GuavaSearchableResourceMetadataCache(numResourceIdsToCache, m_registry);
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    for (long k = 0; k < numResourceIdsToCache; k++) {
        Resource resource = new Resource(String.format("snmp:%d:eth0-x:ifHcInOctets", k));
        cache.merge(ctx, resource, resourceMetadata);
    }
    long start = System.currentTimeMillis();
    String prefix = "snmp:" + (numResourceIdsToCache - 1);
    for (long k = 0; k < numSearches; k++) {
        assertEquals(1, cache.getResourceIdsWithPrefix(ctx, prefix).size());
    }
    long elapsed = System.currentTimeMillis() - start;
    System.err.println("elapsed: " + elapsed);
}
Also used : Context(org.opennms.newts.api.Context) Resource(org.opennms.newts.api.Resource) ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ResourceMetadata

use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.

the class GuavaSearchableResourceMetadataCacheTest method canGetEntriesWithPrefix.

@Test
public void canGetEntriesWithPrefix() {
    Context ctx = Context.DEFAULT_CONTEXT;
    GuavaSearchableResourceMetadataCache cache = new GuavaSearchableResourceMetadataCache(2048, m_registry);
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a").isEmpty());
    Resource resource = new Resource("a:b:c");
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    cache.merge(ctx, resource, resourceMetadata);
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b:c").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b:c:d").isEmpty());
}
Also used : Context(org.opennms.newts.api.Context) Resource(org.opennms.newts.api.Resource) ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata) Test(org.junit.Test)

Example 4 with ResourceMetadata

use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.

the class RedisResourceMetadataCacheIT method canUpdateEntry.

@Test
public void canUpdateEntry() {
    Context ctx = Context.DEFAULT_CONTEXT;
    RedisResourceMetadataCache cache = new RedisResourceMetadataCache(REDIS_HOSTNAME, REDIS_PORT, 8, m_registry, new EscapableResourceIdSplitter());
    // Insert
    Resource resource = new Resource("a:b:c");
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    resourceMetadata.putAttribute("a1", "1");
    cache.merge(ctx, resource, resourceMetadata);
    // Verify
    assertTrue("attribute a1 must be set", cache.get(ctx, resource).get().containsAttribute("a1", "1"));
    // Update
    resourceMetadata = new ResourceMetadata();
    resourceMetadata.putAttribute("a2", "2");
    cache.merge(ctx, resource, resourceMetadata);
    // Verify
    assertTrue("attribute a1 must be set", cache.get(ctx, resource).get().containsAttribute("a1", "1"));
    assertTrue("attribute a2 must be set", cache.get(ctx, resource).get().containsAttribute("a2", "2"));
}
Also used : Context(org.opennms.newts.api.Context) EscapableResourceIdSplitter(org.opennms.newts.cassandra.search.EscapableResourceIdSplitter) Resource(org.opennms.newts.api.Resource) ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata) Test(org.junit.Test)

Example 5 with ResourceMetadata

use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.

the class GuavaSearchableResourceMetadataCache method merge.

@Override
public void merge(Context context, Resource resource, ResourceMetadata metadata) {
    Optional<ResourceMetadata> o = get(context, resource);
    if (!o.isPresent()) {
        ResourceMetadata newMetadata = new ResourceMetadata(m_metricReqs, m_attributeReqs, m_metricMisses, m_attributeMisses);
        newMetadata.merge(metadata);
        String key = key(context, resource.getId());
        m_cache.put(key, newMetadata);
        m_radixTree.put(key, newMetadata);
        return;
    }
    o.get().merge(metadata);
}
Also used : ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata)

Aggregations

ResourceMetadata (org.opennms.newts.cassandra.search.ResourceMetadata)6 Test (org.junit.Test)4 Context (org.opennms.newts.api.Context)4 Resource (org.opennms.newts.api.Resource)4 EscapableResourceIdSplitter (org.opennms.newts.cassandra.search.EscapableResourceIdSplitter)2 Ignore (org.junit.Ignore)1 Jedis (redis.clients.jedis.Jedis)1 Transaction (redis.clients.jedis.Transaction)1