2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.openecomp.appc.adapter.chef.impl;
25 import org.glassfish.grizzly.http.util.HttpStatus;
26 import com.att.cdp.zones.model.Server;
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.
33 public class RequestFailedException extends Exception {
38 private static final long serialVersionUID = 1L;
41 * The operation that was being requested or performed at the time of the failure.
43 private String operation;
46 * A message that details the reason for the failure
48 private String reason;
51 * The server that was being operated upon
53 private Server server;
56 * The id of the server being operated upon if the server object is not available (such as the server was not found)
58 private String serverId;
61 * The most appropriate Http Status code that reflects the error
63 private HttpStatus status;
68 public RequestFailedException() {
69 // intentionally empty
76 public RequestFailedException(String message) {
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.
85 * The operation being performed
87 * The reason that the operation was failed
89 * The http status code that is most appropriate
91 * The server that we were processing
93 @SuppressWarnings("nls")
94 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
95 super(operation + ":" + reason);
96 this.operation = operation;
100 if (server != null) {
101 this.serverId = server.getId();
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.
110 * The exception that we are wrapping
112 * The operation being performed
114 * The reason that the operation was failed
116 * The http status code that is most appropriate
118 * The server that we were processing
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();
138 public RequestFailedException(String message, Throwable cause) {
139 super(message, cause);
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
152 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
153 super(message, cause, enableSuppression, writableStackTrace);
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.)
161 public RequestFailedException(Throwable cause) {
166 * @return The operation being performed
168 public String getOperation() {
173 * @return The reason for the failure
175 public String getReason() {
180 * @return The server being operated upon
182 public Server getServer() {
187 * @return The id of the server being operated upon
189 public String getServerId() {
194 * @return The status code from the operation
196 public HttpStatus getStatus() {
202 * The operation being performed
204 public void setOperation(String operation) {
205 this.operation = operation;
210 * The reason for the failure
212 public void setReason(String reason) {
213 this.reason = reason;
218 * The server being operated upon
220 public void setServer(Server server) {
221 this.server = server;
222 if (server != null) {
223 setServerId(server.getId());
229 * The id of the server being operated upon
231 public void setServerId(String serverId) {
232 this.serverId = serverId;
237 * The status of the request
239 public void setStatus(HttpStatus status) {
240 this.status = status;