Skip to content

Commit

Permalink
[TH2-5004] Added new files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Jul 31, 2023
1 parent e43fb56 commit 2cdeedb
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 0 deletions.
162 changes: 162 additions & 0 deletions src/main/kotlin/com/exactpro/th2/rptdataprovider/ProtoContext.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright 2020-2021 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.exactpro.th2.rptdataprovider


import com.exactpro.cradle.CradleManager
import com.exactpro.th2.common.grpc.Message
import com.exactpro.th2.common.grpc.MessageGroup
import com.exactpro.th2.common.grpc.MessageGroupBatch
import com.exactpro.th2.common.grpc.RawMessage
import com.exactpro.th2.common.schema.grpc.configuration.GrpcConfiguration
import com.exactpro.th2.common.schema.message.MessageRouter
import com.exactpro.th2.rptdataprovider.cache.EventCache
import com.exactpro.th2.rptdataprovider.cache.MessageCache
import com.exactpro.th2.rptdataprovider.entities.configuration.Configuration
import com.exactpro.th2.rptdataprovider.entities.filters.PredicateFactory
import com.exactpro.th2.rptdataprovider.entities.filters.events.AttachedMessageFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventBodyFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventNameFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventStatusFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventTypeFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.ParentEventIdFilter
import com.exactpro.th2.rptdataprovider.entities.filters.messages.AttachedEventFilters
import com.exactpro.th2.rptdataprovider.entities.filters.messages.MessageBodyBinaryFilter
import com.exactpro.th2.rptdataprovider.entities.filters.messages.MessageBodyFilter
import com.exactpro.th2.rptdataprovider.entities.filters.messages.MessageTypeFilter
import com.exactpro.th2.rptdataprovider.entities.internal.MessageWithMetadata
import com.exactpro.th2.rptdataprovider.entities.responses.BaseEventEntity
import com.exactpro.th2.rptdataprovider.handlers.ProtoSearchMessagesHandler
import com.exactpro.th2.rptdataprovider.handlers.SearchMessagesHandler
import com.exactpro.th2.rptdataprovider.producers.EventProducer
import com.exactpro.th2.rptdataprovider.producers.MessageProducer
import com.exactpro.th2.rptdataprovider.producers.ProtoMessageProducer
import com.exactpro.th2.rptdataprovider.serialization.InstantBackwardCompatibilitySerializer
import com.exactpro.th2.rptdataprovider.server.ServerType
import com.exactpro.th2.rptdataprovider.services.cradle.CradleService
import com.exactpro.th2.rptdataprovider.services.rabbitmq.RabbitMqService
import com.exactpro.th2.rptdataprovider.services.rabbitmq.ProtoRabbitMqService
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.http.*
import java.time.Instant

@Suppress("MemberVisibilityCanBePrivate")
class ProtoContext(
configuration: Configuration,

serverType: ServerType,

timeout: Long = configuration.responseTimeout.value.toLong(),
cacheTimeout: Long = configuration.serverCacheTimeout.value.toLong(),

jacksonMapper: ObjectMapper = jacksonObjectMapper()
.registerModule(JavaTimeModule())
.registerModule(SimpleModule("backward_compatibility").apply {
addSerializer(Instant::class.java, InstantBackwardCompatibilitySerializer)
})
.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES),

cradleManager: CradleManager,

protoMessageRouterPublisher: MessageRouter<MessageGroupBatch>,
protoMessageRouterSubscriber: MessageRouter<MessageGroupBatch>,

grpcConfig: GrpcConfiguration,

cradleService: CradleService = CradleService(
configuration,
cradleManager
),

rabbitMqService: RabbitMqService<MessageGroupBatch, MessageGroup, Message> = ProtoRabbitMqService(
configuration,
protoMessageRouterSubscriber,
protoMessageRouterPublisher
),

eventProducer: EventProducer = EventProducer(cradleService, jacksonMapper),

eventCache: EventCache = EventCache(cacheTimeout, configuration.eventCacheSize.value.toLong(), eventProducer),

messageProducer: MessageProducer<RawMessage, Message> = ProtoMessageProducer(
cradleService,
rabbitMqService
),

messageCache: MessageCache<RawMessage, Message> = MessageCache(configuration, messageProducer),

