summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter
diff options
context:
space:
mode:
Diffstat (limited to 'huawei/vnfmadapter')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java112
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java50
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java46
3 files changed, 162 insertions, 46 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 18de1c02..833dda34 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
@@ -16,8 +16,6 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf;
-import net.sf.json.JSONArray;
-
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;
@@ -25,11 +23,10 @@ import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.inf.InterfaceVnfMgr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
-import javax.print.attribute.standard.ReferenceUriSchemesSupported;
-
/**
* create or terminate VNF to M
* <br/>
@@ -49,31 +46,32 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
String path = String.format(ParamConstants.VNF_SCALE, vnfInstanceId);
int scaleType = getScaleType(vnfObject.getString("type"));
- //build request json object
+ // build request json object
JSONObject paramJson = new JSONObject();
JSONObject scaleInfo = new JSONObject();
JSONArray vduList = new JSONArray();
JSONObject vdu = new JSONObject();
- vdu.put("vdu_type",this.getVduType(vnfmObject,vnfInstanceId));//TODO:set vdu_type
- vdu.put("h_steps",vnfObject.get("numberOfSteps"));
+ vdu.put("vdu_type", this.getVduType(vnfmObject, vnfInstanceId));// TODO:set vdu_type
+ vdu.put("h_steps", vnfObject.get("numberOfSteps"));
vduList.add(vdu);
- scaleInfo.put("vnf_id",vnfInstanceId);
- scaleInfo.put("scale_type",0);
- scaleInfo.put("scale_action",scaleType);
- scaleInfo.put("vdu_list",vduList);
- if(scaleType == 0){//scale_in
+ scaleInfo.put("vnf_id", vnfInstanceId);
+ scaleInfo.put("scale_type", 0);
+ scaleInfo.put("scale_action", scaleType);
+ scaleInfo.put("vdu_list", vduList);
+ if(scaleType == 0) {// scale_in
JSONArray vmList = new JSONArray();
try {
JSONObject additionalParam = vnfObject.getJSONObject("additionalParam");
vmList = additionalParam.getJSONArray("vm_list");
- }catch (JSONException e) {
- LOG.error("the param 'additionalParam' or 'vm_list' not found,please check it",e);
+ } catch(JSONException e) {
+ LOG.error("the param 'additionalParam' or 'vm_list' not found,please check it", e);
}
- scaleInfo.put("vm_list",vmList);
+ scaleInfo.put("vm_list", vmList);
}
- paramJson.put("scale_info",scaleInfo);
- JSONObject queryResult = ResultRequestUtil.call(vnfmObject, path, Constant.PUT, paramJson.toString(),Constant.CERTIFICATE);
- LOG.info("SCALE execute result:"+queryResult.toString());
+ paramJson.put("scale_info", scaleInfo);
+ JSONObject queryResult =
+ ResultRequestUtil.call(vnfmObject, path, Constant.PUT, paramJson.toString(), Constant.CERTIFICATE);
+ LOG.info("SCALE execute result:" + queryResult.toString());
try {
int statusCode = queryResult.getInt(Constant.RETCODE);
@@ -93,37 +91,41 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
return restJson;
}
-
- private String getVduType(JSONObject vnfmObject, String vnfInstanceId){
+ private String getVduType(JSONObject vnfmObject, String vnfInstanceId) {
String vduType = "";
try {
- JSONObject queryResult = ResultRequestUtil.call(vnfmObject, String.format(ParamConstants.VNF_GET_VMINFO, vnfInstanceId), Constant.GET, null,Constant.CERTIFICATE);
- LOG.info("getVduType result="+queryResult);
+ JSONObject queryResult =
+ ResultRequestUtil.call(vnfmObject, String.format(ParamConstants.VNF_GET_VMINFO, vnfInstanceId),
+ Constant.GET, null, Constant.CERTIFICATE);
+ LOG.info("getVduType result=" + queryResult);
vduType = queryResult.getJSONObject("data").getJSONArray("vms").getJSONObject(0).getString("vdu_type");
- } catch (Exception e) {
- LOG.error("get vdu_type failed.",e);
+ } catch(Exception e) {
+ LOG.error("get vdu_type failed.", e);
}
- LOG.info("vdu_type="+vduType);
+ LOG.info("vdu_type=" + vduType);
return vduType;
}
- private int getScaleType(String type){
- if("SCALE_OUT".equalsIgnoreCase(type)){
+
+ private int getScaleType(String type) {
+ if("SCALE_OUT".equalsIgnoreCase(type)) {
return 1;
- }else if("SCALE_IN".equalsIgnoreCase(type)){
+ } else if("SCALE_IN".equalsIgnoreCase(type)) {
return 0;
}
return -1;
}
+
@Override
public JSONObject createVnf(JSONObject subJsonObject, JSONObject vnfmObject) {
LOG.info("function=createVnf, msg=enter to create a vnf");
- LOG.info("createVnf csm request body :"+subJsonObject);
+ LOG.info("createVnf csm request body :" + subJsonObject);
JSONObject restJson = new JSONObject();
restJson.put(Constant.RETCODE, Constant.REST_FAIL);
String path = ParamConstants.VNF_INSTANCE + Constant.ROARAND;
- JSONObject queryResult = ResultRequestUtil.call(vnfmObject, path, Constant.POST, subJsonObject.toString(),Constant.CERTIFICATE);
- LOG.info("createVnf csm response content:"+queryResult);
+ JSONObject queryResult =
+ ResultRequestUtil.call(vnfmObject, path, Constant.POST, subJsonObject.toString(), Constant.CERTIFICATE);
+ LOG.info("createVnf csm response content:" + queryResult);
try {
int statusCode = queryResult.getInt(Constant.RETCODE);
@@ -152,7 +154,8 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
restJson.put(Constant.RETCODE, Constant.REST_FAIL);
JSONObject queryResult = ResultRequestUtil.call(vnfmObject,
- String.format(ParamConstants.VNF_INSTANCE_DEL, vnfId) + Constant.ROARAND, Constant.DELETE, null,Constant.CERTIFICATE);
+ String.format(ParamConstants.VNF_INSTANCE_DEL, vnfId) + Constant.ROARAND, Constant.DELETE, null,
+ Constant.CERTIFICATE);
int statusCode = queryResult.getInt(Constant.RETCODE);
@@ -176,7 +179,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
JSONObject queryResult = ResultRequestUtil.call(vnfmObject,
String.format(ParamConstants.VNF_INSTANCE_GET, vnfId) + Constant.ROARAND + "&type=status", Constant.GET,
- null,Constant.CERTIFICATE);
+ null, Constant.CERTIFICATE);
int statusCode = queryResult.getInt("retCode");
@@ -203,7 +206,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
String vnfId = jobId.split("_")[0];
JSONObject queryResult = ResultRequestUtil.call(vnfmObject,
String.format(ParamConstants.VNF_INSTANCE_GET, vnfId) + Constant.ROARAND + "&type=status", Constant.GET,
- null,Constant.CERTIFICATE);
+ null, Constant.CERTIFICATE);
int statusCode = queryResult.getInt("retCode");
@@ -221,4 +224,45 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
return restJson;
}
+
+ /**
+ * <br>
+ *
+ * @param jsonObject
+ * @param vnfmObjcet
+ * @param vnfmId
+ * @param vnfInstanceId
+ * @return
+ * @since NFVO 0.5
+ */
+ public JSONObject healVnf(JSONObject jsonObject, JSONObject vnfmObjcet, String vnfmId, String vnfInstanceId) {
+ LOG.info("healVnf request body :" + jsonObject);
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+
+ String action = jsonObject.getString("action");
+ JSONObject affectedVm = jsonObject.getJSONObject("affectedvm");
+ String vmId = affectedVm.getString("vmid");
+ String path = String.format(ParamConstants.HEAL_VNF, vmId);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("type", "hard");
+ subJsonObject.put("boot_mode", null);
+ if("vmReset".equals(action)) {
+ subJsonObject.put("action", "reset");
+ }
+
+ JSONObject healResult = ResultRequestUtil.callSouth(vnfmObjcet, path, Constant.PUT, subJsonObject.toString(),
+ Constant.CERTIFICATE);
+
+ int statusCode = healResult.getInt("retCode");
+ if(statusCode == Constant.HTTP_OK) {
+
+ restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+ } else {
+ LOG.error("function=getJob, msg=send get vnf msg to csm get wrong status: {}", statusCode);
+ }
+
+ return restJson;
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java
index 0a0a17ff..8b1f4463 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java
@@ -25,7 +25,6 @@ import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf.VnfMgrVnfm;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.dao.inf.VnfmDao;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,17 +48,17 @@ public class VnfMgr {
this.vnfmDao = vnfmDao;
}
-
/**
* Scale vnf
+ *
* @param vnfObject
- * {
- * "vnfInstanceId":"5",
- * "type":"SCALE_OUT",
- * "aspectId":"101",
- * "numberOfSteps":"1",
- * "additionalParam":{}
- * }
+ * {
+ * "vnfInstanceId":"5",
+ * "type":"SCALE_OUT",
+ * "aspectId":"101",
+ * "numberOfSteps":"1",
+ * "additionalParam":{}
+ * }
* @param vnfmId
* @param vnfInstanceId
* @return
@@ -74,9 +73,9 @@ public class VnfMgr {
}
JSONObject vnfmObjcet = VnfmUtil.getVnfmById(vnfmId);
- LOG.info("vnfm info:"+vnfmObjcet);
+ LOG.info("vnfm info:" + vnfmObjcet);
if(vnfmObjcet.isNullObject()) {
- LOG.error("function=scaleVNF,can't find vnfm from db by vnfmId="+vnfmId);
+ LOG.error("function=scaleVNF,can't find vnfm from db by vnfmId=" + vnfmId);
return restJson;
}
restJson = (new VnfMgrVnfm()).scaleVnf(vnfObject, vnfmObjcet, vnfmId, vnfInstanceId);
@@ -114,7 +113,7 @@ public class VnfMgr {
Map<String, String> conMap = new ConcurrentHashMap<>(Constant.DEFAULT_COLLECTION_SIZE);
conMap.put("csarid", vnfObject.getString("vnfPackageId"));
conMap.put("vnfmid", vnfmId);
- conMap.put("vnfDescriptorId",vnfObject.getString("vnfDescriptorId"));
+ conMap.put("vnfDescriptorId", vnfObject.getString("vnfDescriptorId"));
JSONObject resObjcet = (new AdapterResourceManager()).uploadVNFPackage(null, conMap);
@@ -293,4 +292,31 @@ public class VnfMgr {
}
}
}
+
+ /**
+ * <br>
+ *
+ * @param jsonObject
+ * @param vnfInstanceId
+ * @param vnfmId
+ * @return
+ * @since NFVO 0.5
+ */
+ public JSONObject healVnf(JSONObject jsonObject, String vnfInstanceId, String vnfmId) {
+ JSONObject restJson = new JSONObject();
+ restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+
+ if(jsonObject.isNullObject() || jsonObject.isEmpty()) {
+ return restJson;
+ }
+
+ JSONObject vnfmObjcet = VnfmUtil.getVnfmById(vnfmId);
+ LOG.info("vnfm info:" + vnfmObjcet);
+ if(vnfmObjcet.isNullObject()) {
+ LOG.error("function=scaleVNF,can't find vnfm from db by vnfmId=" + vnfmId);
+ return restJson;
+ }
+ restJson = (new VnfMgrVnfm()).healVnf(jsonObject, vnfmObjcet, vnfmId, vnfInstanceId);
+ 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 f35f10d1..e97a3215 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
@@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@@ -271,6 +272,51 @@ public class VnfRoa {
return getJobBody(restJson);
}
+ /**
+ * <br>
+ *
+ * @param context
+ * {
+ * ˇ°actionˇ±: ˇ°vmResetˇ±,
+ * ˇ°affectedvmˇ±: {
+ * ˇ°vmidˇ±: ˇ°804cca71 - 9ae9 - 4511 - 8e30 - d1387718caffˇ±,
+ * ˇ°vduidˇ±: ˇ°vdu_100ˇ±,
+ * ˇ°vmnameˇ±: ˇ°ZTE_SSS_111_PP_2_Lˇ±
+ * }
+ * }
+ * @param resp
+ * @param vnfmId
+ * @param vnfInstanceId
+ * @return
+ * @throws ServiceException
+ * @since NFVO 0.5
+ */
+ @PUT
+ @Path("/{vnfmId}/vnfs/{vnfInstanceId}/heal")
+ public String healVnf(@Context HttpServletRequest context, @Context HttpServletResponse resp,
+ @PathParam("vnfmId") String vnfmId, @PathParam("vnfInstanceId") String vnfInstanceId)
+ throws ServiceException {
+ LOG.warn("function=healVnf, msg=enter to heal a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId);
+ JSONObject restJson = new JSONObject();
+ JSONObject jsonObject = VnfmJsonUtil.getJsonFromContexts(context);
+
+ if(StringUtils.isEmpty(vnfInstanceId) || StringUtils.isEmpty(vnfmId)) {
+ resp.setStatus(Constant.HTTP_INNERERROR);
+ restJson.put("message", "vnfmId is null or vnfInstanceId is null");
+ return restJson.toString();
+ }
+
+ restJson = vnfMgr.healVnf(jsonObject, vnfInstanceId, vnfmId);
+ if(restJson.getInt(Constant.RETCODE) == Constant.REST_FAIL) {
+ LOG.error("function=healVnf, msg=healVnf fail");
+ resp.setStatus(Constant.HTTP_INNERERROR);
+ return restJson.toString();
+ }
+
+ restJson.remove(Constant.RETCODE);
+ return restJson.toString();
+ }
+
private String getJobBody(JSONObject restJson) {
JSONObject responseJson = new JSONObject();
JSONObject jobInfoJson = new JSONObject();