StormAdminServiceImpl implements StormAdminService { @Override public TopologyResponse startParserTopology(String name) throws RestException { TopologyResponse topologyResponse = new TopologyResponse(); if (globalConfigService.get() == null) { topologyResponse.setErrorMessage(TopologyStatusCode.GLOBAL_CONFIG_MISSING.toString()); return topologyResponse; } List<String> sensorTypes = Collections.singletonList(name); SensorParserGroup sensorParserGroup = sensorParserGroupService.findOne(name); if (sensorParserGroup != null) { sensorTypes = new ArrayList<>(sensorParserGroup.getSensors()); } for (String sensorType : sensorTypes) { if (sensorParserConfigService.findOne(sensorType.trim()) == null) { topologyResponse .setErrorMessage(TopologyStatusCode.SENSOR_PARSER_CONFIG_MISSING.toString()); return topologyResponse; } } Collections.sort(sensorTypes); return createResponse( stormCLIClientWrapper.startParserTopology(String.join(ParserTopologyCLI.TOPOLOGY_OPTION_SEPARATOR, sensorTypes)), TopologyStatusCode.STARTED, TopologyStatusCode.START_ERROR ); } @Autowired  StormAdminServiceImpl(StormCLIWrapper stormCLIClientWrapper,
                                 GlobalConfigService globalConfigService,
                                 SensorParserConfigService sensorParserConfigService,
                                 SensorParserGroupService sensorParserGroupService,
                                 StormStatusService stormStatusService); @Override TopologyResponse startParserTopology(String name); @Override TopologyResponse stopParserTopology(String name, boolean stopNow); @Override TopologyResponse startEnrichmentTopology(); @Override TopologyResponse stopEnrichmentTopology(boolean stopNow); @Override TopologyResponse startIndexingTopology(String scriptPath); @Override TopologyResponse stopIndexingTopology(String name, boolean stopNow); @Override Map<String, String> getStormClientStatus();  }
@Test public void startParserTopologyShouldProperlyReturnSuccessTopologyResponse() throws Exception { when(stormCLIClientWrapper.startParserTopology("bro")).thenReturn(0); when(globalConfigService.get()).thenReturn(new HashMap<String, Object>()); when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig()); TopologyResponse expected = new TopologyResponse(); expected.setSuccessMessage(TopologyStatusCode.STARTED.toString()); TopologyResponse actual = stormAdminService.startParserTopology("bro"); assertEquals(expected, actual); assertEquals(expected.hashCode(), actual.hashCode()); }
@Test public void startParserTopologyByGroupShouldProperlyReturnSuccessTopologyResponse() throws Exception { SensorParserGroup group = new SensorParserGroup(); group.setName("group"); group.setSensors(new HashSet<String>() {{ add("bro"); add("snort"); }}); when(sensorParserGroupService.findOne("group")).thenReturn(group); when(stormCLIClientWrapper.startParserTopology("bro,snort")).thenReturn(0); when(globalConfigService.get()).thenReturn(new HashMap<String, Object>()); when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig()); when(sensorParserConfigService.findOne("snort")).thenReturn(new SensorParserConfig()); TopologyResponse expected = new TopologyResponse(); expected.setSuccessMessage(TopologyStatusCode.STARTED.toString()); TopologyResponse actual = stormAdminService.startParserTopology("group"); assertEquals(expected, actual); assertEquals(expected.hashCode(), actual.hashCode()); }
@Test public void startParserTopologyShouldReturnGlobalConfigMissingError() throws Exception { when(globalConfigService.get()).thenReturn(null); TopologyResponse expected = new TopologyResponse(); expected.setErrorMessage(TopologyStatusCode.GLOBAL_CONFIG_MISSING.toString()); assertEquals(expected, stormAdminService.startParserTopology("bro")); }
@Test public void startParserTopologyShouldReturnSensorParserConfigMissingError() throws Exception { when(globalConfigService.get()).thenReturn(new HashMap<String, Object>()); when(sensorParserConfigService.findOne("bro")).thenReturn(null); TopologyResponse expected = new TopologyResponse(); expected.setErrorMessage(TopologyStatusCode.SENSOR_PARSER_CONFIG_MISSING.toString()); assertEquals(expected, stormAdminService.startParserTopology("bro")); }