diff options
author | luxin <luxin7@huawei.com> | 2017-11-16 11:10:25 +0800 |
---|---|---|
committer | luxin <luxin7@huawei.com> | 2017-11-16 11:27:38 +0800 |
commit | f08c8e707f76d0799b42b0faa2b39f42d1855a59 (patch) | |
tree | fe596e204f9a77d07f3a3fce31dd46d98eb54f64 /huawei/vnfmadapter | |
parent | 137529ea77ae7efdfb557c01309e8dfdd8a5466a (diff) |
Add notify lcm interface
Change-Id: Id55a559558287cb85e3aece95a3ad21789291caa
Issue-Id:VFC-594
Signed-off-by: luxin <luxin7@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter')
4 files changed, 70 insertions, 9 deletions
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 67e2497d..43feb8fc 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 @@ -138,8 +138,8 @@ public class AdapterResourceManager implements IResourceManager { LOG.info("unzip CSAR successful.", unzipObject.get(Constant.RETCODE)); // upload vnfd to ftps server - JSONObject uploadResJson = uploadCsar(csarTempObj, csarfilepath); - LOG.info("upload Csar result: {}.", uploadResJson); + // JSONObject uploadResJson = uploadCsar(csarTempObj, csarfilepath); + // LOG.info("upload Csar result: {}.", uploadResJson); Map<String, String> vnfmMap = new HashMap<>(); vnfmMap.put("url", String.format(UrlConstant.REST_VNFMINFO_GET, vnfmid)); @@ -183,7 +183,7 @@ public class AdapterResourceManager implements IResourceManager { } // upload VNF package - csarTempObj.put("vim_id", vimId); + // csarTempObj.put("vim_id", vimId); vnfpkg.put("template", csarTempObj); LOG.info("vnfpkg: " + vnfpkg); 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 6dc49af6..762f3912 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 @@ -16,6 +16,8 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.PUT; @@ -26,11 +28,15 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse; +import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil; +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.process.VnfResourceMgr; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** @@ -96,11 +102,57 @@ public class VnfResourceRoa { @PUT @Path("/lifecycle_changes_notification") - public String notify(@Context HttpServletRequest context) { + public String notify(@Context HttpServletRequest context) throws IOException { LOG.info("function=notify, msg=enter to notify vnf resource"); + JSONObject dataObject = VnfmJsonUtil.getJsonFromContexts(context); + LOG.info("function=notify, dataObject: {}", dataObject); + callLcmNotify(dataObject); JSONObject restJson = new JSONObject(); restJson.put(Constant.RETCODE, Constant.REST_SUCCESS); - return restJson.toString(); } + + private void callLcmNotify(JSONObject dataObject) throws IOException { + String vnfPkgInfo = AdapterResourceManager.readVfnPkgInfoFromJson(); + JSONObject vnfpkgJson = JSONObject.fromObject(vnfPkgInfo); + String vnfmId = vnfpkgJson.getString("vnfmid"); + String vimId = vnfpkgJson.getString("vimid"); + JSONArray affectedVnfc = new JSONArray(); + JSONArray vmList = dataObject.getJSONArray("vm_list"); + String changeType = ""; + String operation = ""; + if(1 == dataObject.getInt("event_type")) { + changeType = "added"; + operation = "Instantiate"; + } else { + changeType = "removed"; + operation = "Terminal"; + } + String vnfcInstanceId = dataObject.getString("vnf_id"); + for(int i = 0; i < vmList.size(); i++) { + JSONObject vm = vmList.getJSONObject(i); + LOG.info("function=callLcmNotify, vm: {}", vm); + JSONObject affectedVm = new JSONObject(); + affectedVm.put("vnfcInstanceId", vnfcInstanceId); + affectedVm.put("changeType", changeType); + affectedVm.put("vimid", vimId); + affectedVm.put("vmid", vm.getString("vm_id")); + affectedVm.put("vmname", vm.getString("vm_name")); + LOG.info("function=callLcmNotify, affectedVm: {}", affectedVm); + affectedVnfc.add(affectedVm); + } + JSONObject notification = new JSONObject(); + notification.put("status", dataObject.getString("vnf_status")); + notification.put("vnfInstanceId", vnfcInstanceId); + notification.put("operation", operation); + notification.put("affectedVnfc", affectedVnfc); + LOG.info("function=callLcmNotify, notification: {}", notification); + String url = "/api/nslcm/v1/ns/" + vnfmId + "/vnfs/" + vnfcInstanceId + "/Notify"; + LOG.info("function=callLcmNotify, url: {}", url); + RestfulResponse rsp = + VnfmRestfulUtil.getRemoteResponse(url, VnfmRestfulUtil.TYPE_POST, notification.toString()); + if(rsp != null) { + LOG.info("function=callLcmNotify, status: {}, content: {}", rsp.getStatus(), rsp.getResponseContent()); + } + } } 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 4b6520f5..98c3fe94 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,7 +24,6 @@ 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; @@ -307,7 +306,7 @@ public class VnfRoa { * @throws ServiceException * @since VFC 1.0 */ - @PUT + @POST @Path("/{vnfmId}/vnfs/{vnfInstanceId}/heal") public String healVnf(@Context HttpServletRequest context, @Context HttpServletResponse resp, @PathParam("vnfmId") String vnfmId, @PathParam("vnfInstanceId") String vnfInstanceId) @@ -330,11 +329,12 @@ public class VnfRoa { } restJson.remove(Constant.RETCODE); - restJson.put("jobId", vnfInstanceId + "_put"); + restJson.put("jobId", vnfInstanceId + "_post"); return restJson.toString(); } private String getJobBody(JSONObject restJson) { + LOG.warn("function=getJobBody, restJson: {}", restJson); JSONObject responseJson = new JSONObject(); JSONObject jobInfoJson = new JSONObject(); JSONObject retJson = restJson.getJSONArray("data").getJSONObject(0); @@ -343,7 +343,14 @@ public class VnfRoa { responseJson.put("status", jobstatusItem.get(retJson.getString(Constant.STATUS))); responseJson.put("errorCode", "null"); responseJson.put("responseId", progressItem.get(retJson.getString(Constant.STATUS))); + if(retJson.getString(Constant.STATUS) == null || retJson.getString(Constant.STATUS) == "null") { + responseJson.put("progress", "100"); + responseJson.put("status", "finished"); + responseJson.put("errorCode", "null"); + responseJson.put("responseId", "100"); + } jobInfoJson.put("responsedescriptor", responseJson); + LOG.warn("function=getJobBody, jobInfoJson: {}", jobInfoJson); return jobInfoJson.toString(); } } diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java index 4b3eb24f..ddf6e44d 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfResourceRoaTest.java @@ -18,6 +18,8 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest; import static org.junit.Assert.assertNotNull; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.junit.After; @@ -250,7 +252,7 @@ public class VnfResourceRoaTest { } @Test - public void testNotify() { + public void testNotify() throws IOException { MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() { @Mock |