Merge "vfc adapter authentication bug fix"
authorSteve Smokowski <ss835w@att.com>
Wed, 12 Dec 2018 12:49:56 +0000 (12:49 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 12 Dec 2018 12:49:56 +0000 (12:49 +0000)
adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java
adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/util/RestfulUtil.java
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.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/DoCreateVFCNetworkServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVFCNetworkServiceInstance.groovy

index c8ea165..893156c 100644 (file)
@@ -23,6 +23,8 @@
 package org.onap.so.adapters.requestsdb;
 
 import java.sql.Timestamp;
+import java.util.List;
+
 import javax.jws.WebService;
 import javax.transaction.Transactional;
 import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException;
@@ -304,5 +306,65 @@ public class MsoRequestsDbAdapterImpl implements MsoRequestsDbAdapter {
                resStatus.setErrorCode(errorCode);
                resStatus.setStatusDescription(statusDescription);
                resourceOperationStatusRepository.save(resStatus);
+
+               updateOperationStatusBasedOnResourceStatus(resStatus);
        }
+       
+    /**
+     * update service operation status when a operation resource status updated
+     * <br>
+     * 
+     * @param operStatus the resource operation status
+     * @since ONAP Amsterdam Release
+     */
+    private void updateOperationStatusBasedOnResourceStatus(ResourceOperationStatus operStatus) {
+       String serviceId = operStatus.getServiceId();
+        String operationId = operStatus.getOperationId();
+
+        logger.debug("Request database - update Operation Status Based On Resource Operation Status with service Id:"
+                + serviceId + ", operationId:" + operationId);
+        
+        List<ResourceOperationStatus> lstResourceStatus = resourceOperationStatusRepository.findByServiceIdAndOperationId(serviceId, operationId);
+               if (lstResourceStatus == null) {
+                       logger.error("Unable to retrieve resourceOperStatus Object by ServiceId: " + serviceId + " operationId: " + operationId);
+                       return;
+               }
+               
+               // count the total progress
+        int resourceCount = lstResourceStatus.size();
+        int progress = 0;
+        boolean isFinished = true;
+        for (ResourceOperationStatus lstResourceStatu : lstResourceStatus) {
+            progress = progress + Integer.valueOf(lstResourceStatu.getProgress()) / resourceCount;
+            if (RequestsDbConstant.Status.PROCESSING.equals(lstResourceStatu.getStatus())) {
+                isFinished = false;
+            }
+        }
+        
+        OperationStatus serviceOperStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId, operationId);
+               if (serviceOperStatus == null) {
+                       String error = "Entity not found. Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: "
+                                       + operationId;
+                       logger.error(error);
+                       
+                       serviceOperStatus = new OperationStatus();
+                       serviceOperStatus.setOperationId(operationId);
+                       serviceOperStatus.setServiceId(serviceId);
+               }
+        
+        progress = progress > 100 ? 100 : progress;
+        serviceOperStatus.setProgress(String.valueOf(progress));
+        serviceOperStatus.setOperationContent(operStatus.getStatusDescription());
+        // if current resource failed. service failed.
+        if(RequestsDbConstant.Status.ERROR.equals(operStatus.getStatus())) {
+            serviceOperStatus.setResult(RequestsDbConstant.Status.ERROR);
+            serviceOperStatus.setReason(operStatus.getStatusDescription());
+        } else if(isFinished) {
+            // if finished
+            serviceOperStatus.setResult(RequestsDbConstant.Status.FINISHED);
+            serviceOperStatus.setProgress(RequestsDbConstant.Progress.ONE_HUNDRED);
+        }
+
+        operationStatusRepository.save(serviceOperStatus);
+    }
 }
index 1db9d95..bb7fa70 100644 (file)
@@ -43,7 +43,6 @@ import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
 import org.onap.so.adapters.vfc.model.RestfulResponse;
 import org.onap.so.logger.MessageEnum;
-
 import org.onap.so.logger.MsoLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;
@@ -66,8 +65,6 @@ public class RestfulUtil {
      */
     private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, RestfulUtil.class);
 
-
-
     private static final int DEFAULT_TIME_OUT = 60000;
 
     private static final String ONAP_IP = "ONAP_IP";
