Merge "Fix automatic package conversion"
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / main / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / service / csm / vnf / VnfMgrVnfm.java
index d1508ba..eb081d1 100644 (file)
 
 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;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.UrlConstant;
 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.inf.InterfaceVnfMgr;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,6 +42,10 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
 
     private static final Logger LOG = LoggerFactory.getLogger(VnfMgrVnfm.class);
 
+    private static final int PARAM_ZERO = 0;
+
+    private static final int PARAM_ONE = 1;
+
     @Override
     public JSONObject scaleVnf(JSONObject vnfObject, JSONObject vnfmObject, String vnfmId, String vnfInstanceId) {
         LOG.warn("function=scaleVnf, msg=enter to scale a vnf");
@@ -55,10 +63,15 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
         vdu.put("h_steps", vnfObject.get("numberOfSteps"));
         vduList.add(vdu);
         scaleInfo.put("vnf_id", vnfInstanceId);
-        scaleInfo.put("scale_type", 0);
+        scaleInfo.put("scale_pattern", "without_plan");
+        scaleInfo.put("scale_type", PARAM_ZERO);
         scaleInfo.put("scale_action", scaleType);
+        scaleInfo.put("scale_step", PARAM_ZERO);
+        scaleInfo.put("scale_step_value", PARAM_ONE);
+        scaleInfo.put("scale_group", vdu.getString("vdu_type"));
         scaleInfo.put("vdu_list", vduList);
-        if(scaleType == 0) {// scale_in
+        if(scaleType == PARAM_ZERO) {
+            // scale_in
             JSONArray vmList = new JSONArray();
             try {
                 JSONObject additionalParam = vnfObject.getJSONObject("additionalParam");
@@ -77,9 +90,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
 
             if(statusCode == Constant.HTTP_CREATED || statusCode == Constant.HTTP_OK) {
                 restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
-                JSONObject resultObj = new JSONObject();
-                resultObj.put(Constant.JOBID, vnfInstanceId + "_" + Constant.PUT);
-                restJson.put("data", resultObj);
+                restJson.put("data", queryResult.getJSONObject("data").getJSONObject("scale_info"));
             } else {
                 LOG.error("function=scaleVnf, msg=send create vnf msg to csm get wrong status: " + statusCode);
             }
@@ -161,9 +172,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
 
         if(statusCode == Constant.HTTP_NOCONTENT || statusCode == Constant.HTTP_OK) {
             restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
-            JSONObject resultObj = new JSONObject();
-            resultObj.put(Constant.JOBID, vnfId + "_" + Constant.DELETE);
-            restJson.put("data", resultObj);
+            restJson.put("data", JSONObject.fromObject(queryResult.getString("data")));
         } else {
             LOG.error("function=removeVnf, msg=send remove vnf msg to csm get wrong status: {}", statusCode);
         }
@@ -178,8 +187,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
         restJson.put(Constant.RETCODE, Constant.REST_FAIL);
 
         JSONObject queryResult = ResultRequestUtil.call(vnfmObject,
-                String.format(ParamConstants.VNF_INSTANCE_GET, vnfId) + Constant.ROARAND + "&type=status", Constant.GET,
-                null, Constant.CERTIFICATE);
+                String.format(ParamConstants.VNF_INSTANCE_GET, vnfId), Constant.GET, null, Constant.CERTIFICATE);
 
         int statusCode = queryResult.getInt(Constant.RETCODE);
 
@@ -189,7 +197,7 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
                 return restJson;
             }
             restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
-            restJson.put("data", JSONObject.fromObject(queryResult.getString("data")).getJSONArray("basic"));
+            restJson.put("data", JSONObject.fromObject(queryResult.getString("data")).getJSONArray("vnf_list"));
         } else {
             LOG.error("function=getVnf, msg=send get vnf msg to csm get wrong status: {}", statusCode);
         }
@@ -197,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);
@@ -257,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);
@@ -265,4 +324,27 @@ public class VnfMgrVnfm implements InterfaceVnfMgr {
 
         return restJson;
     }
+
+    public JSONObject getJobFromVnfm(JSONObject vnfmObjcet, String jobId) {
+        LOG.warn("function=getJobFromVnfm, jobId: {}", jobId);
+        JSONObject restJson = new JSONObject();
+        restJson.put(Constant.RETCODE, Constant.REST_FAIL);
+
+        JSONObject queryResult = ResultRequestUtil.call(vnfmObjcet, String.format(UrlConstant.URL_JOBSTATUS_GET, jobId),
+                Constant.GET, null, Constant.CERTIFICATE);
+
+        int statusCode = queryResult.getInt(Constant.RETCODE);
+        if(statusCode == Constant.HTTP_OK || statusCode == Constant.HTTP_CREATED) {
+            if((queryResult.get("data")) == null) {
+                LOG.warn("function=getJobFromVnfm, msg=query is null {}", queryResult.get("data"));
+                return restJson;
+            }
+            restJson.put(Constant.RETCODE, Constant.REST_SUCCESS);
+            restJson.put("data", JSONObject.fromObject(queryResult.getString("data")));
+        } else {
+            LOG.error("function=getJobFromVnfm, msg=query job from vnfm wrong status: {}", statusCode);
+        }
+
+        return restJson;
+    }
 }