Search in sources :

Example 81 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class SensorParserGroupServiceImplTest method saveShouldThrowExceptionOnSensorInAnotherGroup.

@Test
public void saveShouldThrowExceptionOnSensorInAnotherGroup() throws Exception {
    SensorParserGroup existingGroup = new SensorParserGroup();
    existingGroup.setName("existingGroup");
    existingGroup.setSensors(Collections.singleton("bro"));
    ParserConfigurations parserConfigurations = mock(ParserConfigurations.class);
    when(parserConfigurations.getSensorParserGroups()).thenReturn(new HashMap<String, SensorParserGroup>() {

        {
            put("existingGroup", existingGroup);
        }
    });
    when(cache.get(ParserConfigurations.class)).thenReturn(parserConfigurations);
    when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
    SensorParserGroup newGroup = new SensorParserGroup();
    newGroup.setName("newGroup");
    newGroup.setSensors(Collections.singleton("bro"));
    RestException e = assertThrows(RestException.class, () -> sensorParserGroupService.save(newGroup));
    assertEquals("Sensor bro is already in group existingGroup", e.getMessage());
}
Also used : ParserConfigurations(org.apache.metron.common.configuration.ParserConfigurations) RestException(org.apache.metron.rest.RestException) SensorParserGroup(org.apache.metron.common.configuration.SensorParserGroup) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 82 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class StormAdminServiceImplTest method startParserTopologyShouldProperlyReturnSuccessTopologyResponse.

@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());
}
Also used : TopologyResponse(org.apache.metron.rest.model.TopologyResponse) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 83 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class SensorParserConfigServiceImplTest method saveShouldWrapExceptionInRestException.

@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(setDataBuilder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenThrow(Exception.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);
    final SensorParserConfig sensorParserConfig = new SensorParserConfig();
    sensorParserConfig.setSensorTopic("bro");
    assertThrows(RestException.class, () -> sensorParserConfigService.save("bro", sensorParserConfig));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 84 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class SensorParserConfigServiceImplTest method missingParserClassShouldThrowRestException.

@Test
public void missingParserClassShouldThrowRestException() {
    final SensorParserConfig sensorParserConfig = new SensorParserConfig();
    sensorParserConfig.setSensorTopic("squid");
    ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
    parseMessageRequest.setSensorParserConfig(sensorParserConfig);
    assertThrows(RestException.class, () -> sensorParserConfigService.parseMessage(parseMessageRequest));
}
Also used : ParseMessageRequest(org.apache.metron.rest.model.ParseMessageRequest) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 85 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class SensorParserConfigServiceImplTest method getTestSquidSensorParserConfig.

private SensorParserConfig getTestSquidSensorParserConfig() {
    SensorParserConfig sensorParserConfig = new SensorParserConfig();
    sensorParserConfig.setSensorTopic("squid");
    sensorParserConfig.setParserClassName("org.apache.metron.parsers.GrokParser");
    sensorParserConfig.setParserConfig(new HashMap<String, Object>() {

        {
            put("grokPath", "/patterns/squid");
            put("patternLabel", "SQUID_DELIMITED");
            put("timestampField", "timestamp");
        }
    });
    return sensorParserConfig;
}
Also used : SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig)

Aggregations

SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)97 Test (org.junit.jupiter.api.Test)74 JSONObject (org.json.simple.JSONObject)40 FieldTransformer (org.apache.metron.common.configuration.FieldTransformer)20 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)19 HashMap (java.util.HashMap)15 Config (org.apache.storm.Config)7 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)6 File (java.io.File)5 Map (java.util.Map)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 WriterHandler (org.apache.metron.parsers.bolt.WriterHandler)5 IOException (java.io.IOException)4 SensorParserGroup (org.apache.metron.common.configuration.SensorParserGroup)4 MetronError (org.apache.metron.common.error.MetronError)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 CommandLine (org.apache.commons.cli.CommandLine)3 ParseException (org.apache.commons.cli.ParseException)3 PosixParser (org.apache.commons.cli.PosixParser)3