summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-10-06 20:06:45 +0530
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2017-10-19 05:07:56 +0000
commit7513105889f149c49739c545ba9847da567aa824 (patch)
tree502fd14cb0c57bc8e11a556bb41d964a600e0545
parentc681bd275bbc9d36024ac8eb2e8eccf7f20ce05e (diff)
Integrate VM related operation with AAI
Integrate VM related operation with AAI. Change-Id: Iac4eb1a8bc8cf2bcd614ef12c124f6164dd1343c Issue-ID: VFC-462 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/conf/Config.java9
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java4
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java45
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulResponse.java20
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VmAaiDaoImpl.java197
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java24
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java50
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java28
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java20
-rw-r--r--ResmanagementService/service/src/main/resources/config.properties4
-rw-r--r--ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml4
11 files changed, 363 insertions, 42 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/conf/Config.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/conf/Config.java
index 118cd8e..fe33b19 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/conf/Config.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/conf/Config.java
@@ -59,4 +59,13 @@ public class Config {
public static String getTenantId() {
return prps.getProperty(Constant.TENANT_ID);
}
+
+ public static String getGlobalCustomerId() {
+ return prps.getProperty(Constant.GLOBAL_CUSTOMER_ID);
+ }
+
+ public static String getServiceType() {
+ return prps.getProperty(Constant.SERVICE_TYPE);
+ }
+
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
index b1fbb33..1f4534f 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
@@ -103,6 +103,10 @@ public class Constant {
public static final String TENANT_ID = "tenant-id";
+ public static final String GLOBAL_CUSTOMER_ID = "global-customer-id";
+
+ public static final String SERVICE_TYPE = "service-type";
+
private Constant() {
// private constants
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java
index 53d9a47..8fd7702 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java
@@ -256,6 +256,51 @@ public class UrlConstant {
*/
public static final String LIMITS_URL = "/v1/limits";
+ /**
+ * esr-vnfm url
+ */
+ public static final String ESR_VNFM_URL = "/aai/v11/external-system/esr-vnfm-list/esr-vnfm/";
+
+ /**
+ * generic-vnf url
+ */
+ public static final String GENERIC_VNF_URL = "/aai/v11/network/generic-vnfs/generic-vnf/";
+
+ /**
+ * generic-vnf url
+ */
+ public static final String GENERIC_VNFS_URL = "/aai/v11/network/generic-vnfs";
+
+ /**
+ * customer url
+ */
+ public static final String CUSTOMER_URL = "/aai/v11/business/customers/customer/";
+
+ /**
+ * service-subscription url
+ */
+ public static final String SERVICE_SUBSCRIPTION_URL = "/service-subscriptions/service-subscription/";
+
+ /**
+ * service-instance url
+ */
+ public static final String SERVICE_INSTANCE_URL = "/service-instances/service-instance/";
+
+ /**
+ * cloud-region url
+ */
+ public static final String CLOUD_REGION_URL = "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/";
+
+ /**
+ * tenant url
+ */
+ public static final String CLOUD_TENANT_URL = "/tenants/tenant/";
+
+ /**
+ * vserver url
+ */
+ public static final String VSERVER_URL = "/vservers/vserver/";
+
private UrlConstant() {
// private constructor
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulResponse.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulResponse.java
index f71122c..500c58d 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulResponse.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulResponse.java
@@ -22,7 +22,7 @@ import java.util.Map;
* Response for RestFul requests.<br/>
* <p>
* </p>
- *
+ *
* @author
* @version 28-May-2016
*/
@@ -36,7 +36,7 @@ public class RestfulResponse {
/**
* <br/>
- *
+ *
* @return
* @since
*/
@@ -46,7 +46,7 @@ public class RestfulResponse {
/**
* <br/>
- *
+ *
* @param status
* @since
*/
@@ -56,7 +56,7 @@ public class RestfulResponse {
/**
* <br/>
- *
+ *
* @return
* @since
*/
@@ -66,7 +66,7 @@ public class RestfulResponse {
/**
* <br/>
- *
+ *
* @param header
* @since
*/
@@ -76,7 +76,7 @@ public class RestfulResponse {
/**
* Get response header value as integer.<br/>
- *
+ *
* @param key header param name.
* @return header param value as integer. (-1 if error)
* @since
@@ -93,7 +93,7 @@ public class RestfulResponse {
/**
* Get response header value as long.<br/>
- *
+ *
* @param key header param name.
* @return value as long. -1 if no value.
* @since
@@ -110,7 +110,7 @@ public class RestfulResponse {
/**
* Get http header as string.<br/>
- *
+ *
* @param key header name.
* @return header value.
* @since
@@ -124,7 +124,7 @@ public class RestfulResponse {
/**
* <br/>
- *
+ *
* @return
* @since
*/
@@ -134,7 +134,7 @@ public class RestfulResponse {
/**
* <br/>
- *
+ *
* @param responseString
* @since
*/
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VmAaiDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VmAaiDaoImpl.java
new file mode 100644
index 0000000..8f40a17
--- /dev/null
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VmAaiDaoImpl.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.resmanagement.service.dao.impl.aai;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.commons.lang.StringUtils;
+import org.onap.vfc.nfvo.resmanagement.common.conf.Config;
+import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
+import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
+import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VmDao;
+import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class VmAaiDaoImpl implements VmDao {
+
+ private static int VNF_AAI_DAO_SUCCESS = 1;
+
+ private static int VNF_AAI_DAO_FAIL = -1;
+
+ @Override
+ public VmEntity getVm(String id) {
+ VmEntity vmEntity = null;
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL
+ + Config.getCloudOwner() + "/" + Config.getCloudRegionId() + UrlConstant.CLOUD_TENANT_URL
+ + Config.getTenantId() + UrlConstant.VSERVER_URL + id,
+ restfulParametes, "get");
+
+ if(response.isSuccess()) {
+ JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
+ vmEntity = updateVnfInstnaceId(VmEntity.toEntityFromAai(jsonObject), jsonObject);
+ }
+
+ return vmEntity;
+ }
+
+ private int checkGenericVnfExist(VmEntity vmEntity) {
+ if(!StringUtils.isEmpty(vmEntity.getVnfInstanceId())) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response = RestfulUtil
+ .getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.GENERIC_VNF_URL
+ + vmEntity.getVnfInstanceId(), restfulParametes, "get");
+ if(!response.isSuccess()) {
+ return VNF_AAI_DAO_FAIL;
+ }
+ }
+ return VNF_AAI_DAO_SUCCESS;
+ }
+
+ @Override
+ public int addVm(VmEntity vmEntity) {
+ if(checkGenericVnfExist(vmEntity) == VNF_AAI_DAO_SUCCESS) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData(vmEntity.toStringForAai());
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL
+ + Config.getCloudOwner() + "/" + Config.getCloudRegionId() + UrlConstant.CLOUD_TENANT_URL
+ + Config.getTenantId() + UrlConstant.VSERVER_URL + vmEntity.getVmId(),
+ restfulParametes, "put");
+
+ if(response.isSuccess()) {
+ return VNF_AAI_DAO_SUCCESS;
+ }
+ }
+ return VNF_AAI_DAO_FAIL;
+ }
+
+ @Override
+ public List<VmEntity> getVms(Map<String, Object> condition) {
+ List<VmEntity> vmEntities = new ArrayList<>();
+ if(condition.containsKey(ParamConstant.PARAM_ID)) {
+ VmEntity vmEntity = getVm((String)condition.get(ParamConstant.PARAM_ID));
+ if(vmEntity != null) {
+ vmEntities.add(vmEntity);
+ }
+ } else {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response =
+ RestfulUtil
+ .getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL
+ + Config.getCloudOwner() + "/" + Config.getCloudRegionId()
+ + UrlConstant.CLOUD_TENANT_URL + Config.getTenantId() + "/vservers",
+ restfulParametes, "get");
+
+ JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
+ JSONArray jsonArray = jsonObject.getJSONArray("vserver");
+
+ // update vnfInstanceId
+ for(int i = 0; i < jsonArray.size(); i++) {
+ JSONObject vserverObj = jsonArray.getJSONObject(i);
+ vmEntities.add(updateVnfInstnaceId(VmEntity.toEntityFromAai(vserverObj), vserverObj));
+ }
+ }
+ return vmEntities;
+ }
+
+ private VmEntity updateVnfInstnaceId(VmEntity vmEntity, JSONObject jsonObj) {
+ if(jsonObj.has("relationship-list")) {
+ JSONArray relList = (JSONArray)((JSONObject)jsonObj.get("relationship-list")).get("relationship");
+ for(int i = 0; i < relList.size(); i++) {
+ JSONObject obj = relList.getJSONObject(i);
+ if("generic-vnf".equals(obj.getString("related-to"))) {
+ vmEntity.setVnfInstanceId(StringUtils.substringAfterLast(obj.getString("related-link"), "/"));
+ }
+ }
+ }
+ return vmEntity;
+ }
+
+ @Override
+ public int deleteVmById(String id) {
+ VmEntity vmEntity = getVm(id);
+
+ if(vmEntity != null) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.put("resource-version", vmEntity.getResourceVersion());
+
+ RestfulResponse response =
+ RestfulUtil
+ .getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL
+ + Config.getCloudOwner() + "/" + Config.getCloudRegionId()
+ + UrlConstant.CLOUD_TENANT_URL + Config.getTenantId() + UrlConstant.VSERVER_URL + id,
+ restfulParametes, "delete");
+
+ if(response.isSuccess()) {
+ return VNF_AAI_DAO_SUCCESS;
+ }
+ }
+ return VNF_AAI_DAO_FAIL;
+ }
+
+ @Override
+ public int updateVm(VmEntity vmEntity) {
+
+ VmEntity vm = this.getVm(vmEntity.getVmId());
+ vmEntity.setResourceVersion(vm.getResourceVersion());
+
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData(vmEntity.toStringForAai());
+
+ RestfulResponse response =
+ RestfulUtil.getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CLOUD_REGION_URL
+ + Config.getCloudOwner() + "/" + Config.getCloudRegionId() + UrlConstant.CLOUD_TENANT_URL
+ + Config.getTenantId() + UrlConstant.VSERVER_URL + vmEntity.getVmId(),
+ restfulParametes, "put");
+ return response.isSuccess() ? VNF_AAI_DAO_SUCCESS : VNF_AAI_DAO_FAIL;
+ }
+
+ @Override
+ public int deleteVmByVnfId(String vnfInstanceId) {
+ List<VmEntity> vms = this.getVms(new HashMap<>());
+ Optional<VmEntity> vmOpt = vms.stream().filter(vm -> vnfInstanceId.equals(vm.getVnfInstanceId())).findFirst();
+ if(vmOpt.isPresent()) {
+ return this.deleteVmById(vmOpt.get().getVmId());
+ }
+ return VNF_AAI_DAO_FAIL;
+ }
+
+}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java
index bda5822..fbc6156 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java
@@ -21,6 +21,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
+import org.onap.vfc.nfvo.resmanagement.common.conf.Config;
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
@@ -51,7 +53,7 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
RestfulResponse response = RestfulUtil.getRestfulResponse(
- "https://192.168.17.24:8443/aai/v11/network/generic-vnfs", restfulParametes, "get");
+ Config.getHost() +":" + Config.getPort() + UrlConstant.GENERIC_VNFS_URL, restfulParametes, "get");
if(response.isSuccess()) {
JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
@@ -68,7 +70,7 @@ public class VnfAaiDaoImpl implements VnfDao {
}
private VnfEntity updateVnfInfo(VnfEntity vnfEntity, JSONObject jsonObject) {
- updateVnfInfo(vnfEntity, jsonObject);
+ updateVnfmInfo(vnfEntity, jsonObject);
updateNsInfo(vnfEntity, jsonObject);
return vnfEntity;
}
@@ -87,7 +89,7 @@ public class VnfAaiDaoImpl implements VnfDao {
RestfulParametes restfulParametes = new RestfulParametes();
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
RestfulResponse restfulResponse = RestfulUtil
- .getRestfulResponse("https://192.168.17.24:8443" + relatedLink, restfulParametes, "get");
+ .getRestfulResponse(Config.getHost() +":" + Config.getPort() + relatedLink, restfulParametes, "get");
if(restfulResponse.isSuccess()) {
VnfEntity.updateEntityWithVnfmInfo(vnfEntity,
@@ -113,7 +115,7 @@ public class VnfAaiDaoImpl implements VnfDao {
RestfulParametes restfulParametes = new RestfulParametes();
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
RestfulResponse restfulResponse = RestfulUtil
- .getRestfulResponse("https://192.168.17.24:8443" + relatedLink, restfulParametes, "get");
+ .getRestfulResponse(Config.getHost() +":" + Config.getPort() + relatedLink, restfulParametes, "get");
if(restfulResponse.isSuccess()) {
VnfEntity.updateEntityWithNsInfo(vnfEntity,
@@ -132,7 +134,7 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
RestfulResponse response = RestfulUtil.getRestfulResponse(
- "https://192.168.17.24:8443/aai/v11/network/generic-vnfs/generic-vnf/" + id, restfulParametes, "get");
+ Config.getHost() +":" + Config.getPort() + UrlConstant.GENERIC_VNF_URL + id, restfulParametes, "get");
if(response.isSuccess()) {
JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
@@ -148,7 +150,7 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
// restfulParametes.setRawData(vnfEntity.toEsrVnfmStringForAai());
RestfulResponse response = RestfulUtil.getRestfulResponse(
- "https://192.168.17.24:8443/aai/v11/external-system/esr-vnfm-list/esr-vnfm/" + vnfEntity.getVnfmId(),
+ Config.getHost() +":" + Config.getPort() + UrlConstant.ESR_VNFM_URL + vnfEntity.getVnfmId(),
restfulParametes, "get");
return response == null || !response.isSuccess() ? VNF_AAI_DAO_FAIL : VNF_AAI_DAO_SUCCESS;
}
@@ -158,8 +160,8 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
RestfulResponse response = RestfulUtil.getRestfulResponse(
- "https://192.168.17.24:8443/aai/v11/business/customers/customer/vfc/service-subscriptions/service-subscription"
- + "/vfc-service/service-instances/service-instance/" + vnfEntity.getNsId(), restfulParametes, "get");
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CUSTOMER_URL + Config.getGlobalCustomerId() + UrlConstant.SERVICE_SUBSCRIPTION_URL
+ + Config.getServiceType() + UrlConstant.SERVICE_INSTANCE_URL + vnfEntity.getNsId(), restfulParametes, "get");
return response == null || !response.isSuccess() ? VNF_AAI_DAO_FAIL : VNF_AAI_DAO_SUCCESS;
}
@@ -171,7 +173,7 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.setRawData(vnfEntity.toStringForAai());
RestfulResponse response = RestfulUtil.getRestfulResponse(
- "https://192.168.17.24:8443/aai/v11/network/generic-vnfs/generic-vnf/" + vnfEntity.getId(),
+ Config.getHost() +":" + Config.getPort() + UrlConstant.GENERIC_VNF_URL + vnfEntity.getId(),
restfulParametes, "put");
return response == null || !response.isSuccess() ? VNF_AAI_DAO_FAIL : VNF_AAI_DAO_SUCCESS;
}
@@ -198,7 +200,7 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.put("resource-version", vnfEntity.getVnfmResourceVersion());
RestfulResponse response = RestfulUtil
- .getRestfulResponse("https://192.168.17.24:8443/aai/v11/external-system/esr-vnfm-list/esr-vnfm/"
+ .getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.ESR_VNFM_URL
+ vnfEntity.getVnfmId(), restfulParametes, "delete");
return response == null || !response.isSuccess() ? VNF_AAI_DAO_FAIL : VNF_AAI_DAO_SUCCESS;
}
@@ -214,7 +216,7 @@ public class VnfAaiDaoImpl implements VnfDao {
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
restfulParametes.put("resource-version", vnfEntity.getVnfResourceVersion());
RestfulResponse response = RestfulUtil
- .getRestfulResponse("https://192.168.17.24:8443/aai/v11/network/generic-vnfs/generic-vnf/"
+ .getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.GENERIC_VNF_URL
+ vnfEntity.getVnfInstanceId(), restfulParametes, "delete");
if(response.isSuccess()) {
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java
index 817faca..ebf3f67 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.lang.StringUtils;
import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
+import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
@@ -41,6 +42,8 @@ public class VmEntity implements Serializable {
/** */
private String vnfInstanceId;
+ private String resourceVersion;
+
private static final long serialVersionUID = 1L;
public String getVmId() {
@@ -75,6 +78,14 @@ public class VmEntity implements Serializable {
this.vnfInstanceId = vnfInstanceId;
}
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
public static VmEntity toEntity(JSONObject jsonObject) {
VmEntity vmEntity = new VmEntity();
vmEntity.setVmId(JsonUtil.getJsonFieldStr(jsonObject, "vmId"));
@@ -93,4 +104,43 @@ public class VmEntity implements Serializable {
vmResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId()));
return vmResJson.toString();
}
+
+ public String toStringForAai() {
+ JSONObject vmResJson = new JSONObject();
+ vmResJson.put("vserver-id", StringUtils.trimToEmpty(this.getVmId()));
+ vmResJson.put("vserver-name", StringUtils.trimToEmpty(this.getVmName()));
+ vmResJson.put("prov-status", StringUtils.trimToEmpty(this.getVmStatus()));
+ vmResJson.put("vserver-selflink", "");
+ vmResJson.put("resource-version", StringUtils.trimToEmpty(this.getResourceVersion()));
+
+ if(!StringUtils.isEmpty(this.getVnfInstanceId())) {
+ JSONArray relationshipData = new JSONArray();
+ JSONObject relationshipDataEntry = new JSONObject();
+ relationshipDataEntry.put("relationship-key", "generic-vnf.vnf-id");
+ relationshipDataEntry.put("relationship-value", this.getVnfInstanceId());
+ relationshipData.add(relationshipDataEntry);
+
+ JSONArray relationship = new JSONArray();
+ JSONObject relationshipEntry = new JSONObject();
+ relationshipEntry.put("related-to", "generic-vnf");
+ relationshipEntry.put("relationship-data", relationshipData);
+ relationship.add(relationshipEntry);
+
+ JSONObject relation = new JSONObject();
+ relation.put("relationship", relationship);
+
+ vmResJson.put("relationship-list", relation);
+ }
+ return vmResJson.toString();
+ }
+
+ public static VmEntity toEntityFromAai(JSONObject jsonObject) {
+ VmEntity vmEntity = new VmEntity();
+ vmEntity.setVmId(JsonUtil.getJsonFieldStr(jsonObject, "vserver-id"));
+ vmEntity.setVmName(JsonUtil.getJsonFieldStr(jsonObject, "vserver-name"));
+ vmEntity.setVmStatus(JsonUtil.getJsonFieldStr(jsonObject, "prov-status"));
+ vmEntity.setResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
+ return vmEntity;
+
+ }
}
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 84b8620..7592f21 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
@@ -19,6 +19,8 @@ package org.onap.vfc.nfvo.resmanagement.service.entity;
import java.io.Serializable;
import org.apache.commons.lang.StringUtils;
+import org.onap.vfc.nfvo.resmanagement.common.conf.Config;
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
@@ -341,24 +343,32 @@ public class VnfEntity implements Serializable {
}
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.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vim-id"));
// vim id stores the info as vim-id: <cloud-region-owner>_<cloud-region-id>
- // and esr-sysstem-info contains vim info.
- String str = JsonUtil.getJsonFieldStr(jsonObject, "vim-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("https://192.168.17.24:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/"
+ .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, "esr-system-info-id"));
- vnfEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "system-name"));
- vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(jsonObject, "default-tenant"));
+ 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
}
}
@@ -392,10 +402,10 @@ public class VnfEntity implements Serializable {
JSONArray relationshipData1 = new JSONArray();
JSONObject customer = new JSONObject();
customer.put("relationship-key", "customer.global-customer-id");
- customer.put("relationship-value", "ResManagement-Customer-id");
+ customer.put("relationship-value", Config.getGlobalCustomerId());
JSONObject service = new JSONObject();
service.put("relationship-key", "service-subscription.service-type");
- service.put("relationship-value", "ResManagement-NSID-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());
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java
index 5931ea6..d7574ee 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java
@@ -25,11 +25,11 @@ import org.apache.commons.lang.StringUtils;
import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VmDao;
import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity;
import org.onap.vfc.nfvo.resmanagement.service.group.inf.VmService;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +40,7 @@ import net.sf.json.JSONObject;
* <br>
* <p>
* </p>
- *
+ *
* @author
* @version VFC 1.0 Oct 29, 2016
*/
@@ -52,7 +52,7 @@ public class VmServiceImpl implements VmService {
/**
* <br>
- *
+ *
* @param vmEntity
* @return
* @throws ServiceException
@@ -76,15 +76,15 @@ public class VmServiceImpl implements VmService {
restJson.put("id", vmEntity.getVmId());
restJson.put("name", vmEntity.getVmName());
} else {
- LOGGER.error("function=addVm; msg=add vm into DB error.");
- restJson.put("message", "Add vm into DB error.");
+ LOGGER.error("function=addVm; msg=add vm into AAI error.");
+ restJson.put("message", "Add vm into AAI error.");
}
return restJson;
}
/**
* <br>
- *
+ *
* @param vmId
* @return
* @since VFC 1.0
@@ -128,7 +128,7 @@ public class VmServiceImpl implements VmService {
/**
* <br>
- *
+ *
* @param map
* @return
* @throws ServiceException
@@ -141,7 +141,7 @@ public class VmServiceImpl implements VmService {
/**
* <br>
- *
+ *
* @param id
* @return
* @throws ServiceException
@@ -158,7 +158,7 @@ public class VmServiceImpl implements VmService {
/**
* <br>
- *
+ *
* @param vnfInstanceId
* @throws ServiceException
* @since VFC 1.0
diff --git a/ResmanagementService/service/src/main/resources/config.properties b/ResmanagementService/service/src/main/resources/config.properties
index 2440521..1aac5f4 100644
--- a/ResmanagementService/service/src/main/resources/config.properties
+++ b/ResmanagementService/service/src/main/resources/config.properties
@@ -2,4 +2,6 @@ host_url=https://192.168.17.24
port=8443
cloud-owner=htipl103-cloud-owner-val-18494
cloud-region-id=htipl103-cloud-region-id-val-8824
-tenant-id=htipl-tenant-id-val-51195 \ No newline at end of file
+tenant-id=htipl-tenant-id-val-51195
+global-customer-id=vfc
+service-type=vfc-service \ No newline at end of file
diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
index de9a982..5c72315 100644
--- a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
+++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
@@ -248,8 +248,10 @@
<property name="session" ref="session"></property>
</bean>
+ <bean id="vmAaiDao" class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.aai.VmAaiDaoImpl" />
+
<bean id="vmService" class="org.onap.vfc.nfvo.resmanagement.service.group.impl.VmServiceImpl">
- <property name="vmDao" ref="vmDao"></property>
+ <property name="vmDao" ref="vmAaiDao"></property>
</bean>
<bean id="vmRoa" class="org.onap.vfc.nfvo.resmanagement.service.rest.VmRoa">