b4a6d2922b7d276890836cb0dfcaaa60747aaa53
[appc.git] / appc-adapters / appc-rest-healthcheck-adapter / appc-rest-healthcheck-adapter-bundle / src / main / java / org / openecomp / appc / adapter / restHealthcheck / impl / RequestFailedException.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22
23
24 package org.openecomp.appc.adapter.restHealthcheck.impl;
25
26 import org.glassfish.grizzly.http.util.HttpStatus;
27
28 import com.att.cdp.zones.model.Server;
29
30
31 public class RequestFailedException extends Exception {
32
33     /**
34      *
35      */
36     private static final long serialVersionUID = 1L;
37
38     /**
39      * The operation that was being requested or performed at the time of the failure.
40      */
41     private String operation;
42
43     /**
44      * A message that details the reason for the failure
45      */
46     private String reason;
47
48     /**
49      * The server that was being operated upon
50      */
51     private Server server;
52
53     /**
54      * The id of the server being operated upon if the server object is not available (such as the server was not found)
55      */
56     private String serverId;
57
58     /**
59      * The most appropriate Http Status code that reflects the error
60      */
61     private HttpStatus status;
62
63     /**
64      * 
65      */
66     public RequestFailedException() {
67         // intentionally empty
68     }
69
70     /**
71      * @param message
72      *            The error message
73      */
74     public RequestFailedException(String message) {
75         super(message);
76     }
77
78     /**
79      * Construct the request failed exception with the operation being performed, reason for the failure, http status
80      * code that is most appropriate, and the server we were processing.
81      * 
82      * @param operation
83      *            The operation being performed
84      * @param reason
85      *            The reason that the operation was failed
86      * @param status
87      *            The http status code that is most appropriate
88      * @param server
89      *            The server that we were processing
90      */
91     @SuppressWarnings("nls")
92     public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
93         super(operation + ":" + reason);
94         this.operation = operation;
95         this.reason = reason;
96         this.status = status;
97         this.server = server;
98         if (server != null) {
99             this.serverId = server.getId();
100         }
101     }
102
103     /**
104      * Construct the request failed exception with the operation being performed, reason for the failure, http status
105      * code that is most appropriate, and the server we were processing.
106      * 
107      * @param ex
108      *            The exception that we are wrapping
109      * @param operation
110      *            The operation being performed
111      * @param reason
112      *            The reason that the operation was failed
113      * @param status
114      *            The http status code that is most appropriate
115      * @param server
116      *            The server that we were processing
117      */
118     @SuppressWarnings("nls")
119     public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
120         super(operation + ":" + reason, ex);
121         this.operation = operation;
122         this.reason = reason;
123         this.status = status;
124         this.server = server;
125         if (server != null) {
126             this.serverId = server.getId();
127         }
128     }
129
130     /**
131      * @param message
132      *            The error message
133      * @param cause
134      *            A nested exception
135      */
136     public RequestFailedException(String message, Throwable cause) {
137         super(message, cause);
138     }
139
140     /**
141      * @param message
142      *            The error message
143      * @param cause
144      *            A nested exception
145      * @param enableSuppression
146      *            whether or not suppression is enabled or disabled
147      * @param writableStackTrace
148      *            whether or not the stack trace should be writable
149      */
150     public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
151         super(message, cause, enableSuppression, writableStackTrace);
152     }
153
154     /**
155      * @param cause
156      *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
157      *            permitted, and indicates that the cause is nonexistent or unknown.)
158      */
159     public RequestFailedException(Throwable cause) {
160         super(cause);
161     }
162
163     /**
164      * @return The operation being performed
165      */
166     public String getOperation() {
167         return operation;
168     }
169
170     /**
171      * @return The reason for the failure
172      */
173     public String getReason() {
174         return reason;
175     }
176
177     /**
178      * @return The server being operated upon
179      */
180     public Server getServer() {
181         return server;
182     }
183
184     /**
185      * @return The id of the server being operated upon
186      */
187     public String getServerId() {
188         return serverId;
189     }
190
191     /**
192      * @return The status code from the operation
193      */
194     public HttpStatus getStatus() {
195         return status;
196     }
197
198     /**
199      * @param operation
200      *            The operation being performed
201      */
202     public void setOperation(String operation) {
203         this.operation = operation;
204     }
205
206     /**
207      * @param reason
208      *            The reason for the failure
209      */
210     public void setReason(String reason) {
211         this.reason = reason;
212     }
213
214     /**
215      * @param server
216      *            The server being operated upon
217      */
218     public void setServer(Server server) {
219         this.server = server;
220         if (server != null) {
221             setServerId(server.getId());
222         }
223     }
224
225     /**
226      * @param serverId
227      *            The id of the server being operated upon
228      */
229     public void setServerId(String serverId) {
230         this.serverId = serverId;
231     }
232
233     /**
234      * @param status
235      *            The status of the request
236      */
237     public void setStatus(HttpStatus status) {
238         this.status = status;
239     }
240
241 }