- public void VnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
- int code ;
- try{
- chefInfo(params,ctx);
- String nodeList = params.get("NodeList");
- if (StringUtils.isNotBlank(nodeList))
- {
- String isCallback = params.get("CallbackCapable");
- String chefAction = "/pushy/jobs";
- //need work on this
- String pushRequest="";
- if(isCallback.equals("true")){
- String requestId = params.get("RequestId");
- String callbackUrl = params.get("CallbackUrl");
- pushRequest="{"+
- "\"command\": \"chef-client\","+
- "\"run_timeout\": 300,"+
- "\"nodes\":" +nodeList +","+
- "\"env\": {\"RequestId\": \""+ requestId +"\", \"CallbackUrl\": \""+ callbackUrl +"\"},"+
- "\"capture_output\": true"+
- "}";
- }else{
- pushRequest="{"+
- "\"command\": \"chef-client\","+
- "\"run_timeout\": 300,"+
- "\"nodes\":" +nodeList +","+
- "\"env\": {},"+
- "\"capture_output\": true"+
- "}";
- }
- RequestContext rc = new RequestContext(ctx);
-
- rc.isAlive();
- SvcLogicContext svcLogic = rc.getSvcLogicContext();
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
- ApiMethod am = cac.post(chefAction).body(pushRequest);
-
- am.execute();
- code = am.getReturnCode();
- logger.info("pushRequest:"+pushRequest);
- logger.info("requestbody:"+am.getReqBody());
-
- String message = am.getResponseBodyAsString();
- if (code == 201) {
- int startIndex = message.indexOf("jobs") + 5;
- int endIndex = message.length() - 2;
- String jobID = message.substring(startIndex, endIndex);
- svcLogic.setAttribute("jobID", jobID);
- logger.info(jobID);
- }
- chefServerResult(rc, Integer.toString(code), message);
- }
-
- else
- {
- throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
- }
- }
- catch(JSONException e){
- code =401;
- doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
- }
- catch(Exception e)
- {
+ public void vnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ int code;
+ try {
+ chefInfo(params, ctx);
+ String nodeList = params.get(NODE_LIST_STR);
+ if (StringUtils.isNotBlank(nodeList)) {
+ String isCallback = params.get("CallbackCapable");
+ String chefAction = "/pushy/jobs";
+ // need work on this
+ String pushRequest;
+ if ("true".equals(isCallback)) {
+ String requestId = params.get("RequestId");
+ String callbackUrl = params.get("CallbackUrl");
+ pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
+ + nodeList + "," + "\"env\": {\"RequestId\": \"" + requestId + "\", \"CallbackUrl\": \""
+ + callbackUrl + "\"}," + "\"capture_output\": true" + "}";
+ } else {
+ pushRequest = "{" + "\"command\": \"chef-client\"," + "\"run_timeout\": 300," + "\"nodes\":"
+ + nodeList + "," + "\"env\": {}," + "\"capture_output\": true" + "}";
+ }
+ ChefApiClient cac = chefApiClientFactory.create(chefserver, organizations, username, clientPrivatekey);
+ ChefResponse chefResponse = cac.post(chefAction, pushRequest);
+ code = chefResponse.getStatusCode();
+ logger.info("pushRequest:" + pushRequest);
+ logger.info("requestbody: {}", chefResponse.getBody());
+ String message = chefResponse.getBody();
+ if (code == 201) {
+ int startIndex = message.indexOf("jobs") + 5;
+ int endIndex = message.length() - 2;
+ String jobID = message.substring(startIndex, endIndex);
+ ctx.setAttribute("jobID", jobID);
+ logger.info(jobID);
+ }
+ chefServerResult(ctx, code, message);
+ } else {
+ throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
+ }
+ } catch (Exception e) {