package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf;
+import java.io.IOException;
+
+import org.apache.commons.io.IOUtils;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.ParamConstants;
private static final Logger LOG = LoggerFactory.getLogger(VnfMgrVnfm.class);
+ private static final int PARAM_ZERO = 0;
+
+ private static final int PARAM_ONE = 1;
+
@Override
public JSONObject scaleVnf(JSONObject vnfObject, JSONObject vnfmObject, String vnfmId, String vnfInstanceId) {
LOG.warn("function=scaleVnf, msg=enter to scale a vnf");
vdu.put("h_steps", vnfObject.get("numberOfSteps"));
vduList.add(vdu);
scaleInfo.put("vnf_id", vnfInstanceId);
- scaleInfo.put("scale_type", 0);
+ scaleInfo.put("scale_pattern", "without_plan");
+ scaleInfo.put("scale_type", PARAM_ZERO);
scaleInfo.put("scale_action", scaleType);
+ scaleInfo.put("scale_step", PARAM_ZERO);
+ scaleInfo.put("scale_step_value", PARAM_ONE);
+ scaleInfo.put("scale_group", vdu.getString("vdu_type"));
scaleInfo.put("vdu_list", vduList);
- if(scaleType == 0) {// scale_in
+ if(scaleType == PARAM_ZERO) {
+ // scale_in
JSONArray vmList = new JSONArray();
try {
JSONObject additionalParam = vnfObject.getJSONObject("additionalParam");
if(statusCode == Constant.HTTP_CREATED || statusCode == Constant.HTTP_OK) {
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- JSONObject resultObj = new JSONObject();
- resultObj.put(Constant.JOBID, vnfInstanceId + "_" + Constant.PUT);
- restJson.put("data", resultObj);
+ restJson.put("data", queryResult.getJSONObject("data").getJSONObject("scale_info"));
} else {
LOG.error("function=scaleVnf, msg=send create vnf msg to csm get wrong status: " + statusCode);
}
if(statusCode == Constant.HTTP_NOCONTENT || statusCode == Constant.HTTP_OK) {
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- JSONObject resultObj = new JSONObject();
- resultObj.put(Constant.JOBID, vnfId + "_" + Constant.DELETE);
- restJson.put("data", resultObj);
+ restJson.put("data", JSONObject.fromObject(queryResult.getString("data")));
} else {
LOG.error("function=removeVnf, msg=send remove vnf msg to csm get wrong status: {}", statusCode);
}
restJson.put(Constant.RETCODE, Constant.REST_FAIL);
JSONObject queryResult = ResultRequestUtil.call(vnfmObject,
- String.format(ParamConstants.VNF_INSTANCE_GET, vnfId) + Constant.ROARAND + "&type=status", Constant.GET,
- null, Constant.CERTIFICATE);
+ String.format(ParamConstants.VNF_INSTANCE_GET, vnfId), Constant.GET, null, Constant.CERTIFICATE);
int statusCode = queryResult.getInt(Constant.RETCODE);
return restJson;
}
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- restJson.put("data", JSONObject.fromObject(queryResult.getString("data")).getJSONArray("basic"));
+ restJson.put("data", JSONObject.fromObject(queryResult.getString("data")).getJSONArray("vnf_list"));
} else {
LOG.error("function=getVnf, msg=send get vnf msg to csm get wrong status: {}", statusCode);
}
return restJson;
}
+ public JSONObject getIp(JSONObject vnfmObject, String vnfId) throws IOException {
+ LOG.warn("function=getIp, msg=enter to getIp: {}", vnfId);
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+
+ JSONObject queryResult = ResultRequestUtil.call(vnfmObject,
+ String.format(ParamConstants.VNF_CONFIGURATION_GET, vnfId), Constant.GET, null, Constant.CERTIFICATE);
+
+ int statusCode = queryResult.getInt(Constant.RETCODE);
+
+ if(statusCode == Constant.HTTP_OK || statusCode == Constant.HTTP_CREATED) {
+ if(null == (queryResult.get("data"))) {
+ LOG.warn("function=getIp, msg=query is null {}", queryResult.get("data"));
+ return restJson;
+ }
+ JSONObject config = JSONObject.fromObject(queryResult.getString("data"));
+ LOG.info("function=getIp, query configuration result: {}", config);
+ JSONObject vnfInfo = config.getJSONArray("configuration").getJSONObject(0);
+ JSONObject result = new JSONObject();
+ result.put("vnf_id", vnfInfo.getString("vnf_id"));
+ result.put("vnf_type", vnfInfo.getString("vnf_type"));
+ JSONArray inputs = vnfInfo.getJSONArray("inputs");
+
+ ClassLoader classLoader = getClass().getClassLoader();
+ String ipConfig = IOUtils.toString(classLoader.getResourceAsStream("ipConfig.json"));
+ LOG.info("ipConfig: {}", ipConfig);
+ JSONObject ipCon = JSONObject.fromObject(ipConfig);
+ String vnfType = vnfInfo.getString("vnf_type");
+ if(ipCon.containsKey(vnfType)) {
+ String ipKey = ipCon.getString(vnfInfo.getString("vnf_type"));
+ LOG.info("ipKey: {}", ipKey);
+ String ip = "";
+ for(int i = 0; i < inputs.size(); i++) {
+ JSONObject obj = inputs.getJSONObject(i);
+ if(obj.getString("key_name").equals(ipKey)) {
+ ip = obj.getString("value");
+ break;
+ }
+ }
+ result.put("ip", ip);
+ restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ restJson.put("data", result);
+ }
+
+ } else {
+ LOG.error("function=getIp, msg=send get vnf msg to csm get wrong status: {}", statusCode);
+ }
+
+ return restJson;
+ }
+
@Override
public JSONObject getJob(JSONObject vnfmObject, String jobId) {
LOG.warn("function=getJob, msg=enter to get a job: {}", jobId);
int statusCode = healResult.getInt(Constant.RETCODE);
if(statusCode == Constant.HTTP_OK) {
-
+ LOG.info("healResult:{}", healResult);
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
} else {
LOG.error("function=healVnf, msg=send heal vnf msg to csm get wrong status: {}", statusCode);