@Override public void initialize() throws CollectionInitializationException { if (s_delegate != null) s_delegate.initialize(); }
@Override public String getEffectiveLocation(String location) { if (s_delegate != null) return s_delegate.getEffectiveLocation(location); return null; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { if (s_delegate != null) return s_delegate.getRuntimeAttributes(agent, parameters); return Collections.emptyMap(); }
assertEquals("Location cannot be altered.", targetLocation, opennmsCollector.getEffectiveLocation(targetLocation)); final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams)); allParms.putAll(requiredParams); allParms.putAll(runtimeAttrs); final Map<String, String> marshaledParms = opennmsCollector.marshalParameters(Collections.unmodifiableMap(allParms)); final Map<String, Object> unmarshaledParms = minionCollector.unmarshalParameters(Collections.unmodifiableMap(marshaledParms)); final CollectionSet collectionSet = minionCollector.collect(agentDTO, Collections.unmodifiableMap(unmarshaledParms)); assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
@Test public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException { // create the agent OnmsNode node = mock(OnmsNode.class); OnmsIpInterface iface = mock(OnmsIpInterface.class); when(iface.getNode()).thenReturn(node); when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress()); IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); when(ifaceDao.load(1)).thenReturn(iface); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); final CollectionAgent agent = createAgent(1, ifaceDao, transMgr); // init() should execute without any exceptions final ServiceCollector opennmsCollector = getCollector(); initialize(opennmsCollector); // getEffectiveLocation() should execute without any exceptions // in this context there are no requirements on its return value final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID; opennmsCollector.getEffectiveLocation(targetLocation); // getRuntimeAttributes() should return a valid map final Map<String, Object> requiredParams = getRequiredParameters(); final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams)); // collect() should return a valid collection set final Map<String, Object> allParms = new HashMap<>(); allParms.putAll(requiredParams); allParms.putAll(runtimeAttrs); final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms)); assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); // getRrdRepository() should return a valid repository assertNotNull(opennmsCollector.getRrdRepository(getCollectionName())); }
.withSystemId(systemId) .withServiceAttributes(attributes) .withLocationOverride((s) -> serviceCollector.getEffectiveLocation(s)) .build(); final Map<String, Object> runtimeAttributes = serviceCollector.getRuntimeAttributes(agent, attributes); final Map<String, Object> allAttributes = new HashMap<>(); allAttributes.putAll(attributes); final Map<String, String> marshaledParms = serviceCollector.marshalParameters(allAttributes); marshaledParms.forEach(request::addAttribute); request.setAttributesNeedUnmarshaling(true);
@SuppressWarnings("unchecked") private void setupCollector(String svcName) throws CollectionInitializationException { ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class); svcCollector.initialize(); svcCollector.validateAgent(isA(CollectionAgent.class), isA(Map.class)); expectLastCall().anyTimes(); setupCollector(svcName, svcCollector); }
public Map<String, Object> getParameters(ServiceCollector collector) { if (Boolean.TRUE.equals(attributesNeedUnmarshaling)) { final Map<String, String> parms = new HashMap<>(); attributes.stream().forEach(a -> parms.put(a.getKey(), a.getValue())); return collector.unmarshalParameters(parms); } else { final Map<String, Object> parms = new HashMap<>(); attributes.stream().forEach(a -> parms.put(a.getKey(), a.getValueOrContents())); return parms; } }
@Override public Map<String, String> marshalParameters(Map<String, Object> parameters) { if (s_delegate != null) return s_delegate.marshalParameters(parameters); throw new UnsupportedOperationException(); }
@Override public void validateAgent(CollectionAgent agent, Map<String, Object> parameters) throws CollectionInitializationException { if (s_delegate != null) s_delegate.validateAgent(agent, parameters); }
@Override public CollectorResponseDTO get() { Logging.putPrefix("collectd"); final CollectionAgent agent = request.getAgent(); final Map<String, Object> parameters = request.getParameters(collector); return new CollectorResponseDTO(collector.collect(agent, parameters)); } }, executor);
/** * <p>getRrdRepository</p> * * @param collectionName a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.rrd.RrdRepository} object. */ public RrdRepository getRrdRepository(String collectionName) { return m_collector.getRrdRepository(collectionName); } }
assertEquals("Location cannot be altered.", targetLocation, opennmsCollector.getEffectiveLocation(targetLocation)); final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams)); allParms.putAll(requiredParams); allParms.putAll(runtimeAttrs); final Map<String, String> marshaledParms = opennmsCollector.marshalParameters(Collections.unmodifiableMap(allParms)); final Map<String, Object> unmarshaledParms = minionCollector.unmarshalParameters(Collections.unmodifiableMap(marshaledParms)); final CollectionSet collectionSet = minionCollector.collect(agentDTO, Collections.unmodifiableMap(unmarshaledParms)); assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
@Test public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException { // create the agent OnmsNode node = mock(OnmsNode.class); OnmsIpInterface iface = mock(OnmsIpInterface.class); when(iface.getNode()).thenReturn(node); when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress()); IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); when(ifaceDao.load(1)).thenReturn(iface); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); final CollectionAgent agent = createAgent(1, ifaceDao, transMgr); // init() should execute without any exceptions final ServiceCollector opennmsCollector = getCollector(); initialize(opennmsCollector); // getEffectiveLocation() should execute without any exceptions // in this context there are no requirements on its return value final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID; opennmsCollector.getEffectiveLocation(targetLocation); // getRuntimeAttributes() should return a valid map final Map<String, Object> requiredParams = getRequiredParameters(); final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams)); // collect() should return a valid collection set final Map<String, Object> allParms = new HashMap<>(); allParms.putAll(requiredParams); allParms.putAll(runtimeAttrs); final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms)); assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); // getRrdRepository() should return a valid repository assertNotNull(opennmsCollector.getRrdRepository(getCollectionName())); }
.withSystemId(systemId) .withServiceAttributes(attributes) .withLocationOverride((s) -> serviceCollector.getEffectiveLocation(s)) .build(); final Map<String, Object> runtimeAttributes = serviceCollector.getRuntimeAttributes(agent, attributes); final Map<String, Object> allAttributes = new HashMap<>(); allAttributes.putAll(attributes); final Map<String, String> marshaledParms = serviceCollector.marshalParameters(allAttributes); marshaledParms.forEach(request::addAttribute); request.setAttributesNeedUnmarshaling(true);
/** * NMS-9413: Verifies that collectd does not schedule interfaces when the * {@link ServiceCollector} throws a {@link CollectionInitializationException} * while validating the agent. */ @SuppressWarnings("unchecked") @Test public void testInterfaceIsNotScheduledWhenValidationFails() throws Exception { ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class); svcCollector.initialize(); svcCollector.validateAgent(isA(CollectionAgent.class), isA(Map.class)); expectLastCall().andThrow(new CollectionInitializationException("No!")).once(); setupCollector("SNMP", svcCollector); OnmsIpInterface iface = getInterface(); setupInterface(iface); setupTransactionManager(); expect(m_collectdConfig.getPackages()).andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP())); expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP())).andReturn(true); m_easyMockUtils.replayAll(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.afterPropertiesSet(); m_collectd.start(); m_scheduler.next(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.stop(); m_easyMockUtils.verifyAll(); }
public Map<String, Object> getParameters(ServiceCollector collector) { if (Boolean.TRUE.equals(attributesNeedUnmarshaling)) { final Map<String, String> parms = new HashMap<>(); attributes.stream().forEach(a -> parms.put(a.getKey(), a.getValue())); return collector.unmarshalParameters(parms); } else { final Map<String, Object> parms = new HashMap<>(); attributes.stream().forEach(a -> parms.put(a.getKey(), a.getValueOrContents())); return parms; } }
/** * <p>initialize</p> * * @param agent a {@link org.opennms.netmgt.collection.api.CollectionAgent} object. */ public void initialize(CollectionAgent agent) throws CollectionInitializationException { m_instrumentation.beginCollectorInitialize(m_package.getName(), agent.getNodeId(), agent.getHostAddress(), m_svcName); try { m_collector.validateAgent(agent, getPropertyMap()); } finally { m_instrumentation.endCollectorInitialize(m_package.getName(), agent.getNodeId(), agent.getHostAddress(), m_svcName); } }
@Override public CollectorResponseDTO get() { Logging.putPrefix("collectd"); final CollectionAgent agent = request.getAgent(); final Map<String, Object> parameters = request.getParameters(collector); return new CollectorResponseDTO(collector.collect(agent, parameters)); } }, executor);
/** * <p>getRrdRepository</p> * * @param collectionName a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.rrd.RrdRepository} object. */ public RrdRepository getRrdRepository(String collectionName) { return m_collector.getRrdRepository(collectionName); } }