/** * Returns list of instrumented methods of a given agentId. * <p> * <i> Example URL: /data/agents/{agentId}/methods</i> * </p> * * @param agentId * AGENT ID bounded from path. * @return a Set of {@link MethodIdent} of a given agentId. * @throws BusinessException * If given ID of the agent is not valid. */ @RequestMapping(method = GET, value = "{agentId}/methods") @ResponseBody public Set<MethodIdent> getMethods(@PathVariable long agentId) throws BusinessException { return globalDataAccessService.getCompleteAgent(agentId).getMethodIdents(); }
/** * Returns the complete sensors informations of an agent. * <p> * <i> Example URL: /data/agents/{agentId}/sensors</i> * </p> * * @param agentId * AGENT ID bounded from path. * @return a Set of {@link SensorTypeIdent} of the given agentId. * @throws BusinessException * If given ID of the agent is not valid. */ @RequestMapping(method = GET, value = "{agentId}/sensors") @ResponseBody public Set<SensorTypeIdent> getSensors(@PathVariable long agentId) throws BusinessException { return globalDataAccessService.getCompleteAgent(agentId).getSensorTypeIdents(); }
/** * Internal refresh of the idents. Currently everything is loaded again. */ protected void refreshIdents() { Map<PlatformIdent, AgentStatusData> agentMap = globalDataAccessService.getAgentsOverview(); platformMap.clear(); methodMap.clear(); sensorTypeMap.clear(); jmxDefinitionDataMap.clear(); for (PlatformIdent overview : agentMap.keySet()) { PlatformIdent platformIdent; try { platformIdent = globalDataAccessService.getCompleteAgent(overview.getId()); } catch (BusinessException e) { LOG.warn("Exception occurred trying to refresh sensor information for the agent " + overview.getAgentName() + ".", e); continue; } platformMap.put(platformIdent.getId(), platformIdent); for (MethodIdent methodIdent : platformIdent.getMethodIdents()) { methodMap.put(methodIdent.getId(), methodIdent); } for (SensorTypeIdent sensorTypeIdent : platformIdent.getSensorTypeIdents()) { sensorTypeMap.put(sensorTypeIdent.getId(), sensorTypeIdent); } for (JmxDefinitionDataIdent jmxDefinitionDataIdent : platformIdent.getJmxDefinitionDataIdents()) { jmxDefinitionDataMap.put(jmxDefinitionDataIdent.getId(), jmxDefinitionDataIdent); } } }
@BeforeMethod public void initialize() throws BusinessException { platformIdent = mock(PlatformIdent.class); when(platformIdent.getId()).thenReturn(PLATFORM_ID); when(globalDataAccessService.getAgentsOverview()).thenReturn(Collections.<PlatformIdent, AgentStatusData> singletonMap(platformIdent, null)); when(globalDataAccessService.getCompleteAgent(PLATFORM_ID)).thenReturn(platformIdent); methodIdent = mock(MethodIdent.class); when(methodIdent.getId()).thenReturn(METHOD_SENSOR_ID); when(platformIdent.getMethodIdents()).thenReturn(Collections.singleton(methodIdent)); sensorType = mock(SensorTypeIdent.class); when(sensorType.getId()).thenReturn(SENSOR_ID); when(platformIdent.getSensorTypeIdents()).thenReturn(Collections.singleton(sensorType)); }
@Test public void testIdentsCache() throws BusinessException { assertThat(cachedDataService.getPlatformIdentForId(PLATFORM_ID), is(equalTo(platformIdent))); assertThat(cachedDataService.getMethodIdentForId(METHOD_SENSOR_ID), is(equalTo(methodIdent))); assertThat(cachedDataService.getSensorTypeIdentForId(SENSOR_ID), is(equalTo(sensorType))); verify(globalDataAccessService, times(1)).getAgentsOverview(); verify(globalDataAccessService, times(1)).getCompleteAgent(PLATFORM_ID); verifyNoMoreInteractions(globalDataAccessService); assertThat(cachedDataService.getPlatformIdentForId(100L), is(nullValue())); assertThat(cachedDataService.getMethodIdentForId(100L), is(nullValue())); assertThat(cachedDataService.getSensorTypeIdentForId(100L), is(nullValue())); verify(globalDataAccessService, times(4)).getAgentsOverview(); verify(globalDataAccessService, times(4)).getCompleteAgent(PLATFORM_ID); verifyNoMoreInteractions(globalDataAccessService); verifyNoMoreInteractions(businessContextService); } }