Migrate bundles' configuration mgmt to ConfigurationService
[controller.git] / opendaylight / topologymanager / implementation / src / main / java / org / opendaylight / controller / topologymanager / TopologyUserLinkConfig.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.topologymanager;
11
12 import java.io.Serializable;
13
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 import org.opendaylight.controller.configuration.ConfigurationObject;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * The Interface provides methods to manipulate user configured link.
26  */
27 @XmlRootElement
28 @XmlAccessorType(XmlAccessType.NONE)
29 public class TopologyUserLinkConfig extends ConfigurationObject implements Serializable {
30     private static final long serialVersionUID = 1L;
31     private static final Logger logger = LoggerFactory.getLogger(TopologyUserLinkConfig.class);
32
33     public enum STATUS {
34         SUCCESS("Success"), LINKDOWN("Link Down"), INCORRECT(
35                 "Incorrect Connection");
36         private STATUS(String name) {
37             this.name = name;
38         }
39
40         private String name;
41
42         @Override
43         public String toString() {
44             return name;
45         }
46
47         public static STATUS fromString(String str) {
48             if (str == null) {
49                 return LINKDOWN;
50             }
51             if (str.equals(SUCCESS.toString())) {
52                 return SUCCESS;
53             }
54             if (str.equals(LINKDOWN.toString())) {
55                 return LINKDOWN;
56             }
57             if (str.equals(INCORRECT.toString())) {
58                 return INCORRECT;
59             }
60             return LINKDOWN;
61         }
62     }
63
64     @XmlElement
65     private String status;
66     @XmlElement
67     private String name;
68     @XmlElement
69     private String srcNodeConnector;
70     @XmlElement
71     private String dstNodeConnector;
72
73     public TopologyUserLinkConfig() {
74         super();
75         status = STATUS.LINKDOWN.toString();
76     }
77
78     public TopologyUserLinkConfig(String name, String srcNodeConnector, String dstNodeConnector) {
79         super();
80         this.name = name;
81         this.srcNodeConnector = srcNodeConnector;
82         this.dstNodeConnector = dstNodeConnector;
83     }
84
85
86     public String getName() {
87         return name;
88     }
89
90     public void setName(String name) {
91         this.name = name;
92     }
93
94
95     public STATUS getStatus() {
96         return STATUS.fromString(status);
97     }
98
99     public void setStatus(STATUS s) {
100         this.status = s.toString();
101     }
102
103     public String getSrcNodeConnector() {
104         return srcNodeConnector;
105     }
106
107     public void setSrcNodeConnector(String srcNodeConnector) {
108         this.srcNodeConnector = srcNodeConnector;
109     }
110
111     public String getDstNodeConnector() {
112         return dstNodeConnector;
113     }
114
115     public void setDstNodeConnector(String dstNodeConnector) {
116         this.dstNodeConnector = dstNodeConnector;
117     }
118
119     public boolean isValidNodeConnector(String nodeConnectorStr) {
120         return (NodeConnector.fromString(nodeConnectorStr) != null);
121     }
122
123     public boolean isValid() {
124         if (!isValidResourceName(name)) {
125             logger.debug("Invalid name in user link: {}", name);
126             return false;
127         }
128
129         if (!isValidNodeConnector(srcNodeConnector) ||
130                 !isValidNodeConnector(dstNodeConnector)) {
131             logger.debug("Invalid NodeConnector in user link: {}", name);
132             return false;
133         }
134
135         return true;
136     }
137
138     @Override
139     public int hashCode() {
140         final int prime = 31;
141         int result = 1;
142         result = prime
143                 * result
144                 + ((dstNodeConnector == null) ? 0 : dstNodeConnector.hashCode());
145         result = prime * result + ((name == null) ? 0 : name.hashCode());
146         result = prime
147                 * result
148                 + ((srcNodeConnector == null) ? 0 : srcNodeConnector.hashCode());
149         return result;
150     }
151
152     @Override
153     public boolean equals(Object obj) {
154         if (this == obj) {
155             return true;
156         }
157         if (obj == null) {
158             return false;
159         }
160         if (getClass() != obj.getClass()) {
161             return false;
162         }
163         TopologyUserLinkConfig other = (TopologyUserLinkConfig) obj;
164         if (dstNodeConnector == null) {
165             if (other.dstNodeConnector != null) {
166                 return false;
167             }
168         } else if (!dstNodeConnector.equals(other.dstNodeConnector)) {
169             return false;
170         }
171         if (srcNodeConnector == null) {
172             if (other.srcNodeConnector != null) {
173                 return false;
174             }
175         } else if (!srcNodeConnector.equals(other.srcNodeConnector)) {
176             return false;
177         }
178         return true;
179     }
180
181     @Override
182     public String toString() {
183         return "TopologyUserLinkConfig [status=" + status + ", name=" + name
184                 + ", srcNodeConnector=" + srcNodeConnector
185                 + ", dstNodeConnector=" + dstNodeConnector + "]";
186     }
187 }