summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter/VnfmadapterService/service
diff options
context:
space:
mode:
authorliuqian <liuqian13@huawei.com>2018-05-04 14:25:32 +0800
committerliuqian <liuqian13@huawei.com>2018-05-04 14:25:32 +0800
commitec1a7fc99e21cf716b906fac5b2696ae62f3e9ad (patch)
tree5dbeb5eed2044c830d22c96ba73ca8c2f0505397 /huawei/vnfmadapter/VnfmadapterService/service
parentab30ff201a23bb8ba7a49f80c1748361de47c5a8 (diff)
query jobId support CSM17
Change-Id: Ide24abc8acc6f4e63b24e979b58d963b9f491bbf Issue-ID: VFC-868 Signed-off-by: liuqian <liuqian13@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter/VnfmadapterService/service')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java41
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java45
2 files changed, 70 insertions, 16 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java
index eb081d10..e57d23f4 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java
@@ -19,6 +19,7 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
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;
@@ -90,7 +91,13 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
if(statusCode == Constant.HTTP_CREATED || statusCode == Constant.HTTP_OK) {
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- restJson.put("data", queryResult.getJSONObject("data").getJSONObject("scale_info"));
+ // restJson.put("data",
+ // queryResult.getJSONObject("data").getJSONObject("scale_info"));
+ JSONObject appInfo = queryResult.getJSONObject("data").getJSONObject("scale_info");
+ JSONObject resultObj = new JSONObject();
+ // resultObj.put(Constant.JOBID, vnfInstanceId + "_" + Constant.PUT);
+ handleResponse(resultObj, appInfo, vnfInstanceId, Constant.PUT);
+ restJson.put("data", resultObj);
} else {
LOG.error("function=scaleVnf, msg=send create vnf msg to csm get wrong status: " + statusCode);
}
@@ -144,8 +151,10 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
JSONObject appInfo = JSONObject.fromObject(queryResult.getString("data")).getJSONObject("app_info");
JSONObject resultObj = new JSONObject();
- resultObj.put("vnfInstanceId", appInfo.getString("id"));
- resultObj.put(Constant.JOBID, appInfo.getString("id") + "_" + Constant.POST);
+ // resultObj.put("vnfInstanceId", appInfo.getString("id"));
+ // resultObj.put(Constant.JOBID, appInfo.getString("id") + "_" + Constant.POST);
+ String vnfInstanceId = appInfo.getString("id");
+ handleResponse(resultObj, appInfo, vnfInstanceId, Constant.POST);
restJson.put("data", resultObj);
} else {
LOG.error("function=createVnf, msg=send create vnf msg to csm get wrong status: " + statusCode);
@@ -158,6 +167,17 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
return restJson;
}
+ private void handleResponse(JSONObject result, JSONObject returnObj, String vnfInstanceId, String type) {
+ String jobId = "";
+ if(returnObj.containsKey("job_id")) {
+ jobId = returnObj.getString("job_id") + ":job";
+ } else {
+ jobId = vnfInstanceId + "_" + type + ":no";
+ }
+ result.put("vnfInstanceId", vnfInstanceId);
+ result.put(Constant.JOBID, jobId);
+ }
+
@Override
public JSONObject removeVnf(JSONObject vnfmObject, String vnfId, JSONObject vnfObject) {
LOG.warn("function=removeVnf, msg=enter to remove a vnf: {}", vnfId);
@@ -172,7 +192,16 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
if(statusCode == Constant.HTTP_NOCONTENT || statusCode == Constant.HTTP_OK) {
restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
- restJson.put("data", JSONObject.fromObject(queryResult.getString("data")));
+ // restJson.put("data", JSONObject.fromObject(queryResult.getString("data")));
+ JSONObject appInfo = new JSONObject();
+ if(queryResult.containsKey("data") && StringUtils.isNotEmpty(queryResult.getString("data")))
+ {
+ appInfo = JSONObject.fromObject(queryResult.getString("data"));
+ }
+ JSONObject resultObj = new JSONObject();
+ // resultObj.put(Constant.JOBID, vnfId + "_" + Constant.DELETE);
+ handleResponse(resultObj, appInfo, vnfId, Constant.DELETE);
+ restJson.put("data", resultObj);
} else {
LOG.error("function=removeVnf, msg=send remove vnf msg to csm get wrong status: {}", statusCode);
}
@@ -276,7 +305,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
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=getJob, msg=send get vnf msg to csm get wrong status: {}", statusCode);
}
@@ -327,6 +356,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
public JSONObject getJobFromVnfm(JSONObject vnfmObjcet, String jobId) {
LOG.warn("function=getJobFromVnfm, jobId: {}", jobId);
+
JSONObject restJson = new JSONObject();
restJson.put(Constant.RETCODE, Constant.REST_FAIL);
@@ -347,4 +377,5 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
return restJson;
}
+
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java
index 95515eed..6dd4cdbf 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java
@@ -262,6 +262,20 @@ public class VnfRoa {
public String getJob(@PathParam("jobId") String jobId, @PathParam("vnfmId") String vnfmId,
@Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) {
LOG.warn("function=getJob, msg=enter to get a job: jobId: {}, responseId: {}", jobId, responseId);
+ return getJob(jobId, vnfmId, resp);
+ }
+
+ /**
+ * <br>
+ * common getJob method
+ *
+ * @param jobId
+ * @param vnfmId
+ * @param resp
+ * @return
+ * @since VFC 1.0
+ */
+ private String getJob(String jobId, String vnfmId, HttpServletResponse resp) {
JSONObject restJson = new JSONObject();
if(StringUtils.isEmpty(jobId) || StringUtils.isEmpty(vnfmId)) {
@@ -276,7 +290,7 @@ public class VnfRoa {
return restJson.toString();
}
- return getJobBody(restJson);
+ return getJobBody(restJson, jobId);
}
/**
@@ -323,12 +337,12 @@ public class VnfRoa {
return restJson.toString();
}
- private String getJobBody(JSONObject restJson) {
+ private String getJobBody(JSONObject restJson, String jobId) {
LOG.warn("function=getJobBody, restJson: {}", restJson);
JSONObject responseJson = new JSONObject();
JSONObject jobInfoJson = new JSONObject();
JSONObject retJson = restJson.getJSONArray("data").getJSONObject(0);
- jobInfoJson.put("jobId", retJson.getString("id"));
+ jobInfoJson.put("jobId", jobId);
responseJson.put("progress", progressItem.get(retJson.getString(Constant.STATUS)));
responseJson.put("status", jobstatusItem.get(retJson.getString(Constant.STATUS)));
responseJson.put("errorCode", "null");
@@ -395,14 +409,23 @@ public class VnfRoa {
public String getJobFromVnfm(@PathParam("jobId") String jobId, @PathParam("vnfmId") String vnfmId,
@Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) {
LOG.warn("function=getJobFromVnfm, msg=enter to get a job: jobId: {}, responseId: {}", jobId, responseId);
- JSONObject restJson = vnfMgr.getJobFromVnfm(jobId, vnfmId);
-
- if(restJson.getInt(Constant.RETCODE) == Constant.REST_FAIL) {
- LOG.error("function=getJobFromVnfm, msg=getJobFromVnfm fail");
- resp.setStatus(Constant.HTTP_INNERERROR);
- return restJson.toString();
+ String[] temps = jobId.split(":");
+ String tmpJobId = temps[0];
+ String flag = temps[1];
+ LOG.warn("function=getJobFromVnfm, tmpJobId: {}, flag: {}", tmpJobId, flag);
+
+ if(flag.equalsIgnoreCase("no")) {
+ return getJob(tmpJobId, vnfmId, resp);
+ } else {
+ JSONObject restJson = vnfMgr.getJobFromVnfm(tmpJobId, vnfmId);
+
+ if(restJson.getInt(Constant.RETCODE) == Constant.REST_FAIL) {
+ LOG.error("function=getJobFromVnfm, msg=getJobFromVnfm fail");
+ resp.setStatus(Constant.HTTP_INNERERROR);
+ return restJson.toString();
+ }
+
+ return vnfMgr.transferToLcm(restJson);
}
-
- return vnfMgr.transferToLcm(restJson);
}
}