b7d878e4a85d24b52688e17ad39adaea3d50840a
[ccsdk/cds.git] /
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.service
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.MessagePrioritizationStateService
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.MessageState
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db.MessagePrioritization
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.ids
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.kafka.DefaultMessagePrioritizeProcessor
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.orderByHighestPriority
25 import org.onap.ccsdk.cds.controllerblueprints.core.logger
26
27 /** Sample Prioritization Service, Define spring service injector to register in application*/
28 open class SampleMessagePrioritizationService(private val messagePrioritizationStateService: MessagePrioritizationStateService) :
29     AbstractMessagePrioritizationService(messagePrioritizationStateService) {
30
31     private val log = logger(DefaultMessagePrioritizeProcessor::class)
32
33     /** Child overriding this implementation , if necessary */
34     override suspend fun handleAggregation(messages: List<MessagePrioritization>) {
35         log.info("messages(${messages.ids()}) aggregated")
36         /** Sequence based on Priority and Updated Date */
37         val sequencedMessage = messages.orderByHighestPriority()
38         /** Update all messages to aggregated state */
39         messagePrioritizationStateService.setMessagesState(sequencedMessage.ids(), MessageState.AGGREGATED.name)
40         output(sequencedMessage)
41     }
42
43     /** If consumer wants specific correlation with respect to group and types, then populate the specific types,
44      * otherwise correlation happens with group and correlationId */
45     override fun getGroupCorrelationTypes(messagePrioritization: MessagePrioritization): List<String>? {
46         return when (messagePrioritization.group) {
47             /** Dummy Implementation, This can also be read from file and stored as cached map **/
48             "group-typed" -> arrayListOf("type-0", "type-1", "type-2")
49             else -> null
50         }
51     }
52 }