Include correlationId in group lock.
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / message-prioritizaion / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / message / prioritization / kafka / MessagePrioritizationPunctuators.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.kafka
18
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
26
27 class MessagePriorityExpiryPunctuator(private val messagePrioritizationStateService: MessagePrioritizationStateService) :
28     AbstractBluePrintMessagePunctuator() {
29
30     private val log = logger(MessagePriorityExpiryPunctuator::class)
31     lateinit var configuration: PrioritizationConfiguration
32
33     override suspend fun punctuateNB(timestamp: Long) {
34
35         log.info(
36             "**** executing expiry punctuator applicationId(${processorContext.applicationId()}), " +
37                     "taskId(${processorContext.taskId()})"
38         )
39         val expiryConfiguration = configuration.expiryConfiguration
40         val fetchMessages = messagePrioritizationStateService
41             .getExpiryEligibleMessages(expiryConfiguration.maxPollRecord)
42
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(
48                     expired.id, expired,
49                     To.child(MessagePrioritizationConstants.SINK_OUTPUT)
50                 )
51             }
52         }
53     }
54 }
55
56 class MessagePriorityCleanPunctuator(private val messagePrioritizationStateService: MessagePrioritizationStateService) :
57     AbstractBluePrintMessagePunctuator() {
58
59     private val log = logger(MessagePriorityCleanPunctuator::class)
60     lateinit var configuration: PrioritizationConfiguration
61
62     override suspend fun punctuateNB(timestamp: Long) {
63         log.info(
64             "**** executing clean punctuator applicationId(${processorContext.applicationId()}), " +
65                     "taskId(${processorContext.taskId()})"
66         )
67         // TODO
68     }
69 }