2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.adapter.iaas.impl;
25 import org.glassfish.grizzly.http.util.HttpStatus;
26 import com.att.cdp.zones.model.Server;
27 import com.att.cdp.zones.model.Stack;
30 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
31 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
32 * diagnostic purposes.
34 public class RequestFailedException extends Exception {
39 private static final long serialVersionUID = 1L;
42 * The operation that was being requested or performed at the time of the failure.
44 private String operation;
47 * A message that details the reason for the failure
49 private String reason;
52 * The server that was being operated upon
54 private Server server;
57 * The stack that was being operated upon
61 * The id of the server being operated upon if the server object is not available (such as the server was not found)
63 private String serverId;
66 * The id of the stack being operated upon if the stack object is not available (such as the stack was not found)
68 private String stackId;
70 * The most appropriate Http Status code that reflects the error
72 private HttpStatus status;
77 public RequestFailedException() {
78 // intentionally empty
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.
94 * The operation being performed
96 * The reason that the operation was failed
98 * The http status code that is most appropriate
100 * The server that we were processing
102 @SuppressWarnings("nls")
103 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
104 super(operation + ":" + reason);
105 this.operation = operation;
106 this.reason = reason;
107 this.status = status;
108 this.server = server;
109 if (server != null) {
110 this.serverId = server.getId();
116 * Construct the request failed exception with the operation being performed, reason for the failure, http status
117 * code that is most appropriate, and the stack we were processing.
120 * The operation being performed
122 * The reason that the operation was failed
124 * The http status code that is most appropriate
126 * The stack that we were processing
128 @SuppressWarnings("nls")
129 public RequestFailedException(String operation, String reason, HttpStatus status, Stack stack) {
130 super(operation + ":" + reason);
131 this.operation = operation;
132 this.reason = reason;
133 this.status = status;
136 this.stackId = stack.getId();
141 * Construct the request failed exception with the operation being performed, reason for the failure, http status
142 * code that is most appropriate, and the server we were processing.
145 * The exception that we are wrapping
147 * The operation being performed
149 * The reason that the operation was failed
151 * The http status code that is most appropriate
153 * The server that we were processing
155 @SuppressWarnings("nls")
156 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
157 super(operation + ":" + reason, ex);
158 this.operation = operation;
159 this.reason = reason;
160 this.status = status;
161 this.server = server;
162 if (server != null) {
163 this.serverId = server.getId();
173 public RequestFailedException(String message, Throwable cause) {
174 super(message, cause);
182 * @param enableSuppression
183 * whether or not suppression is enabled or disabled
184 * @param writableStackTrace
185 * whether or not the stack trace should be writable
187 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
188 super(message, cause, enableSuppression, writableStackTrace);
193 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
194 * permitted, and indicates that the cause is nonexistent or unknown.)
196 public RequestFailedException(Throwable cause) {
201 * @return The operation being performed
203 public String getOperation() {
208 * @return The reason for the failure
210 public String getReason() {
215 * @return The server being operated upon
217 public Server getServer() {
222 * @return The id of the server being operated upon
224 public String getServerId() {
229 * @return The status code from the operation
231 public HttpStatus getStatus() {
237 * The operation being performed
239 public void setOperation(String operation) {
240 this.operation = operation;
245 * The reason for the failure
247 public void setReason(String reason) {
248 this.reason = reason;
253 * The server being operated upon
255 public void setServer(Server server) {
256 this.server = server;
257 if (server != null) {
258 setServerId(server.getId());
264 * The id of the server being operated upon
266 public void setServerId(String serverId) {
267 this.serverId = serverId;
272 * The status of the request
274 public void setStatus(HttpStatus status) {
275 this.status = status;