2 * Copyright © 2018-2019 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.kafka
19 import org.apache.kafka.streams.processor.To
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.MessagePrioritizationConstants
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.MessagePrioritizationStateService
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.MessageState
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.PrioritizationConfiguration
24 import org.onap.ccsdk.cds.blueprintsprocessor.message.kafka.AbstractBluePrintMessagePunctuator
25 import org.onap.ccsdk.cds.controllerblueprints.core.logger
27 class MessagePriorityExpiryPunctuator(private val messagePrioritizationStateService: MessagePrioritizationStateService) :
28 AbstractBluePrintMessagePunctuator() {
30 private val log = logger(MessagePriorityExpiryPunctuator::class)
31 lateinit var configuration: PrioritizationConfiguration
33 override suspend fun punctuateNB(timestamp: Long) {
36 "**** executing expiry punctuator applicationId(${processorContext.applicationId()}), " +
37 "taskId(${processorContext.taskId()})"
39 val expiryConfiguration = configuration.expiryConfiguration
40 val fetchMessages = messagePrioritizationStateService
41 .getExpiryEligibleMessages(expiryConfiguration.maxPollRecord)
43 val expiredIds = fetchMessages?.map { it.id }
44 if (expiredIds != null && expiredIds.isNotEmpty()) {
45 messagePrioritizationStateService.updateMessagesState(expiredIds, MessageState.EXPIRED.name)
46 fetchMessages.forEach { expired ->
47 processorContext.forward(
49 To.child(MessagePrioritizationConstants.SINK_OUTPUT)
56 class MessagePriorityCleanPunctuator(private val messagePrioritizationStateService: MessagePrioritizationStateService) :
57 AbstractBluePrintMessagePunctuator() {
59 private val log = logger(MessagePriorityCleanPunctuator::class)
60 lateinit var configuration: PrioritizationConfiguration
62 override suspend fun punctuateNB(timestamp: Long) {
64 "**** executing clean punctuator applicationId(${processorContext.applicationId()}), " +
65 "taskId(${processorContext.taskId()})"