d2bf09587be3199e73b1f4faed9831134fb9c6a3
[appc.git] /
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  * 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.adapter.iaas.impl;
25
26 import org.glassfish.grizzly.http.util.HttpStatus;
27 import com.att.cdp.zones.model.Server;
28 import com.att.cdp.zones.model.Stack;
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 stack that was being operated upon
59      */
60     private Stack stack;
61     /**
62      * The id of the server being operated upon if the server object is not available (such as the server was not found)
63      */
64     private String serverId;
65
66     /**
67      * The id of the stack being operated upon if the stack object is not available (such as the stack was not found)
68      */
69     private String stackId;
70     /**
71      * The most appropriate Http Status code that reflects the error
72      */
73     private HttpStatus status;
74
75     /**
76      * 
77      */
78     public RequestFailedException() {
79         // intentionally empty
80     }
81
82     /**
83      * @param message 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 The operation being performed
94      * @param reason The reason that the operation was failed
95      * @param status The http status code that is most appropriate
96      * @param server The server that we were processing
97      */
98     @SuppressWarnings("nls")
99     public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
100         super(operation + ":" + reason);
101         this.operation = operation;
102         this.reason = reason;
103         this.status = status;
104         this.server = server;
105         if (server != null) {
106             this.serverId = server.getId();
107         }
108     }
109
110
111     /**
112      * Construct the request failed exception with the operation being performed, reason for the failure, http status
113      * code that is most appropriate, and the stack we were processing.
114      *
115      * @param operation The operation being performed
116      * @param reason The reason that the operation was failed
117      * @param status The http status code that is most appropriate
118      * @param stack The stack that we were processing
119      */
120     @SuppressWarnings("nls")
121     public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
122         super(operation + ":" + reason);
123         this.operation = operation;
124         this.reason = reason;
125         this.status = status;
126         this.stack = stack;
127         if (stack != null) {
128             this.stackId = stack.getId();
129         }
130     }
131
132     /**
133      * Construct the request failed exception with the operation being performed, reason for the failure, http status
134      * code that is most appropriate, and the server we were processing.
135      * 
136      * @param ex The exception that we are wrapping
137      * @param operation The operation being performed
138      * @param reason The reason that the operation was failed
139      * @param status The http status code that is most appropriate
140      * @param server The server that we were processing
141      */
142     @SuppressWarnings("nls")
143     public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
144         super(operation + ":" + reason, ex);
145         this.operation = operation;
146         this.reason = reason;
147         this.status = status;
148         this.server = server;
149         if (server != null) {
150             this.serverId = server.getId();
151         }
152     }
153
154     /**
155      * @param message The error message
156      * @param cause A nested exception
157      */
158     public RequestFailedException(String message, Throwable cause) {
159         super(message, cause);
160     }
161
162     /**
163      * @param message The error message
164      * @param cause A nested exception
165      * @param enableSuppression whether or not suppression is enabled or disabled
166      * @param writableStackTrace whether or not the stack trace should be writable
167      */
168     public RequestFailedException(String message, Throwable cause, boolean enableSuppression,
169             boolean writableStackTrace) {
170         super(message, cause, enableSuppression, writableStackTrace);
171     }
172
173     /**
174      * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
175      *        permitted, and indicates that the cause is nonexistent or unknown.)
176      */
177     public RequestFailedException(Throwable cause) {
178         super(cause);
179     }
180
181     /**
182      * @return The operation being performed
183      */
184     public String getOperation() {
185         return operation;
186     }
187
188     /**
189      * @return The reason for the failure
190      */
191     public String getReason() {
192         return reason;
193     }
194
195     /**
196      * @return The server being operated upon
197      */
198     public Server getServer() {
199         return server;
200     }
201
202     /**
203      * @return The id of the server being operated upon
204      */
205     public String getServerId() {
206         return serverId;
207     }
208
209     /**
210      * @return The status code from the operation
211      */
212     public HttpStatus getStatus() {
213         return status;
214     }
215
216     /**
217      * @param operation The operation being performed
218      */
219     public void setOperation(String operation) {
220         this.operation = operation;
221     }
222
223     /**
224      * @param reason The reason for the failure
225      */
226     public void setReason(String reason) {
227         this.reason = reason;
228     }
229
230     /**
231      * @param server The server being operated upon
232      */
233     public void setServer(Server server) {
234         this.server = server;
235         if (server != null) {
236             setServerId(server.getId());
237         }
238     }
239
240     /**
241      * @param serverId The id of the server being operated upon
242      */
243     public void setServerId(String serverId) {
244         this.serverId = serverId;
245     }
246
247     /**
248      * @param status The status of the request
249      */
250     public void setStatus(HttpStatus status) {
251         this.status = status;
252     }
253
254 }