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