Remove commented methods/fields in APPC
[appc.git] / appc-adapters / appc-chef-adapter / appc-chef-adapter-bundle / src / main / java / org / openecomp / appc / adapter / chef / impl / RequestFailedException.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22
23 package org.openecomp.appc.adapter.chef.impl;
24
25 import org.glassfish.grizzly.http.util.HttpStatus;
26 import com.att.cdp.zones.model.Server;
27
28 /**
29  * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
30  * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
31  * diagnostic purposes.
32  */
33 public class RequestFailedException extends Exception {
34
35     /**
36      *
37      */
38     private static final long serialVersionUID = 1L;
39
40     /**
41      * The operation that was being requested or performed at the time of the failure.
42      */
43     private String operation;
44
45     /**
46      * A message that details the reason for the failure
47      */
48     private String reason;
49
50     /**
51      * The server that was being operated upon
52      */
53     private Server server;
54
55     /**
56      * The id of the server being operated upon if the server object is not available (such as the server was not found)
57      */
58     private String serverId;
59
60     /**
61      * The most appropriate Http Status code that reflects the error
62      */
63     private HttpStatus status;
64
65     /**
66      * 
67      */
68     public RequestFailedException() {
69         // intentionally empty
70     }
71
72     /**
73      * @param message
74      *            The error message
75      */
76     public RequestFailedException(String message) {
77         super(message);
78     }
79
80     /**
81      * Construct the request failed exception with the operation being performed, reason for the failure, http status
82      * code that is most appropriate, and the server we were processing.
83      * 
84      * @param operation
85      *            The operation being performed
86      * @param reason
87      *            The reason that the operation was failed
88      * @param status
89      *            The http status code that is most appropriate
90      * @param server
91      *            The server that we were processing
92      */
93     @SuppressWarnings("nls")
94     public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
95         super(operation + ":" + reason);
96         this.operation = operation;
97         this.reason = reason;
98         this.status = status;
99         this.server = server;
100         if (server != null) {
101             this.serverId = server.getId();
102         }
103     }
104
105     /**
106      * Construct the request failed exception with the operation being performed, reason for the failure, http status
107      * code that is most appropriate, and the server we were processing.
108      * 
109      * @param ex
110      *            The exception that we are wrapping
111      * @param operation
112      *            The operation being performed
113      * @param reason
114      *            The reason that the operation was failed
115      * @param status
116      *            The http status code that is most appropriate
117      * @param server
118      *            The server that we were processing
119      */
120     @SuppressWarnings("nls")
121     public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
122         super(operation + ":" + reason, ex);
123         this.operation = operation;
124         this.reason = reason;
125         this.status = status;
126         this.server = server;
127         if (server != null) {
128             this.serverId = server.getId();
129         }
130     }
131
132     /**
133      * @param message
134      *            The error message
135      * @param cause
136      *            A nested exception
137      */
138     public RequestFailedException(String message, Throwable cause) {
139         super(message, cause);
140     }
141
142     /**
143      * @param message
144      *            The error message
145      * @param cause
146      *            A nested exception
147      * @param enableSuppression
148      *            whether or not suppression is enabled or disabled
149      * @param writableStackTrace
150      *            whether or not the stack trace should be writable
151      */
152     public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
153         super(message, cause, enableSuppression, writableStackTrace);
154     }
155
156     /**
157      * @param cause
158      *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
159      *            permitted, and indicates that the cause is nonexistent or unknown.)
160      */
161     public RequestFailedException(Throwable cause) {
162         super(cause);
163     }
164
165     /**
166      * @return The operation being performed
167      */
168     public String getOperation() {
169         return operation;
170     }
171
172     /**
173      * @return The reason for the failure
174      */
175     public String getReason() {
176         return reason;
177     }
178
179     /**
180      * @return The server being operated upon
181      */
182     public Server getServer() {
183         return server;
184     }
185
186     /**
187      * @return The id of the server being operated upon
188      */
189     public String getServerId() {
190         return serverId;
191     }
192
193     /**
194      * @return The status code from the operation
195      */
196     public HttpStatus getStatus() {
197         return status;
198     }
199
200     /**
201      * @param operation
202      *            The operation being performed
203      */
204     public void setOperation(String operation) {
205         this.operation = operation;
206     }
207
208     /**
209      * @param reason
210      *            The reason for the failure
211      */
212     public void setReason(String reason) {
213         this.reason = reason;
214     }
215
216     /**
217      * @param server
218      *            The server being operated upon
219      */
220     public void setServer(Server server) {
221         this.server = server;
222         if (server != null) {
223             setServerId(server.getId());
224         }
225     }
226
227     /**
228      * @param serverId
229      *            The id of the server being operated upon
230      */
231     public void setServerId(String serverId) {
232         this.serverId = serverId;
233     }
234
235     /**
236      * @param status
237      *            The status of the request
238      */
239     public void setStatus(HttpStatus status) {
240         this.status = status;
241     }
242
243 }