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.service
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
27 /** Sample Prioritization Service, Define spring service injector to register in application*/
28 open class SampleMessagePrioritizationService(private val messagePrioritizationStateService: MessagePrioritizationStateService) :
29 AbstractMessagePrioritizationService(messagePrioritizationStateService) {
31 private val log = logger(DefaultMessagePrioritizeProcessor::class)
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)
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")