2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modification Copyright (C) 2017 IBM
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.adapter.iaas.impl;
28 import org.glassfish.grizzly.http.util.HttpStatus;
29 import com.att.cdp.zones.model.Server;
30 import com.att.cdp.zones.model.Stack;
33 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
34 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
35 * diagnostic purposes.
37 public class RequestFailedException extends Exception {
42 private static final long serialVersionUID = 1L;
45 * The operation that was being requested or performed at the time of the failure.
47 private String operation;
50 * A message that details the reason for the failure
52 private String reason;
55 * The server that was being operated upon
57 private Server server;
60 * The stack that was being operated upon
64 * The id of the server being operated upon if the server object is not available (such as the server was not found)
66 private String serverId;
69 * The id of the stack being operated upon if the stack object is not available (such as the stack was not found)
71 private String stackId;
73 * The most appropriate Http Status code that reflects the error
75 private transient HttpStatus status;
80 public RequestFailedException() {
81 // intentionally empty
85 * @param message The error message
87 public RequestFailedException(String message) {
92 * Construct the request failed exception with the operation being performed, reason for the failure, http status
93 * code that is most appropriate, and the server we were processing.
95 * @param operation The operation being performed
96 * @param reason The reason that the operation was failed
97 * @param status The http status code that is most appropriate
98 * @param server The server that we were processing
100 @SuppressWarnings("nls")
101 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
102 super(operation + ":" + reason);
103 this.operation = operation;
104 this.reason = reason;
105 this.status = status;
106 this.server = server;
107 if (server != null) {
108 this.serverId = server.getId();
114 * Construct the request failed exception with the operation being performed, reason for the failure, http status
115 * code that is most appropriate, and the stack we were processing.
117 * @param operation The operation being performed
118 * @param reason The reason that the operation was failed
119 * @param status The http status code that is most appropriate
120 * @param stack The stack that we were processing
122 @SuppressWarnings("nls")
123 public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
124 super(operation + ":" + reason);
125 this.operation = operation;
126 this.reason = reason;
127 this.status = status;
130 this.stackId = stack.getId();
135 * Construct the request failed exception with the operation being performed, reason for the failure, http status
136 * code that is most appropriate, and the server we were processing.
138 * @param ex The exception that we are wrapping
139 * @param operation The operation being performed
140 * @param reason The reason that the operation was failed
141 * @param status The http status code that is most appropriate
142 * @param server The server that we were processing
144 @SuppressWarnings("nls")
145 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
146 super(operation + ":" + reason, ex);
147 this.operation = operation;
148 this.reason = reason;
149 this.status = status;
150 this.server = server;
151 if (server != null) {
152 this.serverId = server.getId();
157 * @param message The error message
158 * @param cause A nested exception
160 public RequestFailedException(String message, Throwable cause) {
161 super(message, cause);
165 * @param message The error message
166 * @param cause A nested exception
167 * @param enableSuppression whether or not suppression is enabled or disabled
168 * @param writableStackTrace whether or not the stack trace should be writable
170 public RequestFailedException(String message, Throwable cause, boolean enableSuppression,
171 boolean writableStackTrace) {
172 super(message, cause, enableSuppression, writableStackTrace);
176 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
177 * permitted, and indicates that the cause is nonexistent or unknown.)
179 public RequestFailedException(Throwable cause) {
184 * @return The operation being performed
186 public String getOperation() {
191 * @return The reason for the failure
193 public String getReason() {
198 * @return The server being operated upon
200 public Server getServer() {
205 * @return The id of the server being operated upon
207 public String getServerId() {
212 * @return The status code from the operation
214 public HttpStatus getStatus() {
219 * @param operation The operation being performed
221 public void setOperation(String operation) {
222 this.operation = operation;
226 * @param reason The reason for the failure
228 public void setReason(String reason) {
229 this.reason = reason;
233 * @param server The server being operated upon
235 public void setServer(Server server) {
236 this.server = server;
237 if (server != null) {
238 setServerId(server.getId());
243 * @param serverId The id of the server being operated upon
245 public void setServerId(String serverId) {
246 this.serverId = serverId;
250 * @param status The status of the request
252 public void setStatus(HttpStatus status) {
253 this.status = status;