use config value instead hard code of url 58/73458/1
authorYulian Han <elaine.hanyulian@huawei.com>
Sat, 24 Nov 2018 08:53:35 +0000 (16:53 +0800)
committerYulian Han <elaine.hanyulian@huawei.com>
Sat, 24 Nov 2018 08:53:35 +0000 (16:53 +0800)
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064411
Issue-ID: SO-1249
Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/util/RestfulUtil.java
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy

index 0536dd3..f6bf8b9 100644 (file)
@@ -82,15 +82,18 @@ public class RestfulUtil {
    private Environment env;
 
     public String getMsbHost() {
-        // MSB_IP will be set as ONAP_IP environment parameter in install flow.
-        String msbIp = System.getenv().get(ONAP_IP);
-       // if ONAP IP is not set. get it from config file.
-        if(null == msbIp || msbIp.isEmpty()) {
-               msbIp = env.getProperty("mso.msb-ip", DEFAULT_MSB_IP);
-       }
+               // MSB_IP will be set as ONAP_IP environment parameter in install flow.
+               String msbIp = System.getenv().get(ONAP_IP);
+               // if ONAP IP is not set. get it from config file.
+               if (null == msbIp || msbIp.isEmpty()) {
+                       msbIp = env.getProperty("mso.msb-ip", DEFAULT_MSB_IP);
+               }
        Integer msbPort = env.getProperty("mso.msb-port", Integer.class, DEFAULT_MSB_PORT);
        
-       return UriBuilder.fromPath("").host(msbIp).port(msbPort).scheme("http").build().toString();
+       String msbEndpoint = UriBuilder.fromPath("").host(msbIp).port(msbPort).scheme("http").build().toString();
+       LOGGER.debug("msbEndpoint in vfc adapter: " + msbEndpoint);
+       
+       return msbEndpoint;
     }
 
     private RestfulUtil() {
@@ -99,7 +102,7 @@ public class RestfulUtil {
 
     public RestfulResponse send(String url, String methodType, String content) {
         String msbUrl = getMsbHost() + url;
-        LOGGER.info(MessageEnum.RA_NS_EXC, "Begin to sent message " + methodType +": " + msbUrl, "org.onap.so.adapters.vfc.util.RestfulUtil",VFC_ADAPTER);
+        LOGGER.debug("Begin to sent message " + methodType +": " + msbUrl);
 
         HttpRequestBase method = null;
         HttpResponse httpResponse = null;
index dabd351..44ee918 100644 (file)
@@ -31,6 +31,7 @@ import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
 import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
+import org.onap.so.bpmn.core.UrnPropertiesReader
 
 import groovy.json.*
 import javax.ws.rs.core.Response
@@ -43,11 +44,10 @@ import org.onap.so.utils.TargetEntity
 public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
        private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateVFCNSResource.class);
 
+//    String vfcUrl = "/vfc/rest/v1/vfcadapter"
 
-    String vfcUrl = "/vfc/rest/v1/vfcadapter"
-
-    String host = "http://mso.mso.testlab.openecomp.org:8080"
-
+//    String host = "http://mso.mso.testlab.openecomp.org:8080"
+       
     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
     JsonUtils jsonUtil = new JsonUtils()
@@ -116,6 +116,18 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
            execution.setVariable("nsParameters", nsParameters)
            execution.setVariable("nsServiceModelUUID", nsServiceModelUUID);
 
+           String vfcAdapterUrl = UrnPropertiesReader.getVariable("mso.adapters.vfc.rest.endpoint", execution)
+                  
+           if (vfcAdapterUrl == null || vfcAdapterUrl.isEmpty()) {
+                  msg = getProcessKey(execution) + ': mso:adapters:vfcc:rest:endpoint URN mapping is not defined'
+                  msoLogger.debug(msg)
+           }
+
+           while (vfcAdapterUrl.endsWith('/')) {
+                  vfcAdapterUrl = vfcAdapterUrl.substring(0, vfcAdapterUrl.length()-1)
+           }              
+                  
+           execution.setVariable("vfcAdapterUrl", vfcAdapterUrl)
 
        } catch (BpmnError e) {
            throw e;
@@ -132,6 +144,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     public void createNetworkService(DelegateExecution execution) {
         msoLogger.trace("createNetworkService ")
+        String vfcAdapterUrl = execution.setVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
         String nsServiceModelUUID = execution.getVariable("nsServiceModelUUID");
         String nsParameters = execution.getVariable("nsParameters");
@@ -149,7 +162,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
                      "additionalParamForNs":${requestInputs}
                 }
                }"""
-        Response apiResponse = postRequest(execution, host + vfcUrl + "/ns", reqBody)
+        Response apiResponse = postRequest(execution, vfcAdapterUrl + "/ns", reqBody)
         String returnCode = apiResponse.getStatus()
         String aaiResponseAsString = apiResponse.readEntity(String.class)
         String nsInstanceId = "";
@@ -165,6 +178,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     public void instantiateNetworkService(DelegateExecution execution) {
         msoLogger.trace("instantiateNetworkService ")
+        String vfcAdapterUrl = execution.setVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
         String nsParameters = execution.getVariable("nsParameters");
         String nsServiceName = execution.getVariable("nsServiceName")
@@ -176,7 +190,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
         "nsParameters":${nsParameters}
        }"""
         String nsInstanceId = execution.getVariable("nsInstanceId")
-        String url = host + vfcUrl + "/ns/" +nsInstanceId + "/instantiate"
+        String url = vfcAdapterUrl + "/ns/" +nsInstanceId + "/instantiate"
         Response apiResponse = postRequest(execution, url, reqBody)
         String returnCode = apiResponse.getStatus()
         String aaiResponseAsString = apiResponse.readEntity(String.class)
@@ -193,9 +207,10 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     public void queryNSProgress(DelegateExecution execution) {
         msoLogger.trace("queryNSProgress ")
+        String vfcAdapterUrl = execution.setVariable("vfcAdapterUrl")
         String jobId = execution.getVariable("jobId")
         String nsOperationKey = execution.getVariable("nsOperationKey");
-        String url = host + vfcUrl + "/jobs/" + jobId
+        String url = vfcAdapterUrl + "/jobs/" + jobId
         Response apiResponse = postRequest(execution, url, nsOperationKey)
         String returnCode = apiResponse.getStatus()
         String aaiResponseAsString = apiResponse.readEntity(String.class)
@@ -251,7 +266,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     private Response postRequest(DelegateExecution execution, String urlString, String requestBody){
         msoLogger.trace("Started Execute VFC adapter Post Process ")
-        msoLogger.info("url:"+url +"\nrequestBody:"+ requestBody)
+        msoLogger.info("url:" + urlString +"\nrequestBody:"+ requestBody)
         Response apiResponse = null
         try{
 
index 61c88db..f6e4fcc 100644 (file)
@@ -263,15 +263,14 @@ public class DoCreateResources extends AbstractServiceTaskProcessor{
             JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceModelUUID, requestAction)
 
             if (resourceRecipe != null) {
-                String recipeURL = BPMNProperties.getProperty("bpelURL", "http://bpmn-infra:8081") + resourceRecipe.getString("orchestrationUri")
+                String recipeURL = BPMNProperties.getProperty("bpelURL", "http://so-bpmn-infra.onap:8081") + resourceRecipe.getString("orchestrationUri")
                 int recipeTimeOut = resourceRecipe.getInt("recipeTimeout")
                 String recipeParamXsd = resourceRecipe.get("paramXSD")
 
                 BpmnRestClient bpmnRestClient = new BpmnRestClient()
                 HttpResponse resp = bpmnRestClient.post(recipeURL, requestId, recipeTimeOut, requestAction, serviceInstanceId, serviceType, resourceInput, recipeParamXsd)
             } else {
-                String exceptionMessage = "Resource receipe is not found for resource modeluuid: " +
-                        resourceInput.getResourceModelInfo().getModelUuid()
+                String exceptionMessage = "Resource receipe is not found for resource modeluuid: " + resourceModelUUID
                 msoLogger.trace(exceptionMessage)
                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, exceptionMessage)
             }