summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluxin <luxin7@huawei.com>2018-01-27 10:01:36 +0800
committerluxin <luxin7@huawei.com>2018-01-27 10:01:36 +0800
commit76279833ee47cd5adce575de9e50dd584c8fe672 (patch)
treecaf2906556ccf054450e0c0d9e0d6bacf710ee7b
parentba31958a569edd78807d3d921296f57703c6cf32 (diff)
Define constant instead of literal
Change-Id: Ied92dbab134e37b3be949e420c9f7579ef18f304 Issue-ID: VFC-672 Signed-off-by: luxin <luxin7@huawei.com>
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java78
1 files changed, 45 insertions, 33 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java
index 7592f21..223207c 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java
@@ -36,6 +36,14 @@ import net.sf.json.JSONObject;
*/
public class VnfEntity implements Serializable {
+ private static final String RESOURCE_VERSION = "resource-version";
+
+ private static final String VNF_ID = "vnf-id";
+
+ private static final String RELATIONSHIP_KEY = "relationship-key";
+
+ private static final String RELATIONSHIP_VALUE = "relationship-value";
+
/** */
private String id;
@@ -316,14 +324,14 @@ public class VnfEntity implements Serializable {
vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "maxRam"));
vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "maxShd"));
vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "maxNet"));
- vnfEntity.setVnfResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
+ vnfEntity.setVnfResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, RESOURCE_VERSION));
return vnfEntity;
}
public static VnfEntity toEntityFromAai(JSONObject jsonObject) {
VnfEntity vnfEntity = new VnfEntity();
- vnfEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "vnf-id"));
- vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnf-id"));
+ vnfEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, VNF_ID));
+ vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, VNF_ID));
vnfEntity.setVnfInstanceName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-name"));
vnfEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-name2"));
vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "service-id"));
@@ -338,37 +346,42 @@ public class VnfEntity implements Serializable {
vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "vnet"));
vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "nshd"));
vnfEntity.setMaxVm(JsonUtil.getJsonFieldInt(jsonObject, "nvm"));
- vnfEntity.setVnfResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
+ vnfEntity.setVnfResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, RESOURCE_VERSION));
return vnfEntity;
}
public static void updateEntityWithVnfmInfo(VnfEntity vnfEntity, JSONObject jsonObject) {
- vnfEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfm-id"));
+ vnfEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfm-id"));
vnfEntity.setVnfmName(JsonUtil.getJsonFieldStr(jsonObject, "vnfm-name"));
- vnfEntity.setVnfmResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
+ vnfEntity.setVnfmResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, RESOURCE_VERSION));
vnfEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vim-id"));
// vim id stores the info as vim-id: <cloud-region-owner>_<cloud-region-id>
// and esr-system-info contains vim info.
String str = vnfEntity.getVimId();
- if (!(str == null) && str.contains("_")){
- String[] result = str.split("_");
- RestfulParametes restfulParametes = new RestfulParametes();
- restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
- RestfulResponse restfulResponse = RestfulUtil
- .getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL
- + result[0] + "/" + result[1] + "/esr-system-info-list/esr-system-info", restfulParametes, "get");
-
- if(restfulResponse.isSuccess()) {
- vnfEntity.setVimId(JsonUtil.getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()), "esr-system-info-id"));
- vnfEntity.setVimName(JsonUtil.getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()), "system-name"));
- vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()), "default-tenant"));
- }
- }
- else{
-
- //do nothing
+ if(!(str == null) && str.contains("_")) {
+ String[] result = str.split("_");
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ RestfulResponse restfulResponse =
+ RestfulUtil
+ .getRestfulResponse(
+ Config.getHost() + ":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL + result[0]
+ + "/" + result[1] + "/esr-system-info-list/esr-system-info",
+ restfulParametes, "get");
+
+ if(restfulResponse.isSuccess()) {
+ vnfEntity.setVimId(JsonUtil.getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()),
+ "esr-system-info-id"));
+ vnfEntity.setVimName(JsonUtil
+ .getJsonFieldStr(JSONObject.fromObject(restfulResponse.getResponseContent()), "system-name"));
+ vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(
+ JSONObject.fromObject(restfulResponse.getResponseContent()), "default-tenant"));
+ }
+ } else {
+
+ // do nothing
}
}
@@ -379,7 +392,7 @@ public class VnfEntity implements Serializable {
public String toStringForAai() {
JSONObject vnfResJson = new JSONObject();
- vnfResJson.put("vnf-id", StringUtils.trimToEmpty(this.getId()));
+ vnfResJson.put(VNF_ID, StringUtils.trimToEmpty(this.getId()));
vnfResJson.put("vnf-name", StringUtils.trimToEmpty(this.getVnfInstanceName()));
vnfResJson.put("vnf-name2", StringUtils.trimToEmpty(this.getName()));
vnfResJson.put("service-id", StringUtils.trimToEmpty(this.getNsId()));
@@ -396,24 +409,23 @@ public class VnfEntity implements Serializable {
vnfResJson.put("orchestration-status", StringUtils.trimToEmpty(this.getVnfStatus()));
JSONObject relationshipDataEntry = new JSONObject();
- relationshipDataEntry.put("relationship-key", "esr-vnfm.vnfm-id");
- relationshipDataEntry.put("relationship-value", this.getVnfmId());
+ relationshipDataEntry.put(RELATIONSHIP_KEY, "esr-vnfm.vnfm-id");
+ relationshipDataEntry.put(RELATIONSHIP_VALUE, this.getVnfmId());
JSONArray relationshipData1 = new JSONArray();
JSONObject customer = new JSONObject();
- customer.put("relationship-key", "customer.global-customer-id");
- customer.put("relationship-value", Config.getGlobalCustomerId());
+ customer.put(RELATIONSHIP_KEY, "customer.global-customer-id");
+ customer.put(RELATIONSHIP_VALUE, Config.getGlobalCustomerId());
JSONObject service = new JSONObject();
- service.put("relationship-key", "service-subscription.service-type");
- service.put("relationship-value", Config.getServiceType());
+ service.put(RELATIONSHIP_KEY, "service-subscription.service-type");
+ service.put(RELATIONSHIP_VALUE, Config.getServiceType());
JSONObject serviceInstance = new JSONObject();
- serviceInstance.put("relationship-key", "service-instance.service-instance-id");
- serviceInstance.put("relationship-value", this.getNsId());
+ serviceInstance.put(RELATIONSHIP_KEY, "service-instance.service-instance-id");
+ serviceInstance.put(RELATIONSHIP_VALUE, this.getNsId());
relationshipData1.add(customer);
relationshipData1.add(service);
relationshipData1.add(serviceInstance);
-
JSONArray relationshipData = new JSONArray();
relationshipData.add(relationshipDataEntry);
JSONArray relationship = new JSONArray();