eventFiltersPredicateFactory: PredicateFactory<BaseEventEntity> = PredicateFactory(
mapOf(
AttachedMessageFilter.filterInfo to AttachedMessageFilter.Companion::build,
ParentEventIdFilter.filterInfo to ParentEventIdFilter.Companion::build,
EventTypeFilter.filterInfo to EventTypeFilter.Companion::build,
EventNameFilter.filterInfo to EventNameFilter.Companion::build,
EventBodyFilter.filterInfo to EventBodyFilter.Companion::build,
EventStatusFilter.filterInfo to EventStatusFilter.Companion::build
), cradleService
),

messageFiltersPredicateFactory: PredicateFactory<MessageWithMetadata<RawMessage, Message>> = PredicateFactory(
mapOf(
AttachedEventFilters.filterInfo to AttachedEventFilters.Companion::build,
MessageTypeFilter.filterInfo to MessageTypeFilter.Companion::build,
MessageBodyFilter.filterInfo to MessageBodyFilter.Companion::build,
MessageBodyBinaryFilter.filterInfo to MessageBodyBinaryFilter.Companion::build
), cradleService
),


enableCaching: Boolean = configuration.enableCaching.value.toBoolean(),

keepAliveTimeout: Long = configuration.keepAliveTimeout.value.toLong(),

cacheControlNotModified: CacheControl = configuration.notModifiedObjectsLifetime.value.toInt().let {
cacheControlConfig(it, enableCaching)
},

cacheControlRarelyModified: CacheControl = configuration.rarelyModifiedObjects.value.toInt().let {
cacheControlConfig(it, enableCaching)
}
): Context<MessageGroupBatch, MessageGroup, RawMessage, Message>(
configuration,
serverType,
timeout,
cacheTimeout,
jacksonMapper,
cradleManager,
grpcConfig,
cradleService,
rabbitMqService,
eventProducer,
eventCache,
messageProducer,
messageCache,
eventFiltersPredicateFactory,
messageFiltersPredicateFactory,
enableCaching,
keepAliveTimeout,
cacheControlNotModified,
cacheControlRarelyModified
) {
override val searchMessagesHandler: SearchMessagesHandler<MessageGroupBatch, MessageGroup, RawMessage, Message> =
ProtoSearchMessagesHandler(this)
}
163 changes: 163 additions & 0 deletions src/main/kotlin/com/exactpro/th2/rptdataprovider/TransportContext.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright 2020-2021 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.exactpro.th2.rptdataprovider


import com.exactpro.cradle.CradleManager
import com.exactpro.th2.common.schema.grpc.configuration.GrpcConfiguration
import com.exactpro.th2.common.schema.message.MessageRouter
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.GroupBatch
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.MessageGroup
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.ParsedMessage
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.RawMessage
import com.exactpro.th2.rptdataprovider.cache.EventCache
import com.exactpro.th2.rptdataprovider.cache.MessageCache
import com.exactpro.th2.rptdataprovider.entities.configuration.Configuration
import com.exactpro.th2.rptdataprovider.entities.filters.PredicateFactory
import com.exactpro.th2.rptdataprovider.entities.filters.events.AttachedMessageFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventBodyFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventNameFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventStatusFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.EventTypeFilter
import com.exactpro.th2.rptdataprovider.entities.filters.events.ParentEventIdFilter
import com.exactpro.th2.rptdataprovider.entities.filters.messages.AttachedEventFilters
import com.exactpro.th2.rptdataprovider.entities.filters.messages.MessageBodyBinaryFilter
import com.exactpro.th2.rptdataprovider.entities.filters.messages.MessageBodyFilter
import com.exactpro.th2.rptdataprovider.entities.filters.messages.MessageTypeFilter
import com.exactpro.th2.rptdataprovider.entities.internal.MessageWithMetadata
import com.exactpro.th2.rptdataprovider.entities.responses.BaseEventEntity
import com.exactpro.th2.rptdataprovider.handlers.SearchMessagesHandler
import com.exactpro.th2.rptdataprovider.handlers.TransportSearchMessagesHandler
import com.exactpro.th2.rptdataprovider.producers.EventProducer
import com.exactpro.th2.rptdataprovider.producers.MessageProducer
import com.exactpro.th2.rptdataprovider.producers.TransportMessageProducer
import com.exactpro.th2.rptdataprovider.serialization.InstantBackwardCompatibilitySerializer
import com.exactpro.th2.rptdataprovider.server.ServerType
import com.exactpro.th2.rptdataprovider.services.cradle.CradleService
import com.exactpro.th2.rptdataprovider.services.rabbitmq.RabbitMqService
import com.exactpro.th2.rptdataprovider.services.rabbitmq.TransportRabbitMqService
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.http.*
import java.time.Instant

