use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupControllerIntegrationTest method testGetAll.
@Test
public void testGetAll() throws Exception {
SensorParserGroup group1 = JSONUtils.INSTANCE.load(group1BroSquid, SensorParserGroup.class);
this.sensorParserGroupService.save(group1);
TestUtils.assertEventually(() -> assertEquals(group1, this.sensorParserGroupService.findOne("group1")));
SensorParserGroup group2 = JSONUtils.INSTANCE.load(group2YafJsonMap, SensorParserGroup.class);
this.sensorParserGroupService.save(group2);
TestUtils.assertEventually(() -> assertEquals(group2, this.sensorParserGroupService.findOne("group2")));
this.mockMvc.perform(get(sensorParserGroupUrl).with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.*", hasSize(2))).andExpect(jsonPath("$.group1.*", hasSize(numFields.get()))).andExpect(jsonPath("$.group1.name").value("group1")).andExpect(jsonPath("$.group1.description").value("group1 description")).andExpect(jsonPath("$.group1.sensors[0]").value("squid")).andExpect(jsonPath("$.group1.sensors[1]").value("bro")).andExpect(jsonPath("$.group2.*", hasSize(numFields.get()))).andExpect(jsonPath("$.group2.name").value("group2")).andExpect(jsonPath("$.group2.description").value("group2 description")).andExpect(jsonPath("$.group2.sensors[0]").value("jsonMap")).andExpect(jsonPath("$.group2.sensors[1]").value("yaf"));
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupControllerIntegrationTest method testDelete.
@Test
public void testDelete() throws Exception {
SensorParserGroup group1 = JSONUtils.INSTANCE.load(group1BroSquid, SensorParserGroup.class);
this.sensorParserGroupService.save(group1);
TestUtils.assertEventually(() -> assertEquals(group1, this.sensorParserGroupService.findOne("group1")));
this.mockMvc.perform(delete(sensorParserGroupUrl + "/group1").with(httpBasic(user, password)).with(csrf())).andExpect(status().isOk());
this.mockMvc.perform(delete(sensorParserGroupUrl + "/missingGroup").with(httpBasic(user, password))).andExpect(status().isNotFound());
{
// we must wait for the config to find its way into the config.
TestUtils.assertEventually(() -> assertNull(sensorParserGroupService.findOne("group1")));
}
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImpl method delete.
/**
* Deletes a SensorParserGroup from Zookeeper.
* @param name SensorParserGroup name
* @return True if a SensorParserGroup was deleted
* @throws RestException Writing to Zookeeper resulted in an error
*/
@Override
public boolean delete(String name) throws RestException {
ParserConfigurations parserConfigurations = cache.get(ParserConfigurations.class);
Map<String, SensorParserGroup> groups = parserConfigurations.getSensorParserGroups();
boolean deleted = false;
if (groups.containsKey(name)) {
groups.remove(name);
saveGroups(parserConfigurations, new HashSet<>(groups.values()));
deleted = true;
}
return deleted;
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupServiceImpl method save.
/**
* Saves a SensorParserGroup in Zookeeper. Checks for various error conditions including empty sensors field, missing
* configs for each sensor and sensors already included in another group.
* @param sensorParserGroup
* @return
* @throws RestException
*/
@Override
public SensorParserGroup save(SensorParserGroup sensorParserGroup) throws RestException {
ParserConfigurations parserConfigurations = cache.get(ParserConfigurations.class);
Map<String, SensorParserGroup> groups = new HashMap<>(parserConfigurations.getSensorParserGroups());
groups.remove(sensorParserGroup.getName());
if (sensorParserGroup.getSensors().size() == 0) {
throw new RestException("A parser group must contain sensors");
}
for (String sensor : sensorParserGroup.getSensors()) {
// check if sensor config exists
if (sensorParserConfigService.findOne(sensor) == null) {
throw new RestException(String.format("Could not find config for sensor %s", sensor));
}
// check if sensor is in another group
for (SensorParserGroup group : groups.values()) {
Set<String> groupSensors = group.getSensors();
if (groupSensors.contains(sensor)) {
throw new RestException(String.format("Sensor %s is already in group %s", sensor, group.getName()));
}
}
}
groups.put(sensorParserGroup.getName(), sensorParserGroup);
saveGroups(parserConfigurations, new HashSet<>(groups.values()));
return sensorParserGroup;
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class StormStatusServiceImpl method getTopologyId.
/**
* Retrieves the Storm topology id from the given topology name. If a topology name is detected to be an aggregate
* parser topology, the SensorParserGroups are checked for a match.
* @param name Topology or SensorParserGroup name
* @return Topology id
*/
protected String getTopologyId(String name) {
String id = null;
for (TopologyStatus topology : getTopologySummary().getTopologies()) {
String topologyName = topology.getName();
// check sensor group
if (topologyName.contains(ParserTopologyCLI.STORM_JOB_SEPARATOR)) {
Set<String> 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;
}
}
if (topologyName.equals(name)) {
id = topology.getId();
break;
}
}
return id;
}
Aggregations