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