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=========================================================
25 package org.onap.appc.adapter.chef.impl;
28 import java.util.Arrays;
29 import java.util.List;
31 import java.util.Properties;
33 import org.apache.commons.lang.StringUtils;
34 import org.apache.http.HttpEntity;
35 import org.apache.http.HttpResponse;
36 import org.apache.http.client.methods.HttpGet;
37 import org.apache.http.client.HttpClient;
38 import org.apache.http.impl.client.CloseableHttpClient;
39 import org.apache.http.impl.client.HttpClients;
40 import org.apache.http.util.EntityUtils;
41 import org.json.JSONException;
42 import org.json.JSONObject;
43 import org.onap.appc.Constants;
44 import org.onap.appc.adapter.chef.ChefAdapter;
45 import org.onap.appc.adapter.chef.chefapi.ApiMethod;
46 import org.onap.appc.adapter.chef.chefclient.ChefApiClient;
47 import org.onap.appc.configuration.Configuration;
48 import org.onap.appc.configuration.ConfigurationFactory;
49 import org.onap.appc.exceptions.APPCException;
50 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
51 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
53 import com.att.eelf.configuration.EELFLogger;
54 import com.att.eelf.configuration.EELFManager;
57 * This class implements the {@link ChefAdapter} interface. This interface
58 * defines the behaviors that our service provides.
60 public class ChefAdapterImpl implements ChefAdapter {
61 // chef server Initialize variable
62 private String username = "";
63 private String clientPrivatekey = "";
64 private String chefserver = "";
65 private String serverAddress = "";
66 private String organizations = "";
68 @SuppressWarnings("nls")
69 public static final String MDC_ADAPTER = "adapter";
71 @SuppressWarnings("nls")
72 public static final String MDC_SERVICE = "service";
74 @SuppressWarnings("nls")
75 public static final String OUTCOME_FAILURE = "failure";
77 @SuppressWarnings("nls")
78 public static final String OUTCOME_SUCCESS = "success";
80 @SuppressWarnings("nls")
81 public static final String PROPERTY_PROVIDER = "provider";
83 @SuppressWarnings("nls")
84 public static final String PROPERTY_PROVIDER_IDENTITY = "identity";
86 @SuppressWarnings("nls")
87 public static final String PROPERTY_PROVIDER_NAME = "name";
89 @SuppressWarnings("nls")
90 public static final String PROPERTY_PROVIDER_TENANT = "tenant";
92 @SuppressWarnings("nls")
93 public static final String PROPERTY_PROVIDER_TENANT_NAME = "name";
95 @SuppressWarnings("nls")
96 public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR
98 @SuppressWarnings("nls")
99 public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid";
101 @SuppressWarnings("nls")
102 public static final String PROPERTY_PROVIDER_TYPE = "type";
105 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefAdapterImpl.class);
107 private static final char LPAREN = '(';
109 private static final char NL = '\n';
111 private static final char QUOTE = '\'';
113 private static final char RPAREN = ')';
114 private static final char SPACE = ' ';
116 private final String CANNOT_FIND_PRIVATE_KEY_STR = "Cannot find the private key in the APPC file system, please load the private key to ";
119 * A reference to the adapter configuration object.
121 private Configuration configuration;
124 * This default constructor is used as a work around because the activator wasnt
127 public ChefAdapterImpl() {
131 public ChefAdapterImpl(Properties props) {
137 * This constructor is used primarily in the test cases to bypass initialization
138 * of the adapter for isolated, disconnected testing
141 * True if the adapter is to be initialized, can false if not
144 public ChefAdapterImpl(boolean initialize) {
151 public ChefAdapterImpl(String key) {
158 * Returns the symbolic name of the adapter
160 * @return The adapter name
161 * @see org.onap.appc.adapter.chef.ChefAdapter#getAdapterName()
164 public String getAdapterName() {
165 return "chef adapter";
168 @SuppressWarnings("nls")
170 public void VnfcEnvironment(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
173 logger.info("environment of VNF-C");
174 chefInfo(params,ctx);
175 RequestContext rc = new RequestContext(ctx);
176 logger.info("Context"+ctx );
178 String env = params.get("Environment");
179 logger.info("Environmnet"+env );
181 chefServerResult(rc, "200", "Skip Environment block ");}
183 JSONObject env_J = new JSONObject(env);
184 String envName = env_J.getString("name");
187 String message = null;
188 if (privateKeyCheck()) {
189 // update the details of an environment on the Chef server.
190 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
191 ApiMethod am = cac.put("/environments/"+envName).body(env);
193 code = am.getReturnCode();
194 message = am.getResponseBodyAsString();
196 //need create a new environment
197 am = cac.post("/environments").body(env);
199 code = am.getReturnCode();
200 message = am.getResponseBodyAsString();
201 logger.info("requestbody"+am.getReqBody());
206 message = "Cannot find the private key in the APPC file system, please load the private key to "
208 doFailure(ctx,code,message);
210 chefServerResult(rc, Integer.toString(code), message);
214 catch(JSONException e){
216 doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
220 doFailure(ctx, code, "Error posting request :Reason = " + e.getMessage());
224 @SuppressWarnings("nls")
226 public void VnfcNodeobjects(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
227 logger.info("update the nodeObjects of VNF-C");
230 chefInfo(params,ctx);
231 String nodeList_S = params.get("NodeList");
232 String node_S = params.get("Node");
233 if (StringUtils.isNotBlank(nodeList_S) && StringUtils.isNotBlank(node_S))
235 nodeList_S = nodeList_S.replace("[","");
236 nodeList_S = nodeList_S.replace("]","");
237 nodeList_S = nodeList_S.replace("\"","");
238 nodeList_S = nodeList_S.replace(" ","");
239 List<String> nodes = Arrays.asList(nodeList_S.split("\\s*,\\s*"));
240 RequestContext rc = new RequestContext(ctx);
243 String message = null;
244 if (privateKeyCheck()) {
245 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
247 for(int i = 0; i < nodes.size(); i++){
248 String nodeName=nodes.get(i);
249 JSONObject node_J = new JSONObject(node_S);
250 node_J.remove("name");
251 node_J.put("name",nodeName);
252 String nodeObject=node_J.toString();
253 logger.info(nodeObject);
254 ApiMethod am = cac.put("/nodes/"+nodeName).body(nodeObject);
256 code = am.getReturnCode();
257 message = am.getResponseBodyAsString();
265 message = "Cannot find the private key in the APPC file system, please load the private key to "
267 doFailure(ctx,code,message);
269 chefServerResult(rc, Integer.toString(code), message);
274 throw new SvcLogicException("Missing Mandatory param(s) Node , NodeList ");
277 catch(JSONException e){
279 doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
283 doFailure(ctx, code, "Error posting request :Reason = " + ex.getMessage());
289 public void VnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
292 chefInfo(params,ctx);
293 String nodeList = params.get("NodeList");
294 if (StringUtils.isNotBlank(nodeList))
296 String isCallback = params.get("CallbackCapable");
297 String chefAction = "/pushy/jobs";
299 String pushRequest="";
300 if(isCallback.equals("true")){
301 String requestId = params.get("RequestId");
302 String callbackUrl = params.get("CallbackUrl");
304 "\"command\": \"chef-client\","+
305 "\"run_timeout\": 300,"+
306 "\"nodes\":" +nodeList +","+
307 "\"env\": {\"RequestId\": \""+ requestId +"\", \"CallbackUrl\": \""+ callbackUrl +"\"},"+
308 "\"capture_output\": true"+
312 "\"command\": \"chef-client\","+
313 "\"run_timeout\": 300,"+
314 "\"nodes\":" +nodeList +","+
316 "\"capture_output\": true"+
319 RequestContext rc = new RequestContext(ctx);
322 SvcLogicContext svcLogic = rc.getSvcLogicContext();
323 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
324 ApiMethod am = cac.post(chefAction).body(pushRequest);
327 code = am.getReturnCode();
328 logger.info("pushRequest:"+pushRequest);
329 logger.info("requestbody:"+am.getReqBody());
331 String message = am.getResponseBodyAsString();
333 int startIndex = message.indexOf("jobs") + 5;
334 int endIndex = message.length() - 2;
335 String jobID = message.substring(startIndex, endIndex);
336 svcLogic.setAttribute("jobID", jobID);
339 chefServerResult(rc, Integer.toString(code), message);
344 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
347 catch(JSONException e){
349 doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
354 doFailure(ctx,code,e.getMessage());
360 @SuppressWarnings("nls")
362 public void fetchResults (Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
365 chefInfo(params,ctx);
366 String nodeList_S = params.get("NodeList");
367 if (StringUtils.isNotBlank(nodeList_S) )
369 nodeList_S = nodeList_S.replace("[","");
370 nodeList_S = nodeList_S.replace("]","");
371 nodeList_S = nodeList_S.replace("\"","");
372 nodeList_S = nodeList_S.replace(" ","");
373 List<String> nodes = Arrays.asList(nodeList_S.split("\\s*,\\s*"));
374 JSONObject Result = new JSONObject();
375 String returnCode= "200";
376 String returnMessage="";
377 for (int i = 0; i < nodes.size(); i++){
378 String node=nodes.get(i);
379 String chefAction="/nodes/"+node;
381 String message = null;
382 if (privateKeyCheck()) {
383 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
384 ApiMethod am = cac.get(chefAction);
386 code = am.getReturnCode();
387 message = am.getResponseBodyAsString();
390 message = "Cannot find the private key in the APPC file system, please load the private key to "
392 doFailure(ctx,code,message);
395 JSONObject nodeResult = new JSONObject();
396 JSONObject allNodeData = new JSONObject(message);
397 allNodeData=allNodeData.getJSONObject("normal");
398 String attribute= "PushJobOutput";
402 resultData = allNodeData.getString(attribute);
403 } catch (Exception exc1) {
405 resultData = allNodeData.getJSONObject(attribute).toString();
406 } catch (Exception exc2) {
408 resultData = allNodeData.getJSONArray(attribute).toString();
409 }catch (Exception exc3){
411 returnMessage="cannot find "+attribute;
416 nodeResult.put(attribute,resultData);
418 Result.put(node,nodeResult);
421 returnMessage = message+" Cannot access: "+ node;
422 doFailure(ctx,code,message);
427 RequestContext rc = new RequestContext(ctx);
429 if (!returnCode.equals("500")){
430 returnMessage=Result.toString();
433 chefServerResult(rc, returnCode, returnMessage);
438 throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
441 catch(JSONException e){
443 doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
447 doFailure(ctx, code, "Error posting request :Reason = " + ex.getMessage());
455 @SuppressWarnings("nls")
457 public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) {
458 logger.info("nodeObejctBuilder");
459 String name = params.get("nodeobject.name");
460 String normal = params.get("nodeobject.normal");
461 String overrides = params.get("nodeobject.overrides");
462 String defaults = params.get("nodeobject.defaults");
463 String runList = params.get("nodeobject.run_list");
464 String chefEnvironment = params.get("nodeobject.chef_environment");
465 String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults
466 + "},\"chef_type\":\"node\",\"run_list\":[" + runList + "],\"override\":{" + overrides
467 + "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\""
468 + chefEnvironment + "\"}";
469 logger.info(nodeObject);
471 RequestContext rc = new RequestContext(ctx);
473 SvcLogicContext svcLogic = rc.getSvcLogicContext();
474 svcLogic.setAttribute("chef.nodeObject", nodeObject);
478 * send get request to chef server
479 * @throws SvcLogicException
481 public void chefInfo(Map<String, String> params,SvcLogicContext ctx) throws SvcLogicException {
483 username = params.get("username");
484 serverAddress = params.get("serverAddress");
485 organizations = params.get("organizations");
486 if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(serverAddress)&& StringUtils.isNotBlank(organizations))
488 chefserver = "https://" + serverAddress + "/organizations/" + organizations;
489 clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + username + ".pem";
490 logger.info( " clientPrivatekey " + clientPrivatekey);
494 String message ="Missing mandatory param(s) such as username,serverAddres,organizations";
495 doFailure(ctx,401,message);
502 public Boolean privateKeyCheck() {
503 File f = new File(clientPrivatekey);
505 logger.info( "Key exists");
509 logger.info( "Key doesnot exists");
514 @SuppressWarnings("nls")
516 public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
517 String contextData = "someValue";
518 String allConfigData = params.get("allConfig");
519 String key = params.get("key");
520 String dgContext = params.get("dgContext");
521 JSONObject josnConfig = new JSONObject(allConfigData);
524 contextData = josnConfig.getString(key);
525 } catch (Exception ex) {
527 contextData = josnConfig.getJSONObject(key).toString();
528 } catch (Exception exc) {
529 contextData = josnConfig.getJSONArray(key).toString();
533 RequestContext rc = new RequestContext(ctx);
535 SvcLogicContext svcLogic = rc.getSvcLogicContext();
536 svcLogic.setAttribute(dgContext, contextData);
539 @SuppressWarnings("nls")
541 public void combineStrings(Map<String, String> params, SvcLogicContext ctx) {
543 String string1 = params.get("String1");
544 String string2 = params.get("String2");
545 String dgContext = params.get("dgContext");
546 String contextData = string1 + string2;
547 RequestContext rc = new RequestContext(ctx);
549 SvcLogicContext svcLogic = rc.getSvcLogicContext();
550 svcLogic.setAttribute(dgContext, contextData);
554 * Send GET request to chef server
555 * @throws SvcLogicException
557 @SuppressWarnings("nls")
560 public void chefGet(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
561 logger.info("chef get method");
562 chefInfo(params,ctx);
563 String chefAction = params.get("chefAction");
564 RequestContext rc = new RequestContext(ctx);
567 String message = null;
569 if (privateKeyCheck()) {
570 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
571 ApiMethod am = cac.get(chefAction);
573 code = am.getReturnCode();
574 message = am.getResponseBodyAsString();
577 message = "Cannot find the private key in the APPC file system, please load the private key to "
580 chefServerResult(rc, Integer.toString(code), message);
584 * Send PUT request to chef server
585 * @throws SvcLogicException
587 @SuppressWarnings("nls")
590 public void chefPut(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
591 chefInfo(params,ctx);
592 String chefAction = params.get("chefAction");
593 String chefNodeStr = params.get("chefRequestBody");
594 RequestContext rc = new RequestContext(ctx);
598 if (privateKeyCheck()) {
599 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
601 ApiMethod am = cac.put(chefAction).body(chefNodeStr);
603 code = am.getReturnCode();
604 message = am.getResponseBodyAsString();
607 message = "Cannot find the private key in the APPC file system, please load the private key to "
611 logger.info(code + " " + message);
612 chefServerResult(rc, Integer.toString(code), message);
616 * send Post request to chef server
617 * @throws SvcLogicException
620 public void chefPost(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
621 chefInfo(params,ctx);
622 logger.info("chef Post method");
623 logger.info(username + " " + clientPrivatekey + " " + chefserver + " " + organizations);
624 String chefNodeStr = params.get("chefRequestBody");
625 String chefAction = params.get("chefAction");
627 RequestContext rc = new RequestContext(ctx);
631 // should load pem from somewhere else
632 if (privateKeyCheck()) {
633 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
635 // need pass path into it
637 ApiMethod am = cac.post(chefAction).body(chefNodeStr);
639 code = am.getReturnCode();
640 message = am.getResponseBodyAsString();
643 message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
645 logger.info(code + " " + message);
646 chefServerResult(rc, Integer.toString(code), message);
650 * send delete request to chef server
651 * @throws SvcLogicException
654 public void chefDelete(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
655 logger.info("chef delete method");
656 chefInfo(params,ctx);
657 String chefAction = params.get("chefAction");
658 RequestContext rc = new RequestContext(ctx);
661 String message =null;
662 if (privateKeyCheck()) {
663 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
664 ApiMethod am = cac.delete(chefAction);
666 code = am.getReturnCode();
667 message = am.getResponseBodyAsString();
670 message = "Cannot find the private key in the APPC file system, please load the private key to "
674 logger.info(code + " " + message);
675 chefServerResult(rc, Integer.toString(code), message);
679 * Trigger target vm run chef
682 public void trigger(Map<String, String> params, SvcLogicContext ctx) {
683 logger.info("Run trigger method");
684 String tVmIp = params.get("ip");
685 RequestContext rc = new RequestContext(ctx);
688 try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
689 HttpGet httpGet = new HttpGet(tVmIp);
690 HttpResponse response = null;
691 response = httpClient.execute(httpGet);
692 int responseCode = response.getStatusLine().getStatusCode();
693 HttpEntity entity = response.getEntity();
694 String responseOutput = EntityUtils.toString(entity);
695 chefClientResult(rc, Integer.toString(responseCode), responseOutput);
697 } catch (Exception ex) {
698 doFailure(rc, 500, ex.toString());
702 @SuppressWarnings("nls")
704 public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
707 chefInfo(params,ctx);
708 String jobID = params.get("jobid");
709 String retry= params.get("retryTimes");
710 String intrva= params.get("retryInterval");
711 if (StringUtils.isNotBlank(retry) && StringUtils.isNotBlank(intrva))
714 int retryTimes = Integer.parseInt(params.get("retryTimes"));
715 int retryInterval = Integer.parseInt(params.get("retryInterval"));
717 String chefAction = "/pushy/jobs/" + jobID;
719 RequestContext rc = new RequestContext(ctx);
721 SvcLogicContext svcLogic = rc.getSvcLogicContext();
724 for (int i = 0; i < retryTimes; i++) {
726 Thread.sleep(retryInterval); // 1000 milliseconds is one second.
727 } catch (InterruptedException ex) {
728 Thread.currentThread().interrupt();
730 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
731 ApiMethod am = cac.get(chefAction);
733 code = am.getReturnCode();
734 message = am.getResponseBodyAsString();
735 JSONObject obj = new JSONObject(message);
736 status = obj.getString("status");
737 if (!status.equals("running")) {
738 logger.info(i + " time " + code + " " + status);
743 if (status.equals("complete")) {
744 svcLogic.setAttribute("chefServerResult.code", "200");
745 svcLogic.setAttribute("chefServerResult.message", message);
747 if (status.equals("running")) {
748 svcLogic.setAttribute("chefServerResult.code", "202");
749 svcLogic.setAttribute("chefServerResult.message", "chef client runtime out");
751 svcLogic.setAttribute("chefServerResult.code", "500");
752 svcLogic.setAttribute("chefServerResult.message", message);
759 throw new SvcLogicException("Missing Mandatory param(s) retryTimes , retryInterval ");
766 doFailure(ctx,code,e.getMessage());
770 @SuppressWarnings("nls")
772 public void pushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
775 chefInfo(params,ctx);
776 String pushRequest = params.get("pushRequest");
777 String chefAction = "/pushy/jobs";
778 RequestContext rc = new RequestContext(ctx);
780 SvcLogicContext svcLogic = rc.getSvcLogicContext();
781 ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
782 ApiMethod am = cac.post(chefAction).body(pushRequest);
785 code = am.getReturnCode();
786 String message = am.getResponseBodyAsString();
788 int startIndex = message.indexOf("jobs") + 6;
789 int endIndex = message.length() - 2;
790 String jobID = message.substring(startIndex, endIndex);
791 svcLogic.setAttribute("jobID", jobID);
794 chefServerResult(rc, Integer.toString(code), message);
799 doFailure(ctx,code,e.getMessage());
803 @SuppressWarnings("static-method")
804 private void doFailure(RequestContext rc, int code, String message) {
805 SvcLogicContext svcLogic = rc.getSvcLogicContext();
806 String msg = (message == null) ? Integer.toString(code) : message;
807 if (msg.contains("\n")) {
808 msg = msg.substring(msg.indexOf("\n"));
813 status = Integer.toString(code);
814 } catch (Exception e) {
818 svcLogic.setAttribute("chefAgent.code", status);
819 svcLogic.setAttribute("chefAgent.message", msg);
824 * The request context that manages the state and recovery of the
825 * request for the life of its processing.
827 @SuppressWarnings("static-method")
828 private void doSuccess(RequestContext rc) {
829 SvcLogicContext svcLogic = rc.getSvcLogicContext();
830 svcLogic.setAttribute("chefAgent.code", "200");
832 @SuppressWarnings("static-method")
833 private void chefServerResult(RequestContext rc, String code, String message) {
834 String msg = (message == null) ? " " : message;
835 SvcLogicContext svcLogic = rc.getSvcLogicContext();
836 svcLogic.setStatus(OUTCOME_SUCCESS);
837 svcLogic.setAttribute("chefServerResult.code", code);
838 svcLogic.setAttribute("chefServerResult.message", message);
839 logger.info("chefServerResult.code"+svcLogic.getAttribute("chefServerResult.code"));
840 logger.info("chefServerResult.message"+svcLogic.getAttribute("chefServerResult.message"));
842 @SuppressWarnings("static-method")
843 private void chefClientResult(RequestContext rc, String code, String message) {
844 String msg = (message == null) ? " " : message;
845 SvcLogicContext svcLogic = rc.getSvcLogicContext();
846 svcLogic.setStatus(OUTCOME_SUCCESS);
847 svcLogic.setAttribute("chefClientResult.code", code);
848 svcLogic.setAttribute("chefClientResult.message", message);
849 logger.info("chefClientResult.code"+svcLogic.getAttribute("chefClientResult.code"));
850 logger.info("chefClientResult.message"+svcLogic.getAttribute("chefClientResult.message"));
854 * initialize the provider adapter by building the context cache
856 private void initialize() {
858 logger.info("Initialize Chef Adapter");
862 @SuppressWarnings("static-method")
863 private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException {
865 if (message.contains("\n")) {
866 message = message.substring(message.indexOf("\n"));
868 svcLogic.setStatus(OUTCOME_FAILURE);
869 svcLogic.setAttribute("chefServerResult.code",Integer.toString(code));
870 svcLogic.setAttribute("chefServerResult.message",message);
872 throw new SvcLogicException("Chef Adapater Error = " + message );