2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.iaas.impl;
26 import org.glassfish.grizzly.http.util.HttpStatus;
27 import com.att.cdp.zones.model.Server;
28 import com.att.cdp.zones.model.Stack;
31 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
32 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
33 * diagnostic purposes.
35 public class RequestFailedException extends Exception {
40 private static final long serialVersionUID = 1L;
43 * The operation that was being requested or performed at the time of the failure.
45 private String operation;
48 * A message that details the reason for the failure
50 private String reason;
53 * The server that was being operated upon
55 private Server server;
58 * The stack that was being operated upon
62 * The id of the server being operated upon if the server object is not available (such as the server was not found)
64 private String serverId;
67 * The id of the stack being operated upon if the stack object is not available (such as the stack was not found)
69 private String stackId;
71 * The most appropriate Http Status code that reflects the error
73 private HttpStatus status;
78 public RequestFailedException() {
79 // intentionally empty
83 * @param message The error message
85 public RequestFailedException(String message) {
90 * Construct the request failed exception with the operation being performed, reason for the failure, http status
91 * code that is most appropriate, and the server we were processing.
93 * @param operation The operation being performed
94 * @param reason The reason that the operation was failed
95 * @param status The http status code that is most appropriate
96 * @param server The server that we were processing
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();
112 * Construct the request failed exception with the operation being performed, reason for the failure, http status
113 * code that is most appropriate, and the stack we were processing.
115 * @param operation The operation being performed
116 * @param reason The reason that the operation was failed
117 * @param status The http status code that is most appropriate
118 * @param stack The stack that we were processing
120 @SuppressWarnings("nls")
121 public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
122 super(operation + ":" + reason);
123 this.operation = operation;
124 this.reason = reason;
125 this.status = status;
128 this.stackId = stack.getId();
133 * Construct the request failed exception with the operation being performed, reason for the failure, http status
134 * code that is most appropriate, and the server we were processing.
136 * @param ex The exception that we are wrapping
137 * @param operation The operation being performed
138 * @param reason The reason that the operation was failed
139 * @param status The http status code that is most appropriate
140 * @param server The server that we were processing
142 @SuppressWarnings("nls")
143 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
144 super(operation + ":" + reason, ex);
145 this.operation = operation;
146 this.reason = reason;
147 this.status = status;
148 this.server = server;
149 if (server != null) {
150 this.serverId = server.getId();
155 * @param message The error message
156 * @param cause A nested exception
158 public RequestFailedException(String message, Throwable cause) {
159 super(message, cause);
163 * @param message The error message
164 * @param cause A nested exception
165 * @param enableSuppression whether or not suppression is enabled or disabled
166 * @param writableStackTrace whether or not the stack trace should be writable
168 public RequestFailedException(String message, Throwable cause, boolean enableSuppression,
169 boolean writableStackTrace) {
170 super(message, cause, enableSuppression, writableStackTrace);
174 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
175 * permitted, and indicates that the cause is nonexistent or unknown.)
177 public RequestFailedException(Throwable cause) {
182 * @return The operation being performed
184 public String getOperation() {
189 * @return The reason for the failure
191 public String getReason() {
196 * @return The server being operated upon
198 public Server getServer() {
203 * @return The id of the server being operated upon
205 public String getServerId() {
210 * @return The status code from the operation
212 public HttpStatus getStatus() {
217 * @param operation The operation being performed
219 public void setOperation(String operation) {
220 this.operation = operation;
224 * @param reason The reason for the failure
226 public void setReason(String reason) {
227 this.reason = reason;
231 * @param server The server being operated upon
233 public void setServer(Server server) {
234 this.server = server;
235 if (server != null) {
236 setServerId(server.getId());
241 * @param serverId The id of the server being operated upon
243 public void setServerId(String serverId) {
244 this.serverId = serverId;
248 * @param status The status of the request
250 public void setStatus(HttpStatus status) {
251 this.status = status;