summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtil.java100
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java14
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/ConnectMgrVnfm.java63
3 files changed, 161 insertions, 16 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtil.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtil.java
index fa3d0aea..ab947cba 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtil.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtil.java
@@ -167,7 +167,8 @@ public final class ResultRequestUtil {
String token = mgrVcmm.getAccessSession();
String roaRand = mgrVcmm.getRoaRand();
String vnfmUrl = vnfmObject.getString("url");
- removeTokens(vnfmUrl, token, roaRand);
+ String user = vnfmObject.getString("userName");
+ removeTokens(vnfmUrl, token, roaRand, user);
} catch(IOException e) {
LOG.info("function=call, msg=IOException, e is {}", e);
} catch(ReflectiveOperationException e) {
@@ -193,9 +194,102 @@ public final class ResultRequestUtil {
*
* @since NFVO 0.5
*/
- private static void removeTokens(String vnfmUrl, String token, String roaRand) {
+ private static void removeTokens(String vnfmUrl, String token, String roaRand, String user) {
HttpMethod httpMethodToken = null;
- String tokenUrl = String.format(ParamConstants.CSM_AUTH_DISCONNECT, "manoadmin", roaRand);
+ String tokenUrl = String.format(ParamConstants.CSM_AUTH_DISCONNECT, user, roaRand);
+ LOG.info("removeTokens tokenUrl=" + tokenUrl);
+ try {
+ httpMethodToken = new HttpRequests.Builder(Constant.CERTIFICATE).setUrl(vnfmUrl.trim(), tokenUrl)
+ .setParams("").addHeader("X-Auth-Token", token).delete().execute();
+ int statusCode = httpMethodToken.getStatusCode();
+ String result = httpMethodToken.getResponseBodyAsString();
+ LOG.info("removeTokens int=" + statusCode + ", result=" + result);
+ } catch(IOException e) {
+ LOG.info("function=call, msg=IOException, e is {}", e);
+ } catch(Throwable e) {
+ LOG.info("function=call, msg=Throwable, e is {}", e);
+ } finally {
+ if(httpMethodToken != null) {
+ httpMethodToken.releaseConnection();
+ }
+ }
+ }
+
+ /**
+ * <br>
+ *
+ * @param vnfmObject
+ * @param path
+ * @param methodName
+ * @param paramsJson
+ * @param authModel
+ * @return
+ * @since NFVO 0.5
+ */
+ public static JSONObject callSouth(JSONObject vnfmObject, String path, String methodName, String paramsJson,
+ String authModel) {
+ LOG.info("request-param=" + paramsJson + ",authModel=" + authModel + ",path=" + path + ",vnfmInfo="
+ + vnfmObject);
+ JSONObject resultJson = new JSONObject();
+
+ ConnectMgrVnfm mgrVcmm = new ConnectMgrVnfm();
+
+ if(Constant.HTTP_OK != mgrVcmm.connectSouth(vnfmObject, authModel)) {
+ resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
+ resultJson.put("data", "connect fail.");
+ return resultJson;
+ }
+
+ HttpMethod httpMethod = null;
+ try {
+
+ String result = null;
+ String vnfPath = path.contains("%s") ? String.format(path, mgrVcmm.getRoaRand()) : path;
+ LOG.info("function=call, msg=url is {}, session is {}", vnfmObject.getString("url") + vnfPath,
+ mgrVcmm.getAccessSession());
+ HttpRequests.Builder builder =
+ new HttpRequests.Builder(authModel).addHeader(Constant.ACCESSSESSION, mgrVcmm.getAccessSession())
+ .setUrl(vnfmObject.getString("url"), vnfPath).setParams(paramsJson);
+ MethodType methodType = MethodType.methodType(HttpRequests.Builder.class, new Class[0]);
+ MethodHandle mt =
+ MethodHandles.lookup().findVirtual(builder.getClass(), methodName, methodType).bindTo(builder);
+
+ builder = (HttpRequests.Builder)mt.invoke();
+ httpMethod = builder.execute();
+ result = httpMethod.getResponseBodyAsString();
+ LOG.warn("function=call, msg=response status is {}. result is {}", httpMethod.getStatusCode(), result);
+ resultJson.put(Constant.RETCODE, httpMethod.getStatusCode());
+ resultJson.put("data", result);
+
+ // logout delete tokens
+ String token = mgrVcmm.getAccessSession();
+ String oldUrl = vnfmObject.getString("url").trim();
+ String newUrl = oldUrl.replaceAll("30001", "30000");
+ String user = vnfmObject.getString("userName");
+ removeV3Tokens(newUrl, token, user);
+ } catch(IOException e) {
+ LOG.info("function=call, msg=IOException, e is {}", e);
+ } catch(ReflectiveOperationException e) {
+ LOG.info("function=call, msg=ReflectiveOperationException, e is {}", e);
+ } catch(Throwable e) {
+ LOG.info("function=call, msg=Throwable, e is {}", e);
+ } finally {
+ if(httpMethod != null) {
+ httpMethod.releaseConnection();
+ }
+ }
+
+ if(httpMethod == null) {
+ resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
+ resultJson.put("data", "get connection error");
+ }
+
+ return resultJson;
+ }
+
+ private static void removeV3Tokens(String vnfmUrl, String token, String user) {
+ HttpMethod httpMethodToken = null;
+ String tokenUrl = String.format(ParamConstants.CSM_AUTH_CONNECT_SOUTH_DISCONNECT, user);
LOG.info("removeTokens tokenUrl=" + tokenUrl);
try {
httpMethodToken = new HttpRequests.Builder(Constant.CERTIFICATE).setUrl(vnfmUrl.trim(), tokenUrl)
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java
index 1f932d7b..af486093 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/ParamConstants.java
@@ -17,9 +17,7 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant;
/**
- *
* @author
- *
* @version NFVO 0.5 Sep 6, 2016
*/
public class ParamConstants {
@@ -29,9 +27,9 @@ public class ParamConstants {
public static final String GET_TOKENS_V2 =
"{\"auth\":{\"identity\": {\"methods\": [\"password\"],\"password\": {\"user\": {\"name\": \"%s\",\"password\": \"%s\"}}}}}";
- public static final String GET_IAM_TOKENS =
+ public static final String GET_TOKENS_V3 =
"{\"auth\": {\"identity\": {\"methods\": [\"password\"],\"password\": {\"user\": {\"name\": "
- + "\"%s\",\"password\": \"%s\",\"domain\": {\"name\": \"%s\"}}}},\"scope\": {\"domain\": {\"name\": \"%s\"}}}}";
+ + "\"%s\",\"password\": \"%s\",\"domain\": {\"name\": \"%s\"}}}}}}";
public static final String GET_TOKEN_SUC_RESP =
"{\"token\": {\"methods\": [\"password\"],\"expires_at\": \"\",\"user\": {\"id\": \"%s\","
@@ -45,7 +43,9 @@ public class ParamConstants {
public static final String REST_3RD_HANDSHAKE = "/rest/plat/ssm/v1/sessions/verify";
- public static final String IAM_AUTH = "/v3/auth/tokens";
+ public static final String CSM_AUTH_CONNECT_SOUTH = "/v3/auth/tokens";
+
+ public static final String CSM_AUTH_CONNECT_SOUTH_DISCONNECT = "/v3/auth/tokens/%s";
public static final String CSM_AUTH_CONNECT = "/v2/auth/tokens";
@@ -65,7 +65,6 @@ public class ParamConstants {
public static final String VNFMGR_INSTANCE = "/vnfmgr/v1/instances";
-
public static final String VNFD_FLAVOR = "/vnfdmgr/v1/flavor";
public static final String UPDATE_RESOURCE = "/rest/v1/resmanage/resuse/updateres";
@@ -106,7 +105,6 @@ public class ParamConstants {
public static final String VNF_GET_VMINFO = "/v2/vapps/instances/%s/vm";
-
public static final String MSB_REGISTER_URL = "/openoapi/microservices/v1/services";
public static final String MSB_UNREGISTER_URL = "/openoapi/microservices/v1/services/hw-vnfm";
@@ -117,6 +115,8 @@ public class ParamConstants {
public static final String GRANT_RES_URL = "/openoapi/resmgr/v1/resource/grant";
+ public static final String HEAL_VNF = "/v2/vapps/instances/vm/%s/action";
+
private ParamConstants() {
// private contstructor
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/ConnectMgrVnfm.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/ConnectMgrVnfm.java
index 26430799..8be8b7dc 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/ConnectMgrVnfm.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/ConnectMgrVnfm.java
@@ -36,7 +36,7 @@ import net.sf.json.JSONObject;
* .</br>
*
* @author
- * @version NFVO 0.5 Sep 14, 2016
+ * @version NFVO 0.5 Sep 14, 2016
*/
public class ConnectMgrVnfm {
@@ -62,16 +62,15 @@ public class ConnectMgrVnfm {
this.roaRand = roaRand;
}
-
/**
* Make connection
* <br>
*
* @param vnfmObj
* @return
- * @since NFVO 0.5
+ * @since NFVO 0.5
*/
- public int connect(JSONObject vnfmObj,String authModel) {
+ public int connect(JSONObject vnfmObj, String authModel) {
LOG.info("function=connect, msg=enter connect function.");
ConnectInfo info = new ConnectInfo(vnfmObj.getString("url"), vnfmObj.getString("userName"),
@@ -87,7 +86,7 @@ public class ConnectMgrVnfm {
statusCode = httpMethod.getStatusCode();
String result = httpMethod.getResponseBodyAsString();
- LOG.info("connect result:"+result);
+ LOG.info("connect result:" + result);
if(statusCode == HttpStatus.SC_CREATED) {
JSONObject accessObj = JSONObject.fromObject(result);
JSONObject tokenObj = accessObj.getJSONObject("token");
@@ -114,13 +113,65 @@ public class ConnectMgrVnfm {
return statusCode;
}
+
+ /**
+ * <br>
+ *
+ * @param vnfmObj
+ * @param authModel
+ * @return
+ * @since NFVO 0.5
+ */
+ public int connectSouth(JSONObject vnfmObj, String authModel) {
+ LOG.info("function=connectSouth, msg=enter connect function.");
+ String oldUrl = vnfmObj.getString("url").trim();
+ String newUrl = oldUrl.replaceAll("30001", "30000");
+ LOG.info("function=connectSouth, url={}.", newUrl);
+ ConnectInfo info =
+ new ConnectInfo(newUrl, vnfmObj.getString("userName"), vnfmObj.getString("password"), authModel);
+ HttpMethod httpMethod = null;
+ int statusCode = Constant.INTERNAL_EXCEPTION;
+
+ try {
+ httpMethod = new HttpRequests.Builder(info.getAuthenticateMode())
+ .setUrl(info.getUrl(), ParamConstants.CSM_AUTH_CONNECT_SOUTH)
+ .setParams(String.format(ParamConstants.GET_TOKENS_V3, info.getUserName(), info.getUserPwd()))
+ .post().execute();
+ statusCode = httpMethod.getStatusCode();
+
+ String result = httpMethod.getResponseBodyAsString();
+ LOG.info("connect result:" + result);
+ if(statusCode == HttpStatus.SC_CREATED) {
+ Header header = httpMethod.getResponseHeader("accessSession");
+ setAccessSession(header.getValue());
+ statusCode = HttpStatus.SC_OK;
+ } else {
+ LOG.error("connect fail, code:" + statusCode + " re:" + result);
+ }
+
+ } catch(JSONException e) {
+ LOG.error("function=connect, msg=connect JSONException e={}.", e);
+ } catch(VnfmException e) {
+ LOG.error("function=connect, msg=connect VnfmException e={}.", e);
+ } catch(IOException e) {
+ LOG.error("function=connect, msg=connect IOException e={}.", e);
+ } finally {
+ clearCSMPwd(info);
+ if(httpMethod != null) {
+ httpMethod.releaseConnection();
+ }
+ }
+ return statusCode;
+
+ }
+
/**
* Make connection
* <br>
*
* @param vnfmObj
* @return
- * @since NFVO 0.5
+ * @since NFVO 0.5
*/
public int connect(JSONObject vnfmObj) {
LOG.info("function=connect, msg=enter connect function.");