diff options
author | Patrick Brady <pb071s@att.com> | 2017-06-01 10:45:37 -0700 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-06-02 13:05:15 -0700 |
commit | c7d0075d223eab9f89fd28853c4b138792059be9 (patch) | |
tree | 40aa3e41e598ea7a59bcf6899a2004c1abab11c2 /appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src | |
parent | 8aac2df744820304ee29354333661699e9695939 (diff) |
Merge of new rebased code
Change-Id: I9b8d1f69eb3e0af1935ed8304fea4bf54c1aac47
Signed-off-by: Patrick Brady <pb071s@att.com>
Diffstat (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src')
7 files changed, 397 insertions, 274 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/ChefAdapter.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/ChefAdapter.java index 907ded5d2..7859d6bbc 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/ChefAdapter.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/ChefAdapter.java @@ -199,5 +199,19 @@ public interface ChefAdapter extends SvcLogicJavaPlugin { void chefGet(Map<String, String> params, SvcLogicContext ctx) ; void chefPut(Map<String, String> params, SvcLogicContext ctx) ; + +void chefPost(Map<String, String> params, SvcLogicContext ctx) ; + + void chefDelete(Map<String, String> params, SvcLogicContext ctx) ; + + void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) ; + + void checkPushJob(Map<String, String> params, SvcLogicContext ctx) ; + + void pushJob(Map<String, String> params, SvcLogicContext ctx) ; + + void retrieveData (Map<String, String> params, SvcLogicContext ctx) ; + + void combineStrings (Map<String, String> params, SvcLogicContext ctx) ; } diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/Delete.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/Delete.java new file mode 100644 index 000000000..410f00a94 --- /dev/null +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/Delete.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.chef.chefapi; + +import org.apache.http.client.methods.HttpDelete; + +public class Delete extends ApiMethod{ + + public Delete(HttpDelete method) { + super("DELETE"); + this.method = method; + } + +} diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/Post.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/Post.java new file mode 100644 index 000000000..7dc8baa40 --- /dev/null +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefapi/Post.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.chef.chefapi; + +import org.apache.http.client.methods.*; +import org.apache.http.entity.StringEntity; + +public class Post extends ApiMethod{ + + public Post(HttpRequestBase method) { + super("POST"); + this.method = method; + } + + public ApiMethod body(String body){ + this.reqBody = body; + StringEntity params =new StringEntity (body,"UTF-8"); + params.setContentType("application/json"); + HttpPost post = (HttpPost) method; + post.setEntity(params); + return this; + } + +} diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/ChefApiClient.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/ChefApiClient.java index 743fe8456..ca36aa4b6 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/ChefApiClient.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/ChefApiClient.java @@ -67,4 +67,28 @@ public class ChefApiClient { put.setChefPath(path); return put; } + public Post post(String path){ + Post post = new Post(new HttpPost(endpoint+path)); + post.setPemPath(pemPath); + post.setUserId(userId); + post.setOrganizations(organizations); + post.setChefPath(path); + return post; + } + + public Delete delete(String path){ + Delete del = new Delete(new HttpDelete(endpoint+path)); + del.setPemPath(pemPath); + del.setUserId(userId); + del.setOrganizations(organizations); + del.setChefPath(path); + return del; + } + + +/* public Header[] buildHeaders(){ + + return null; + } +*/ } diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/Utils.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/Utils.java index d814762f8..cb479fc2e 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/Utils.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/chefclient/Utils.java @@ -35,8 +35,10 @@ import java.security.Signature; import java.security.SignatureException; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openssl.PEMReader; +import org.bouncycastle.openssl.PEMParser; import org.bouncycastle.util.encoders.Base64; +import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; +import org.bouncycastle.openssl.PEMKeyPair; public class Utils { private Utils(){} @@ -66,7 +68,10 @@ public class Utils { Security.addProvider(new BouncyCastleProvider()); try { - KeyPair kp = (KeyPair) new PEMReader(br).readObject(); + PEMParser pemParser = new PEMParser(br); + JcaPEMKeyConverter converter = new JcaPEMKeyConverter(); + Object object = pemParser.readObject(); + KeyPair kp = converter.getKeyPair((PEMKeyPair) object);; PrivateKey privateKey = kp.getPrivate(); Signature instance = Signature.getInstance("RSA"); instance.initSign(privateKey); diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java index 5985bcfd1..01e256d08 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java @@ -78,6 +78,23 @@ import static com.att.eelf.configuration.Configuration.*; import java.io.IOException; import java.net.InetAddress; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Properties; +//chef +import org.openecomp.appc.adapter.chef.chefapi.*; +import org.openecomp.appc.adapter.chef.chefclient.*; + +//json +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; /** * This class implements the {@link ChefAdapter} interface. This interface * defines the behaviors that our service provides. @@ -279,6 +296,94 @@ public class ChefAdapterImpl implements ChefAdapter { * org.openecomp.sdnc.sli.SvcLogicContext) */ + + /** + * build node object + */ + + @SuppressWarnings("nls") + @Override + public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) { + logger.info("nodeObejctBuilder"); + String name = params.get("org.openecomp.appc.instance.nodeobject.name"); + String normal = params.get("org.openecomp.appc.instance.nodeobject.normal"); + String overrides = params.get("org.openecomp.appc.instance.nodeobject.overrides"); + String defaults = params.get("org.openecomp.appc.instance.nodeobject.defaults"); + String run_list = params.get("org.openecomp.appc.instance.nodeobject.run_list"); + String chef_environment = params.get("org.openecomp.appc.instance.nodeobject.chef_environment"); + String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults + + "},\"chef_type\":\"node\",\"run_list\":[" + run_list + "],\"override\":{" + overrides + + "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\"" + + chef_environment + "\"}"; + logger.info(nodeObject); + + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + svcLogic.setAttribute("org.openecomp.appc.chef.nodeObject", nodeObject); + + } + + /** + * Send get request to chef server + */ + + public void chefInfo(Map<String, String> params) { + clientName = params.get("org.openecomp.appc.instance.username"); + serverAddress = params.get("org.openecomp.appc.instance.serverAddress"); + organizations = params.get("org.openecomp.appc.instance.organizations"); + chefserver = "https://" + serverAddress + "/organizations/" + organizations; + clientPrivatekey = "/opt/openecomp/appc/chef/" + serverAddress + "/" + organizations + "/" + clientName + ".pem"; + } + + public Boolean privateKeyCheck() { + File f = new File(clientPrivatekey); + if (f.exists()) { + return true; + } else { + return false; + } + } + + @SuppressWarnings("nls") + @Override + public void retrieveData(Map<String, String> params, SvcLogicContext ctx) { + String contextData = "someValue"; + String allConfigData = params.get("org.openecomp.appc.instance.allConfig"); + String key = params.get("org.openecomp.appc.instance.key"); + String dgContext = params.get("org.openecomp.appc.instance.dgContext"); + JSONObject josnConfig = new JSONObject(allConfigData); + try { + contextData = josnConfig.getString(key); + } catch (Exception ex) { + try { + contextData = josnConfig.getJSONObject(key).toString(); + } catch (Exception exc) { + contextData = josnConfig.getJSONArray(key).toString(); + } + } + + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + svcLogic.setAttribute(dgContext, contextData); + } + + @SuppressWarnings("nls") + @Override + public void combineStrings(Map<String, String> params, SvcLogicContext ctx) { + + String String1 = params.get("org.openecomp.appc.instance.String1"); + String String2 = params.get("org.openecomp.appc.instance.String2"); + String dgContext = params.get("org.openecomp.appc.instance.dgContext"); + String contextData = String1 + String2; + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + svcLogic.setAttribute(dgContext, contextData); + } + + /** * Send GET request to chef server */ @@ -287,19 +392,25 @@ public class ChefAdapterImpl implements ChefAdapter { @Override public void chefGet(Map<String, String> params, SvcLogicContext ctx) { logger.info("chef get method"); - String chefAction= params.get("org.openecomp.appc.instance.chefAction"); + chefInfo(params); + String chefAction = params.get("org.openecomp.appc.instance.chefAction"); RequestContext rc = new RequestContext(ctx); rc.isAlive(); - //should load pem from somewhere else - ChefApiClient cac = new ChefApiClient(clientName,clientPrivatekey,chefserver,organizations); - // need pass path into it - //"/nodes" - ApiMethod am = cac.get(chefAction); - am.execute(); - int code = am.getReturnCode(); - String message = am.getResponseBodyAsString(); - logger.info(code + " " + message); - chefServerResult(rc,Integer.toString(code),message); + int code; + String message = null; + if (privateKeyCheck()) { + ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations); + ApiMethod am = cac.get(chefAction); + am.execute(); + code = am.getReturnCode(); + message = am.getResponseBodyAsString(); + } else { + code = 500; + message = "Cannot find the private key in the APPC file system, please load the private key to " + + clientPrivatekey; + } + chefServerResult(rc, Integer.toString(code), message); + } /** @@ -309,29 +420,93 @@ public class ChefAdapterImpl implements ChefAdapter { @SuppressWarnings("nls") @Override public void chefPut(Map<String, String> params, SvcLogicContext ctx) { - - logger.info("chef PUT method"); - logger.info(clientName+" "+clientPrivatekey+" "+chefserver+" "+organizations); - String chefAction= params.get("org.openecomp.appc.instance.chefAction"); - String runList= params.get("org.openecomp.appc.instance.runList"); - String attributes= params.get("org.openecomp.appc.instance.attributes"); - logger.info(attributes); - String CHEF_NODE_STR = "{\"json_class\":\"Chef::Node\",\"default\":{},\"chef_type\":\"node\",\"run_list\":[\""+runList+"\"],\"override\":{},\"automatic\":{},\"normal\":{"+attributes+"},\"name\":\"testnode\",\"chef_environment\":\"_default\"}"; + chefInfo(params); + String chefAction = params.get("org.openecomp.appc.instance.chefAction"); + String CHEF_NODE_STR = params.get("org.openecomp.appc.instance.chefRequestBody"); RequestContext rc = new RequestContext(ctx); rc.isAlive(); - //should load pem from somewhere else - ChefApiClient cac = new ChefApiClient(clientName,clientPrivatekey,chefserver,organizations); - - // need pass path into it - //"/nodes/testnode" - ApiMethod am = cac.put(chefAction).body(CHEF_NODE_STR); - am.execute(); - int code = am.getReturnCode(); - String message = am.getResponseBodyAsString(); + int code; + String message = null; + if (privateKeyCheck()) { + ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations); + + ApiMethod am = cac.put(chefAction).body(CHEF_NODE_STR); + am.execute(); + code = am.getReturnCode(); + message = am.getResponseBodyAsString(); + } else { + code = 500; + message = "Cannot find the private key in the APPC file system, please load the private key to " + + clientPrivatekey; + } logger.info(code + " " + message); - chefServerResult(rc,Integer.toString(code),message); + chefServerResult(rc, Integer.toString(code), message); + } + /** + * Send Post request to chef server + */ + + @SuppressWarnings("nls") + @Override + public void chefPost(Map<String, String> params, SvcLogicContext ctx) { + chefInfo(params); + logger.info("chef Post method"); + logger.info(clientName + " " + clientPrivatekey + " " + chefserver + " " + organizations); + String CHEF_NODE_STR = params.get("org.openecomp.appc.instance.chefRequestBody"); + String chefAction = params.get("org.openecomp.appc.instance.chefAction"); + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + int code; + String message = null; + // should load pem from somewhere else + if (privateKeyCheck()) { + ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations); + + // need pass path into it + // "/nodes/testnode" + ApiMethod am = cac.post(chefAction).body(CHEF_NODE_STR); + am.execute(); + code = am.getReturnCode(); + message = am.getResponseBodyAsString(); + } else { + code = 500; + message = "Cannot find the private key in the APPC file system, please load the private key to " + + clientPrivatekey; + } + logger.info(code + " " + message); + chefServerResult(rc, Integer.toString(code), message); + } + + /** + * Send delete request to chef server + */ + + @SuppressWarnings("nls") + @Override + public void chefDelete(Map<String, String> params, SvcLogicContext ctx) { + logger.info("chef delete method"); + chefInfo(params); + String chefAction = params.get("org.openecomp.appc.instance.chefAction"); + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + int code; + String message = null; + if (privateKeyCheck()) { + ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations); + ApiMethod am = cac.delete(chefAction); + am.execute(); + code = am.getReturnCode(); + message = am.getResponseBodyAsString(); + } else { + code = 500; + message = "Cannot find the private key in the APPC file system, please load the private key to " + + clientPrivatekey; + } + logger.info(code + " " + message); + chefServerResult(rc, Integer.toString(code), message); + } /** @@ -362,6 +537,78 @@ public class ChefAdapterImpl implements ChefAdapter { } + @SuppressWarnings("nls") + @Override + public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) { + chefInfo(params); + String jobID = params.get("org.openecomp.appc.instance.jobid"); + int retryTimes = Integer.parseInt(params.get("org.openecomp.appc.instance.retryTimes")); + int retryInterval = Integer.parseInt(params.get("org.openecomp.appc.instance.retryInterval")); + String chefAction = "/pushy/jobs/" + jobID; + + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + String message = ""; + String status = ""; + for (int i = 0; i < retryTimes; i++) { + try { + Thread.sleep(retryInterval); // 1000 milliseconds is one second. + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations); + ApiMethod am = cac.get(chefAction); + am.execute(); + int code = am.getReturnCode(); + message = am.getResponseBodyAsString(); + JSONObject obj = new JSONObject(message); + status = obj.getString("status"); + if (!status.equals("running")) { + logger.info(i + " time " + code + " " + status); + break; + } + + } + if (status.equals("complete")) { + svcLogic.setAttribute("org.openecomp.appc.chefServerResult.code", "200"); + svcLogic.setAttribute("org.openecomp.appc.chefServerResult.message", message); + } else { + if (status.equals("running")) { + svcLogic.setAttribute("org.openecomp.appc.chefServerResult.code", "202"); + svcLogic.setAttribute("org.openecomp.appc.chefServerResult.message", "chef client runtime out"); + } else { + svcLogic.setAttribute("org.openecomp.appc.chefServerResult.code", "500"); + svcLogic.setAttribute("org.openecomp.appc.chefServerResult.message", message); + } + } + } + + + @SuppressWarnings("nls") + @Override + public void pushJob(Map<String, String> params, SvcLogicContext ctx) { + chefInfo(params); + String pushRequest = params.get("org.openecomp.appc.instance.pushRequest"); + String chefAction = "/pushy/jobs"; + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations); + ApiMethod am = cac.post(chefAction).body(pushRequest); + ; + am.execute(); + int code = am.getReturnCode(); + String message = am.getResponseBodyAsString(); + if (code == 201) { + int startIndex = message.indexOf("jobs") + 6; + int endIndex = message.length() - 2; + String jobID = message.substring(startIndex, endIndex); + svcLogic.setAttribute("org.openecomp.appc.jobID", jobID); + logger.info(jobID); + } + chefServerResult(rc, Integer.toString(code), message); + } @SuppressWarnings("static-method") diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/RequestFailedException.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/RequestFailedException.java deleted file mode 100644 index 047eb8b1f..000000000 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/RequestFailedException.java +++ /dev/null @@ -1,243 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - - -package org.openecomp.appc.adapter.chef.impl; - -import org.glassfish.grizzly.http.util.HttpStatus; -import com.att.cdp.zones.model.Server; - -/** - * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used - * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for - * diagnostic purposes. - */ -public class RequestFailedException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * The operation that was being requested or performed at the time of the failure. - */ - private String operation; - - /** - * A message that details the reason for the failure - */ - private String reason; - - /** - * The server that was being operated upon - */ - private Server server; - - /** - * The id of the server being operated upon if the server object is not available (such as the server was not found) - */ - private String serverId; - - /** - * The most appropriate Http Status code that reflects the error - */ - private HttpStatus status; - - /** - * - */ - public RequestFailedException() { - // intentionally empty - } - - /** - * @param message - * The error message - */ - public RequestFailedException(String message) { - super(message); - } - - /** - * Construct the request failed exception with the operation being performed, reason for the failure, http status - * code that is most appropriate, and the server we were processing. - * - * @param operation - * The operation being performed - * @param reason - * The reason that the operation was failed - * @param status - * The http status code that is most appropriate - * @param server - * The server that we were processing - */ - @SuppressWarnings("nls") - public RequestFailedException(String operation, String reason, HttpStatus status, Server server) { - super(operation + ":" + reason); - this.operation = operation; - this.reason = reason; - this.status = status; - this.server = server; - if (server != null) { - this.serverId = server.getId(); - } - } - - /** - * Construct the request failed exception with the operation being performed, reason for the failure, http status - * code that is most appropriate, and the server we were processing. - * - * @param ex - * The exception that we are wrapping - * @param operation - * The operation being performed - * @param reason - * The reason that the operation was failed - * @param status - * The http status code that is most appropriate - * @param server - * The server that we were processing - */ - @SuppressWarnings("nls") - public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) { - super(operation + ":" + reason, ex); - this.operation = operation; - this.reason = reason; - this.status = status; - this.server = server; - if (server != null) { - this.serverId = server.getId(); - } - } - - /** - * @param message - * The error message - * @param cause - * A nested exception - */ - public RequestFailedException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param message - * The error message - * @param cause - * A nested exception - * @param enableSuppression - * whether or not suppression is enabled or disabled - * @param writableStackTrace - * whether or not the stack trace should be writable - */ - public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } - - /** - * @param cause - * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or unknown.) - */ - public RequestFailedException(Throwable cause) { - super(cause); - } - - /** - * @return The operation being performed - */ - public String getOperation() { - return operation; - } - - /** - * @return The reason for the failure - */ - public String getReason() { - return reason; - } - - /** - * @return The server being operated upon - */ - public Server getServer() { - return server; - } - - /** - * @return The id of the server being operated upon - */ - public String getServerId() { - return serverId; - } - - /** - * @return The status code from the operation - */ - public HttpStatus getStatus() { - return status; - } - - /** - * @param operation - * The operation being performed - */ - public void setOperation(String operation) { - this.operation = operation; - } - - /** - * @param reason - * The reason for the failure - */ - public void setReason(String reason) { - this.reason = reason; - } - - /** - * @param server - * The server being operated upon - */ - public void setServer(Server server) { - this.server = server; - if (server != null) { - setServerId(server.getId()); - } - } - - /** - * @param serverId - * The id of the server being operated upon - */ - public void setServerId(String serverId) { - this.serverId = serverId; - } - - /** - * @param status - * The status of the request - */ - public void setStatus(HttpStatus status) { - this.status = status; - } - -} |