2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.adapter.iaas.impl;
27 import org.glassfish.grizzly.http.util.HttpStatus;
28 import com.att.cdp.zones.model.Server;
29 import com.att.cdp.zones.model.Stack;
32 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
33 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
34 * diagnostic purposes.
36 public class RequestFailedException extends Exception {
41 private static final long serialVersionUID = 1L;
44 * The operation that was being requested or performed at the time of the failure.
46 private String operation;
49 * A message that details the reason for the failure
51 private String reason;
54 * The server that was being operated upon
56 private Server server;
59 * The stack that was being operated upon
63 * The id of the server being operated upon if the server object is not available (such as the server was not found)
65 private String serverId;
68 * The id of the stack being operated upon if the stack object is not available (such as the stack was not found)
70 private String stackId;
72 * The most appropriate Http Status code that reflects the error
74 private HttpStatus status;
79 public RequestFailedException() {
80 // intentionally empty
84 * @param message The error message
86 public RequestFailedException(String message) {
91 * Construct the request failed exception with the operation being performed, reason for the failure, http status
92 * code that is most appropriate, and the server we were processing.
94 * @param operation The operation being performed
95 * @param reason The reason that the operation was failed
96 * @param status The http status code that is most appropriate
97 * @param server The server that we were processing
99 @SuppressWarnings("nls")
100 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
101 super(operation + ":" + reason);
102 this.operation = operation;
103 this.reason = reason;
104 this.status = status;
105 this.server = server;
106 if (server != null) {
107 this.serverId = server.getId();
113 * Construct the request failed exception with the operation being performed, reason for the failure, http status
114 * code that is most appropriate, and the stack we were processing.
116 * @param operation The operation being performed
117 * @param reason The reason that the operation was failed
118 * @param status The http status code that is most appropriate
119 * @param stack The stack that we were processing
121 @SuppressWarnings("nls")
122 public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
123 super(operation + ":" + reason);
124 this.operation = operation;
125 this.reason = reason;
126 this.status = status;
129 this.stackId = stack.getId();
134 * Construct the request failed exception with the operation being performed, reason for the failure, http status
135 * code that is most appropriate, and the server we were processing.
137 * @param ex The exception that we are wrapping
138 * @param operation The operation being performed
139 * @param reason The reason that the operation was failed
140 * @param status The http status code that is most appropriate
141 * @param server The server that we were processing
143 @SuppressWarnings("nls")
144 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
145 super(operation + ":" + reason, ex);
146 this.operation = operation;
147 this.reason = reason;
148 this.status = status;
149 this.server = server;
150 if (server != null) {
151 this.serverId = server.getId();
156 * @param message The error message
157 * @param cause A nested exception
159 public RequestFailedException(String message, Throwable cause) {
160 super(message, cause);
164 * @param message The error message
165 * @param cause A nested exception
166 * @param enableSuppression whether or not suppression is enabled or disabled
167 * @param writableStackTrace whether or not the stack trace should be writable
169 public RequestFailedException(String message, Throwable cause, boolean enableSuppression,
170 boolean writableStackTrace) {
171 super(message, cause, enableSuppression, writableStackTrace);
175 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
176 * permitted, and indicates that the cause is nonexistent or unknown.)
178 public RequestFailedException(Throwable cause) {
183 * @return The operation being performed
185 public String getOperation() {
190 * @return The reason for the failure
192 public String getReason() {
197 * @return The server being operated upon
199 public Server getServer() {
204 * @return The id of the server being operated upon
206 public String getServerId() {
211 * @return The status code from the operation
213 public HttpStatus getStatus() {
218 * @param operation The operation being performed
220 public void setOperation(String operation) {
221 this.operation = operation;
225 * @param reason The reason for the failure
227 public void setReason(String reason) {
228 this.reason = reason;
232 * @param server The server being operated upon
234 public void setServer(Server server) {
235 this.server = server;
236 if (server != null) {
237 setServerId(server.getId());
242 * @param serverId The id of the server being operated upon
244 public void setServerId(String serverId) {
245 this.serverId = serverId;
249 * @param status The status of the request
251 public void setStatus(HttpStatus status) {
252 this.status = status;