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=========================================================
22 package org.openecomp.appc.adapter.iaas.impl;
24 import org.glassfish.grizzly.http.util.HttpStatus;
25 import com.att.cdp.zones.model.Server;
26 import com.att.cdp.zones.model.Stack;
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 stack that was being operated upon
60 * The id of the server being operated upon if the server object is not available (such as the server was not found)
62 private String serverId;
65 * The id of the stack being operated upon if the stack object is not available (such as the stack was not found)
67 private String stackId;
69 * The most appropriate Http Status code that reflects the error
71 private HttpStatus status;
76 public RequestFailedException() {
77 // intentionally empty
84 public RequestFailedException(String message) {
89 * Construct the request failed exception with the operation being performed, reason for the failure, http status
90 * code that is most appropriate, and the server we were processing.
93 * The operation being performed
95 * The reason that the operation was failed
97 * The http status code that is most appropriate
99 * The server that we were processing
101 @SuppressWarnings("nls")
102 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
103 super(operation + ":" + reason);
104 this.operation = operation;
105 this.reason = reason;
106 this.status = status;
107 this.server = server;
108 if (server != null) {
109 this.serverId = server.getId();
115 * Construct the request failed exception with the operation being performed, reason for the failure, http status
116 * code that is most appropriate, and the stack we were processing.
119 * The operation being performed
121 * The reason that the operation was failed
123 * The http status code that is most appropriate
125 * The stack that we were processing
127 @SuppressWarnings("nls")
128 public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
129 super(operation + ":" + reason);
130 this.operation = operation;
131 this.reason = reason;
132 this.status = status;
135 this.stackId = stack.getId();
140 * Construct the request failed exception with the operation being performed, reason for the failure, http status
141 * code that is most appropriate, and the server we were processing.
144 * The exception that we are wrapping
146 * The operation being performed
148 * The reason that the operation was failed
150 * The http status code that is most appropriate
152 * The server that we were processing
154 @SuppressWarnings("nls")
155 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
156 super(operation + ":" + reason, ex);
157 this.operation = operation;
158 this.reason = reason;
159 this.status = status;
160 this.server = server;
161 if (server != null) {
162 this.serverId = server.getId();
172 public RequestFailedException(String message, Throwable cause) {
173 super(message, cause);
181 * @param enableSuppression
182 * whether or not suppression is enabled or disabled
183 * @param writableStackTrace
184 * whether or not the stack trace should be writable
186 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
187 super(message, cause, enableSuppression, writableStackTrace);
192 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
193 * permitted, and indicates that the cause is nonexistent or unknown.)
195 public RequestFailedException(Throwable cause) {
200 * @return The operation being performed
202 public String getOperation() {
207 * @return The reason for the failure
209 public String getReason() {
214 * @return The server being operated upon
216 public Server getServer() {
221 * @return The id of the server being operated upon
223 public String getServerId() {
228 * @return The status code from the operation
230 public HttpStatus getStatus() {
236 * The operation being performed
238 public void setOperation(String operation) {
239 this.operation = operation;
244 * The reason for the failure
246 public void setReason(String reason) {
247 this.reason = reason;
252 * The server being operated upon
254 public void setServer(Server server) {
255 this.server = server;
256 if (server != null) {
257 setServerId(server.getId());
263 * The id of the server being operated upon
265 public void setServerId(String serverId) {
266 this.serverId = serverId;
271 * The status of the request
273 public void setStatus(HttpStatus status) {
274 this.status = status;