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