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