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