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 java.util.Optional;
32 import org.apache.commons.lang.StringUtils;
33 import org.json.JSONException;
34 import org.json.JSONObject;
35 import org.onap.appc.adapter.chef.ChefAdapter;
36 import org.onap.appc.adapter.chef.chefclient.ChefApiClientFactory;
37 import org.onap.appc.adapter.chef.chefclient.api.ChefApiClient;
38 import org.onap.appc.adapter.chef.chefclient.api.ChefResponse;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
43 * This class implements the {@link ChefAdapter} interface. This interface defines the behaviors that our service
46 public class ChefAdapterImpl implements ChefAdapter {
48 // chef server Initialize variable
49 private String username = StringUtils.EMPTY;
50 private String clientPrivatekey = StringUtils.EMPTY;
51 private String chefserver = StringUtils.EMPTY;
52 private String serverAddress = StringUtils.EMPTY;
53 private String organizations = StringUtils.EMPTY;
55 @SuppressWarnings("nls")
56 public static final String MDC_ADAPTER = "adapter";
58 @SuppressWarnings("nls")
59 public static final String MDC_SERVICE = "service";
61 @SuppressWarnings("nls")
62 public static final String OUTCOME_FAILURE = "failure";
64 @SuppressWarnings("nls")
65 public static final String OUTCOME_SUCCESS = "success";
67 @SuppressWarnings("nls")
68 public static final String PROPERTY_PROVIDER = "provider";
70 @SuppressWarnings("nls")
71 public static final String PROPERTY_PROVIDER_IDENTITY = "identity";
73 @SuppressWarnings("nls")
74 public static final String PROPERTY_PROVIDER_NAME = "name";
76 @SuppressWarnings("nls")
77 public static final String PROPERTY_PROVIDER_TENANT = "tenant";
79 @SuppressWarnings("nls")
80 public static final String PROPERTY_PROVIDER_TENANT_NAME = "name";
82 @SuppressWarnings("nls")
83 public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR
85 @SuppressWarnings("nls")
86 public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid";
88 @SuppressWarnings("nls")
89 public static final String PROPERTY_PROVIDER_TYPE = "type";
92 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefAdapterImpl.class);
94 private static final String CANNOT_FIND_PRIVATE_KEY_STR =
95 "Cannot find the private key in the APPC file system, please load the private key to ";
97 private static final String POSTING_REQUEST_JSON_ERROR_STR = "Error posting request due to invalid JSON block: ";
98 private static final String POSTING_REQUEST_ERROR_STR = "Error posting request: ";
99 private static final String CHEF_CLIENT_RESULT_CODE_STR = "chefClientResult.code";
100 private static final String CHEF_SERVER_RESULT_CODE_STR = "chefServerResult.code";
101 private static final String CHEF_CLIENT_RESULT_MSG_STR = "chefClientResult.message";
102 private static final String CHEF_SERVER_RESULT_MSG_STR = "chefServerResult.message";
103 private static final String CHEF_ACTION_STR = "chefAction";
104 private static final String NODE_LIST_STR = "NodeList";
105 private final ChefApiClientFactory chefApiClientFactory;
106 private final PrivateKeyChecker privateKeyChecker;
108 ChefAdapterImpl(ChefApiClientFactory chefApiClientFactory, PrivateKeyChecker privateKeyChecker) {
109 this.chefApiClientFactory = chefApiClientFactory;
110 this.privateKeyChecker = privateKeyChecker;
111 logger.info("Initialize Chef Adapter");
114 @SuppressWarnings("nls")
116 public void vnfcEnvironment(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
118 logger.info("environment of VNF-C");
119 chefInfo(params, ctx);
120 String env = params.get("Environment");
121 logger.info("Environmnet" + env);
122 if (env.equals(StringUtils.EMPTY)) {
123 chefServerResult(ctx, 200, "Skip Environment block ");
126 if (privateKeyChecker.doesExist(clientPrivatekey)) {
128 JSONObject envJ = new JSONObject(env);
129 String envName = envJ.getString("name");
130 // update the details of an environment on the Chef server.
131 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
132 ChefResponse chefResponse = chefApiClient.put("/environments/" + envName, env);
133 code = chefResponse.getStatusCode();
134 message = chefResponse.getBody();
136 // need create a new environment
137 chefResponse = chefApiClient.post("/environments", env);
138 code = chefResponse.getStatusCode();
139 message = chefResponse.getBody();
140 logger.info("requestbody {}", chefResponse.getBody());
142 chefServerResult(ctx, code, message);
143 } catch (JSONException e) {
145 logger.error(POSTING_REQUEST_JSON_ERROR_STR, e);
146 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
147 } catch (Exception e) {
149 logger.error(POSTING_REQUEST_ERROR_STR, e);
150 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
154 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
155 doFailure(ctx, code, message);
160 @SuppressWarnings("nls")
162 public void vnfcNodeobjects(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
163 logger.info("update the nodeObjects of VNF-C");
166 chefInfo(params, ctx);
167 String nodeListS = params.get(NODE_LIST_STR);
168 String nodeS = params.get("Node");
169 if (StringUtils.isNotBlank(nodeListS) && StringUtils.isNotBlank(nodeS)) {
170 nodeListS = nodeListS.replace("[", StringUtils.EMPTY);
171 nodeListS = nodeListS.replace("]", StringUtils.EMPTY);
172 nodeListS = nodeListS.replace("\"", StringUtils.EMPTY);
173 nodeListS = nodeListS.replace(" ", StringUtils.EMPTY);
174 List<String> nodes = Arrays.asList(nodeListS.split("\\s*,\\s*"));
176 String message = null;
177 if (privateKeyChecker.doesExist(clientPrivatekey)) {
178 ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
180 for (String nodeName: nodes) {
181 JSONObject nodeJ = new JSONObject(nodeS);
182 nodeJ.remove("name");
183 nodeJ.put("name", nodeName);
184 String nodeObject = nodeJ.toString();
185 logger.info(nodeObject);
186 ChefResponse chefResponse = cac.put("/nodes/" + nodeName, nodeObject);
187 code = chefResponse.getStatusCode();
188 message = chefResponse.getBody();
195 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
196 doFailure(ctx, code, message);
198 chefServerResult(ctx, code, message);
200 throw new SvcLogicException("Missing Mandatory param(s) Node , NodeList ");
202 } catch (JSONException e) {
204 logger.error(POSTING_REQUEST_JSON_ERROR_STR, e);
205 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
206 } catch (Exception e) {
208 logger.error(POSTING_REQUEST_ERROR_STR, e);
209 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
214 public void vnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
217 chefInfo(params, ctx);
218 String nodeList = params.get(NODE_LIST_STR);
219 if (StringUtils.isNotBlank(nodeList)) {
220 String isCallback = params.get("CallbackCapable");
221 String chefAction = "/pushy/jobs";
224 if ("true".equals(isCallback)) {
225 String requestId = params.get("RequestId");
226 String callbackUrl = params.get("CallbackUrl");
227 pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
228 + nodeList + "," + "\"env\": {\"RequestId\": \"" + requestId + "\", \"CallbackUrl\": \""
229 + callbackUrl + "\"}," + "\"capture_output\": true" + "}";
231 pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
232 + nodeList + "," + "\"env\": {}," + "\"capture_output\": true" + "}";
234 ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
235 ChefResponse chefResponse = cac.post(chefAction, pushRequest);
236 code = chefResponse.getStatusCode();
237 logger.info("pushRequest:" + pushRequest);
238 logger.info("requestbody: {}", chefResponse.getBody());
239 String message = chefResponse.getBody();
241 int startIndex = message.indexOf("jobs") + 5;
242 int endIndex = message.length() - 2;
243 String jobID = message.substring(startIndex, endIndex);
244 ctx.setAttribute("jobID", jobID);
247 chefServerResult(ctx, code, message);
249 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
251 } catch (Exception e) {
253 logger.error(POSTING_REQUEST_ERROR_STR, e);
254 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
258 @SuppressWarnings("nls")
260 public void fetchResults(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
263 chefInfo(params, ctx);
264 String nodeListS = params.get(NODE_LIST_STR);
265 if (StringUtils.isNotBlank(nodeListS)) {
266 nodeListS = nodeListS.replace("[", StringUtils.EMPTY);
267 nodeListS = nodeListS.replace("]", StringUtils.EMPTY);
268 nodeListS = nodeListS.replace("\"", StringUtils.EMPTY);
269 nodeListS = nodeListS.replace(" ", StringUtils.EMPTY);
270 List<String> nodes = Arrays.asList(nodeListS.split("\\s*,\\s*"));
271 JSONObject result = new JSONObject();
272 String returnMessage = StringUtils.EMPTY;
274 for (String node : nodes) {
275 String chefAction = "/nodes/" + node;
277 if (privateKeyChecker.doesExist(clientPrivatekey)) {
278 ChefResponse chefResponse = getApiMethod(chefAction);
279 code = chefResponse.getStatusCode();
280 message = chefResponse.getBody();
283 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
284 doFailure(ctx, code, message);
287 JSONObject nodeResult = new JSONObject();
288 JSONObject allNodeData = new JSONObject(message);
289 allNodeData = allNodeData.getJSONObject("normal");
290 String attribute = "PushJobOutput";
292 String resultData = allNodeData.optString(attribute, null);
293 if (resultData == null) {
294 resultData = Optional.ofNullable(allNodeData.optJSONObject(attribute))
295 .map(p -> p.toString()).orElse(null);
296 if (resultData == null) {
297 resultData = Optional.ofNullable(allNodeData.optJSONArray(attribute))
298 .map(p -> p.toString()).orElse(null);
300 if (resultData == null) {
302 returnMessage = "Cannot find " + attribute;
307 nodeResult.put(attribute, resultData);
308 result.put(node, nodeResult);
309 returnMessage = result.toString();
312 returnMessage = message + " Cannot access: " + node;
313 doFailure(ctx, code, message);
318 chefServerResult(ctx, code, returnMessage);
320 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
322 } catch (JSONException e) {
324 logger.error(POSTING_REQUEST_JSON_ERROR_STR, e);
325 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
326 } catch (Exception e) {
328 logger.error(POSTING_REQUEST_ERROR_STR , e);
329 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
333 private ChefResponse getApiMethod(String chefAction) {
334 ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
335 return cac.get(chefAction);
341 @SuppressWarnings("nls")
343 public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) {
344 logger.info("nodeObejctBuilder");
345 String name = params.get("nodeobject.name");
346 String normal = params.get("nodeobject.normal");
347 String overrides = params.get("nodeobject.overrides");
348 String defaults = params.get("nodeobject.defaults");
349 String runList = params.get("nodeobject.run_list");
350 String chefEnvironment = params.get("nodeobject.chef_environment");
351 String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults
352 + "},\"chef_type\":\"node\",\"run_list\":[" + runList + "],\"override\":{" + overrides
353 + "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\""
354 + chefEnvironment + "\",}";
355 logger.info(nodeObject);
356 ctx.setAttribute("chef.nodeObject", nodeObject);
360 * send get request to chef server
362 private void chefInfo(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
364 username = params.get("username");
365 serverAddress = params.get("serverAddress");
366 organizations = params.get("organizations");
367 if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(serverAddress)
368 && StringUtils.isNotBlank(organizations)) {
369 chefserver = "https://" + serverAddress + "/organizations/" + organizations;
370 clientPrivatekey = "/opt/onap/appc/chef/" + serverAddress + "/" + organizations + "/" + username + ".pem";
371 logger.info(" clientPrivatekey " + clientPrivatekey);
373 doFailure(ctx, 401, "Missing mandatory param(s) such as username, serverAddress, organizations");
377 @SuppressWarnings("nls")
379 public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
380 String allConfigData = params.get("allConfig");
381 String key = params.get("key");
382 String dgContext = params.get("dgContext");
383 JSONObject jsonConfig = new JSONObject(allConfigData);
384 String contextData = fetchContextData(key, jsonConfig);
386 ctx.setAttribute(dgContext, contextData);
389 private String fetchContextData(String key, JSONObject jsonConfig) {
391 return jsonConfig.getString(key);
392 } catch (Exception e) {
393 logger.error("Failed getting string value corresponding to " + key + ". Trying to fetch nested json object", e);
395 return jsonConfig.getJSONObject(key).toString();
396 } catch (Exception ex) {
397 logger.error("Failed getting json object corresponding to " + key + ". Trying to fetch array", ex);
398 return jsonConfig.getJSONArray(key).toString();
403 @SuppressWarnings("nls")
405 public void combineStrings(Map<String, String> params, SvcLogicContext ctx) {
406 String string1 = params.get("String1");
407 String string2 = params.get("String2");
408 String dgContext = params.get("dgContext");
409 String contextData = string1 + string2;
410 ctx.setAttribute(dgContext, contextData);
414 * Send GET request to chef server
416 @SuppressWarnings("nls")
419 public void chefGet(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
420 logger.info("chef get method");
421 chefInfo(params, ctx);
422 String chefAction = params.get(CHEF_ACTION_STR);
426 if (privateKeyChecker.doesExist(clientPrivatekey)) {
427 ChefResponse chefResponse = getApiMethod(chefAction);
428 code = chefResponse.getStatusCode();
429 message = chefResponse.getBody();
432 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
434 chefServerResult(ctx, code, message);
438 * Send PUT request to chef server
440 @SuppressWarnings("nls")
443 public void chefPut(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
444 chefInfo(params, ctx);
445 String chefAction = params.get(CHEF_ACTION_STR);
446 String chefNodeStr = params.get("chefRequestBody");
449 if (privateKeyChecker.doesExist(clientPrivatekey)) {
450 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
452 ChefResponse chefResponse = chefApiClient.put(chefAction, chefNodeStr);
453 code = chefResponse.getStatusCode();
454 message = chefResponse.getBody();
457 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
459 logger.info(code + " " + message);
460 chefServerResult(ctx, code, message);
464 * send Post request to chef server
467 public void chefPost(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
468 chefInfo(params, ctx);
469 logger.info("chef Post method");
470 logger.info(username + " " + clientPrivatekey + " " + chefserver + " " + organizations);
471 String chefNodeStr = params.get("chefRequestBody");
472 String chefAction = params.get(CHEF_ACTION_STR);
476 // should load pem from somewhere else
477 if (privateKeyChecker.doesExist(clientPrivatekey)) {
478 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
480 // need pass path into it
482 ChefResponse chefResponse = chefApiClient.post(chefAction, chefNodeStr);
483 code = chefResponse.getStatusCode();
484 message = chefResponse.getBody();
487 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
489 logger.info(code + " " + message);
490 chefServerResult(ctx, code, message);
494 * send delete request to chef server
497 public void chefDelete(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
498 logger.info("chef delete method");
499 chefInfo(params, ctx);
500 String chefAction = params.get(CHEF_ACTION_STR);
503 if (privateKeyChecker.doesExist(clientPrivatekey)) {
504 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
505 ChefResponse chefResponse = chefApiClient.delete(chefAction);
506 code = chefResponse.getStatusCode();
507 message = chefResponse.getBody();
510 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
512 logger.info(code + " " + message);
513 chefServerResult(ctx, code, message);
517 * Trigger target vm run chef
520 public void trigger(Map<String, String> params, SvcLogicContext svcLogicContext) {
521 logger.info("Run trigger method");
522 String tVmIp = params.get("ip");
525 ChefResponse chefResponse = chefApiClientFactory.create(tVmIp).get("");
526 chefClientResult(svcLogicContext, chefResponse.getStatusCode(), chefResponse.getBody());
527 svcLogicContext.setAttribute("chefAgent.code", "200");
528 } catch (Exception e) {
529 logger.error("An error occurred when executing trigger method", e);
530 svcLogicContext.setAttribute("chefAgent.code", "500");
531 svcLogicContext.setAttribute("chefAgent.message", e.toString());
535 @SuppressWarnings("nls")
537 public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
540 chefInfo(params, ctx);
541 String jobID = params.get("jobid");
542 String retry = params.get("retryTimes");
543 String intrva = params.get("retryInterval");
544 if (StringUtils.isNotBlank(jobID) && StringUtils.isNotBlank(retry) && StringUtils.isNotBlank(intrva)) {
546 int retryTimes = Integer.parseInt(params.get("retryTimes"));
547 int retryInterval = Integer.parseInt(params.get("retryInterval"));
549 String chefAction = "/pushy/jobs/" + jobID;
551 String message = StringUtils.EMPTY;
552 String status = StringUtils.EMPTY;
553 for (int i = 0; i < retryTimes; i++) {
554 sleepFor(retryInterval);
555 ChefResponse chefResponse = getApiMethod(chefAction);
556 code = chefResponse.getStatusCode();
557 message = chefResponse.getBody();
558 JSONObject obj = new JSONObject(message);
559 status = obj.getString("status");
560 if (!"running".equals(status)) {
561 logger.info(i + " time " + code + " " + status);
565 resolveSvcLogicAttributes(ctx, message, status);
567 throw new SvcLogicException("Missing Mandatory param(s) retryTimes , retryInterval ");
569 } catch (Exception e) {
571 logger.error("An error occurred when executing checkPushJob method", e);
572 doFailure(ctx, code, e.getMessage());
576 private void resolveSvcLogicAttributes(SvcLogicContext svcLogic, String message, String status) {
577 if ("complete".equals(status)) {
578 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "200");
579 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, message);
580 } else if ("running".equals(status)) {
581 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "202");
582 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, "chef client runtime out");
584 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "500");
585 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, message);
589 private void sleepFor(int retryInterval) {
591 Thread.sleep(retryInterval); // 1000 milliseconds is one second.
592 } catch (InterruptedException ex) {
593 Thread.currentThread().interrupt();
597 @SuppressWarnings("nls")
599 public void pushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
602 chefInfo(params, ctx);
603 String pushRequest = params.get("pushRequest");
604 String chefAction = "/pushy/jobs";
605 ChefApiClient chefApiClient = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
606 ChefResponse chefResponse = chefApiClient.post(chefAction, pushRequest);
608 code = chefResponse.getStatusCode();
609 String message = chefResponse.getBody();
611 int startIndex = message.indexOf("jobs") + 6;
612 int endIndex = message.length() - 2;
613 String jobID = message.substring(startIndex, endIndex);
614 ctx.setAttribute("jobID", jobID);
617 chefServerResult(ctx, code, message);
618 } catch (Exception e) {
620 logger.error("An error occurred when executing pushJob method", e);
621 doFailure(ctx, code, e.getMessage());
625 @SuppressWarnings("static-method")
626 private void chefServerResult(SvcLogicContext svcLogicContext, int code, String message) {
627 initSvcLogic(svcLogicContext, code, message, "server");
630 @SuppressWarnings("static-method")
631 private void chefClientResult(SvcLogicContext svcLogicContext, int code, String message) {
632 initSvcLogic(svcLogicContext, code, message, "client");
635 private void initSvcLogic(SvcLogicContext svcLogicContext, int code, String message, String target) {
637 String codeStr = "server".equals(target) ? CHEF_SERVER_RESULT_CODE_STR : CHEF_CLIENT_RESULT_CODE_STR;
638 String messageStr = "client".equals(target) ? CHEF_CLIENT_RESULT_MSG_STR : CHEF_SERVER_RESULT_MSG_STR;
640 svcLogicContext.setStatus(OUTCOME_SUCCESS);
641 svcLogicContext.setAttribute(codeStr, Integer.toString(code));
642 svcLogicContext.setAttribute(messageStr, message);
643 logger.info(codeStr + ": " + svcLogicContext.getAttribute(codeStr));
644 logger.info(messageStr + ": " + svcLogicContext.getAttribute(messageStr));
647 @SuppressWarnings("static-method")
648 private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException {
650 String cutMessage = message.contains("\n") ? message.substring(message.indexOf('\n')) : message;
652 svcLogic.setStatus(OUTCOME_FAILURE);
653 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, Integer.toString(code));
654 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, cutMessage);
656 throw new SvcLogicException("Chef Adapter error:" + cutMessage);