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
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.
96 * The operation being performed
98 * The reason that the operation was failed
100 * The http status code that is most appropriate
102 * The server that we were processing
104 @SuppressWarnings("nls")
105 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
106 super(operation + ":" + reason);
107 this.operation = operation;
108 this.reason = reason;
109 this.status = status;
110 this.server = server;
111 if (server != null) {
112 this.serverId = server.getId();
118 * Construct the request failed exception with the operation being performed, reason for the failure, http status
119 * code that is most appropriate, and the stack we were processing.
122 * The operation being performed
124 * The reason that the operation was failed
126 * The http status code that is most appropriate
128 * The stack that we were processing
130 @SuppressWarnings("nls")
131 public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
132 super(operation + ":" + reason);
133 this.operation = operation;
134 this.reason = reason;
135 this.status = status;
138 this.stackId = stack.getId();
143 * Construct the request failed exception with the operation being performed, reason for the failure, http status
144 * code that is most appropriate, and the server we were processing.
147 * The exception that we are wrapping
149 * The operation being performed
151 * The reason that the operation was failed
153 * The http status code that is most appropriate
155 * The server that we were processing
157 @SuppressWarnings("nls")
158 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
159 super(operation + ":" + reason, ex);
160 this.operation = operation;
161 this.reason = reason;
162 this.status = status;
163 this.server = server;
164 if (server != null) {
165 this.serverId = server.getId();
175 public RequestFailedException(String message, Throwable cause) {
176 super(message, cause);
184 * @param enableSuppression
185 * whether or not suppression is enabled or disabled
186 * @param writableStackTrace
187 * whether or not the stack trace should be writable
189 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
190 super(message, cause, enableSuppression, writableStackTrace);
195 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
196 * permitted, and indicates that the cause is nonexistent or unknown.)
198 public RequestFailedException(Throwable cause) {
203 * @return The operation being performed
205 public String getOperation() {
210 * @return The reason for the failure
212 public String getReason() {
217 * @return The server being operated upon
219 public Server getServer() {
224 * @return The id of the server being operated upon
226 public String getServerId() {
231 * @return The status code from the operation
233 public HttpStatus getStatus() {
239 * The operation being performed
241 public void setOperation(String operation) {
242 this.operation = operation;
247 * The reason for the failure
249 public void setReason(String reason) {
250 this.reason = reason;
255 * The server being operated upon
257 public void setServer(Server server) {
258 this.server = server;
259 if (server != null) {
260 setServerId(server.getId());
266 * The id of the server being operated upon
268 public void setServerId(String serverId) {
269 this.serverId = serverId;
274 * The status of the request
276 public void setStatus(HttpStatus status) {
277 this.status = status;