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