Search in sources :

Example 1 with MetaAlertCreateRequest

use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.

the class ElasticsearchMetaAlertIntegrationTest method shouldCreateMetaAlert.

@Test
public void shouldCreateMetaAlert() throws Exception {
    // Load alerts
    List<Map<String, Object>> alerts = buildAlerts(3);
    elasticsearchAdd(alerts, INDEX, SENSOR_NAME);
    // Verify load was successful
    findCreatedDocs(Arrays.asList(new GetRequest("message_0", SENSOR_NAME), new GetRequest("message_1", SENSOR_NAME), new GetRequest("message_2", SENSOR_NAME)));
    {
        MetaAlertCreateRequest metaAlertCreateRequest = new MetaAlertCreateRequest() {

            {
                setAlerts(new ArrayList<GetRequest>() {

                    {
                        add(new GetRequest("message_1", SENSOR_NAME));
                        add(new GetRequest("message_2", SENSOR_NAME, INDEX));
                    }
                });
                setGroups(Collections.singletonList("group"));
            }
        };
        MetaAlertCreateResponse metaAlertCreateResponse = metaDao.createMetaAlert(metaAlertCreateRequest);
        {
            // Verify metaAlert was created
            findCreatedDoc(metaAlertCreateResponse.getGuid(), MetaAlertDao.METAALERT_TYPE);
        }
        {
            // Verify alert 0 was not updated with metaalert field
            Document alert = metaDao.getLatest("message_0", SENSOR_NAME);
            Assert.assertEquals(4, alert.getDocument().size());
            Assert.assertNull(alert.getDocument().get(METAALERT_FIELD));
        }
        {
            // Verify alert 1 was properly updated with metaalert field
            Document alert = metaDao.getLatest("message_1", SENSOR_NAME);
            Assert.assertEquals(5, alert.getDocument().size());
            Assert.assertEquals(1, ((List) alert.getDocument().get(METAALERT_FIELD)).size());
            Assert.assertEquals(metaAlertCreateResponse.getGuid(), ((List) alert.getDocument().get(METAALERT_FIELD)).get(0));
        }
        {
            // Verify alert 2 was properly updated with metaalert field
            Document alert = metaDao.getLatest("message_2", SENSOR_NAME);
            Assert.assertEquals(5, alert.getDocument().size());
            Assert.assertEquals(1, ((List) alert.getDocument().get(METAALERT_FIELD)).size());
            Assert.assertEquals(metaAlertCreateResponse.getGuid(), ((List) alert.getDocument().get(METAALERT_FIELD)).get(0));
        }
    }
}
Also used : GetRequest(org.apache.metron.indexing.dao.search.GetRequest) ArrayList(java.util.ArrayList) MetaAlertCreateResponse(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateResponse) MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) Document(org.apache.metron.indexing.dao.update.Document) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with MetaAlertCreateRequest

use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.

the class SolrMetaAlertDaoTest method testCreateMetaAlertEmptyGuids.

@Test
public void testCreateMetaAlertEmptyGuids() {
    SolrDao solrDao = new SolrDao();
    solrDao.init(accessConfig);
    SolrMetaAlertDao emaDao = new SolrMetaAlertDao();
    emaDao.init(solrDao);
    MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
    assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
Also used : MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) Test(org.junit.jupiter.api.Test)

Example 3 with MetaAlertCreateRequest

use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.

the class SolrMetaAlertDaoTest method testCreateMetaAlertEmptyGroups.

@Test
public void testCreateMetaAlertEmptyGroups() {
    SolrDao solrDao = new SolrDao();
    solrDao.init(accessConfig);
    MultiIndexDao miDao = new MultiIndexDao(solrDao);
    SolrMetaAlertDao emaDao = new SolrMetaAlertDao();
    emaDao.init(miDao);
    MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
    createRequest.setAlerts(Collections.singletonList(new GetRequest("don't", "care")));
    assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
Also used : MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) Test(org.junit.jupiter.api.Test)

Example 4 with MetaAlertCreateRequest

use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.

the class ElasticsearchMetaAlertDaoTest method testCreateMetaAlertEmptyGuids.

@Test
public void testCreateMetaAlertEmptyGuids() {
    ElasticsearchDao esDao = new ElasticsearchDao();
    ElasticsearchMetaAlertDao emaDao = new ElasticsearchMetaAlertDao();
    emaDao.init(esDao);
    MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
    assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
Also used : MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) Test(org.junit.jupiter.api.Test)

Example 5 with MetaAlertCreateRequest

use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.

the class ElasticsearchMetaAlertDaoTest method testCreateMetaAlertEmptyGroups.

@Test
public void testCreateMetaAlertEmptyGroups() {
    ElasticsearchDao esDao = new ElasticsearchDao();
    MultiIndexDao miDao = new MultiIndexDao(esDao);
    ElasticsearchMetaAlertDao emaDao = new ElasticsearchMetaAlertDao();
    emaDao.init(miDao);
    MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
    createRequest.setAlerts(Collections.singletonList(new GetRequest("don't", "care")));
    assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
Also used : MultiIndexDao(org.apache.metron.indexing.dao.MultiIndexDao) MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) Test(org.junit.jupiter.api.Test)

Aggregations

MetaAlertCreateRequest (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest)5 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MultiIndexDao (org.apache.metron.indexing.dao.MultiIndexDao)1 MetaAlertCreateResponse (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateResponse)1 GetRequest (org.apache.metron.indexing.dao.search.GetRequest)1 Document (org.apache.metron.indexing.dao.update.Document)1 Test (org.junit.Test)1