summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluxin <luxin7@huawei.com>2017-10-26 15:46:53 +0800
committerluxin <luxin7@huawei.com>2017-10-26 15:46:53 +0800
commit4cf7e3a0cb9b6079919397b98c2517e8aeeb3231 (patch)
treeaf009dda544ab8ae10da986bb323120d7cb25b79
parent15df2b7050cd377b548b02181cda8b78b5963f9a (diff)
Fix ESR interface bug
Change-Id: I9678ff291f1a914fbedaa338c139b73bb8981d88 Issue-Id:VFC-552 Signed-off-by: luxin <luxin7@huawei.com>
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java67
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java15
2 files changed, 55 insertions, 27 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java
index 2e595d6..d9e8867 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java
@@ -16,6 +16,10 @@
package org.onap.vfc.nfvo.resmanagement.common;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.codec.binary.Base64;
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;
@@ -109,7 +113,24 @@ public class VimUtil {
LOG.error("Get vim ERROR, VimId is null. ");
return null;
}
- JSONObject esrResponse = RestfulUtil.getResponseObj(String.format(UrlConstant.ESR_GET_VIM_URL, vimId), "get");
+ Map<String, String> headerMap = new HashMap<>(5);
+ headerMap.put("Content-Type", "application/json");
+ headerMap.put("Accept", "application/json");
+ headerMap.put("X-TransactionId", "9999");
+ headerMap.put("X-FromAppId", "esr-server");
+
+ Base64 token = new Base64();
+ String authen = new String(token.encode(("AAI:AAI").getBytes()));
+ headerMap.put("Authorization", "Basic " + authen);
+ LOG.info("getVimById headerMap: {}", headerMap.toString());
+ RestfulParametes parametes = new RestfulParametes();
+ parametes.setHeaderMap(headerMap);
+ String[] cloud = vimId.trim().split("_");
+ String cloudOwner = cloud[0];
+ String cloudRegionId = cloud[1];
+
+ JSONObject esrResponse = RestfulUtil.getResponseObj(
+ String.format(UrlConstant.ESR_GET_VIMS_URL, cloudOwner, cloudRegionId), parametes, "get");
LOG.info("Get vims from ESR! EsrResponse:{}", esrResponse);
if(null == esrResponse) {
LOG.error("ESR return fail.");
@@ -124,43 +145,41 @@ public class VimUtil {
*
* @param vimId
* @param esrResponse
+ * http://172.30.3.34:80/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/vmware/fake/esr-system-info-list
* {
- * "esr-system-info-id": "",
- * "system-name": "",
- * "type": "",
- * "vendor": "",
- * "version": "",
- * "service-url": "",
- * "user-name": "",
- * "password": "",
- * "system-type": "",
- * "protocal": "",
- * "ssl-cacert": "",
- * "ssl-insecure": "",
- * "ip-address": "",
- * "port": "",
- * "cloud-domain": "",
- * "default-tenant": "",
- * "resource-version": "",
- * "relationship-list": [
+ * "esr-system-info": [
+ * {
+ * "esr-system-info-id": "f77da8eb-11c4-46e4-a10b-380c91215cfd",
+ * "service-url": "https://172.30.2.2:5000/v3",
+ * "user-name": "admin",
+ * "password": "admin",
+ * "system-type": "VIM",
+ * "ssl-insecure": true,
+ * "cloud-domain": "default",
+ * "default-tenant": "admin",
+ * "system-status": "active",
+ * "resource-version": "1508909163786"
+ * }
* ]
* }
* @return
* @since VFC 1.0
*/
- private static JSONObject parseEsrResponse(String vimId, JSONObject esrResponse) {
+ private static JSONObject parseEsrResponse(String vimId, JSONObject esr) {
+ JSONObject esrResponse = esr.getJSONArray("esr-system-info").getJSONObject(0);
+ LOG.info("parseEsrResponse: {}", esrResponse);
JSONObject vimInfo = new JSONObject();
vimInfo.put("vimId", vimId);
- vimInfo.put("name", esrResponse.getString("system-name"));
+ vimInfo.put("name", esrResponse.getString("esr-system-info-id"));
vimInfo.put("url", esrResponse.getString("service-url"));
vimInfo.put("userName", esrResponse.getString("user-name"));
vimInfo.put("password", esrResponse.getString("password"));
vimInfo.put("tenant", esrResponse.getString("default-tenant"));
- vimInfo.put("vendor", esrResponse.getString("vendor"));
- vimInfo.put("version", esrResponse.getString("version"));
+ vimInfo.put("vendor", "");
+ vimInfo.put("version", "");
vimInfo.put("description", "");
vimInfo.put("domain", esrResponse.getString("cloud-domain"));
- vimInfo.put("type", esrResponse.getString("type"));
+ vimInfo.put("type", esrResponse.getString("system-type"));
vimInfo.put("createTime", "");
LOG.info("parseEsrResponse vimInfo: {}", vimInfo);
return vimInfo;
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java
index 7695fbd..993d0ae 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java
@@ -32,6 +32,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
+import org.onap.vfc.nfvo.resmanagement.common.VimUtil;
import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;
import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
@@ -74,6 +75,14 @@ public class VnfRoa {
}
@GET
+ @Path("/{vimId}")
+ public JSONObject getVimById(@Context HttpServletRequest context, @PathParam("vimId") String vimId)
+ throws ServiceException {
+
+ return VimUtil.getVimById(vimId);
+ }
+
+ @GET
@Path("/{vnfId}")
public JSONObject getVnf(@Context HttpServletRequest context, @PathParam("vnfId") String id)
throws ServiceException {
@@ -90,7 +99,7 @@ public class VnfRoa {
@POST
public JSONObject addVnf(@Context HttpServletRequest context) throws ServiceException {
JSONObject object = RequestUtil.getJsonRequestBody(context);
- if (null == object) {
+ if(null == object) {
LOGGER.error("function=addVnf; msg=add error, because vnf is null.");
throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.add.null"));
}
@@ -98,7 +107,7 @@ public class VnfRoa {
LOGGER.info("VnfRoa::addVnf:{}", object.toString());
try {
return vnfService.addVnf(VnfEntity.toEntity(object));
- } catch (ServiceException se) {
+ } catch(ServiceException se) {
LOGGER.error("VnfRoa::addVnf error:{}" + se);
return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
}
@@ -108,7 +117,7 @@ public class VnfRoa {
@Path("/{id}")
public JSONObject deleteVnf(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id)
throws ServiceException {
- if (id == null) {
+ if(id == null) {
LOGGER.error("function=deleteVnf; msg=delete error, because id is null.");
throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.delete.id.null"));
}