summaryrefslogtreecommitdiffstats
path: root/huawei
diff options
context:
space:
mode:
authorliuqian <liuqian13@huawei.com>2018-05-23 16:18:09 +0800
committerliuqian <liuqian13@huawei.com>2018-05-23 16:18:09 +0800
commitb134e6b307a65cf282e25a1c53f0f68e2807ddec (patch)
tree77f2d1504945fd233c1de2a10dff52131154657e /huawei
parent65de5e8a56100c0c44b8fce128d4b8c8e67a2a0c (diff)
add some new function
Change-Id: I02a8a4059d8b372e88f886b5fc668098f3365cbb Issue-ID: VFC-920 Signed-off-by: liuqian <liuqian13@huawei.com>
Diffstat (limited to 'huawei')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/deployment/src/main/release/etc/vnfpkginfo/scalein_vm_ids.json2
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java154
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java25
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java26
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoa.java7
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java15
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/config.properties1
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/spring/Vnfmadapter/services.xml3
8 files changed, 214 insertions, 19 deletions
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
index a62900dd..e0402a9d 100644
--- 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
@@ -4,7 +4,7 @@
"vm_id": ""
},
{
- "vim_id": ""
+ "vm_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/csm/vnf/ScaleManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java
new file mode 100644
index 00000000..7b0a4db6
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2018 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.SystemEnvVariablesFactory;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONException;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version VFC 1.0 2018年5月17日
+ */
+public abstract class ScaleManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ScaleManager.class);
+
+ private static String VM_IDS_PATH =
+ SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty(Constant.FILE_SEPARATOR) + "etc"
+ + System.getProperty(Constant.FILE_SEPARATOR) + "vnfpkginfo"
+ + System.getProperty(Constant.FILE_SEPARATOR) + "vms" + System.getProperty(Constant.FILE_SEPARATOR);
+
+ public static void beforeScaleOut(JSONObject queryVms, String vnfId) {
+ try {
+ JSONArray vms = queryVms.getJSONObject("data").getJSONArray("vms");
+ writeVmIdsToFile(vnfId, vms);
+ } catch(JSONException e) {
+ LOG.error("function=beforeScaleOut, msg=recode current vms JSONException");
+ }
+ }
+
+ public static JSONArray beforeScaleIn(JSONObject queryVms, String vnfId) {
+ JSONArray vmList = new JSONArray();
+ try {
+ JSONArray vms = queryVms.getJSONObject("data").getJSONArray("vms");
+ JSONArray recodeVms = readVmIdsFile(vnfId);
+ if(!recodeVms.isEmpty()) {
+ for(int i = 0; i < vms.size(); i++) {
+ JSONObject obj = vms.getJSONObject(i);
+ String vmId = obj.getString("id");
+ if(isScaleOutVm(recodeVms, vmId)) {
+ JSONObject vmIdObj = new JSONObject();
+ vmIdObj.put("vm_id", vmId);
+ vmList.add(vmIdObj);
+ }
+ }
+ }
+ } catch(JSONException e) {
+ LOG.error("function=beforeScaleIn, msg=recode current vms JSONException");
+ }
+ return vmList;
+ }
+
+ private static boolean isScaleOutVm(JSONArray recodeVms, String vmId) {
+ for(int i = 0; i < recodeVms.size(); i++) {
+ JSONObject obj = recodeVms.getJSONObject(i);
+ String oldVmId = obj.getString("id");
+ if(oldVmId.equalsIgnoreCase(vmId)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static String getVmIdsFilePath(String vnfId) {
+ return VM_IDS_PATH + vnfId + ".json";
+ }
+
+ private static void writeVmIdsToFile(String vnfId, JSONArray vms) {
+ String filePath = getVmIdsFilePath(vnfId);
+ FileOutputStream outStream = null;
+ try {
+ File destFile = FileUtils.getFile(filePath);
+
+ File parentFile = destFile.getParentFile();
+ if(parentFile != null) {
+ if(!parentFile.mkdirs() && !parentFile.isDirectory()) {
+ throw new IOException("Destination '" + parentFile + "' directory cannot be created");
+ }
+ }
+ if(!destFile.exists()) {
+ destFile.createNewFile();
+ }
+ outStream = new FileOutputStream(destFile);
+ outStream.write(vms.toString().getBytes());
+ } catch(IOException e) {
+ LOG.error("function=writeVmIdsToFile, msg=write vms to file ioexception, e : {}", e);
+ } finally {
+ IOUtils.closeQuietly(outStream);
+ }
+ }
+
+ private static JSONArray readVmIdsFile(String vnfId) {
+ String filePath = getVmIdsFilePath(vnfId);
+ InputStream ins = null;
+ BufferedInputStream bins = null;
+ String fileContent = "";
+ try {
+ ins = FileUtils.openInputStream(FileUtils.getFile(filePath));
+ 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 JSONArray.fromObject(fileContent);
+ }
+ } catch(IOException e) {
+ LOG.error("function=readVmIdsFile, msg=read vms from file IOException, filePath : {}", filePath);
+ } catch(JSONException e) {
+ LOG.error("function=readVmIdsFile, msg=read vms from file JSONException, fileContent : {}", fileContent);
+ } finally {
+ IOUtils.closeQuietly(bins);
+ IOUtils.closeQuietly(ins);
+ }
+ return new JSONArray();
+ }
+}
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 185d31cb..42d5b875 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
@@ -51,6 +51,11 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
@Override
public JSONObject scaleVnf(JSONObject vnfObject, JSONObject vnfmObject, String vnfmId, String vnfInstanceId) {
LOG.warn("function=scaleVnf, msg=enter to scale a vnf");
+
+ JSONObject queryVms = ResultRequestUtil.call(vnfmObject,
+ String.format(ParamConstants.VNF_GET_VMINFO, vnfInstanceId), Constant.GET, null, Constant.CERTIFICATE);
+ LOG.info("function=scaleVnf, msg=query vms result=" + queryVms);
+
JSONObject restJson = new JSONObject();
restJson.put(Constant.RETCODE, Constant.REST_FAIL);
String path = String.format(ParamConstants.VNF_SCALE, vnfInstanceId);
@@ -61,7 +66,12 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
JSONObject scaleInfo = new JSONObject();
JSONArray vduList = new JSONArray();
JSONObject vdu = new JSONObject();
- vdu.put("vdu_type", this.getVduType(vnfmObject, vnfInstanceId));
+
+ if(vnfObject.containsKey("configedVduType")) {
+ vdu.put("vdu_type", vnfObject.getString("configedVduType"));
+ } else {
+ vdu.put("vdu_type", this.getVduType(vnfmObject, queryVms));
+ }
vdu.put("h_steps", vnfObject.get("numberOfSteps"));
vduList.add(vdu);
scaleInfo.put("vnf_id", vnfInstanceId);
@@ -78,13 +88,18 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
try {
// JSONObject additionalParam = vnfObject.getJSONObject("additionalParam");
// vmList = additionalParam.getJSONArray("vm_list");
- vmList = AdapterResourceManager.readScaleInVmIdFromJson().getJSONArray("vm_list");
+ vmList = ScaleManager.beforeScaleIn(queryVms, vnfInstanceId);
+ if(vmList.isEmpty()) {
+ vmList = AdapterResourceManager.readScaleInVmIdFromJson().getJSONArray("vm_list");
+ }
} catch(JSONException e) {
LOG.error("the param 'additionalParam' or 'vm_list' not found,please check it", e);
}
if(null != vmList && !vmList.isEmpty()) {
scaleInfo.put("vm_list", vmList);
}
+ } else if(scaleType == PARAM_ONE) {
+ ScaleManager.beforeScaleOut(queryVms, vnfInstanceId);
}
paramJson.put("scale_info", scaleInfo);
JSONObject queryResult =
@@ -118,13 +133,9 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
return restJson;
}
- private String getVduType(JSONObject vnfmObject, String vnfInstanceId) {
+ private String getVduType(JSONObject vnfmObject, JSONObject queryResult) {
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);
vduType = queryResult.getJSONObject("data").getJSONArray("vms").getJSONObject(0).getString("vdu_type");
} catch(Exception e) {
LOG.error("get vdu_type failed.", e);
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 a06a995c..7b5c1baf 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
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.commons.lang3.StringUtils;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager;
@@ -50,6 +51,16 @@ public class VnfMgr {
this.vnfmDao = vnfmDao;
}
+ private String configedVduType;
+
+
+ /**
+ * @param configedVduType The configedVduType to set.
+ */
+ public void setConfigedVduType(String configedVduType) {
+ this.configedVduType = configedVduType;
+ }
+
/**
* Scale vnf
*
@@ -80,6 +91,9 @@ public class VnfMgr {
LOG.error("function=scaleVNF,can't find vnfm from db by vnfmId=" + vnfmId);
return restJson;
}
+ if(StringUtils.isNotEmpty(configedVduType)) {
+ vnfObject.put("configedVduType", configedVduType);
+ }
restJson = (new VnfMgrVnfm()).scaleVnf(vnfObject, vnfmObjcet, vnfmId, vnfInstanceId);
} catch(JSONException e) {
LOG.error("function=scaleVNF, msg=JSONException occurs, e={}.", e);
@@ -344,9 +358,17 @@ public class VnfMgr {
JSONObject responseJson = new JSONObject();
JSONObject jobInfoJson = new JSONObject();
JSONObject jobInfo = restJson.getJSONObject("data").getJSONObject("job_info");
- jobInfoJson.put("jobId", jobInfo.getString("job_id"));
+ jobInfoJson.put("jobId", jobInfo.getString("job_id") + ":job");
responseJson.put("progress", jobInfo.getString("task_progress_rate"));
- responseJson.put("status", jobInfo.getString("task_status"));
+
+ String taskStatus = jobInfo.getString("task_status");
+ if(taskStatus.equalsIgnoreCase("Successfully") || taskStatus.equalsIgnoreCase("finished")) {
+ responseJson.put("status", "finished");
+ } else if(taskStatus.equalsIgnoreCase("Failed")) {
+ responseJson.put("status", "error");
+ } else {
+ responseJson.put("status", "processing");
+ }
responseJson.put("errorCode", jobInfo.getString("error_code"));
responseJson.put("responseId", jobInfo.getString("task_progress_rate"));
jobInfoJson.put("responsedescriptor", responseJson);
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoa.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoa.java
index bacfb81c..c16f0730 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoa.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoa.java
@@ -133,12 +133,13 @@ public class VnfResourceRoa {
JSONObject vm = vmList.getJSONObject(i);
LOG.info("function=callLcmNotify, vm: {}", vm);
JSONObject affectedVm = new JSONObject();
- affectedVm.put("vnfcInstanceId", vm.getString("vm_id"));
+ String vimVimId = vm.getString("vim_vm_id");
+ affectedVm.put("vnfcInstanceId", vimVimId);
affectedVm.put("changeType", changeType);
affectedVm.put("vimid", vimId);
- affectedVm.put("vmid", vm.getString("vm_id"));
+ affectedVm.put("vmid", vimVimId);
affectedVm.put("vmname", vm.getString("vm_name"));
- affectedVm.put("vduid", vm.getString("vm_id"));
+ affectedVm.put("vduid", vimVimId);
LOG.info("function=callLcmNotify, affectedVm: {}", affectedVm);
affectedVnfc.add(affectedVm);
}
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 6dd4cdbf..15786b66 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,7 +262,7 @@ 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);
+ return getJobProcess(jobId, vnfmId, resp, jobId);
}
/**
@@ -275,7 +275,7 @@ public class VnfRoa {
* @return
* @since VFC 1.0
*/
- private String getJob(String jobId, String vnfmId, HttpServletResponse resp) {
+ private String getJobProcess(String jobId, String vnfmId, HttpServletResponse resp, String orgJobId) {
JSONObject restJson = new JSONObject();
if(StringUtils.isEmpty(jobId) || StringUtils.isEmpty(vnfmId)) {
@@ -285,12 +285,12 @@ public class VnfRoa {
restJson = vnfMgr.getJob(jobId, vnfmId);
if(restJson.getInt(Constant.RETCODE) == Constant.REST_FAIL) {
- LOG.error("function=getJob, msg=getJob fail");
+ LOG.error("function=getJobProcess, msg=getJob fail");
resp.setStatus(Constant.HTTP_INNERERROR);
return restJson.toString();
}
- return getJobBody(restJson, jobId);
+ return getJobBody(restJson, orgJobId);
}
/**
@@ -411,11 +411,14 @@ public class VnfRoa {
LOG.warn("function=getJobFromVnfm, msg=enter to get a job: jobId: {}, responseId: {}", jobId, responseId);
String[] temps = jobId.split(":");
String tmpJobId = temps[0];
- String flag = temps[1];
+ String flag = "";
+ if(temps.length > 1) {
+ flag = temps[1];
+ }
LOG.warn("function=getJobFromVnfm, tmpJobId: {}, flag: {}", tmpJobId, flag);
if(flag.equalsIgnoreCase("no")) {
- return getJob(tmpJobId, vnfmId, resp);
+ return getJobProcess(tmpJobId, vnfmId, resp, jobId);
} else {
JSONObject restJson = vnfMgr.getJobFromVnfm(tmpJobId, vnfmId);
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/config.properties b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/config.properties
new file mode 100644
index 00000000..7f913926
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/config.properties
@@ -0,0 +1 @@
+vnf.scaleout.config.vdutype= \ No newline at end of file
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/spring/Vnfmadapter/services.xml b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/spring/Vnfmadapter/services.xml
index e14a37f4..f71aa51a 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/spring/Vnfmadapter/services.xml
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/spring/Vnfmadapter/services.xml
@@ -41,6 +41,8 @@
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+ <context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>
+
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
<bean id="source" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
@@ -75,6 +77,7 @@
<bean id="vnfMgr" class="org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr">
<property name="vnfmDao" ref="vnfmDao"></property>
+ <property name="configedVduType" value="${vnf.scaleout.config.vdutype}"></property>
</bean>
<bean id="VnfRoa" class="org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest.VnfRoa">