From b274e9e57cd32e9fd42725d22db33584e2d8407c Mon Sep 17 00:00:00 2001 From: liuqian Date: Wed, 16 May 2018 10:01:22 +0800 Subject: update driver scaling process Change-Id: I058647bf164f529264dbde89b1b349a7d779e1e5 Issue-ID: VFC-868 Signed-off-by: liuqian --- .../release/etc/vnfpkginfo/scalein_vm_ids.json | 10 ++++++ .../adapter/impl/AdapterResourceManager.java | 37 ++++++++++++++++++++++ .../vnfmadapter/service/csm/vnf/VnfMgrVnfm.java | 14 +++++--- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release/etc/vnfpkginfo/scalein_vm_ids.json (limited to 'huawei') diff --git a/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release/etc/vnfpkginfo/scalein_vm_ids.json b/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release/etc/vnfpkginfo/scalein_vm_ids.json new file mode 100644 index 00000000..a62900dd --- /dev/null +++ b/huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release/etc/vnfpkginfo/scalein_vm_ids.json @@ -0,0 +1,10 @@ +{ + "vm_list": [ + { + "vm_id": "" + }, + { + "vim_id": "" + } + ] +} \ No newline at end of file diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java index f9bafb68..ef7a07ae 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java @@ -655,6 +655,43 @@ public class AdapterResourceManager implements IResourceManager { return fileContent; } + /** + * Get scalein vm ids.
+ * + * @return + * @throws IOException + * @since VFC 1.0 + */ + public static JSONObject readScaleInVmIdFromJson() { + String fileContent = ""; + + String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR) + + "vnfpkginfo" + System.getProperty(Constant.FILE_SEPARATOR) + "scalein_vm_ids.json"; + + try (InputStream ins = new FileInputStream(fileName)) { + try (BufferedInputStream bins = new BufferedInputStream(ins)) { + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if(num > 0) { + fileContent = new String(contentByte); + } + } + + if(StringUtils.isNotEmpty(fileContent)) { + return JSONObject.fromObject(fileContent); + } + } catch(FileNotFoundException e) { + LOG.error(fileName + "is not found!", e); + } catch(JSONException e) { + LOG.error(fileName + "is not json!", e); + } catch(IOException e) { + LOG.error(fileName + "io exception!", e); + } + return null; + } + private static JSONObject readVnfdIdInfoFromJson() { JSONObject jsonObject = new JSONObject(); 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 e57d23f4..242ccbdf 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 @@ -21,6 +21,7 @@ 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.adapter.impl.AdapterResourceManager; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.ParamConstants; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.UrlConstant; @@ -75,12 +76,15 @@ public class VnfMgrVnfm implements InterfaceVnfMgr { // scale_in JSONArray vmList = new JSONArray(); try { - JSONObject additionalParam = vnfObject.getJSONObject("additionalParam"); - vmList = additionalParam.getJSONArray("vm_list"); + // JSONObject additionalParam = vnfObject.getJSONObject("additionalParam"); + // vmList = additionalParam.getJSONArray("vm_list"); + vmList = AdapterResourceManager.readScaleInVmIdFromJson().getJSONArray("vm_list"); } catch(JSONException e) { LOG.error("the param 'additionalParam' or 'vm_list' not found,please check it", e); } - scaleInfo.put("vm_list", vmList); + if(null != vmList && !vmList.isEmpty()) { + scaleInfo.put("vm_list", vmList); + } } paramJson.put("scale_info", scaleInfo); JSONObject queryResult = @@ -93,7 +97,9 @@ public class VnfMgrVnfm implements InterfaceVnfMgr { restJson.put(Constant.RETCODE, Constant.REST_SUCCESS); // restJson.put("data", // queryResult.getJSONObject("data").getJSONObject("scale_info")); - JSONObject appInfo = queryResult.getJSONObject("data").getJSONObject("scale_info"); + // JSONObject appInfo = + // queryResult.getJSONObject("data").getJSONObject("scale_info"); + JSONObject appInfo = new JSONObject(); JSONObject resultObj = new JSONObject(); // resultObj.put(Constant.JOBID, vnfInstanceId + "_" + Constant.PUT); handleResponse(resultObj, appInfo, vnfInstanceId, Constant.PUT); -- cgit 1.2.3-korg