summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java2
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfm.java56
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgr.java21
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java4
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/ipConfig.json4
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java7
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java28
7 files changed, 94 insertions, 28 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java
index 549cc1d8..738590db 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java
@@ -103,6 +103,8 @@ public class ParamConstants {
public static final String VNF_INSTANCE_GET = "/v2/vnfm/instances/%s";
+ public static final String VNF_CONFIGURATION_GET = "/v2/vnfm/configurations/%s";
+
public static final String VNF_SCALE = "/v2/vapps/instances/%s/scale";
public static final String VNF_GET_VMINFO = "/v2/vapps/instances/%s/vm";
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 b712ff6b..eb081d10 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,6 +16,9 @@
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;
@@ -202,6 +205,57 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
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);
@@ -262,7 +316,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
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);
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 e4eb5efc..ce0fcac9 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
@@ -16,9 +16,8 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
+import net.sf.json.JSONException;
+import net.sf.json.JSONObject;
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;
@@ -29,8 +28,9 @@ import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sf.json.JSONException;
-import net.sf.json.JSONObject;
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Provide function for instantiate or terminate VNF
@@ -169,7 +169,7 @@ public class VnfMgr {
* @return
* @since VFC 1.0
*/
- public JSONObject getVnf(String vnfId, String vnfmId) {
+ public JSONObject getVnf(String vnfId, String vnfmId) throws IOException {
LOG.warn("function=getVnf ,msg=enter to get a vnf, vnfId:{}, vnfmId:{}", vnfId, vnfmId);
JSONObject restJson = new JSONObject();
restJson.put(Constant.RETCODE, Constant.REST_FAIL);
@@ -181,8 +181,9 @@ public class VnfMgr {
}
restJson = (new VnfMgrVnfm()).getVnf(vnfmObjcet, vnfId);
+ JSONObject ipObj = (new VnfMgrVnfm()).getIp(vnfmObjcet, vnfId);
- return restJson.getInt(Constant.RETCODE) == Constant.REST_FAIL ? restJson : getVnfBody(restJson);
+ return restJson.getInt(Constant.RETCODE) == Constant.REST_FAIL ? restJson : getVnfBody(restJson, ipObj);
} catch(JSONException e) {
LOG.error("function=getVnf, msg=JSONException occurs, e={}.", e);
@@ -191,7 +192,7 @@ public class VnfMgr {
return restJson;
}
- private JSONObject getVnfBody(JSONObject restJson) {
+ private JSONObject getVnfBody(JSONObject restJson, JSONObject ipObj) {
try {
JSONObject vnfInfoJson = new JSONObject();
JSONObject basicInfoJson = new JSONObject();
@@ -208,7 +209,9 @@ public class VnfMgr {
basicInfoJson.put("vnfProvider", "hw");
basicInfoJson.put("vnfType", retJson.get("vnf_type"));
basicInfoJson.put("vnfStatus", retJson.getString(Constant.STATUS));
-
+ if(ipObj.getInt(Constant.RETCODE) == Constant.REST_SUCCESS) {
+ basicInfoJson.put("ipInfo", ipObj.getJSONObject("data"));
+ }
vnfInfoJson.put("vnfInfo", basicInfoJson);
vnfInfoJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
return vnfInfoJson;
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 66b7d61f..95515eed 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
@@ -16,6 +16,7 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -209,7 +210,7 @@ public class VnfRoa {
@GET
@Path("/{vnfmId}/vnfs/{vnfInstanceId}")
public String getVnf(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp,
- @PathParam("vnfInstanceId") String vnfInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId) throws IOException {
LOG.warn("function=getVnf, msg=enter to get a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId);
JSONObject restJson = new JSONObject();
@@ -226,6 +227,7 @@ public class VnfRoa {
}
restJson.remove(Constant.RETCODE);
+ LOG.info("function=getVnf, restJson: {}", restJson);
return restJson.toString();
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/ipConfig.json b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/ipConfig.json
new file mode 100644
index 00000000..467bd96d
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/ipConfig.json
@@ -0,0 +1,4 @@
+{
+ "vUGE": "MNG_IP",
+ "vUSN": "MNG_IP"
+} \ No newline at end of file
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java
index 075f7ef8..7e34e79e 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfMgrTest.java
@@ -19,6 +19,7 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.util.Map;
import org.junit.Before;
@@ -239,7 +240,7 @@ public class VnfMgrTest {
}
@Test
- public void testGetVnf() {
+ public void testGetVnf() throws IOException {
new MockUp<VnfmUtil>() {
@Mock
@@ -296,7 +297,7 @@ public class VnfMgrTest {
}
@Test
- public void testGetVnfFail() {
+ public void testGetVnfFail() throws IOException {
new MockUp<VnfmUtil>() {
@Mock
@@ -313,7 +314,7 @@ public class VnfMgrTest {
}
@Test
- public void testGetVnfFail1() {
+ public void testGetVnfFail1() throws IOException {
new MockUp<VnfmUtil>() {
@Mock
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
index 8012b5cb..4ec0110c 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
@@ -16,12 +16,10 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -31,10 +29,12 @@ import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.ServiceExcepti
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr;
-import mockit.Mock;
-import mockit.MockUp;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class VnfRoaTest {
@@ -284,7 +284,7 @@ public class VnfRoaTest {
}
@Test
- public void testGetVnfByVnfIdIsEmpty() throws ServiceException {
+ public void testGetVnfByVnfIdIsEmpty() throws IOException, ServiceException {
final JSONObject restJson = new JSONObject();
MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
HttpServletRequest mockInstance = proxyStub.getMockInstance();
@@ -307,7 +307,7 @@ public class VnfRoaTest {
}
@Test
- public void testGetVnfByVnfmIdIsEmpty() throws ServiceException {
+ public void testGetVnfByVnfmIdIsEmpty() throws IOException, ServiceException {
final JSONObject restJson = new JSONObject();
MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
HttpServletRequest mockInstance = proxyStub.getMockInstance();
@@ -330,7 +330,7 @@ public class VnfRoaTest {
}
@Test
- public void testGetVnfFail() throws ServiceException {
+ public void testGetVnfFail() throws IOException, ServiceException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_FAIL);
MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
@@ -361,7 +361,7 @@ public class VnfRoaTest {
}
@Test
- public void testGetVnf() throws ServiceException {
+ public void testGetVnf() throws IOException, ServiceException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};