public class ChefAdapterImpl implements ChefAdapter {
// chef server Initialize variable
- public String username = "";
+ public String clientName = "";
public String clientPrivatekey = "";
public String chefserver = "";
public String serverAddress = "";
String message = null;
if (privateKeyCheck()) {
// update the details of an environment on the Chef server.
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.put("/environments/"+envName).body(env);
am.execute();
code = am.getReturnCode();
int code=200;
String message = null;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
for(int i = 0; i < nodes.size(); i++){
String nodeName=nodes.get(i);
rc.isAlive();
SvcLogicContext svcLogic = rc.getSvcLogicContext();
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.post(chefAction).body(pushRequest);
am.execute();
int code;
String message = null;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.get(chefAction);
am.execute();
code = am.getReturnCode();
}
+
+ /**
+ * build node object
+ */
+
@SuppressWarnings("nls")
@Override
public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) {
logger.info("nodeObejctBuilder");
- String name = params.get("nodeobject.name");
- String normal = params.get("nodeobject.normal");
- String overrides = params.get("nodeobject.overrides");
- String defaults = params.get("nodeobject.defaults");
- String run_list = params.get("nodeobject.run_list");
- String chef_environment = params.get("nodeobject.chef_environment");
+ String name = params.get("org.openecomp.appc.instance.nodeobject.name");
+ String normal = params.get("org.openecomp.appc.instance.nodeobject.normal");
+ String overrides = params.get("org.openecomp.appc.instance.nodeobject.overrides");
+ String defaults = params.get("org.openecomp.appc.instance.nodeobject.defaults");
+ String run_list = params.get("org.openecomp.appc.instance.nodeobject.run_list");
+ String chef_environment = params.get("org.openecomp.appc.instance.nodeobject.chef_environment");
String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults
+ "},\"chef_type\":\"node\",\"run_list\":[" + run_list + "],\"override\":{" + overrides
+ "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\""
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
SvcLogicContext svcLogic = rc.getSvcLogicContext();
- svcLogic.setAttribute("chef.nodeObject", nodeObject);
+ svcLogic.setAttribute("org.openecomp.appc.chef.nodeObject", nodeObject);
}
+ /**
+ * Nicolas send get request to chef server
+ */
public void chefInfo(Map<String, String> params) {
- username = params.get("username");
- serverAddress = params.get("serverAddress");
- organizations = params.get("organizations");
+ clientName = params.get("org.openecomp.appc.instance.username");
+ serverAddress = params.get("org.openecomp.appc.instance.serverAddress");
+ organizations = params.get("org.openecomp.appc.instance.organizations");
chefserver = "https://" + serverAddress + "/organizations/" + organizations;
- clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + username + ".pem";
+ clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + clientName + ".pem";
}
public Boolean privateKeyCheck() {
@Override
public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
String contextData = "someValue";
- String allConfigData = params.get("allConfig");
- String key = params.get("key");
- String dgContext = params.get("dgContext");
+ String allConfigData = params.get("org.openecomp.appc.instance.allConfig");
+ String key = params.get("org.openecomp.appc.instance.key");
+ String dgContext = params.get("org.openecomp.appc.instance.dgContext");
JSONObject josnConfig = new JSONObject(allConfigData);
try {
contextData = josnConfig.getString(key);
@Override
public void combineStrings(Map<String, String> params, SvcLogicContext ctx) {
- String String1 = params.get("String1");
- String String2 = params.get("String2");
- String dgContext = params.get("dgContext");
+ String String1 = params.get("org.openecomp.appc.instance.String1");
+ String String2 = params.get("org.openecomp.appc.instance.String2");
+ String dgContext = params.get("org.openecomp.appc.instance.dgContext");
String contextData = String1 + String2;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
SvcLogicContext svcLogic = rc.getSvcLogicContext();
svcLogic.setAttribute(dgContext, contextData);
}
+
+
+ /**
+ * Send GET request to chef server
+ */
@SuppressWarnings("nls")
@Override
public void chefGet(Map<String, String> params, SvcLogicContext ctx) {
logger.info("chef get method");
chefInfo(params);
- String chefAction = params.get("chefAction");
+ String chefAction = params.get("org.openecomp.appc.instance.chefAction");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
String message = null;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.get(chefAction);
am.execute();
code = am.getReturnCode();
@Override
public void chefPut(Map<String, String> params, SvcLogicContext ctx) {
chefInfo(params);
- String chefAction = params.get("chefAction");
- String CHEF_NODE_STR = params.get("chefRequestBody");
+ String chefAction = params.get("org.openecomp.appc.instance.chefAction");
+ String CHEF_NODE_STR = params.get("org.openecomp.appc.instance.chefRequestBody");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
String message = null;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.put(chefAction).body(CHEF_NODE_STR);
am.execute();
}
logger.info(code + " " + message);
chefServerResult(rc, Integer.toString(code), message);
- }
+ }
+
/**
- * send Post request to chef server
+ * Nicolas send Post request to chef server
*/
@SuppressWarnings("nls")
public void chefPost(Map<String, String> params, SvcLogicContext ctx) {
chefInfo(params);
logger.info("chef Post method");
- logger.info(username + " " + clientPrivatekey + " " + chefserver + " " + organizations);
- String CHEF_NODE_STR = params.get("chefRequestBody");
- String chefAction = params.get("chefAction");
+ logger.info(clientName + " " + clientPrivatekey + " " + chefserver + " " + organizations);
+ String CHEF_NODE_STR = params.get("org.openecomp.appc.instance.chefRequestBody");
+ String chefAction = params.get("org.openecomp.appc.instance.chefAction");
+
+ // attributes="\"reconfig-test\":{\"secret\":\"newpass2\"}";
+ // String CHEF_NODE_STR =
+ // "{\"json_class\":\"Chef::Node\",\"default\":{},\"chef_type\":\"node\",\"run_list\":[\""+runList+"\"],\"override\":{},\"automatic\":{},\"normal\":{"+attributes+"},\"name\":\"testnode\",\"chef_environment\":\"_default\"}";
+ // String CHEF_NODE_STR = "{\"json_class\":\"Chef::Node\"}";
+ // logger.info(vm_url);
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
String message = null;
+ // should load pem from somewhere else
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+
+ // need pass path into it
+ // "/nodes/testnode"
ApiMethod am = cac.post(chefAction).body(CHEF_NODE_STR);
am.execute();
code = am.getReturnCode();
chefServerResult(rc, Integer.toString(code), message);
}
+ /**
+ * Nicolas send delete request to chef server
+ */
@SuppressWarnings("nls")
@Override
public void chefDelete(Map<String, String> params, SvcLogicContext ctx) {
logger.info("chef delete method");
chefInfo(params);
- String chefAction = params.get("chefAction");
+ String chefAction = params.get("org.openecomp.appc.instance.chefAction");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
String message = null;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.delete(chefAction);
am.execute();
code = am.getReturnCode();
logger.info(code + " " + message);
chefServerResult(rc, Integer.toString(code), message);
}
+
+
+
+
@SuppressWarnings("nls")
}
}
+
+
+
@SuppressWarnings("nls")
@Override
public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) {
chefInfo(params);
- String jobID = params.get("jobid");
- int retryTimes = Integer.parseInt(params.get("retryTimes"));
- int retryInterval = Integer.parseInt(params.get("retryInterval"));
+ String jobID = params.get("org.openecomp.appc.instance.jobid");
+ int retryTimes = Integer.parseInt(params.get("org.openecomp.appc.instance.retryTimes"));
+ int retryInterval = Integer.parseInt(params.get("org.openecomp.appc.instance.retryInterval"));
String chefAction = "/pushy/jobs/" + jobID;
RequestContext rc = new RequestContext(ctx);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.get(chefAction);
am.execute();
int code = am.getReturnCode();
}
if (status.equals("complete")) {
- svcLogic.setAttribute("chefServerResult.code", "200");
- svcLogic.setAttribute("chefServerResult.message", message);
+ svcLogic.setAttribute("org.openecomp.appc.chefServerResult.code", "200");
+ svcLogic.setAttribute("org.openecomp.appc.chefServerResult.message", message);
} else {
if (status.equals("running")) {
- svcLogic.setAttribute("chefServerResult.code", "202");
- svcLogic.setAttribute("chefServerResult.message", "chef client runtime out");
+ svcLogic.setAttribute("org.openecomp.appc.chefServerResult.code", "202");
+ svcLogic.setAttribute("org.openecomp.appc.chefServerResult.message", "chef client runtime out");
} else {
- svcLogic.setAttribute("chefServerResult.code", "500");
- svcLogic.setAttribute("chefServerResult.message", message);
+ svcLogic.setAttribute("org.openecomp.appc.chefServerResult.code", "500");
+ svcLogic.setAttribute("org.openecomp.appc.chefServerResult.message", message);
}
}
}
@Override
public void pushJob(Map<String, String> params, SvcLogicContext ctx) {
chefInfo(params);
- String pushRequest = params.get("pushRequest");
+ String pushRequest = params.get("org.openecomp.appc.instance.pushRequest");
String chefAction = "/pushy/jobs";
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
SvcLogicContext svcLogic = rc.getSvcLogicContext();
- ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.post(chefAction).body(pushRequest);
;
am.execute();
int startIndex = message.indexOf("jobs") + 6;
int endIndex = message.length() - 2;
String jobID = message.substring(startIndex, endIndex);
- svcLogic.setAttribute("jobID", jobID);
+ svcLogic.setAttribute("org.openecomp.appc.jobID", jobID);
logger.info(jobID);
}
chefServerResult(rc, Integer.toString(code), message);
}
-
@SuppressWarnings("static-method")
private void doFailure(RequestContext rc, int code, String message) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();