Add message prioritization module
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / message-prioritizaion / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / message / prioritization / utils / MessagePrioritizationSample.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.utils
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.CleanConfiguration
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.ExpiryConfiguration
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.PrioritizationConfiguration
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.ShutDownConfiguration
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db.MessagePrioritization
24 import java.util.*
25
26 object MessagePrioritizationSample {
27
28     fun samplePrioritizationConfiguration(): PrioritizationConfiguration {
29         return PrioritizationConfiguration().apply {
30             inputTopicSelector = "prioritize-input"
31             outputTopic = "prioritize-output-topic"
32             expiredTopic = "prioritize-expired-topic"
33             expiryConfiguration = ExpiryConfiguration().apply {
34                 frequencyMilli = 10000L
35                 maxPollRecord = 2000
36             }
37             shutDownConfiguration = ShutDownConfiguration().apply {
38                 waitMill = 2000L
39             }
40             cleanConfiguration = CleanConfiguration().apply {
41                 frequencyMilli = 10000L
42                 expiredRecordsHoldDays = 5
43             }
44         }
45     }
46
47     private fun currentDatePlusDays(days: Int): Date {
48         val calender = Calendar.getInstance()
49         calender.add(Calendar.DATE, days)
50         return calender.time
51     }
52
53     fun sampleMessages(messageState: String, count: Int): List<MessagePrioritization> {
54         return sampleMessages("sample-group", messageState, count)
55     }
56
57     fun sampleMessages(groupName: String, messageState: String, count: Int): List<MessagePrioritization> {
58         val messages: MutableList<MessagePrioritization> = arrayListOf()
59         repeat(count) {
60             val backPressureMessage = createMessage(groupName, messageState,
61                     "sample-type", null)
62             messages.add(backPressureMessage)
63         }
64         return messages
65     }
66
67     fun sampleMessageWithSameCorrelation(groupName: String, messageState: String, count: Int): List<MessagePrioritization> {
68         val messages: MutableList<MessagePrioritization> = arrayListOf()
69         repeat(count) {
70             val backPressureMessage = createMessage(groupName, messageState, "sample-type",
71                     "key1=value1,key2=value2")
72             messages.add(backPressureMessage)
73         }
74         return messages
75     }
76
77     fun sampleMessageWithDifferentTypeSameCorrelation(groupName: String, messageState: String,
78                                                       count: Int): List<MessagePrioritization> {
79         val messages: MutableList<MessagePrioritization> = arrayListOf()
80         repeat(count) {
81             val backPressureMessage = createMessage(groupName, messageState, "type-$it",
82                     "key1=value1,key2=value2")
83             messages.add(backPressureMessage)
84         }
85         return messages
86     }
87
88     fun createMessage(groupName: String, messageState: String, messageType: String,
89                       messageCorrelationId: String?): MessagePrioritization {
90
91         return MessagePrioritization().apply {
92             id = UUID.randomUUID().toString()
93             group = groupName
94             type = messageType
95             state = messageState
96             correlationId = messageCorrelationId
97             message = "I am the Message"
98             createdDate = Date()
99             updatedDate = Date()
100             expiryDate = currentDatePlusDays(3)
101         }
102     }
103 }