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;
27 import java.util.Arrays;
28 import java.util.List;
30 import java.util.Properties;
31 import org.apache.commons.lang.StringUtils;
32 import org.apache.http.HttpEntity;
33 import org.apache.http.HttpResponse;
34 import org.apache.http.client.methods.HttpGet;
35 import org.apache.http.impl.client.CloseableHttpClient;
36 import org.apache.http.impl.client.HttpClients;
37 import org.apache.http.util.EntityUtils;
38 import org.json.JSONException;
39 import org.json.JSONObject;
40 import org.onap.appc.adapter.chef.ChefAdapter;
41 import org.onap.appc.adapter.chef.chefapi.ApiMethod;
42 import org.onap.appc.adapter.chef.chefclient.ChefApiClient;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
45 import com.att.eelf.configuration.EELFLogger;
46 import com.att.eelf.configuration.EELFManager;
49 * This class implements the {@link ChefAdapter} interface. This interface
50 * defines the behaviors that our service provides.
52 public class ChefAdapterImpl implements ChefAdapter {
54 // chef server Initialize variable
55 private String username = StringUtils.EMPTY;
56 private String clientPrivatekey = StringUtils.EMPTY;
57 private String chefserver = StringUtils.EMPTY;
58 private String serverAddress = StringUtils.EMPTY;
59 private String organizations = StringUtils.EMPTY;
61 @SuppressWarnings("nls")
62 public static final String MDC_ADAPTER = "adapter";
64 @SuppressWarnings("nls")
65 public static final String MDC_SERVICE = "service";
67 @SuppressWarnings("nls")
68 public static final String OUTCOME_FAILURE = "failure";
70 @SuppressWarnings("nls")
71 public static final String OUTCOME_SUCCESS = "success";
73 @SuppressWarnings("nls")
74 public static final String PROPERTY_PROVIDER = "provider";
76 @SuppressWarnings("nls")
77 public static final String PROPERTY_PROVIDER_IDENTITY = "identity";
79 @SuppressWarnings("nls")
80 public static final String PROPERTY_PROVIDER_NAME = "name";
82 @SuppressWarnings("nls")
83 public static final String PROPERTY_PROVIDER_TENANT = "tenant";
85 @SuppressWarnings("nls")
86 public static final String PROPERTY_PROVIDER_TENANT_NAME = "name";
88 @SuppressWarnings("nls")
89 public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR
91 @SuppressWarnings("nls")
92 public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid";
94 @SuppressWarnings("nls")
95 public static final String PROPERTY_PROVIDER_TYPE = "type";
98 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefAdapterImpl.class);
100 private static final String CANNOT_FIND_PRIVATE_KEY_STR =
101 "Cannot find the private key in the APPC file system, please load the private key to ";
103 private static final String POSTING_REQUEST_JSON_ERROR_STR = "Error posting request due to invalid JSON block: ";
104 private static final String POSTING_REQUEST_ERROR_STR = "Error posting request: ";
105 private static final String CHEF_CLIENT_RESULT_CODE_STR = "chefClientResult.code";
106 private static final String CHEF_SERVER_RESULT_CODE_STR = "chefServerResult.code";
107 private static final String CHEF_CLIENT_RESULT_MSG_STR = "chefClientResult.message";
108 private static final String CHEF_SERVER_RESULT_MSG_STR = "chefServerResult.message";
109 private static final String CHEF_ACTION_STR = "chefAction";
110 private static final String NODE_LIST_STR = "NodeList";
113 * This default constructor is used as a work around because the activator wasnt
116 public ChefAdapterImpl() {
120 public ChefAdapterImpl(Properties props) {
125 * This constructor is used primarily in the test cases to bypass initialization
126 * of the adapter for isolated, disconnected testing
129 * True if the adapter is to be initialized, can false if not
132 public ChefAdapterImpl(boolean initialize) {
138 public ChefAdapterImpl(String key) {
143 * Returns the symbolic name of the adapter
145 * @return The adapter name
146 * @see org.onap.appc.adapter.chef.ChefAdapter#getAdapterName()
149 public String getAdapterName() {
150 return "chef adapter";
153 @SuppressWarnings("nls")
155 public void vnfcEnvironment(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
158 logger.info("environment of VNF-C");
159 chefInfo(params, ctx);
160 RequestContext rc = new RequestContext(ctx);
161 logger.info("Context" + ctx);
163 String env = params.get("Environment");
164 logger.info("Environmnet" + env);
165 if (env.equals(StringUtils.EMPTY)) {
166 chefServerResult(rc, 200, "Skip Environment block ");
168 JSONObject envJ = new JSONObject(env);
169 String envName = envJ.getString("name");
171 if (privateKeyCheck()) {
172 // update the details of an environment on the Chef server.
173 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
174 ApiMethod am = cac.put("/environments/" + envName).body(env);
176 code = am.getReturnCode();
177 message = am.getResponseBodyAsString();
179 // need create a new environment
180 am = cac.post("/environments").body(env);
182 code = am.getReturnCode();
183 message = am.getResponseBodyAsString();
184 logger.info("requestbody" + am.getReqBody());
189 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
190 doFailure(ctx, code, message);
192 chefServerResult(rc, code, message);
196 catch (JSONException e) {
198 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
199 } catch (Exception e) {
201 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
205 @SuppressWarnings("nls")
207 public void vnfcNodeobjects(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
208 logger.info("update the nodeObjects of VNF-C");
211 chefInfo(params, ctx);
212 String nodeListS = params.get(NODE_LIST_STR);
213 String nodeS = params.get("Node");
214 if (StringUtils.isNotBlank(nodeListS) && StringUtils.isNotBlank(nodeS)) {
215 nodeListS = nodeListS.replace("[", StringUtils.EMPTY);
216 nodeListS = nodeListS.replace("]", StringUtils.EMPTY);
217 nodeListS = nodeListS.replace("\"", StringUtils.EMPTY);
218 nodeListS = nodeListS.replace(" ", StringUtils.EMPTY);
219 List<String> nodes = Arrays.asList(nodeListS.split("\\s*,\\s*"));
220 RequestContext rc = new RequestContext(ctx);
223 String message = null;
224 if (privateKeyCheck()) {
225 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
227 for (int i = 0; i < nodes.size(); i++) {
228 String nodeName = nodes.get(i);
229 JSONObject nodeJ = new JSONObject(nodeS);
230 nodeJ.remove("name");
231 nodeJ.put("name", nodeName);
232 String nodeObject = nodeJ.toString();
233 logger.info(nodeObject);
234 ApiMethod am = cac.put("/nodes/" + nodeName).body(nodeObject);
236 code = am.getReturnCode();
237 message = am.getResponseBodyAsString();
244 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
245 doFailure(ctx, code, message);
247 chefServerResult(rc, code, message);
250 throw new SvcLogicException("Missing Mandatory param(s) Node , NodeList ");
252 } catch (JSONException e) {
254 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
255 } catch (Exception ex) {
257 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + ex.getMessage());
262 public void vnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
265 chefInfo(params, ctx);
266 String nodeList = params.get(NODE_LIST_STR);
267 if (StringUtils.isNotBlank(nodeList)) {
268 String isCallback = params.get("CallbackCapable");
269 String chefAction = "/pushy/jobs";
272 if ("true".equals(isCallback)) {
273 String requestId = params.get("RequestId");
274 String callbackUrl = params.get("CallbackUrl");
275 pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
276 + nodeList + "," + "\"env\": {\"RequestId\": \"" + requestId + "\", \"CallbackUrl\": \""
277 + callbackUrl + "\"}," + "\"capture_output\": true" + "}";
279 pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
280 + nodeList + "," + "\"env\": {}," + "\"capture_output\": true" + "}";
282 RequestContext rc = new RequestContext(ctx);
285 SvcLogicContext svcLogic = rc.getSvcLogicContext();
286 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
287 ApiMethod am = cac.post(chefAction).body(pushRequest);
289 code = am.getReturnCode();
290 logger.info("pushRequest:" + pushRequest);
291 logger.info("requestbody:" + am.getReqBody());
292 String message = am.getResponseBodyAsString();
294 int startIndex = message.indexOf("jobs") + 5;
295 int endIndex = message.length() - 2;
296 String jobID = message.substring(startIndex, endIndex);
297 svcLogic.setAttribute("jobID", jobID);
300 chefServerResult(rc, code, message);
303 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
305 } catch (JSONException e) {
307 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
308 } catch (Exception e) {
310 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage());
314 @SuppressWarnings("nls")
316 public void fetchResults(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
319 chefInfo(params, ctx);
320 String nodeListS = params.get(NODE_LIST_STR);
321 if (StringUtils.isNotBlank(nodeListS)) {
322 nodeListS = nodeListS.replace("[", StringUtils.EMPTY);
323 nodeListS = nodeListS.replace("]", StringUtils.EMPTY);
324 nodeListS = nodeListS.replace("\"", StringUtils.EMPTY);
325 nodeListS = nodeListS.replace(" ", StringUtils.EMPTY);
326 List<String> nodes = Arrays.asList(nodeListS.split("\\s*,\\s*"));
327 JSONObject result = new JSONObject();
328 String returnMessage = StringUtils.EMPTY;
330 for (String node : nodes) {
331 String chefAction = "/nodes/" + node;
333 if (privateKeyCheck()) {
334 ApiMethod am = getApiMethod(chefAction);
335 code = am.getReturnCode();
336 message = am.getResponseBodyAsString();
339 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
340 doFailure(ctx, code, message);
343 JSONObject nodeResult = new JSONObject();
344 JSONObject allNodeData = new JSONObject(message);
345 allNodeData = allNodeData.getJSONObject("normal");
346 String attribute = "PushJobOutput";
348 String resultData = allNodeData.optString(attribute);
349 if (resultData == null) {
350 resultData = allNodeData.optJSONObject(attribute).toString();
352 if (resultData == null) {
353 resultData = allNodeData.optJSONArray(attribute).toString();
355 if (resultData == null) {
357 returnMessage = "Cannot find " + attribute;
362 nodeResult.put(attribute, resultData);
363 result.put(node, nodeResult);
364 returnMessage = result.toString();
367 returnMessage = message + " Cannot access: " + node;
368 doFailure(ctx, code, message);
373 RequestContext rc = new RequestContext(ctx);
375 chefServerResult(rc, code, returnMessage);
377 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
379 } catch (JSONException e) {
381 doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage());
382 } catch (Exception ex) {
384 doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + ex.getMessage());
388 private ApiMethod getApiMethod(String chefAction) {
389 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
391 return cac.get(chefAction).execute();
397 @SuppressWarnings("nls")
399 public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) {
400 logger.info("nodeObejctBuilder");
401 String name = params.get("nodeobject.name");
402 String normal = params.get("nodeobject.normal");
403 String overrides = params.get("nodeobject.overrides");
404 String defaults = params.get("nodeobject.defaults");
405 String runList = params.get("nodeobject.run_list");
406 String chefEnvironment = params.get("nodeobject.chef_environment");
407 String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults
408 + "},\"chef_type\":\"node\",\"run_list\":[" + runList + "],\"override\":{" + overrides
409 + "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\""
410 + chefEnvironment + "\"}";
411 logger.info(nodeObject);
412 RequestContext rc = new RequestContext(ctx);
414 SvcLogicContext svcLogic = rc.getSvcLogicContext();
415 svcLogic.setAttribute("chef.nodeObject", nodeObject);
419 * send get request to chef server
421 * @throws SvcLogicException
423 private void chefInfo(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
425 username = params.get("username");
426 serverAddress = params.get("serverAddress");
427 organizations = params.get("organizations");
428 if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(serverAddress)
429 && StringUtils.isNotBlank(organizations)) {
430 chefserver = "https://" + serverAddress + "/organizations/" + organizations;
431 clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + username + ".pem";
432 logger.info(" clientPrivatekey " + clientPrivatekey);
434 doFailure(ctx, 401, "Missing mandatory param(s) such as username, serverAddress, organizations");
438 private Boolean privateKeyCheck() {
439 File f = new File(clientPrivatekey);
441 logger.info("Key exists");
444 logger.info("Key doesn't exists");
449 @SuppressWarnings("nls")
451 public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
453 String allConfigData = params.get("allConfig");
454 String key = params.get("key");
455 String dgContext = params.get("dgContext");
456 JSONObject josnConfig = new JSONObject(allConfigData);
459 contextData = josnConfig.getString(key);
460 } catch (Exception e) {
462 contextData = josnConfig.getJSONObject(key).toString();
463 } catch (Exception ex) {
464 contextData = josnConfig.getJSONArray(key).toString();
468 RequestContext rc = new RequestContext(ctx);
470 SvcLogicContext svcLogic = rc.getSvcLogicContext();
471 svcLogic.setAttribute(dgContext, contextData);
474 @SuppressWarnings("nls")
476 public void combineStrings(Map<String, String> params, SvcLogicContext ctx) {
477 String string1 = params.get("String1");
478 String string2 = params.get("String2");
479 String dgContext = params.get("dgContext");
480 String contextData = string1 + string2;
481 RequestContext rc = new RequestContext(ctx);
483 SvcLogicContext svcLogic = rc.getSvcLogicContext();
484 svcLogic.setAttribute(dgContext, contextData);
488 * Send GET request to chef server
490 * @throws SvcLogicException
492 @SuppressWarnings("nls")
495 public void chefGet(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
496 logger.info("chef get method");
497 chefInfo(params, ctx);
498 String chefAction = params.get(CHEF_ACTION_STR);
499 RequestContext rc = new RequestContext(ctx);
504 if (privateKeyCheck()) {
505 ApiMethod am = getApiMethod(chefAction);
506 code = am.getReturnCode();
507 message = am.getResponseBodyAsString();
510 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
512 chefServerResult(rc, code, message);
516 * Send PUT request to chef server
518 * @throws SvcLogicException
520 @SuppressWarnings("nls")
523 public void chefPut(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
524 chefInfo(params, ctx);
525 String chefAction = params.get(CHEF_ACTION_STR);
526 String chefNodeStr = params.get("chefRequestBody");
527 RequestContext rc = new RequestContext(ctx);
531 if (privateKeyCheck()) {
532 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
534 ApiMethod am = cac.put(chefAction).body(chefNodeStr);
536 code = am.getReturnCode();
537 message = am.getResponseBodyAsString();
540 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
542 logger.info(code + " " + message);
543 chefServerResult(rc, code, message);
547 * send Post request to chef server
549 * @throws SvcLogicException
552 public void chefPost(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
553 chefInfo(params, ctx);
554 logger.info("chef Post method");
555 logger.info(username + " " + clientPrivatekey + " " + chefserver + " " + organizations);
556 String chefNodeStr = params.get("chefRequestBody");
557 String chefAction = params.get(CHEF_ACTION_STR);
559 RequestContext rc = new RequestContext(ctx);
563 // should load pem from somewhere else
564 if (privateKeyCheck()) {
565 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
567 // need pass path into it
569 ApiMethod am = cac.post(chefAction).body(chefNodeStr);
571 code = am.getReturnCode();
572 message = am.getResponseBodyAsString();
575 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
577 logger.info(code + " " + message);
578 chefServerResult(rc, code, message);
582 * send delete request to chef server
584 * @throws SvcLogicException
587 public void chefDelete(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
588 logger.info("chef delete method");
589 chefInfo(params, ctx);
590 String chefAction = params.get(CHEF_ACTION_STR);
591 RequestContext rc = new RequestContext(ctx);
595 if (privateKeyCheck()) {
596 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
597 ApiMethod am = cac.delete(chefAction);
599 code = am.getReturnCode();
600 message = am.getResponseBodyAsString();
603 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
605 logger.info(code + " " + message);
606 chefServerResult(rc, code, message);
610 * Trigger target vm run chef
613 public void trigger(Map<String, String> params, SvcLogicContext ctx) {
614 logger.info("Run trigger method");
615 String tVmIp = params.get("ip");
616 RequestContext rc = new RequestContext(ctx);
619 try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
620 HttpGet httpGet = new HttpGet(tVmIp);
621 HttpResponse response = httpClient.execute(httpGet);
622 int responseCode = response.getStatusLine().getStatusCode();
623 HttpEntity entity = response.getEntity();
624 String responseOutput = EntityUtils.toString(entity);
625 chefClientResult(rc, responseCode, responseOutput);
627 } catch (Exception e) {
628 doFailure(rc, 500, e.toString());
632 @SuppressWarnings("nls")
634 public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
637 chefInfo(params, ctx);
638 String jobID = params.get("jobid");
639 String retry = params.get("retryTimes");
640 String intrva = params.get("retryInterval");
641 if (StringUtils.isNotBlank(retry) && StringUtils.isNotBlank(intrva)) {
643 int retryTimes = Integer.parseInt(params.get("retryTimes"));
644 int retryInterval = Integer.parseInt(params.get("retryInterval"));
646 String chefAction = "/pushy/jobs/" + jobID;
648 RequestContext rc = new RequestContext(ctx);
650 SvcLogicContext svcLogic = rc.getSvcLogicContext();
651 String message = StringUtils.EMPTY;
652 String status = StringUtils.EMPTY;
653 for (int i = 0; i < retryTimes; i++) {
654 sleepFor(retryInterval);
655 ApiMethod am = getApiMethod(chefAction);
656 code = am.getReturnCode();
657 message = am.getResponseBodyAsString();
658 JSONObject obj = new JSONObject(message);
659 status = obj.getString("status");
660 if (!"running".equals(status)) {
661 logger.info(i + " time " + code + " " + status);
665 if ("complete".equals(status)) {
666 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "200");
667 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, message);
669 if ("running".equals(status)) {
670 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "202");
671 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, "chef client runtime out");
673 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, "500");
674 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, message);
679 throw new SvcLogicException("Missing Mandatory param(s) retryTimes , retryInterval ");
681 } catch (Exception e) {
683 doFailure(ctx, code, e.getMessage());
687 private void sleepFor(int retryInterval) {
689 Thread.sleep(retryInterval); // 1000 milliseconds is one second.
690 } catch (InterruptedException ex) {
691 Thread.currentThread().interrupt();
695 @SuppressWarnings("nls")
697 public void pushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
700 chefInfo(params, ctx);
701 String pushRequest = params.get("pushRequest");
702 String chefAction = "/pushy/jobs";
703 RequestContext rc = new RequestContext(ctx);
705 SvcLogicContext svcLogic = rc.getSvcLogicContext();
706 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
707 ApiMethod am = cac.post(chefAction).body(pushRequest);
710 code = am.getReturnCode();
711 String message = am.getResponseBodyAsString();
713 int startIndex = message.indexOf("jobs") + 6;
714 int endIndex = message.length() - 2;
715 String jobID = message.substring(startIndex, endIndex);
716 svcLogic.setAttribute("jobID", jobID);
719 chefServerResult(rc, code, message);
720 } catch (Exception e) {
722 doFailure(ctx, code, e.getMessage());
726 @SuppressWarnings("static-method")
727 private void doFailure(RequestContext rc, int code, String message) {
728 SvcLogicContext svcLogic = rc.getSvcLogicContext();
729 String msg = (message == null) ? Integer.toString(code) : message;
730 if (msg.contains("\n")) {
731 msg = msg.substring(msg.indexOf("\n"));
736 status = Integer.toString(code);
737 } catch (Exception e) {
741 svcLogic.setAttribute("chefAgent.code", status);
742 svcLogic.setAttribute("chefAgent.message", msg);
747 * The request context that manages the state and recovery of the
748 * request for the life of its processing.
750 @SuppressWarnings("static-method")
751 private void doSuccess(RequestContext rc) {
752 SvcLogicContext svcLogic = rc.getSvcLogicContext();
753 svcLogic.setAttribute("chefAgent.code", "200");
756 @SuppressWarnings("static-method")
757 private void chefServerResult(RequestContext rc, int code, String message) {
758 initSvcLogic(rc, code, message, "server");
761 @SuppressWarnings("static-method")
762 private void chefClientResult(RequestContext rc, int code, String message) {
763 initSvcLogic(rc, code, message, "client");
766 private void initSvcLogic(RequestContext rc, int code, String message, String target) {
768 SvcLogicContext svcLogic = rc.getSvcLogicContext();
769 String codeStr = "server".equals(target) ? CHEF_SERVER_RESULT_CODE_STR : CHEF_CLIENT_RESULT_CODE_STR;
770 String messageStr = "client".equals(target) ? CHEF_SERVER_RESULT_MSG_STR : CHEF_CLIENT_RESULT_MSG_STR;
772 svcLogic.setStatus(OUTCOME_SUCCESS);
773 svcLogic.setAttribute(codeStr, Integer.toString(code));
774 svcLogic.setAttribute(messageStr, message);
775 logger.info(codeStr + ": " + svcLogic.getAttribute(codeStr));
776 logger.info(messageStr + ": " + svcLogic.getAttribute(messageStr));
781 * initialize the provider adapter by building the context cache
783 private void initialize() {
785 logger.info("Initialize Chef Adapter");
788 @SuppressWarnings("static-method")
789 private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException {
791 String cutMessage = message.contains("\n") ? message.substring(message.indexOf('\n')) : message;
793 svcLogic.setStatus(OUTCOME_FAILURE);
794 svcLogic.setAttribute(CHEF_SERVER_RESULT_CODE_STR, Integer.toString(code));
795 svcLogic.setAttribute(CHEF_SERVER_RESULT_MSG_STR, cutMessage);
797 throw new SvcLogicException("Chef Adapter error:" + cutMessage);