f66c14a59898e11961538f2a4c8afb2944ad9285
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 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.apps.blueprintsprocessor.functions.netconf.executor.data
18
19 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo
20 import java.util.*
21
22
23 class DeviceResponse {
24     lateinit var deviceInfo: DeviceInfo
25     lateinit var status: String
26     var errorMessage: String? = null
27     var responseMessage: String? = null
28     var requestMessage: String? = null
29     var subDeviceResponse: MutableMap<Any, Any>? = null
30
31     fun addSubDeviceResponse(key: String, subDeviceResponse: DeviceResponse) {
32         if (this.subDeviceResponse == null) {
33             this.subDeviceResponse = hashMapOf()
34         }
35         this.subDeviceResponse!![key] = subDeviceResponse
36     }
37 }
38
39 class NetconfDeviceOutputEvent {
40
41         private var type: NetconfDeviceOutputEvent.Type
42         private var messagePayload: String? = null
43         private var messageID: String? = null
44         private var deviceInfo: DeviceInfo? = null
45         private var subject: Any? = null
46         private var time: Long = 0
47
48         /**
49          * Type of device related events.
50          */
51         enum class Type {
52             DEVICE_REPLY,
53             DEVICE_NOTIFICATION,
54             DEVICE_UNREGISTERED,
55             DEVICE_ERROR,
56             SESSION_CLOSED
57         }
58
59         /**
60          * Creates an event of a given type and for the specified subject and the current time.
61          *
62          * @param type event type
63          * @param subject event subject
64          * @param payload message from the device
65          * @param msgID id of the message related to the event
66          * @param netconfDeviceInfo device of event
67          */
68         constructor(type: Type, subject: String, payload: String, msgID: Optional<String>, netconfDeviceInfo: DeviceInfo) {
69             this.type = type
70             this.subject = subject
71             this.messagePayload = payload
72             this.deviceInfo = netconfDeviceInfo
73             this.messageID = msgID.get()
74         }
75
76         /**
77          * Creates an event of a given type and for the specified subject and time.
78          *
79          * @param type event type
80          * @param subject event subject
81          * @param payload message from the device
82          * @param msgID id of the message related to the event
83          * @param netconfDeviceInfo device of event
84          * @param time occurrence time
85          */
86         constructor(type: Type, subject: Any, payload: String, msgID: String, netconfDeviceInfo: DeviceInfo, time: Long) {
87             this.type = type
88             this.subject = subject
89             this.time = time
90             this.messagePayload = payload
91             this.deviceInfo = netconfDeviceInfo
92             this.messageID = msgID
93         }
94
95     /**
96      * return the message payload of the reply form the device.
97      *
98      * @return reply
99      */
100     fun getMessagePayload(): String? {
101         return messagePayload
102     }
103
104     /**
105      * Event-related device information.
106      *
107      * @return information about the device
108      */
109     fun getDeviceInfo(): DeviceInfo? {
110         return deviceInfo
111     }
112
113     /**
114      * Reply messageId.
115      *
116      * @return messageId
117      */
118     fun getMessageID(): String? {
119         return messageID
120     }
121
122 }