fix some sonar issues
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceResult.java
1 /*
2  * Copyright © 2017 AT&T, 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
9 package org.opendaylight.transportpce.pce;
10
11 import org.opendaylight.transportpce.common.ResponseCodes;
12 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
13 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class PceResult {
18     /* Logging. */
19     private static final Logger LOG = LoggerFactory.getLogger(PceResult.class);
20     private String calcMessage = "503 Calculator Unavailable";
21     private boolean calcStatus = false;
22     private String responseCode = ResponseCodes.RESPONSE_FAILED;
23     private long resultWavelength = -1;
24     // for now it is constant returned as received from A-end
25     private long rate = -1;
26
27     public enum LocalCause {
28         NONE, TOO_HIGH_LATENCY, NO_PATH_EXISTS, INT_PROBLEM;
29     }
30
31     private LocalCause localCause = LocalCause.NONE;
32
33     private AToZDirection atozdirection = null;
34     private ZToADirection ztoadirection = null;
35
36     public PceResult() {
37     }
38
39     public void setRC(String rc) {
40         switch (rc) {
41             case ResponseCodes.RESPONSE_OK:
42                 this.calcMessage = "Path is calculated";
43                 this.calcStatus = true;
44                 this.responseCode = ResponseCodes.RESPONSE_OK;
45                 break;
46             case ResponseCodes.RESPONSE_FAILED:
47                 this.responseCode = ResponseCodes.RESPONSE_FAILED;
48                 this.calcStatus = false;
49                 this.calcMessage = "No path available";
50                 break;
51             default:
52                 LOG.error("setRC: RespondeCodes unknown");
53         }
54     }
55
56     @Override
57     public String toString() {
58         return ("[" + this.calcMessage + "] code:[" + this.responseCode + "] wavelength=" + this.resultWavelength
59                 + " localCause=" + this.localCause + " rate=" + this.rate);
60     }
61
62     public boolean getStatus() {
63         return this.calcStatus;
64     }
65
66     public String getMessage() {
67         return this.calcMessage;
68     }
69
70     public String getResponseCode() {
71         return this.responseCode;
72     }
73
74     public long getResultWavelength() {
75         return this.resultWavelength;
76     }
77
78     public void setResultWavelength(long resultWavelength) {
79         this.resultWavelength = resultWavelength;
80     }
81
82     public AToZDirection getAtoZDirection() {
83         return this.atozdirection;
84     }
85
86     public ZToADirection getZtoADirection() {
87         return this.ztoadirection;
88     }
89
90     public void setAtoZDirection(AToZDirection atozdirectionIn) {
91         this.atozdirection = atozdirectionIn;
92     }
93
94     public void setZtoADirection(ZToADirection ztoadirectionIn) {
95         this.ztoadirection = ztoadirectionIn;
96     }
97
98     public long getRate() {
99         return this.rate;
100     }
101
102     public void setRate(long rate) {
103         this.rate = rate;
104     }
105
106     public LocalCause getLocalCause() {
107         return this.localCause;
108     }
109
110     public void setLocalCause(LocalCause lc) {
111         // For now keep the very first fatal problem
112         // TODO. Later this value might become history of algo if all significant problems are added here as to List
113         if (this.localCause == LocalCause.NONE) {
114             this.localCause = lc;
115         }
116     }
117
118
119     public void setCalcMessage(String calcMessage) {
120         this.calcMessage = calcMessage;
121     }
122
123
124 }