Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Th2 3673 common need to change the filter #201

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private MultiValuedMap<String, FieldFilterConfiguration> extractConfigMapFromRou
MultiValuedMap<String, FieldFilterConfiguration> msgFieldFilters = MultiMapUtils.newListValuedHashMap();
msgFieldFilters.putAll(routerFilter.getMessage());
msgFieldFilters.putAll(routerFilter.getMetadata());
Nikita-Smirnov-Exactpro marked this conversation as resolved.
Show resolved Hide resolved
msgFieldFilters.putAll(routerFilter.getProperties());
return msgFieldFilters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Map<String, String> getFields(com.google.protobuf.Message message) {
DIRECTION_KEY, messageID.getDirection().name()
);

messageFields.putAll(th2Msg.getMetadata().getPropertiesMap());
messageFields.putAll(metadataMsgFields);

return messageFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ class AnyMessageFilterStrategy : AbstractFilterStrategy<Message>() {
override fun getFields(message: Message): MutableMap<String, String> {
check(message is AnyMessage) { "Message is not an ${AnyMessage::class.qualifiedName}: ${message.toJson()}" }

val result = HashMap<String, String>();
val result = HashMap<String, String>()

when {
message.hasMessage() -> {
result.putAll(message.message.fieldsMap.mapValues { it.value.simpleValue })

val metadata = message.message.metadata
result.putAll(message.message.metadata.propertiesMap)
result[AbstractTh2MsgFilterStrategy.SESSION_ALIAS_KEY] = metadata.id.connectionId.sessionAlias
result[AbstractTh2MsgFilterStrategy.MESSAGE_TYPE_KEY] = metadata.messageType
result[AbstractTh2MsgFilterStrategy.DIRECTION_KEY] = metadata.id.direction.name
Nikita-Smirnov-Exactpro marked this conversation as resolved.
Show resolved Hide resolved
}
message.hasRawMessage() -> {
val metadata = message.rawMessage.metadata
result.putAll(message.rawMessage.metadata.propertiesMap)
result[AbstractTh2MsgFilterStrategy.SESSION_ALIAS_KEY] = metadata.id.connectionId.sessionAlias
result[AbstractTh2MsgFilterStrategy.DIRECTION_KEY] = metadata.id.direction.name
Nikita-Smirnov-Exactpro marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ data class GrpcRawFilterStrategy(var filters: List<GrpcRouterFilterConfiguration
data class GrpcRouterFilterConfiguration(
@JsonProperty(required = true) var endpoint: String,
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var metadata: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap(),
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var message: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap()
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var message: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap(),
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var properties: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap()
) : RouterFilter, Configuration() {

@JsonGetter("metadata")
Expand All @@ -39,4 +40,7 @@ data class GrpcRouterFilterConfiguration(
@JsonGetter("message")
fun getJsonMessage(): Collection<FieldFilterConfiguration> = message.values()

@JsonGetter("properties")
fun getJsonProperties(): Collection<FieldFilterConfiguration> = properties.values()

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ data class QueueConfiguration(

data class MqRouterFilterConfiguration(
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var metadata: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap(),
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var message: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap()
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var message: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap(),
@JsonDeserialize(using = MultiMapFiltersDeserializer::class) override var properties: MultiValuedMap<String, FieldFilterConfiguration> = emptyMultiMap()
) : Configuration(), RouterFilter {

constructor(
metadata: Collection<FieldFilterConfiguration> = emptyList(),
message: Collection<FieldFilterConfiguration> = emptyList()
message: Collection<FieldFilterConfiguration> = emptyList(),
properties: Collection<FieldFilterConfiguration> = emptyList()
) : this(
MultiMapUtils.newListValuedHashMap<String, FieldFilterConfiguration>().also { metadataMultiMap ->
metadata.forEach {
Expand All @@ -63,6 +65,11 @@ data class MqRouterFilterConfiguration(
message.forEach {
messageMultiMap.put(it.fieldName, it)
}
},
MultiMapUtils.newListValuedHashMap<String, FieldFilterConfiguration>().also { propertiesMultiMap ->
properties.forEach {
propertiesMultiMap.put(it.fieldName, it)
}
}
)

Expand All @@ -71,6 +78,9 @@ data class MqRouterFilterConfiguration(

@JsonGetter("message")
fun getJsonMessage(): Collection<FieldFilterConfiguration> = message.values()

@JsonGetter("properties")
fun getJsonProperties(): Collection<FieldFilterConfiguration> = properties.values()
}

data class FieldFilterConfigurationOld(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ import org.apache.commons.collections4.MultiValuedMap
interface RouterFilter {
val metadata: MultiValuedMap<String, FieldFilterConfiguration>
val message: MultiValuedMap<String, FieldFilterConfiguration>
val properties: MultiValuedMap<String, FieldFilterConfiguration>
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,14 @@ class TestJsonConfiguration {
FieldFilterOperation.EQUAL
)
),
listOf(FieldFilterConfiguration("test_field", "test_value", FieldFilterOperation.EQUAL))
listOf(FieldFilterConfiguration("test_field", "test_value", FieldFilterOperation.EQUAL)),
listOf(
FieldFilterConfiguration(
"method",
"POST",
FieldFilterOperation.EQUAL
)
),
),
MqRouterFilterConfiguration(
listOf(
Expand All @@ -196,6 +203,10 @@ class TestJsonConfiguration {
listOf(
FieldFilterConfiguration("test_field", "test_value0", FieldFilterOperation.EQUAL),
FieldFilterConfiguration("test_field", "test_value1", FieldFilterOperation.EQUAL)
),
listOf(
FieldFilterConfiguration("method1", "POST", FieldFilterOperation.EQUAL),
FieldFilterConfiguration("method2", "GET", FieldFilterOperation.NOT_EQUAL)
)
)
)
Expand Down
Loading