use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupControllerIntegrationTest method testError.
@Test
public void testError() 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(post(sensorParserGroupUrl).with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(errorGroup)).andExpect(status().isInternalServerError()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.responseCode").value(500)).andExpect(jsonPath("$.message").value("Sensor bro is already in group group1")).andExpect(jsonPath("$.fullMessage").value("RestException: Sensor bro is already in group group1"));
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class SensorParserGroupControllerIntegrationTest method testUpdate.
@Test
public void testUpdate() 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(post(sensorParserGroupUrl).with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(group1BroSquid)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.*", hasSize(numFields.get()))).andExpect(jsonPath("$.name").value("group1")).andExpect(jsonPath("$.description").value("group1 description")).andExpect(jsonPath("$.sensors[0]").value("squid")).andExpect(jsonPath("$.sensors[1]").value("bro"));
}
use of org.apache.metron.common.configuration.SensorParserGroup in project metron by apache.
the class StormAdminServiceImpl method startParserTopology.
/**
* Starts a parser topology. The name should either be a sensor name or group name in the case of aggregate parser topologies.
* @param name SensorParserConfig or SensorParserGroup name
* @return ToplogyResponse
* @throws RestException Global Config or SensorParserConfigs not found or starting the topology resulted in an error.
*/
@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);
// If name is a group then look up sensors to build the actual topology 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;
}
}
// sort the sensor types so the topology name is consistent
Collections.sort(sensorTypes);
return createResponse(stormCLIClientWrapper.startParserTopology(String.join(ParserTopologyCLI.TOPOLOGY_OPTION_SEPARATOR, sensorTypes)), TopologyStatusCode.STARTED, TopologyStatusCode.START_ERROR);
}
Aggregations