Skip to content

Commit

Permalink
GEN-1662 : Fix - on dashboard soft delete, chart should not be visible (
Browse files Browse the repository at this point in the history
  • Loading branch information
sonika-shah committed Oct 16, 2024
1 parent 4ac6111 commit f10de7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public void deleteByScript(String entityType, String scriptTxt, Map<String, Obje
} catch (Exception ie) {
LOG.error(
String.format(
"Issue in Creating new search document for entityType [%s]. Reason[%s], Cause[%s], Stack [%s]",
"Issue in deleting new search document for entityType [%s]. Reason[%s], Cause[%s], Stack [%s]",
entityType, ie.getMessage(), ie.getCause(), ExceptionUtils.getStackTrace(ie)));
}
}
Expand Down Expand Up @@ -637,6 +637,16 @@ public void deleteOrUpdateChildren(EntityInterface entity, IndexMapping indexMap
new ImmutablePair<>(
REMOVE_TAGS_CHILDREN_SCRIPT,
Collections.singletonMap("fqn", entity.getFullyQualifiedName())));
case Entity.DASHBOARD -> {
String scriptTxt =
String.format(
"if (ctx._source.dashboards.size() == 1) { ctx._source.put('deleted', '%s') }",
true);
searchClient.softDeleteOrRestoreChildren(
indexMapping.getChildAliases(clusterAlias),
scriptTxt,
List.of(new ImmutablePair<>("dashboards.id", docId)));
}
case Entity.TEST_SUITE -> {
TestSuite testSuite = (TestSuite) entity;
if (Boolean.TRUE.equals(testSuite.getExecutable())) {
Expand Down Expand Up @@ -687,6 +697,16 @@ public void softDeleteOrRestoredChildren(
indexMapping.getChildAliases(clusterAlias),
scriptTxt,
List.of(new ImmutablePair<>("service.id", docId)));
case Entity.DASHBOARD -> {
scriptTxt =
String.format(
"if (ctx._source.dashboards.size() == 1) { ctx._source.put('deleted', '%s') }",
delete);
searchClient.softDeleteOrRestoreChildren(
indexMapping.getChildAliases(clusterAlias),
scriptTxt,
List.of(new ImmutablePair<>("dashboards.id", docId)));
}
default -> searchClient.softDeleteOrRestoreChildren(
indexMapping.getChildAliases(clusterAlias),
scriptTxt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ public JsonObject aggregate(String query, String index, JsonObject aggregationJs
@SneakyThrows
public void updateSearch(UpdateRequest updateRequest) {
if (updateRequest != null) {
updateRequest.docAsUpsert(true);
updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
LOG.debug(SENDING_REQUEST_TO_ELASTIC_SEARCH, updateRequest);
client.update(updateRequest, RequestOptions.DEFAULT);
Expand Down Expand Up @@ -1568,6 +1567,7 @@ public void createEntity(String indexName, String docId, String doc) {
if (isClientAvailable) {
UpdateRequest updateRequest = new UpdateRequest(indexName, docId);
updateRequest.doc(doc, XContentType.JSON);
updateRequest.docAsUpsert(true);
updateSearch(updateRequest);
}
}
Expand All @@ -1577,6 +1577,7 @@ public void createTimeSeriesEntity(String indexName, String docId, String doc) {
if (isClientAvailable) {
UpdateRequest updateRequest = new UpdateRequest(indexName, docId);
updateRequest.doc(doc, XContentType.JSON);
updateRequest.docAsUpsert(true);
updateSearch(updateRequest);
}
}
Expand Down

0 comments on commit f10de7f

Please sign in to comment.