diff --git a/metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/StormStatusServiceImpl.java b/metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/StormStatusServiceImpl.java index 25df549783..e561a960f1 100644 --- a/metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/StormStatusServiceImpl.java +++ b/metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/StormStatusServiceImpl.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.apache.metron.common.configuration.SensorParserGroup; @@ -83,9 +84,14 @@ public TopologyStatus getTopologyStatus(String name) { public List getAllTopologyStatus() { List topologyStatus = new ArrayList<>(); for (TopologyStatus topology : getTopologySummary().getTopologies()) { - topologyStatus.add(restTemplate - .getForObject(getStormUiProperty() + TOPOLOGY_URL + "/" + topology.getId(), - TopologyStatus.class)); + TopologyStatus status = restTemplate + .getForObject(getStormUiProperty() + TOPOLOGY_URL + "/" + topology.getId(), + TopologyStatus.class); + if (status != null) { + Optional groupName = topologyNameToGroupName(status.getName()); + groupName.ifPresent(status::setName); + topologyStatus.add(status); + } } return topologyStatus; } @@ -149,15 +155,10 @@ protected String getTopologyId(String name) { String topologyName = topology.getName(); // check sensor group - if (topologyName.contains(ParserTopologyCLI.STORM_JOB_SEPARATOR)) { - Set sensors = new HashSet<>(Arrays.asList(topologyName.split(ParserTopologyCLI.STORM_JOB_SEPARATOR))); - SensorParserGroup group = sensorParserGroupService.findOne(name); - if (group == null) { - break; - } else if (sensors.equals(group.getSensors())){ - id = topology.getId(); - break; - } + Optional groupName = topologyNameToGroupName(topologyName); + if (groupName.isPresent() && groupName.get().equals(name)) { + id = topology.getId(); + break; } if (topologyName.equals(name)) { @@ -167,4 +168,18 @@ protected String getTopologyId(String name) { } return id; } + + public Optional topologyNameToGroupName(String topologyName) { + Optional groupName = Optional.empty(); + if (topologyName.contains(ParserTopologyCLI.STORM_JOB_SEPARATOR)) { + Set sensors = new HashSet<>(Arrays.asList(topologyName.split(ParserTopologyCLI.STORM_JOB_SEPARATOR))); + for (SensorParserGroup group: sensorParserGroupService.getAll().values()) { + if (sensors.equals(group.getSensors())) { + groupName = Optional.of(group.getName()); + break; + } + } + } + return groupName; + } } diff --git a/metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/StormStatusServiceImplTest.java b/metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/StormStatusServiceImplTest.java index eac9be57ee..f1e5dffda9 100644 --- a/metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/StormStatusServiceImplTest.java +++ b/metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/StormStatusServiceImplTest.java @@ -148,7 +148,9 @@ public void getTopologyStatusByGroupShouldReturnTopologyStatus() throws Exceptio add("bro"); add("snort"); }}); - when(sensorParserGroupService.findOne("group")).thenReturn(group); + when(sensorParserGroupService.getAll()).thenReturn(new HashMap() {{ + put("group", group); + }}); when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI); when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary); when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_snort_id", TopologyStatus.class)).thenReturn(topologyStatus); @@ -165,23 +167,41 @@ public void getTopologyStatusByGroupShouldReturnTopologyStatus() throws Exceptio @Test public void getAllTopologyStatusShouldReturnAllTopologyStatus() throws Exception { - final TopologyStatus topologyStatus = new TopologyStatus(); - topologyStatus.setStatus(TopologyStatusCode.STARTED); - topologyStatus.setName("bro"); - topologyStatus.setId("bro_id"); + final TopologyStatus broTopologyStatus = new TopologyStatus(); + broTopologyStatus.setStatus(TopologyStatusCode.STARTED); + broTopologyStatus.setName("bro"); + broTopologyStatus.setId("bro_id"); + final TopologyStatus groupTopologyStatus = new TopologyStatus(); + groupTopologyStatus.setStatus(TopologyStatusCode.STARTED); + groupTopologyStatus.setName("snort__yaf"); + groupTopologyStatus.setId("snort__yaf_id"); final TopologySummary topologySummary = new TopologySummary(); - topologySummary.setTopologies(new TopologyStatus[]{topologyStatus}); + topologySummary.setTopologies(new TopologyStatus[]{broTopologyStatus, groupTopologyStatus}); + SensorParserGroup group = new SensorParserGroup(); + group.setName("group"); + group.setSensors(new HashSet() {{ + add("snort"); + add("yaf"); + }}); + when(sensorParserGroupService.getAll()).thenReturn(new HashMap() {{ + put("group", group); + }}); when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI); when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary); - when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id", TopologyStatus.class)).thenReturn(topologyStatus); - - TopologyStatus expected = new TopologyStatus(); - expected.setStatus(TopologyStatusCode.STARTED); - expected.setName("bro"); - expected.setId("bro_id"); - - assertEquals(new ArrayList() {{ add(expected); }}, stormStatusService.getAllTopologyStatus()); + when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id", TopologyStatus.class)).thenReturn(broTopologyStatus); + when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/snort__yaf_id", TopologyStatus.class)).thenReturn(groupTopologyStatus); + + TopologyStatus expectedBro = new TopologyStatus(); + expectedBro.setStatus(TopologyStatusCode.STARTED); + expectedBro.setName("bro"); + expectedBro.setId("bro_id"); + TopologyStatus expectedGroup = new TopologyStatus(); + expectedGroup.setStatus(TopologyStatusCode.STARTED); + expectedGroup.setName("group"); + expectedGroup.setId("snort__yaf_id"); + + assertEquals(new ArrayList() {{ add(expectedBro); add(expectedGroup); }}, stormStatusService.getAllTopologyStatus()); } diff --git a/metron-platform/metron-common/src/main/config/zookeeper/global.json b/metron-platform/metron-common/src/main/config/zookeeper/global.json index b638ca3bb4..baabf24db1 100644 --- a/metron-platform/metron-common/src/main/config/zookeeper/global.json +++ b/metron-platform/metron-common/src/main/config/zookeeper/global.json @@ -6,5 +6,16 @@ "update.hbase.table": "metron_update", "update.hbase.cf": "t", "es.client.settings": { - } + }, + "parser.groups": [ + { + "name": "group", + "description": "group", + "sensors": [ + "bro", + "snort", + "yaf" + ] + } + ] }