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