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