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