Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions metron-interface/metron-alerts/src/app/model/replace-request.ts

This file was deleted.

26 changes: 0 additions & 26 deletions metron-interface/metron-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ Request and Response objects are JSON formatted. The JSON schemas are available
| [ `GET /api/v1/storm/{name}`](#get-apiv1stormname)|
| [ `GET /api/v1/storm/supervisors`](#get-apiv1stormsupervisors)|
| [ `PATCH /api/v1/update/patch`](#patch-apiv1updatepatch)|
| [ `PUT /api/v1/update/replace`](#put-apiv1updatereplace)|
| [ `POST /api/v1/update/add/comment`](#put-apiv1updateaddcomment)|
| [ `POST /api/v1/update/remove/comment`](#put-apiv1updateremovecomment)|
| [ `GET /api/v1/user`](#get-apiv1user)|
Expand Down Expand Up @@ -978,31 +977,6 @@ Request and Response objects are JSON formatted. The JSON schemas are available
* Returns:
* 200 - Nothing
* 404 - Document not found

### `PUT /api/v1/update/replace`
* Description: Replace a document
* Input:
* request - Replacement request
* guid - The Patch UUID
* sensorType - The sensor type
* replacement - A Map representing the replaced document
* Example replacing a `bro` message with guid of `000-000-0000` :
```
{
"guid" : "000-000-0000",
"sensorType" : "bro",
"replacement" : {
"source:type": "bro",
"guid" : "bro_index_2017.01.01.01:1",
"ip_src_addr":"192.168.1.2",
"ip_src_port": 8009,
"timestamp":200,
"rejected":false
}
}
```
* Returns:
* 200 - Current user

### `POST /api/v1/update/add/comment`
* Description: Add a comment to an alert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.metron.indexing.dao.update.Document;
import org.apache.metron.indexing.dao.update.OriginalNotFoundException;
import org.apache.metron.indexing.dao.update.PatchRequest;
import org.apache.metron.indexing.dao.update.ReplaceRequest;
import org.apache.metron.rest.RestException;
import org.apache.metron.rest.service.UpdateService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -57,17 +56,6 @@ ResponseEntity<Document> patch(
}
}

@ApiOperation(value = "Replace a document with a full replacement")
@ApiResponse(message = "Returns the complete replaced document.", code = 200)
@RequestMapping(value = "/replace", method = RequestMethod.POST)
ResponseEntity<Document> replace(
final @ApiParam(name = "request", value = "Replacement request", required = true)
@RequestBody
ReplaceRequest request
) throws RestException {
return new ResponseEntity<>(service.replace(request), HttpStatus.OK);
}

@ApiOperation(value = "Add a comment to an alert")
@ApiResponse(message = "Returns the complete alert document with comments added.", code = 200)
@RequestMapping(value = "/add/comment", method = RequestMethod.POST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import org.apache.metron.indexing.dao.update.Document;
import org.apache.metron.indexing.dao.update.OriginalNotFoundException;
import org.apache.metron.indexing.dao.update.PatchRequest;
import org.apache.metron.indexing.dao.update.ReplaceRequest;
import org.apache.metron.rest.RestException;

public interface UpdateService {

Document patch(PatchRequest request) throws RestException, OriginalNotFoundException;
Document replace(ReplaceRequest request) throws RestException;
Document addComment(CommentAddRemoveRequest request) throws RestException;
Document removeComment(CommentAddRemoveRequest request) throws RestException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.metron.indexing.dao.update.Document;
import org.apache.metron.indexing.dao.update.OriginalNotFoundException;
import org.apache.metron.indexing.dao.update.PatchRequest;
import org.apache.metron.indexing.dao.update.ReplaceRequest;
import org.apache.metron.rest.RestException;
import org.apache.metron.rest.service.UpdateService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,15 +51,6 @@ public Document patch(PatchRequest request) throws RestException, OriginalNotFou
}
}

@Override
public Document replace(ReplaceRequest request) throws RestException {
try {
return dao.replace(request, Optional.of(System.currentTimeMillis()));
} catch (Exception e) {
throw new RestException(e.getMessage(), e);
}
}

@Override
public Document addComment(CommentAddRemoveRequest request) throws RestException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,15 @@
*/
package org.apache.metron.rest.controller;

import static org.apache.metron.rest.MetronRestConstants.TEST_PROFILE;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.google.common.collect.ImmutableMap;
import java.util.NavigableMap;
import org.adrianwalker.multilinestring.Multiline;
import org.apache.curator.framework.CuratorFramework;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.metron.common.utils.JSONUtils;
import org.apache.metron.hbase.mock.MockHBaseTableProvider;
import org.apache.metron.hbase.mock.MockHTable;
import org.apache.metron.indexing.dao.HBaseDao;
import org.apache.metron.indexing.dao.SearchIntegrationTest;
import org.apache.metron.indexing.dao.search.AlertComment;
import org.apache.metron.indexing.dao.update.CommentAddRemoveRequest;
import org.apache.metron.rest.service.UpdateService;
import org.junit.Assert;
Expand All @@ -51,11 +38,23 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.util.NavigableMap;

import static org.apache.metron.rest.MetronRestConstants.TEST_PROFILE;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(TEST_PROFILE)
Expand Down Expand Up @@ -101,23 +100,6 @@ public class UpdateControllerIntegrationTest extends DaoControllerTest {
@Multiline
public static String patch;

/**
{
"guid" : "bro_2",
"sensorType" : "bro",
"replacement" : {
"source:type": "bro",
"guid" : "bro_2",
"ip_src_addr":"192.168.1.2",
"ip_src_port": 8009,
"timestamp":200,
"rejected":false
}
}
*/
@Multiline
public static String replace;

/**
{
"guid" : "bro_2",
Expand Down Expand Up @@ -154,38 +136,50 @@ public void setup() throws Exception {
}

@Test
public void test() throws Exception {
public void shouldPatchDocument() throws Exception {
String guid = "bro_2";
ResultActions result = this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0));
try {
result.andExpect(status().isOk())

// request used to find the message
MockHttpServletRequestBuilder findOneRequest = post(searchUrl + "/findOne")
.with(httpBasic(user, password))
.with(csrf())
.contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))
.content(findMessage0);

// request used to patch the document
MockHttpServletRequestBuilder patchRequest = patch(updateUrl + "/patch")
.with(httpBasic(user, password))
.with(csrf())
.contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))
.content(patch);

// the document should exist, but without the 'project' field defined
this.mockMvc.perform(findOneRequest)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")))
.andExpect(jsonPath("$.source:type").value("bro"))
.andExpect(jsonPath("$.guid").value(guid))
.andExpect(jsonPath("$.project").doesNotExist())
.andExpect(jsonPath("$.timestamp").value(2))
;
}
catch(Throwable t) {
System.err.println(result.andReturn().getResponse().getContentAsString());
throw t;
}
.andExpect(jsonPath("$.timestamp").value(2));

// nothing is recorded in HBase
MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(TABLE);
Assert.assertEquals(0,table.size());
this.mockMvc.perform(patch(updateUrl+ "/patch").with(httpBasic(user, password))
.with(csrf())
.contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))
.content(patch)
)

// patch the document
this.mockMvc.perform(patchRequest)
.andExpect(status().isOk());
this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0))

// the document should now have the 'project' field
this.mockMvc.perform(findOneRequest)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")))
.andExpect(jsonPath("$.source:type").value("bro"))
.andExpect(jsonPath("$.guid").value(guid))
.andExpect(jsonPath("$.project").value("metron"))
.andExpect(jsonPath("$.timestamp").value(2))
;
.andExpect(jsonPath("$.timestamp").value(2));

// the change should be recorded in HBase
Assert.assertEquals(1,table.size());
{
//ensure hbase is up to date
Expand All @@ -194,28 +188,6 @@ public void test() throws Exception {
NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes());
Assert.assertEquals(1, columns.size());
}
this.mockMvc.perform(post(updateUrl+ "/replace").with(httpBasic(user, password))
.with(csrf())
.contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))
.content(replace)
)
.andExpect(status().isOk());
this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")))
.andExpect(jsonPath("$.source:type").value("bro"))
.andExpect(jsonPath("$.guid").value(guid))
.andExpect(jsonPath("$.project").doesNotExist())
.andExpect(jsonPath("$.timestamp").value(200))
;
Assert.assertEquals(1,table.size());
{
//ensure hbase is up to date
Get g = new Get(new HBaseDao.Key(guid, "bro").toBytes());
Result r = table.get(g);
NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes());
Assert.assertEquals(2, columns.size());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
*/
package org.apache.metron.elasticsearch.dao;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.metron.elasticsearch.client.ElasticsearchClient;
import org.apache.metron.elasticsearch.client.ElasticsearchClientFactory;
import org.apache.metron.indexing.dao.AccessConfig;
Expand All @@ -38,12 +33,17 @@
import org.apache.metron.indexing.dao.update.Document;
import org.apache.metron.indexing.dao.update.OriginalNotFoundException;
import org.apache.metron.indexing.dao.update.PatchRequest;
import org.apache.metron.indexing.dao.update.ReplaceRequest;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.index.query.QueryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class ElasticsearchDao implements IndexDao {

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down Expand Up @@ -155,11 +155,6 @@ public Document patch(RetrieveLatestDao retrieveLatestDao, PatchRequest request,
return updateDao.patch(retrieveLatestDao, request, timestamp);
}

@Override
public Document replace(ReplaceRequest request, Optional<Long> timestamp) throws IOException {
return updateDao.replace(request, timestamp);
}

@Override
public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException {
return updateDao.addCommentToAlert(request);
Expand Down
Loading