312554ede25b7545031715834bb0e54d89f73d4f
[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 class NetconfExecutionRequest {
24     lateinit var requestId: String
25     val action: String? = null
26     val source: String? = null
27     val loginKey: String? = null
28     val loginAccount: String? = null
29     val targetIP: String? = null
30     val port: Int = 0
31     val connectionTimeoutSec: Int = 0
32     val implementationScript: String? = null
33     val context: MutableMap<String, Any> = mutableMapOf()
34 }
35
36 class DeviceResponse {
37     lateinit var deviceInfo: DeviceInfo
38     lateinit var status: String
39     var errorMessage: String? = null
40     var responseMessage: String? = null
41     var requestMessage: String? = null
42     var subDeviceResponse: MutableMap<Any, Any>? = null
43
44     fun addSubDeviceResponse(key: String, subDeviceResponse: DeviceResponse) {
45         if (this.subDeviceResponse == null) {
46             this.subDeviceResponse = hashMapOf()
47         }
48         this.subDeviceResponse!![key] = subDeviceResponse
49     }
50 }
51
52 class NetconfExecutionResponse {
53     val status: String? = null
54     val errorMessage: String? = null
55     val responseData: Any = Any()
56 }
57
58 open class NetconfException(message: String) : IOException(message)
59
60 class NetconfDeviceOutputEvent {
61     private var type: NetconfDeviceOutputEvent.Type
62     private var messagePayload: String? = null
63     private var messageID: String? = null
64     private var deviceInfo: DeviceInfo? = null
65     private var subject: Any? = null
66     private var time: Long = 0
67
68     /**
69      * Type of device related events.
70      */
71     enum class Type {
72         DEVICE_REPLY,
73         DEVICE_NOTIFICATION,
74         DEVICE_UNREGISTERED,
75         DEVICE_ERROR,
76         SESSION_CLOSED
77     }
78
79     /**
80      * Creates an event of a given type and for the specified subject and the current time.
81      *
82      * @param type event type
83      * @param subject event subject
84      * @param payload message from the device
85      * @param msgID id of the message related to the event
86      * @param netconfDeviceInfo device of event
87      */
88     constructor(type: Type, subject: String, payload: String, msgID: Optional<String>, netconfDeviceInfo: DeviceInfo) {
89         this.type = type
90         this.subject = subject
91         this.messagePayload = payload
92         this.deviceInfo = netconfDeviceInfo
93         this.messageID = msgID.get()
94     }
95
96     /**
97      * Creates an event of a given type and for the specified subject and time.
98      *
99      * @param type event type
100      * @param subject event subject
101      * @param payload message from the device
102      * @param msgID id of the message related to the event
103      * @param netconfDeviceInfo device of event
104      * @param time occurrence time
105      */
106     constructor(type: Type, subject: Any, payload: String, msgID: String, netconfDeviceInfo: DeviceInfo, time: Long) {
107         this.type = type
108         this.subject = subject
109         this.time = time
110         this.messagePayload = payload
111         this.deviceInfo = netconfDeviceInfo
112         this.messageID = msgID
113     }
114
115 }