@@ -82,15 +79,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 +99,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;
@@ -201,12 +201,10 @@ public class RestfulUtil {
 
     private static void logError(String errMsg, Throwable t) {
         LOGGER.error(MessageEnum.RA_NS_EXC, VFC_ADAPTER, "", MsoLogger.ErrorCode.AvailabilityError, errMsg, t);
-
     }
 
     private static void logError(String errMsg) {
         LOGGER.error(MessageEnum.RA_NS_EXC, VFC_ADAPTER, "", MsoLogger.ErrorCode.AvailabilityError, errMsg);
-
     }
 
     private static RestfulResponse createResponse(int statusCode, String content) {
index 1531e4d..7df9c7b 100644 (file)
@@ -262,6 +262,9 @@ public class ResourceRequestBuilder {
                String catalogEndPoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint");
        HttpClient client = new HttpClient(UriBuilder.fromUri(catalogEndPoint).path(SERVICE_URL_TOSCA_CSAR).queryParam("serviceModelUuid", uuid).build().toURL(), "application/json", TargetEntity.CATALOG_DB);
        
+       client.addAdditionalHeader("Accept", "application/json");
+//     client.addBasicAuthHeader (UrnPropertiesReader.getVariable("mso.adapters.db.auth"), UrnPropertiesReader.getVariable("mso.msoKey"));
+       client.addAdditionalHeader("Authorization", UrnPropertiesReader.getVariable("mso.db.auth"));
         Response response = client.get();
         String value = response.readEntity(String.class);
 
@@ -272,7 +275,7 @@ public class ResourceRequestBuilder {
         File csarFile = new File(filePath);
 
         if(!csarFile.exists()) {
-            throw new Exception("csar file does not exist.");
+            throw new Exception("csar file does not exist in filePath:" + csarFile.getAbsolutePath());
         }
 
         return csarFile.getAbsolutePath();
@@ -284,7 +287,7 @@ public class ResourceRequestBuilder {
         try {
             return mapper.readValue(jsonstr, type);
         } catch(IOException e) {
-            LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "fail to unMarshal json", e);
+            LOGGER.error("fail to unMarshal json" + e.getMessage ());
         }
         return null;
     }
index e3702f1..2a2d1f4 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,6 @@ 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 host = "http://mso.mso.testlab.openecomp.org:8080"
-
     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
     JsonUtils jsonUtil = new JsonUtils()
@@ -116,6 +112,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 +140,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     public void createNetworkService(DelegateExecution execution) {
         msoLogger.trace("createNetworkService ")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
         String nsServiceModelUUID = execution.getVariable("nsServiceModelUUID");
         String nsParameters = execution.getVariable("nsParameters");
@@ -149,8 +158,8 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
                      "additionalParamForNs":${requestInputs}
                 }
                }"""
-        Response apiResponse = postRequest(execution, host + vfcUrl + "/ns", reqBody)
-        String returnCode = apiResponse.getStatus()
+        Response apiResponse = postRequest(execution, vfcAdapterUrl + "/ns", reqBody)
+        String returnCode = apiResponse.getStatus ()
         String aaiResponseAsString = apiResponse.readEntity(String.class)
         String nsInstanceId = "";
         if(returnCode== "200" || returnCode == "201"){
@@ -165,6 +174,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     public void instantiateNetworkService(DelegateExecution execution) {
         msoLogger.trace("instantiateNetworkService ")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
         String nsParameters = execution.getVariable("nsParameters");
         String nsServiceName = execution.getVariable("nsServiceName")
@@ -176,7 +186,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 +203,10 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
      */
     public void queryNSProgress(DelegateExecution execution) {
         msoLogger.trace("queryNSProgress ")
+        String vfcAdapterUrl = execution.getVariable("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)
@@ -214,7 +225,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
         try {
             Thread.sleep(5000);
         } catch(InterruptedException e) {
-            msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Time Delay exception" + e , "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
+            msoLogger.error( "Time Delay exception" + e.getMessage());
         }
     }
 
@@ -239,7 +250,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
             getAAIClient().connect(nsUri,relatedServiceUri)
             msoLogger.info("NS relationship to Service added successfully")
         }catch(Exception e){
-            msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while Creating NS relationship.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.getMessage(),e);
+            msoLogger.error("Exception occured while Creating NS relationship."+ e.getMessage());
             throw new BpmnError("MSOWorkflowException")
         }
     }
@@ -251,24 +262,30 @@ 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{
 
-                       URL url = new URL(urlString);
-
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
-                       httpClient.addAdditionalHeader("Accept", "application/json")
-                       httpClient.addAdditionalHeader("Authorization", "Basic QlBFTENsaWVudDpwYXNzd29yZDEk")
+            URL url = new URL(urlString);
+            
+            // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
+            // user 'bepl' authHeader is the same with mso.db.auth
+            String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
+            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            httpClient.addAdditionalHeader("Accept", "application/json")
+            httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
-                       apiResponse = httpClient.post(requestBody)
+            apiResponse = httpClient.post(requestBody)
+            
+            msoLogger.debug("response code:"+ apiResponse.getStatus() +"\nresponse body:"+ apiResponse.readEntity(String.class))
 
-            msoLogger.info("response code:"+ apiResponse.getStatus() +"\nresponse body:"+ apiResponse.readEntity(String.class))
-            msoLogger.trace("Completed Execute VF-C adapter Post Process ")
         }catch(Exception e){
-            msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Post Call.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
-            throw new BpmnError("MSOWorkflowException")
-        }
+            msoLogger.error("VFC Aatpter Post Call Exception:" + e.getMessage());
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VFC Aatpter Post Call Exception")
+        }              
+               
+        msoLogger.trace("Completed Execute VF-C adapter Post Process ")
+        
         return apiResponse
     }
 
index a3c30dc..1e7f731 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 org.onap.so.utils.TargetEntity
 
@@ -44,9 +45,6 @@ import javax.ws.rs.core.Response
 public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {
        private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVFCNetworkServiceInstance.class);
 
-    String vfcUrl = "/vfc/rest/v1/vfcadapter"
-
-    String host = "http://mso.mso.testlab.openecomp.org:8080"
 
     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
@@ -100,6 +98,19 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
            execution.setVariable("nsOperationKey", nsOperationKey);
            execution.setVariable("nsParameters", nsParameters)
 
+           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;
@@ -116,6 +127,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
      */
     public void createNetworkService(DelegateExecution execution) {
         msoLogger.trace("createNetworkService")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
         String nsParameters = execution.getVariable("nsParameters");
         String nsServiceName = execution.getVariable("nsServiceName")
@@ -126,7 +138,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
                 "nsOperationKey":${nsOperationKey},
                 "nsParameters":${nsParameters}
                }"""
-        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 = "";
@@ -142,6 +154,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
      */
     public void instantiateNetworkService(DelegateExecution execution) {
         msoLogger.trace("instantiateNetworkService")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
         String nsParameters = execution.getVariable("nsParameters");
         String nsServiceName = execution.getVariable("nsServiceName")
@@ -153,7 +166,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
         "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)
@@ -170,9 +183,10 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
      */
     public void queryNSProgress(DelegateExecution execution) {
         msoLogger.trace("queryNSProgress")
+        String vfcAdapterUrl = execution.getVariable("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)
@@ -233,17 +247,20 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
         try{
 
                        URL url = new URL(urlString);
+            
+            // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
+            // user 'bepl' authHeader is the same with mso.db.auth
+            String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
+            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            httpClient.addAdditionalHeader("Accept", "application/json")
+            httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
-                       httpClient.addAdditionalHeader("Accept", "application/json")
-                       httpClient.addAdditionalHeader("Authorization", "Basic QlBFTENsaWVudDpwYXNzd29yZDEk")
-
-                       apiResponse = httpClient.post(requestBody)
+            apiResponse = httpClient.post(requestBody)
 
             msoLogger.debug("response code:"+ apiResponse.getStatus() +"\nresponse body:"+ apiResponse.readEntity(String.class))
             msoLogger.trace("Completed Execute VF-C adapter Post Process")
         }catch(Exception e){
-                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing AAI Post Call", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
+                       msoLogger.error("Exception occured while executing VFC Adapter Post Call"  + e.getMessage ());
             throw new BpmnError("MSOWorkflowException")
         }
         return apiResponse
index d855479..ee094b0 100644 (file)
@@ -32,6 +32,7 @@ import org.onap.so.client.aai.entities.uri.AAIUriFactory
 import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
 import org.onap.so.utils.TargetEntity
+import org.onap.so.bpmn.core.UrnPropertiesReader
 
 import javax.ws.rs.core.Response
 /**
@@ -41,11 +42,6 @@ import javax.ws.rs.core.Response
 public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {
        private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVFCNetworkServiceInstance.class);
 
-
-    String vfcUrl = "/vfc/rest/v1/vfcadapter"
-
-    String host = "http://mso.mso.testlab.openecomp.org:8080"
-
     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
     JsonUtils jsonUtil = new JsonUtils()
@@ -83,6 +79,20 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
              }"""
             execution.setVariable("nsOperationKey", nsOperationKey);
             msoLogger.info("nsOperationKey:" + nsOperationKey)
+
+            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;
         } catch (Exception ex){
@@ -123,8 +133,9 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
     public void deleteNetworkService(DelegateExecution execution) {
 
         msoLogger.trace("deleteNetworkService  start ")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey");
-        String url = host + vfcUrl + "/ns/" + execution.getVariable("nsInstanceId")
+        String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId")
         Response apiResponse = deleteRequest(execution, url, nsOperationKey)
         String returnCode = apiResponse.getStatus()
         String operationStatus = "error";
@@ -142,8 +153,9 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
     public void terminateNetworkService(DelegateExecution execution) {
 
         msoLogger.trace("terminateNetworkService  start ")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String nsOperationKey = execution.getVariable("nsOperationKey")
-        String url =  host + vfcUrl + "/ns/" + execution.getVariable("nsInstanceId") + "/terminate"
+        String url =  vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId") + "/terminate"
         Response apiResponse = postRequest(execution, url, nsOperationKey)
         String returnCode = apiResponse.getStatus()
         String aaiResponseAsString = apiResponse.readEntity(String.class)
@@ -161,9 +173,10 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
     public void queryNSProgress(DelegateExecution execution) {
 
         msoLogger.trace("queryNSProgress  start ")
+        String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
         String jobId = execution.getVariable("jobId")
         String nsOperationKey = execution.getVariable("nsOperationKey");
-        String url =  host + vfcUrl + "/jobs/" +  execution.getVariable("jobId")
+        String url =  vfcAdapterUrl + "/jobs/" +  execution.getVariable("jobId")
         Response apiResponse = postRequest(execution, url, nsOperationKey)
         String returnCode = apiResponse.getStatus()
         String apiResponseAsString = apiResponse.readEntity(String.class)
@@ -206,9 +219,12 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
                try{
                        URL url = new URL(urlString);
 
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
-                       httpClient.addAdditionalHeader("Accept", "application/json")
-                       httpClient.addAdditionalHeader("Authorization", "Basic QlBFTENsaWVudDpwYXNzd29yZDEk")
+                       // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
+            // user 'bepl' authHeader is the same with mso.db.auth
+            String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
+            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            httpClient.addAdditionalHeader("Accept", "application/json")
+            httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
                        apiResponse = httpClient.post(requestBody)
 
@@ -216,7 +232,7 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
 
                        msoLogger.trace("Completed Execute VF-C adapter Post Process ")
                }catch(Exception e){
-            msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing VF-C Post Call. Exception is: \n" + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
+            msoLogger.error("Exception occured while executing VF-C Post Call. Exception is: \n" + e.getMessage());
             throw new BpmnError("MSOWorkflowException")
         }
         return apiResponse
@@ -234,14 +250,18 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
         try{
 
                        URL Url = new URL(url)
-                       HttpClient httpClient = new HttpClient(Url, "application/json", TargetEntity.VNF_ADAPTER)
-                       httpClient.addAdditionalHeader("Accept", "application/json")
-                       httpClient.addAdditionalHeader("Authorization", "Basic QlBFTENsaWVudDpwYXNzd29yZDEk")
+            // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
+            // user 'bepl' authHeader is the same with mso.db.auth
+            String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
+            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            httpClient.addAdditionalHeader("Accept", "application/json")
+            httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
+
                        r = httpClient.delete(requestBody)
 
             msoLogger.trace("Completed Execute VF-C adapter Delete Process ")
         }catch(Exception e){
-            msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing VF-C Post Call. Exception is: \n" + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
+            msoLogger.error("Exception occured while executing VF-C Post Call. Exception is: \n" + e.getMessage());
             throw new BpmnError("MSOWorkflowException")
         }
         return r