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