@Suppress("MemberVisibilityCanBePrivate")
class TransportContext(
configuration: Configuration,

serverType: ServerType,

timeout: Long = configuration.responseTimeout.value.toLong(),
cacheTimeout: Long = configuration.serverCacheTimeout.value.toLong(),

jacksonMapper: ObjectMapper = jacksonObjectMapper()
.registerModule(JavaTimeModule())
.registerModule(SimpleModule("backward_compatibility").apply {
addSerializer(Instant::class.java, InstantBackwardCompatibilitySerializer)
})
.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES),

cradleManager: CradleManager,

transportMessageRouterPublisher: MessageRouter<GroupBatch>,
transportMessageRouterSubscriber: MessageRouter<GroupBatch>,

grpcConfig: GrpcConfiguration,

cradleService: CradleService = CradleService(
configuration,
cradleManager
),

rabbitMqService: RabbitMqService<GroupBatch, MessageGroup, ParsedMessage> = TransportRabbitMqService(
configuration,
transportMessageRouterPublisher,
transportMessageRouterSubscriber
),

eventProducer: EventProducer = EventProducer(cradleService, jacksonMapper),

eventCache: EventCache = EventCache(cacheTimeout, configuration.eventCacheSize.value.toLong(), eventProducer),

messageProducer: MessageProducer<RawMessage, ParsedMessage> = TransportMessageProducer(
cradleService,
rabbitMqService
),

messageCache: MessageCache<RawMessage, ParsedMessage> = MessageCache(configuration, messageProducer),

eventFiltersPredicateFactory: PredicateFactory<BaseEventEntity> = PredicateFactory(
mapOf(
AttachedMessageFilter.filterInfo to AttachedMessageFilter.Companion::build,
ParentEventIdFilter.filterInfo to ParentEventIdFilter.Companion::build,
EventTypeFilter.filterInfo to EventTypeFilter.Companion::build,
EventNameFilter.filterInfo to EventNameFilter.Companion::build,
EventBodyFilter.filterInfo to EventBodyFilter.Companion::build,
EventStatusFilter.filterInfo to EventStatusFilter.Companion::build
), cradleService
),

messageFiltersPredicateFactory: PredicateFactory<MessageWithMetadata<RawMessage, ParsedMessage>> = PredicateFactory(
mapOf(
AttachedEventFilters.filterInfo to AttachedEventFilters.Companion::build,
MessageTypeFilter.filterInfo to MessageTypeFilter.Companion::build,
MessageBodyFilter.filterInfo to MessageBodyFilter.Companion::build,
MessageBodyBinaryFilter.filterInfo to MessageBodyBinaryFilter.Companion::build
), cradleService
),


enableCaching: Boolean = configuration.enableCaching.value.toBoolean(),

keepAliveTimeout: Long = configuration.keepAliveTimeout.value.toLong(),

cacheControlNotModified: CacheControl = configuration.notModifiedObjectsLifetime.value.toInt().let {
cacheControlConfig(it, enableCaching)
},

cacheControlRarelyModified: CacheControl = configuration.rarelyModifiedObjects.value.toInt().let {
cacheControlConfig(it, enableCaching)
}
): Context<GroupBatch, MessageGroup, RawMessage, ParsedMessage>(
configuration,
serverType,
timeout,
cacheTimeout,
jacksonMapper,
cradleManager,
grpcConfig,
cradleService,
rabbitMqService,
eventProducer,
eventCache,
messageProducer,
messageCache,
eventFiltersPredicateFactory,
messageFiltersPredicateFactory,
enableCaching,
keepAliveTimeout,
cacheControlNotModified,
cacheControlRarelyModified
) {
override val searchMessagesHandler: SearchMessagesHandler<GroupBatch, MessageGroup, RawMessage, ParsedMessage> =
TransportSearchMessagesHandler(this)

}
Loading

0 comments on commit 2cdeedb

Please sign in to comment.