0b63ea58fded5dc6f3d89a8303369afa6cef8453
[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.io.IOException
21 import java.util.*
22
23
24
25
26 class NetconfExecutionRequest {
27     lateinit var requestId: String
28     val action: String? = null
29     val source: String? = null
30     val loginKey: String? = null
31     val loginAccount: String? = null
32     val targetIP: String? = null
33     val port: Int = 0
34     val connectionTimeoutSec: Int = 0
35     val implementationScript: String? = null
36     val context: MutableMap<String, Any> = mutableMapOf()
37 }
38
39 class DeviceResponse {
40     lateinit var deviceInfo: DeviceInfo
41     lateinit var status: String
42     var errorMessage: String? = null
43     var responseMessage: String? = null
44     var requestMessage: String? = null
45     var subDeviceResponse: MutableMap<Any, Any>? = null
46
47     fun addSubDeviceResponse(key: String, subDeviceResponse: DeviceResponse) {
48         if (this.subDeviceResponse == null) {
49             this.subDeviceResponse = hashMapOf()
50         }
51         this.subDeviceResponse!![key] = subDeviceResponse
52     }
53 }
54
55 class NetconfExecutionResponse {
56     val status: String? = null
57     val errorMessage: String? = null
58     val responseData: Any = Any()
59 }
60
61
62 class NetconfDeviceOutputEvent {
63
64         private var type: NetconfDeviceOutputEvent.Type
65         private var messagePayload: String? = null
66         private var messageID: String? = null
67         private var deviceInfo: DeviceInfo? = null
68         private var subject: Any? = null
69         private var time: Long = 0
70
71         /**
72          * Type of device related events.
73          */
74         enum class Type {
75             DEVICE_REPLY,
76             DEVICE_NOTIFICATION,
77             DEVICE_UNREGISTERED,
78             DEVICE_ERROR,
79             SESSION_CLOSED
80         }
81
82         /**
83          * Creates an event of a given type and for the specified subject and the current time.
84          *
85          * @param type event type
86          * @param subject event subject
87          * @param payload message from the device
88          * @param msgID id of the message related to the event
89          * @param netconfDeviceInfo device of event
90          */
91         constructor(type: Type, subject: String, payload: String, msgID: Optional<String>, netconfDeviceInfo: DeviceInfo) {
92             this.type = type
93             this.subject = subject
94             this.messagePayload = payload
95             this.deviceInfo = netconfDeviceInfo
96             this.messageID = msgID.get()
97         }
98
99         /**
100          * Creates an event of a given type and for the specified subject and time.
101          *
102          * @param type event type
103          * @param subject event subject
104          * @param payload message from the device
105          * @param msgID id of the message related to the event
106          * @param netconfDeviceInfo device of event
107          * @param time occurrence time
108          */
109         constructor(type: Type, subject: Any, payload: String, msgID: String, netconfDeviceInfo: DeviceInfo, time: Long) {
110             this.type = type
111             this.subject = subject
112             this.time = time
113             this.messagePayload = payload
114             this.deviceInfo = netconfDeviceInfo
115             this.messageID = msgID
116         }
117
118     /**
119      * return the message payload of the reply form the device.
120      *
121      * @return reply
122      */
123     fun getMessagePayload(): String? {
124         return messagePayload
125     }
126
127     /**
128      * Event-related device information.
129      *
130      * @return information about the device
131      */
132     fun getDeviceInfo(): DeviceInfo? {
133         return deviceInfo
134     }
135
136     /**
137      * Reply messageId.
138      *
139      * @return messageId
140      */
141     fun getMessageID(): String? {
142         return messageID
143     }
144
145 }