Merge "Bug-915: Adding static document generation. Currently the API Explorer can...
[controller.git] / opendaylight / netconf / netconf-monitoring / src / main / java / org / opendaylight / controller / netconf / monitoring / xml / model / MonitoringSession.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.netconf.monitoring.xml.model;
9
10 import com.google.common.base.Joiner;
11 import javax.xml.bind.annotation.XmlElement;
12 import javax.xml.bind.annotation.XmlTransient;
13 import org.opendaylight.controller.netconf.monitoring.MonitoringConstants;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210.Session1;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
16 import org.opendaylight.yangtools.yang.common.QName;
17
18 final class MonitoringSession {
19
20     @XmlTransient
21     private Session managementSession;
22
23     public MonitoringSession(Session managementSession) {
24         this.managementSession = managementSession;
25     }
26
27     public MonitoringSession() {
28     }
29
30     public void setManagementSession(Session managementSession) {
31         this.managementSession = managementSession;
32     }
33
34     @XmlElement(name = "session-id")
35     public long getId() {
36         return managementSession.getSessionId();
37     }
38
39     @XmlElement(name = "source-host")
40     public String getSourceHost() {
41         return managementSession.getSourceHost().getDomainName().getValue();
42     }
43
44     @XmlElement(name = "login-time")
45     public String getLoginTime() {
46         return managementSession.getLoginTime().getValue();
47     }
48
49     @XmlElement(name = "in-bad-rpcs")
50     public Long getInBadRpcs() {
51         return managementSession.getInBadRpcs().getValue();
52     }
53
54     @XmlElement(name = "in-rpcs")
55     public Long getInRpcs() {
56         return managementSession.getInRpcs().getValue();
57     }
58
59     @XmlElement(name = "out-notifications")
60     public Long getOutNotifications() {
61         return managementSession.getOutNotifications().getValue();
62     }
63
64     @XmlElement(name = "out-rpc-errors")
65     public Long getOutRpcErrors() {
66         return managementSession.getOutRpcErrors().getValue();
67     }
68
69     @XmlElement(name = "transport")
70     public String getTransport() {
71         try {
72             QName qName = (QName) managementSession.getTransport().getField("QNAME").get(null);
73             // Add extension prefix if transport type is from extension yang module
74             if (qName.getNamespace().toString().equals(MonitoringConstants.EXTENSION_NAMESPACE)) {
75                 return Joiner.on(':').join(MonitoringConstants.EXTENSION_NAMESPACE_PREFIX, qName.getLocalName());
76             } else {
77                 return qName.getLocalName();
78             }
79         } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
80             throw new IllegalArgumentException("Unknown transport type " + managementSession.getTransport(), e);
81         }
82     }
83
84     @XmlElement(name= "session-identifier", namespace = MonitoringConstants.EXTENSION_NAMESPACE)
85     public String getSessionType() {
86         return managementSession.getAugmentation(Session1.class).getSessionIdentifier();
87     }
88
89     @XmlElement(name = "username")
90     public String getUsername() {
91         return managementSession.getUsername();
92     }
93 }