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=========================================================
24 package org.onap.appc.adapter.chef.impl;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import java.util.Arrays;
29 import java.util.List;
31 import org.apache.commons.lang.StringUtils;
32 import org.json.JSONException;
33 import org.json.JSONObject;
34 import org.onap.appc.adapter.chef.ChefAdapter;
35 import org.onap.appc.adapter.chef.chefclient.ChefApiClientFactory;
36 import org.onap.appc.adapter.chef.chefclient.api.ChefApiClient;
37 import org.onap.appc.adapter.chef.chefclient.api.ChefResponse;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 * This class implements the {@link ChefAdapter} interface. This interface defines the behaviors that our service
45 public class ChefAdapterImpl implements ChefAdapter {
47 // chef server Initialize variable
48 private String username = StringUtils.EMPTY;
49 private String clientPrivatekey = StringUtils.EMPTY;
50 private String chefserver = StringUtils.EMPTY;
51 private String serverAddress = StringUtils.EMPTY;
52 private String organizations = StringUtils.EMPTY;
54 @SuppressWarnings("nls")
55 public static final String MDC_ADAPTER = "adapter";
57 @SuppressWarnings("nls")
58 public static final String MDC_SERVICE = "service";
60 @SuppressWarnings("nls")
61 public static final String OUTCOME_FAILURE = "failure";
63 @SuppressWarnings("nls")
64 public static final String OUTCOME_SUCCESS = "success";
66 @SuppressWarnings("nls")
67 public static final String PROPERTY_PROVIDER = "provider";
69 @SuppressWarnings("nls")
70 public static final String PROPERTY_PROVIDER_IDENTITY = "identity";
72 @SuppressWarnings("nls")
73 public static final String PROPERTY_PROVIDER_NAME = "name";
75 @SuppressWarnings("nls")
76 public static final String PROPERTY_PROVIDER_TENANT = "tenant";
78 @SuppressWarnings("nls")
79 public static final String PROPERTY_PROVIDER_TENANT_NAME = "name";
81 @SuppressWarnings("nls")
82 public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR
84 @SuppressWarnings("nls")
85 public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid";
87 @SuppressWarnings("nls")
88 public static final String PROPERTY_PROVIDER_TYPE = "type";
91 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefAdapterImpl.class);
93 private static final String CANNOT_FIND_PRIVATE_KEY_STR =
94 "Cannot find the private key in the APPC file system, please load the private key to ";
96 private static final String POSTING_REQUEST_JSON_ERROR_STR = "Error posting request due to invalid JSON block: ";
97 private static final String POSTING_REQUEST_ERROR_STR = "Error posting request: ";
98 private static final String CHEF_CLIENT_RESULT_CODE_STR = "chefClientResult.code";
99 private static final String CHEF_SERVER_RESULT_CODE_STR = "chefServerResult.code";
100 private static final String CHEF_CLIENT_RESULT_MSG_STR = "chefClientResult.message";
101 private static final String CHEF_SERVER_RESULT_MSG_STR = "chefServerResult.message";
102 private static final String CHEF_ACTION_STR = "chefAction";
103 private static final String NODE_LIST_STR = "NodeList";
104 private final ChefApiClientFactory chefApiClientFactory;
105 private final PrivateKeyChecker privateKeyChecker;
107 ChefAdapterImpl(ChefApiClientFactory chefApiClientFactory, PrivateKeyChecker privateKeyChecker) {
108 this.chefApiClientFactory = chefApiClientFactory;
109 this.privateKeyChecker = privateKeyChecker;
110 logger.info("Initialize Chef Adapter");
113 @SuppressWarnings("nls")
115 public void vnfcEnvironment(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
117 logger.info("environment of VNF-C");
118 chefInfo(params, ctx);
119 String env = params.get("Environment");
120 logger.info("Environmnet" + env);
121 if (env.equals(StringUtils.EMPTY)) {
122 chefServerResult(ctx, 200, "Skip Environment block ");
125 if (privateKeyChecker.doesExist(clientPrivatekey)) {
127 JSONObject envJ = new JSONObject(env);
128 String envName = envJ.getString("name");
129 // update the details of an environment on the Chef server.
130 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
131 ChefResponse chefResponse = chefApiClient.put("/environments/" + envName, env);
132 code = chefResponse.getStatusCode();
133 message = chefResponse.getBody();
135 // need create a new environment
136 chefResponse = chefApiClient.post("/environments", env);
137 code = chefResponse.getStatusCode();
138 message = chefResponse.getBody();
139 logger.info("requestbody {}", chefResponse.getBody());
141 chefServerResult(ctx, code, message);
142 } catch (JSONException e) {
144 logger.error(POSTING_REQUEST_JSON_ERROR_STR, e);
145 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
146 } catch (Exception e) {
148 logger.error(POSTING_REQUEST_ERROR_STR, e);
149 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
153 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
154 doFailure(ctx, code, message);
159 @SuppressWarnings("nls")
161 public void vnfcNodeobjects(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
162 logger.info("update the nodeObjects of VNF-C");
165 chefInfo(params, ctx);
166 String nodeListS = params.get(NODE_LIST_STR);
167 String nodeS = params.get("Node");
168 if (StringUtils.isNotBlank(nodeListS) && StringUtils.isNotBlank(nodeS)) {
169 nodeListS = nodeListS.replace("[", StringUtils.EMPTY);
170 nodeListS = nodeListS.replace("]", StringUtils.EMPTY);
171 nodeListS = nodeListS.replace("\"", StringUtils.EMPTY);
172 nodeListS = nodeListS.replace(" ", StringUtils.EMPTY);
173 List<String> nodes = Arrays.asList(nodeListS.split("\\s*,\\s*"));
175 String message = null;
176 if (privateKeyChecker.doesExist(clientPrivatekey)) {
177 ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
179 for (String nodeName: nodes) {
180 JSONObject nodeJ = new JSONObject(nodeS);
181 nodeJ.remove("name");
182 nodeJ.put("name", nodeName);
183 String nodeObject = nodeJ.toString();
184 logger.info(nodeObject);
185 ChefResponse chefResponse = cac.put("/nodes/" + nodeName, nodeObject);
186 code = chefResponse.getStatusCode();
187 message = chefResponse.getBody();
194 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
195 doFailure(ctx, code, message);
197 chefServerResult(ctx, code, message);
199 throw new SvcLogicException("Missing Mandatory param(s) Node , NodeList ");
201 } catch (JSONException e) {
203 logger.error(POSTING_REQUEST_JSON_ERROR_STR, e);
204 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
205 } catch (Exception e) {
207 logger.error(POSTING_REQUEST_ERROR_STR, e);
208 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
213 public void vnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
216 chefInfo(params, ctx);
217 String nodeList = params.get(NODE_LIST_STR);
218 if (StringUtils.isNotBlank(nodeList)) {
219 String isCallback = params.get("CallbackCapable");
220 String chefAction = "/pushy/jobs";
223 if ("true".equals(isCallback)) {
224 String requestId = params.get("RequestId");
225 String callbackUrl = params.get("CallbackUrl");
226 pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
227 + nodeList + "," + "\"env\": {\"RequestId\": \"" + requestId + "\", \"CallbackUrl\": \""
228 + callbackUrl + "\"}," + "\"capture_output\": true" + "}";
230 pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
231 + nodeList + "," + "\"env\": {}," + "\"capture_output\": true" + "}";
233 ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
234 ChefResponse chefResponse = cac.post(chefAction, pushRequest);
235 code = chefResponse.getStatusCode();
236 logger.info("pushRequest:" + pushRequest);
237 logger.info("requestbody: {}", chefResponse.getBody());
238 String message = chefResponse.getBody();
240 int startIndex = message.indexOf("jobs") + 5;
241 int endIndex = message.length() - 2;
242 String jobID = message.substring(startIndex, endIndex);
243 ctx.setAttribute("jobID", jobID);
246 chefServerResult(ctx, code, message);
248 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
250 } catch (Exception e) {
252 logger.error(POSTING_REQUEST_ERROR_STR, e);
253 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
257 @SuppressWarnings("nls")
259 public void fetchResults(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
262 chefInfo(params, ctx);
263 String nodeListS = params.get(NODE_LIST_STR);
264 if (StringUtils.isNotBlank(nodeListS)) {
265 nodeListS = nodeListS.replace("[", StringUtils.EMPTY);
266 nodeListS = nodeListS.replace("]", StringUtils.EMPTY);
267 nodeListS = nodeListS.replace("\"", StringUtils.EMPTY);
268 nodeListS = nodeListS.replace(" ", StringUtils.EMPTY);
269 List<String> nodes = Arrays.asList(nodeListS.split("\\s*,\\s*"));
270 JSONObject result = new JSONObject();
271 String returnMessage = StringUtils.EMPTY;
273 for (String node : nodes) {
274 String chefAction = "/nodes/" + node;
276 if (privateKeyChecker.doesExist(clientPrivatekey)) {
277 ChefResponse chefResponse = getApiMethod(chefAction);
278 code = chefResponse.getStatusCode();
279 message = chefResponse.getBody();
282 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
283 doFailure(ctx, code, message);
286 JSONObject nodeResult = new JSONObject();
287 JSONObject allNodeData = new JSONObject(message);
288 allNodeData = allNodeData.getJSONObject("normal");
289 String attribute = "PushJobOutput";
291 String resultData = allNodeData.optString(attribute);
292 if (resultData == null) {
293 resultData = allNodeData.optJSONObject(attribute).toString();
295 if (resultData == null) {
296 resultData = allNodeData.optJSONArray(attribute).toString();
298 if (resultData == null) {
300 returnMessage = "Cannot find " + attribute;
305 nodeResult.put(attribute, resultData);
306 result.put(node, nodeResult);
307 returnMessage = result.toString();
310 returnMessage = message + " Cannot access: " + node;
311 doFailure(ctx, code, message);
316 chefServerResult(ctx, code, returnMessage);
318 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
320 } catch (JSONException e) {
322 logger.error(POSTING_REQUEST_JSON_ERROR_STR, e);
323 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
324 } catch (Exception e) {
326 logger.error(POSTING_REQUEST_ERROR_STR , e);
327 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
331 private ChefResponse getApiMethod(String chefAction) {
332 ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
333 return cac.get(chefAction);
339 @SuppressWarnings("nls")
341 public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) {
342 logger.info("nodeObejctBuilder");
343 String name = params.get("nodeobject.name");
344 String normal = params.get("nodeobject.normal");
345 String overrides = params.get("nodeobject.overrides");
346 String defaults = params.get("nodeobject.defaults");
347 String runList = params.get("nodeobject.run_list");
348 String chefEnvironment = params.get("nodeobject.chef_environment");
349 String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults
350 + "},\"chef_type\":\"node\",\"run_list\":[" + runList + "],\"override\":{" + overrides
351 + "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\""
352 + chefEnvironment + "\",}";
353 logger.info(nodeObject);
354 ctx.setAttribute("chef.nodeObject", nodeObject);
358 * send get request to chef server
360 private void chefInfo(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
362 username = params.get("username");
363 serverAddress = params.get("serverAddress");
364 organizations = params.get("organizations");
365 if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(serverAddress)
366 && StringUtils.isNotBlank(organizations)) {
367 chefserver = "https://" + serverAddress + "/organizations/" + organizations;
368 clientPrivatekey = "/opt/onap/appc/chef/" + serverAddress + "/" + organizations + "/" + username + ".pem";
369 logger.info(" clientPrivatekey " + clientPrivatekey);
371 doFailure(ctx, 401, "Missing mandatory param(s) such as username, serverAddress, organizations");
375 @SuppressWarnings("nls")
377 public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
378 String allConfigData = params.get("allConfig");
379 String key = params.get("key");
380 String dgContext = params.get("dgContext");
381 JSONObject jsonConfig = new JSONObject(allConfigData);
382 String contextData = fetchContextData(key, jsonConfig);
384 ctx.setAttribute(dgContext, contextData);
387 private String fetchContextData(String key, JSONObject jsonConfig) {
389 return jsonConfig.getString(key);
390 } catch (Exception e) {
391 logger.error("Failed getting string value corresponding to " + key + ". Trying to fetch nested json object", e);
393 return jsonConfig.getJSONObject(key).toString();
394 } catch (Exception ex) {
395 logger.error("Failed getting json object corresponding to " + key + ". Trying to fetch array", ex);
396 return jsonConfig.getJSONArray(key).toString();
401 @SuppressWarnings("nls")
403 public void combineStrings(Map<String, String> params, SvcLogicContext ctx) {
404 String string1 = params.get("String1");
405 String string2 = params.get("String2");
406 String dgContext = params.get("dgContext");
407 String contextData = string1 + string2;
408 ctx.setAttribute(dgContext, contextData);
412 * Send GET request to chef server
414 @SuppressWarnings("nls")
417 public void chefGet(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
418 logger.info("chef get method");
419 chefInfo(params, ctx);
420 String chefAction = params.get(CHEF_ACTION_STR);
424 if (privateKeyChecker.doesExist(clientPrivatekey)) {
425 ChefResponse chefResponse = getApiMethod(chefAction);
426 code = chefResponse.getStatusCode();
427 message = chefResponse.getBody();
430 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
432 chefServerResult(ctx, code, message);
436 * Send PUT request to chef server
438 @SuppressWarnings("nls")
441 public void chefPut(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
442 chefInfo(params, ctx);
443 String chefAction = params.get(CHEF_ACTION_STR);
444 String chefNodeStr = params.get("chefRequestBody");
447 if (privateKeyChecker.doesExist(clientPrivatekey)) {
448 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
450 ChefResponse chefResponse = chefApiClient.put(chefAction, chefNodeStr);
451 code = chefResponse.getStatusCode();
452 message = chefResponse.getBody();
455 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
457 logger.info(code + " " + message);
458 chefServerResult(ctx, code, message);
462 * send Post request to chef server
465 public void chefPost(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
466 chefInfo(params, ctx);
467 logger.info("chef Post method");
468 logger.info(username + " " + clientPrivatekey + " " + chefserver + " " + organizations);
469 String chefNodeStr = params.get("chefRequestBody");
470 String chefAction = params.get(CHEF_ACTION_STR);
474 // should load pem from somewhere else
475 if (privateKeyChecker.doesExist(clientPrivatekey)) {
476 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
478 // need pass path into it
480 ChefResponse chefResponse = chefApiClient.post(chefAction, chefNodeStr);
481 code = chefResponse.getStatusCode();
482 message = chefResponse.getBody();
485 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
487 logger.info(code + " " + message);
488 chefServerResult(ctx, code, message);
492 * send delete request to chef server
495 public void chefDelete(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
496 logger.info("chef delete method");
497 chefInfo(params, ctx);
498 String chefAction = params.get(CHEF_ACTION_STR);
501 if (privateKeyChecker.doesExist(clientPrivatekey)) {
502 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
503 ChefResponse chefResponse = chefApiClient.delete(chefAction);
504 code = chefResponse.getStatusCode();
505 message = chefResponse.getBody();
508 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
510 logger.info(code + " " + message);
511 chefServerResult(ctx, code, message);
515 * Trigger target vm run chef
518 public void trigger(Map<String, String> params, SvcLogicContext svcLogicContext) {
519 logger.info("Run trigger method");
520 String tVmIp = params.get("ip");
523 ChefResponse chefResponse = chefApiClientFactory.create(tVmIp).get("");
524 chefClientResult(svcLogicContext, chefResponse.getStatusCode(), chefResponse.getBody());
525 svcLogicContext.setAttribute("chefAgent.code", "200");
526 } catch (Exception e) {
527 logger.error("An error occurred when executing trigger method", e);
528 svcLogicContext.setAttribute("chefAgent.code", "500");
529 svcLogicContext.setAttribute("chefAgent.message", e.toString());
533 @SuppressWarnings("nls")
535 public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
538 chefInfo(params, ctx);
539 String jobID = params.get("jobid");
540 String retry = params.get("retryTimes");
541 String intrva = params.get("retryInterval");
542 if (StringUtils.isNotBlank(jobID) && StringUtils.isNotBlank(retry) && StringUtils.isNotBlank(intrva)) {
544 int retryTimes = Integer.parseInt(params.get("retryTimes"));
545 int retryInterval = Integer.parseInt(params.get("retryInterval"));
547 String chefAction = "/pushy/jobs/" + jobID;
549 String message = StringUtils.EMPTY;
550 String status = StringUtils.EMPTY;
551 for (int i = 0; i < retryTimes; i++) {
552 sleepFor(retryInterval);
553 ChefResponse chefResponse = getApiMethod(chefAction);
554 code = chefResponse.getStatusCode();
555 message = chefResponse.getBody();
556 JSONObject obj = new JSONObject(message);
557 status = obj.getString("status");
558 if (!"running".equals(status)) {
559 logger.info(i + " time " + code + " " + status);
563 resolveSvcLogicAttributes(ctx, message, status);
565 throw new SvcLogicException("Missing Mandatory param(s) retryTimes , retryInterval ");
567 } catch (Exception e) {
569 logger.error("An error occurred when executing checkPushJob method", e);
570 doFailure(ctx, code, e.getMessage());
574 private void resolveSvcLogicAttributes(SvcLogicContext svcLogic, String message, String status) {
575 if ("complete".equals(status)) {
576 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "200");
577 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, message);
578 } else if ("running".equals(status)) {
579 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "202");
580 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, "chef client runtime out");
582 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "500");
583 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, message);
587 private void sleepFor(int retryInterval) {
589 Thread.sleep(retryInterval); // 1000 milliseconds is one second.
590 } catch (InterruptedException ex) {
591 Thread.currentThread().interrupt();
595 @SuppressWarnings("nls")
597 public void pushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
600 chefInfo(params, ctx);
601 String pushRequest = params.get("pushRequest");
602 String chefAction = "/pushy/jobs";
603 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
604 ChefResponse chefResponse = chefApiClient.post(chefAction, pushRequest);
606 code = chefResponse.getStatusCode();
607 String message = chefResponse.getBody();
609 int startIndex = message.indexOf("jobs") + 6;
610 int endIndex = message.length() - 2;
611 String jobID = message.substring(startIndex, endIndex);
612 ctx.setAttribute("jobID", jobID);
615 chefServerResult(ctx, code, message);
616 } catch (Exception e) {
618 logger.error("An error occurred when executing pushJob method", e);
619 doFailure(ctx, code, e.getMessage());
623 @SuppressWarnings("static-method")
624 private void chefServerResult(SvcLogicContext svcLogicContext, int code, String message) {
625 initSvcLogic(svcLogicContext, code, message, "server");
628 @SuppressWarnings("static-method")
629 private void chefClientResult(SvcLogicContext svcLogicContext, int code, String message) {
630 initSvcLogic(svcLogicContext, code, message, "client");
633 private void initSvcLogic(SvcLogicContext svcLogicContext, int code, String message, String target) {
635 String codeStr = "server".equals(target) ? CHEF_SERVER_RESULT_CODE_STR : CHEF_CLIENT_RESULT_CODE_STR;
636 String messageStr = "client".equals(target) ? CHEF_CLIENT_RESULT_MSG_STR : CHEF_SERVER_RESULT_MSG_STR;
638 svcLogicContext.setStatus(OUTCOME_SUCCESS);
639 svcLogicContext.setAttribute(codeStr, Integer.toString(code));
640 svcLogicContext.setAttribute(messageStr, message);
641 logger.info(codeStr + ": " + svcLogicContext.getAttribute(codeStr));
642 logger.info(messageStr + ": " + svcLogicContext.getAttribute(messageStr));
645 @SuppressWarnings("static-method")
646 private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException {
648 String cutMessage = message.contains("\n") ? message.substring(message.indexOf('\n')) : message;
650 svcLogic.setStatus(OUTCOME_FAILURE);
651 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, Integer.toString(code));
652 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, cutMessage);
654 throw new SvcLogicException("Chef Adapter error:" + cutMessage);