Search in sources :

Example 16 with SensorParserGroup

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"));
}
Also used : SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with SensorParserGroup

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"));
}
Also used : SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with SensorParserGroup

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);
}
Also used : TopologyResponse(org.apache.metron.rest.model.TopologyResponse) SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup)

Aggregations

SensorParserGroup (org.apache.metron.common.configuration.SensorParserGroup)18 Test (org.junit.jupiter.api.Test)14 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)4 RestException (org.apache.metron.rest.RestException)4 TopologyResponse (org.apache.metron.rest.model.TopologyResponse)2 TopologyStatus (org.apache.metron.rest.model.TopologyStatus)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TopologySummary (org.apache.metron.rest.model.TopologySummary)1