First part of onap rename
[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 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.onap.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 The error message
85      */
86     public RequestFailedException(String message) {
87         super(message);
88     }
89
90     /**
91      * Construct the request failed exception with the operation being performed, reason for the failure, http status
92      * code that is most appropriate, and the server we were processing.
93      * 
94      * @param operation The operation being performed
95      * @param reason The reason that the operation was failed
96      * @param status The http status code that is most appropriate
97      * @param server The server that we were processing
98      */
99     @SuppressWarnings("nls")
100     public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
101         super(operation + ":" + reason);
102         this.operation = operation;
103         this.reason = reason;
104         this.status = status;
105         this.server = server;
106         if (server != null) {
107             this.serverId = server.getId();
108         }
109     }
110
111
112     /**
113      * Construct the request failed exception with the operation being performed, reason for the failure, http status
114      * code that is most appropriate, and the stack we were processing.
115      *
116      * @param operation The operation being performed
117      * @param reason The reason that the operation was failed
118      * @param status The http status code that is most appropriate
119      * @param stack The stack that we were processing
120      */
121     @SuppressWarnings("nls")
122     public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
123         super(operation + ":" + reason);
124         this.operation = operation;
125         this.reason = reason;
126         this.status = status;
127         this.stack = stack;
128         if (stack != null) {
129             this.stackId = stack.getId();
130         }
131     }
132
133     /**
134      * Construct the request failed exception with the operation being performed, reason for the failure, http status
135      * code that is most appropriate, and the server we were processing.
136      * 
137      * @param ex The exception that we are wrapping
138      * @param operation The operation being performed
139      * @param reason The reason that the operation was failed
140      * @param status The http status code that is most appropriate
141      * @param server The server that we were processing
142      */
143     @SuppressWarnings("nls")
144     public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
145         super(operation + ":" + reason, ex);
146         this.operation = operation;
147         this.reason = reason;
148         this.status = status;
149         this.server = server;
150         if (server != null) {
151             this.serverId = server.getId();
152         }
153     }
154
155     /**
156      * @param message The error message
157      * @param cause A nested exception
158      */
159     public RequestFailedException(String message, Throwable cause) {
160         super(message, cause);
161     }
162
163     /**
164      * @param message The error message
165      * @param cause A nested exception
166      * @param enableSuppression whether or not suppression is enabled or disabled
167      * @param writableStackTrace whether or not the stack trace should be writable
168      */
169     public RequestFailedException(String message, Throwable cause, boolean enableSuppression,
170             boolean writableStackTrace) {
171         super(message, cause, enableSuppression, writableStackTrace);
172     }
173
174     /**
175      * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
176      *        permitted, and indicates that the cause is nonexistent or unknown.)
177      */
178     public RequestFailedException(Throwable cause) {
179         super(cause);
180     }
181
182     /**
183      * @return The operation being performed
184      */
185     public String getOperation() {
186         return operation;
187     }
188
189     /**
190      * @return The reason for the failure
191      */
192     public String getReason() {
193         return reason;
194     }
195
196     /**
197      * @return The server being operated upon
198      */
199     public Server getServer() {
200         return server;
201     }
202
203     /**
204      * @return The id of the server being operated upon
205      */
206     public String getServerId() {
207         return serverId;
208     }
209
210     /**
211      * @return The status code from the operation
212      */
213     public HttpStatus getStatus() {
214         return status;
215     }
216
217     /**
218      * @param operation The operation being performed
219      */
220     public void setOperation(String operation) {
221         this.operation = operation;
222     }
223
224     /**
225      * @param reason The reason for the failure
226      */
227     public void setReason(String reason) {
228         this.reason = reason;
229     }
230
231     /**
232      * @param server The server being operated upon
233      */
234     public void setServer(Server server) {
235         this.server = server;
236         if (server != null) {
237             setServerId(server.getId());
238         }
239     }
240
241     /**
242      * @param serverId The id of the server being operated upon
243      */
244     public void setServerId(String serverId) {
245         this.serverId = serverId;
246     }
247
248     /**
249      * @param status The status of the request
250      */
251     public void setStatus(HttpStatus status) {
252         this.status = status;
253     }
254
255 }