add some new function
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / main / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / service / process / VnfMgr.java
index 83c0b55..7b5c1ba 100644 (file)
@@ -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);
@@ -237,9 +251,9 @@ public class VnfMgr {
         restJson.put("vapp_name", vnfObject.get("vnfInstanceName"));
         restJson.put("project_id", vnfmId);
         restJson.put("parameters", resObject.getJSONObject("parameters"));
-               if (resObject.containsKey("emsUuid")) {
-                       restJson.put("emsUuid", resObject.getString("emsUuid"));
-               }
+        if(resObject.containsKey("emsUuid")) {
+            restJson.put("emsUuid", resObject.getString("emsUuid"));
+        }
         restJson.put("nfvo_id", "");
         restJson.put("location", "");
         restJson.put("vnfm_id", vnfmId);
@@ -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);
@@ -366,10 +388,11 @@ public class VnfMgr {
         if(vnfInstanceId == null) {
             url = "/v2/vapps/instances/query/vms";
         } else {
-            url = String.format("/v2/vapps/instances/%s/vms", vnfInstanceId);
+            url = String.format("/v2/vapps/instances/%s/vm", vnfInstanceId);
         }
         restJson = ResultRequestUtil.call(vnfmObjcet, url, Constant.GET, null, Constant.CERTIFICATE);
         LOG.info("function=getVmsFromVnfm, restJson: {}", restJson);
         return restJson;
     }
+
 }