mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-20 04:43:42 +00:00
[Fixes] Patch Minor Fixes (#14919)
* Patch Minor Fixes * Patch Minor Fixes * java checkstyke * Fix Failing Test * fix filtering
This commit is contained in:
parent
9dca086053
commit
6d015980b7
@ -29,6 +29,7 @@ import java.util.stream.Collectors;
|
|||||||
import javax.ws.rs.BadRequestException;
|
import javax.ws.rs.BadRequestException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.openmetadata.common.utils.CommonUtil;
|
import org.openmetadata.common.utils.CommonUtil;
|
||||||
|
import org.openmetadata.schema.api.events.AlertFilteringInput;
|
||||||
import org.openmetadata.schema.api.events.CreateEventSubscription;
|
import org.openmetadata.schema.api.events.CreateEventSubscription;
|
||||||
import org.openmetadata.schema.entity.events.Argument;
|
import org.openmetadata.schema.entity.events.Argument;
|
||||||
import org.openmetadata.schema.entity.events.ArgumentsInput;
|
import org.openmetadata.schema.entity.events.ArgumentsInput;
|
||||||
@ -98,7 +99,7 @@ public final class AlertUtil {
|
|||||||
|
|
||||||
public static boolean shouldTriggerAlert(String entityType, FilteringRules config) {
|
public static boolean shouldTriggerAlert(String entityType, FilteringRules config) {
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
// OpenMetadataWide Setting apply to all ChangeEvents
|
// OpenMetadataWide Setting apply to all ChangeEvents
|
||||||
if (config.getResources().size() == 1 && config.getResources().get(0).equals("all")) {
|
if (config.getResources().size() == 1 && config.getResources().get(0).equals("all")) {
|
||||||
@ -186,92 +187,71 @@ public final class AlertUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static FilteringRules validateAndBuildFilteringConditions(
|
public static FilteringRules validateAndBuildFilteringConditions(
|
||||||
CreateEventSubscription createEventSubscription) {
|
List<String> resource,
|
||||||
// Resource Validation
|
CreateEventSubscription.AlertType alertType,
|
||||||
List<EventFilterRule> finalRules = new ArrayList<>();
|
AlertFilteringInput input) {
|
||||||
List<EventFilterRule> actions = new ArrayList<>();
|
|
||||||
List<String> resource = createEventSubscription.getResources();
|
|
||||||
if (resource.size() > 1) {
|
if (resource.size() > 1) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
"Only one resource can be specified. Multiple resources are not supported.");
|
"Only one resource can be specified. Multiple resources are not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createEventSubscription
|
if (alertType.equals(CreateEventSubscription.AlertType.NOTIFICATION)) {
|
||||||
.getAlertType()
|
|
||||||
.equals(CreateEventSubscription.AlertType.NOTIFICATION)) {
|
|
||||||
Map<String, EventFilterRule> supportedFilters =
|
Map<String, EventFilterRule> supportedFilters =
|
||||||
|
buildFilteringRulesMap(
|
||||||
EventsSubscriptionRegistry.getEntityNotificationDescriptor(resource.get(0))
|
EventsSubscriptionRegistry.getEntityNotificationDescriptor(resource.get(0))
|
||||||
.getSupportedFilters()
|
.getSupportedFilters());
|
||||||
.stream()
|
|
||||||
.collect(
|
|
||||||
Collectors.toMap(
|
|
||||||
EventFilterRule::getName,
|
|
||||||
eventFilterRule ->
|
|
||||||
JsonUtils.deepCopy(eventFilterRule, EventFilterRule.class)));
|
|
||||||
// Input validation
|
// Input validation
|
||||||
if (createEventSubscription.getInput() != null) {
|
if (input != null) {
|
||||||
listOrEmpty(createEventSubscription.getInput().getFilters())
|
|
||||||
.forEach(
|
|
||||||
argumentsInput ->
|
|
||||||
finalRules.add(
|
|
||||||
getFilterRule(
|
|
||||||
supportedFilters,
|
|
||||||
argumentsInput,
|
|
||||||
buildInputArgumentsMap(argumentsInput))));
|
|
||||||
}
|
|
||||||
return new FilteringRules()
|
return new FilteringRules()
|
||||||
.withResources(resource)
|
.withResources(resource)
|
||||||
.withRules(finalRules)
|
.withRules(buildRulesList(supportedFilters, input.getFilters()))
|
||||||
.withActions(Collections.emptyList());
|
.withActions(Collections.emptyList());
|
||||||
} else if (createEventSubscription
|
}
|
||||||
.getAlertType()
|
} else if (alertType.equals(CreateEventSubscription.AlertType.OBSERVABILITY)) {
|
||||||
.equals(CreateEventSubscription.AlertType.OBSERVABILITY)) {
|
|
||||||
// Build a Map of Entity Filter Name
|
// Build a Map of Entity Filter Name
|
||||||
Map<String, EventFilterRule> supportedFilters =
|
Map<String, EventFilterRule> supportedFilters =
|
||||||
|
buildFilteringRulesMap(
|
||||||
EventsSubscriptionRegistry.getObservabilityDescriptor(resource.get(0))
|
EventsSubscriptionRegistry.getObservabilityDescriptor(resource.get(0))
|
||||||
.getSupportedFilters()
|
.getSupportedFilters());
|
||||||
.stream()
|
|
||||||
.collect(
|
|
||||||
Collectors.toMap(
|
|
||||||
EventFilterRule::getName,
|
|
||||||
eventFilterRule ->
|
|
||||||
JsonUtils.deepCopy(eventFilterRule, EventFilterRule.class)));
|
|
||||||
// Build a Map of Actions
|
// Build a Map of Actions
|
||||||
Map<String, EventFilterRule> supportedActions =
|
Map<String, EventFilterRule> supportedActions =
|
||||||
|
buildFilteringRulesMap(
|
||||||
EventsSubscriptionRegistry.getObservabilityDescriptor(resource.get(0))
|
EventsSubscriptionRegistry.getObservabilityDescriptor(resource.get(0))
|
||||||
.getSupportedActions()
|
.getSupportedActions());
|
||||||
.stream()
|
|
||||||
.collect(
|
|
||||||
Collectors.toMap(
|
|
||||||
EventFilterRule::getName,
|
|
||||||
eventFilterRule ->
|
|
||||||
JsonUtils.deepCopy(eventFilterRule, EventFilterRule.class)));
|
|
||||||
|
|
||||||
// Input validation
|
// Input validation
|
||||||
if (createEventSubscription.getInput() != null) {
|
if (input != null) {
|
||||||
listOrEmpty(createEventSubscription.getInput().getFilters())
|
return new FilteringRules()
|
||||||
.forEach(
|
.withResources(resource)
|
||||||
argumentsInput ->
|
.withRules(buildRulesList(supportedFilters, input.getFilters()))
|
||||||
finalRules.add(
|
.withActions(buildRulesList(supportedActions, input.getActions()));
|
||||||
getFilterRule(
|
}
|
||||||
supportedFilters,
|
|
||||||
argumentsInput,
|
|
||||||
buildInputArgumentsMap(argumentsInput))));
|
|
||||||
listOrEmpty(createEventSubscription.getInput().getActions())
|
|
||||||
.forEach(
|
|
||||||
argumentsInput ->
|
|
||||||
actions.add(
|
|
||||||
getFilterRule(
|
|
||||||
supportedActions,
|
|
||||||
argumentsInput,
|
|
||||||
buildInputArgumentsMap(argumentsInput))));
|
|
||||||
}
|
}
|
||||||
return new FilteringRules()
|
return new FilteringRules()
|
||||||
.withResources(resource)
|
.withResources(resource)
|
||||||
.withRules(finalRules)
|
.withRules(Collections.emptyList())
|
||||||
.withActions(actions);
|
.withActions(Collections.emptyList());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
private static Map<String, EventFilterRule> buildFilteringRulesMap(
|
||||||
|
List<EventFilterRule> filteringRules) {
|
||||||
|
return filteringRules.stream()
|
||||||
|
.collect(
|
||||||
|
Collectors.toMap(
|
||||||
|
EventFilterRule::getName,
|
||||||
|
eventFilterRule -> JsonUtils.deepCopy(eventFilterRule, EventFilterRule.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<EventFilterRule> buildRulesList(
|
||||||
|
Map<String, EventFilterRule> lookUp, List<ArgumentsInput> input) {
|
||||||
|
List<EventFilterRule> rules = new ArrayList<>();
|
||||||
|
listOrEmpty(input)
|
||||||
|
.forEach(
|
||||||
|
argumentsInput ->
|
||||||
|
rules.add(
|
||||||
|
getFilterRule(lookUp, argumentsInput, buildInputArgumentsMap(argumentsInput))));
|
||||||
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, List<String>> buildInputArgumentsMap(ArgumentsInput filter) {
|
private static Map<String, List<String>> buildInputArgumentsMap(ArgumentsInput filter) {
|
||||||
|
|||||||
@ -13,11 +13,17 @@
|
|||||||
|
|
||||||
package org.openmetadata.service.jdbi3;
|
package org.openmetadata.service.jdbi3;
|
||||||
|
|
||||||
|
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
||||||
|
import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty;
|
||||||
|
import static org.openmetadata.service.events.subscription.AlertUtil.validateAndBuildFilteringConditions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.openmetadata.schema.api.events.CreateEventSubscription;
|
import org.openmetadata.schema.api.events.CreateEventSubscription;
|
||||||
|
import org.openmetadata.schema.entity.events.Argument;
|
||||||
|
import org.openmetadata.schema.entity.events.ArgumentsInput;
|
||||||
import org.openmetadata.schema.entity.events.EventFilterRule;
|
import org.openmetadata.schema.entity.events.EventFilterRule;
|
||||||
import org.openmetadata.schema.entity.events.EventSubscription;
|
import org.openmetadata.schema.entity.events.EventSubscription;
|
||||||
import org.openmetadata.schema.entity.events.SubscriptionDestination;
|
import org.openmetadata.schema.entity.events.SubscriptionDestination;
|
||||||
@ -66,6 +72,30 @@ public class EventSubscriptionRepository extends EntityRepository<EventSubscript
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(EventSubscription entity, boolean update) {
|
public void prepare(EventSubscription entity, boolean update) {
|
||||||
|
// Sort Filters and Actions
|
||||||
|
if (entity.getInput() != null) {
|
||||||
|
listOrEmpty(entity.getInput().getFilters())
|
||||||
|
.sort(Comparator.comparing(ArgumentsInput::getName));
|
||||||
|
listOrEmpty(entity.getInput().getActions())
|
||||||
|
.sort(Comparator.comparing(ArgumentsInput::getName));
|
||||||
|
|
||||||
|
// Sort Input Args
|
||||||
|
listOrEmpty(entity.getInput().getFilters())
|
||||||
|
.forEach(
|
||||||
|
filter ->
|
||||||
|
listOrEmpty(filter.getArguments()).sort(Comparator.comparing(Argument::getName)));
|
||||||
|
listOrEmpty(entity.getInput().getActions())
|
||||||
|
.forEach(
|
||||||
|
filter ->
|
||||||
|
listOrEmpty(filter.getArguments()).sort(Comparator.comparing(Argument::getName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update && !nullOrEmpty(entity.getFilteringRules())) {
|
||||||
|
entity.setFilteringRules(
|
||||||
|
validateAndBuildFilteringConditions(
|
||||||
|
entity.getFilteringRules().getResources(), entity.getAlertType(), entity.getInput()));
|
||||||
|
}
|
||||||
|
|
||||||
validateFilterRules(entity);
|
validateFilterRules(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -120,10 +120,10 @@ public class EventSubscriptionResource
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(OpenMetadataApplicationConfig config) {
|
public void initialize(OpenMetadataApplicationConfig config) {
|
||||||
try {
|
try {
|
||||||
repository.initSeedDataFromResources();
|
|
||||||
EventsSubscriptionRegistry.initialize(
|
EventsSubscriptionRegistry.initialize(
|
||||||
listOrEmpty(EventSubscriptionResource.getNotificationsFilterDescriptors()),
|
listOrEmpty(EventSubscriptionResource.getNotificationsFilterDescriptors()),
|
||||||
listOrEmpty(EventSubscriptionResource.getObservabilityFilterDescriptors()));
|
listOrEmpty(EventSubscriptionResource.getObservabilityFilterDescriptors()));
|
||||||
|
repository.initSeedDataFromResources();
|
||||||
initializeEventSubscriptions();
|
initializeEventSubscriptions();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// Starting application should not fail
|
// Starting application should not fail
|
||||||
@ -599,7 +599,9 @@ public class EventSubscriptionResource
|
|||||||
.withTrigger(create.getTrigger())
|
.withTrigger(create.getTrigger())
|
||||||
.withEnabled(create.getEnabled())
|
.withEnabled(create.getEnabled())
|
||||||
.withBatchSize(create.getBatchSize())
|
.withBatchSize(create.getBatchSize())
|
||||||
.withFilteringRules(validateAndBuildFilteringConditions(create))
|
.withFilteringRules(
|
||||||
|
validateAndBuildFilteringConditions(
|
||||||
|
create.getResources(), create.getAlertType(), create.getInput()))
|
||||||
.withDestinations(getSubscriptions(create.getDestinations()))
|
.withDestinations(getSubscriptions(create.getDestinations()))
|
||||||
.withProvider(create.getProvider())
|
.withProvider(create.getProvider())
|
||||||
.withRetries(create.getRetries())
|
.withRetries(create.getRetries())
|
||||||
|
|||||||
@ -281,7 +281,10 @@ public class EventSubscriptionResourceTest
|
|||||||
change,
|
change,
|
||||||
"filteringRules",
|
"filteringRules",
|
||||||
createdAlert.getFilteringRules(),
|
createdAlert.getFilteringRules(),
|
||||||
AlertUtil.validateAndBuildFilteringConditions(genericWebhookActionRequest));
|
AlertUtil.validateAndBuildFilteringConditions(
|
||||||
|
genericWebhookActionRequest.getResources(),
|
||||||
|
genericWebhookActionRequest.getAlertType(),
|
||||||
|
genericWebhookActionRequest.getInput()));
|
||||||
|
|
||||||
createdAlert =
|
createdAlert =
|
||||||
updateAndCheckEntity(
|
updateAndCheckEntity(
|
||||||
@ -299,7 +302,10 @@ public class EventSubscriptionResourceTest
|
|||||||
change,
|
change,
|
||||||
"filteringRules",
|
"filteringRules",
|
||||||
createdAlert.getFilteringRules(),
|
createdAlert.getFilteringRules(),
|
||||||
AlertUtil.validateAndBuildFilteringConditions(genericWebhookActionRequest));
|
AlertUtil.validateAndBuildFilteringConditions(
|
||||||
|
genericWebhookActionRequest.getResources(),
|
||||||
|
genericWebhookActionRequest.getAlertType(),
|
||||||
|
genericWebhookActionRequest.getInput()));
|
||||||
|
|
||||||
createdAlert =
|
createdAlert =
|
||||||
updateAndCheckEntity(
|
updateAndCheckEntity(
|
||||||
@ -317,7 +323,10 @@ public class EventSubscriptionResourceTest
|
|||||||
change,
|
change,
|
||||||
"filteringRules",
|
"filteringRules",
|
||||||
createdAlert.getFilteringRules(),
|
createdAlert.getFilteringRules(),
|
||||||
AlertUtil.validateAndBuildFilteringConditions(genericWebhookActionRequest));
|
AlertUtil.validateAndBuildFilteringConditions(
|
||||||
|
genericWebhookActionRequest.getResources(),
|
||||||
|
genericWebhookActionRequest.getAlertType(),
|
||||||
|
genericWebhookActionRequest.getInput()));
|
||||||
|
|
||||||
createdAlert =
|
createdAlert =
|
||||||
updateAndCheckEntity(
|
updateAndCheckEntity(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user