diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
3 files changed, 124 insertions, 149 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy index 34f2f0157d..94df0a977a 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy @@ -39,7 +39,7 @@ import org.onap.so.bpmn.core.UrnPropertiesReader import groovy.json.* //import javax.ws.rs.core.Response -import org.onap.so.utils.TargetEntity +//import org.onap.so.utils.TargetEntity /** * This groovy class supports the <class>DoCreateVFCNetworkServiceInstance.bpmn</class> process. @@ -272,96 +272,30 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor { msoLogger.trace("Started Execute VFC adapter Post Process ") msoLogger.info("url:" + urlString +"\nrequestBody:"+ requestBody) APIResponse 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 YnBlbDpwYXNzd29yZDEk") - -// apiResponse = httpClient.post(requestBody) -// msoLogger.info("response code:"+ apiResponse.getStatus() +"\nresponse body:"+ apiResponse.readEntity(String.class)) - - // Get the Basic Auth credentials for the VFCAdapter (yes... we ARE using the PO adapters credentials) - String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution) - - msoLogger.debug("basicAuthValuePO: " + basicAuthValuePO) - if (basicAuthValuePO == null || basicAuthValuePO.isEmpty()) { - msoLogger.debug("mso:adapters:po:auth URN mapping is not defined") - } - - RESTConfig config = new RESTConfig(urlString) - RESTClient client = null; - int statusCode = 0; - try { - client = new RESTClient(config).addHeader("Accept", "application/json").addAuthorizationHeader(basicAuthValuePO) - - apiResponse = client.httpPost(requestBody) + try{ + // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7' + def basicAuthHeaderValue = "" + RESTConfig config = new RESTConfig(urlString) + RESTClient client = null; + int statusCode = 0; - statusCode = apiResponse.getStatusCode() + // user 'bepl' authHeader is the same with mso.db.auth + String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution) + + client = new RESTClient(config) + client.addHeader("Accept", "application/json") + client.addAuthorizationHeader(basicAuthValuedb) + client.addHeader("Content-Type", "application/json") - if(statusCode == 200 || statusCode == 201) { - return apiResponse - } - }catch(Exception e){ - msoLogger.error("VFC Aatpter Post Call Exception using mso.adapters.po.auth:" + e.getMessage()); - } - - msoLogger.debug("response code:"+ statusCode +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) - - msoLogger.debug("VFC Aatpter Post Call using mso.msoKey") - String basicAuthValue = UrnPropertiesReader.getVariable("mso.msoKey", execution) - msoLogger.debug("basicAuthValue: " + basicAuthValue) - if (basicAuthValue == null || basicAuthValue.isEmpty()) { - msoLogger.debug("mso:msoKey URN mapping is not defined") - } - try { - client = new RESTClient(config).addHeader("Accept", "application/json").addAuthorizationHeader(basicAuthValue) - apiResponse = client.httpPost(requestBody) - statusCode = apiResponse.getStatusCode() - if(statusCode == 200 || statusCode == 201) { - return apiResponse - } - }catch(Exception e){ - msoLogger.error("VFC Aatpter Post Call Exception using mso.msoKey:" + e.getMessage()); - - } - - msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) + msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) - msoLogger.debug("VFC Aatpter Post Call using mso.db.auth") - String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution) - msoLogger.debug("basicAuthValuedb: " + basicAuthValuedb) - if (basicAuthValuedb == null || basicAuthValuedb.isEmpty()) { - msoLogger.debug("mso:db.auth URN mapping is not defined") - } - try { - client = new RESTClient(config).addHeader("Accept", "application/json").addAuthorizationHeader(basicAuthValuedb) - - apiResponse = client.httpPost(requestBody) - statusCode = apiResponse.getStatusCode() - - if(statusCode == 200 || statusCode == 201) { - return apiResponse - } }catch(Exception e){ - msoLogger.error("VFC Aatpter Post Call Exception using mso.msoKey:" + e.getMessage()); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VFC Aatpter Post Call Exception by using mso.msoKey or mso.adapters.po.auth") + msoLogger.error("Exception occured while executing VF-C Post Call. Exception is: \n" + e.getMessage()); + throw new BpmnError("MSOWorkflowException") } - - - msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) - String auth = "Basic QlBFTENsaWVudDpwYXNzd29yZDEk" - msoLogger.debug("auth: " + basicAuthValuedb) - client = new RESTClient(config).addHeader("Accept", "application/json").addAuthorizationHeader(auth) - - apiResponse = client.httpPost(requestBody) - - msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) msoLogger.trace("Completed Execute VF-C adapter Post Process ") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy index f4a542afe9..0502f7949a 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy @@ -28,15 +28,18 @@ import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.client.HttpClient +//import org.onap.so.client.HttpClient import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger +import org.onap.so.rest.APIResponse +import org.onap.so.rest.RESTClient +import org.onap.so.rest.RESTConfig import org.onap.so.bpmn.core.UrnPropertiesReader -import org.onap.so.utils.TargetEntity +//import org.onap.so.utils.TargetEntity import groovy.json.* -import javax.ws.rs.core.Response +//import javax.ws.rs.core.Response /** * This groovy class supports the <class>DoCreateVFCNetworkServiceInstance.bpmn</class> process. @@ -138,7 +141,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces "nsOperationKey":${nsOperationKey}, "nsParameters":${nsParameters} }""" - Response apiResponse = postRequest(execution, vfcAdapterUrl + "/ns", reqBody) + APIResponse apiResponse = postRequest(execution, vfcAdapterUrl + "/ns", reqBody) String returnCode = apiResponse.getStatus() String aaiResponseAsString = apiResponse.readEntity(String.class) String nsInstanceId = ""; @@ -167,7 +170,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces }""" String nsInstanceId = execution.getVariable("nsInstanceId") String url = vfcAdapterUrl + "/ns/" +nsInstanceId + "/instantiate" - Response apiResponse = postRequest(execution, url, reqBody) + APIResponse apiResponse = postRequest(execution, url, reqBody) String returnCode = apiResponse.getStatus() String aaiResponseAsString = apiResponse.readEntity(String.class) String jobId = ""; @@ -187,7 +190,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces String jobId = execution.getVariable("jobId") String nsOperationKey = execution.getVariable("nsOperationKey"); String url = vfcAdapterUrl + "/jobs/" + jobId - Response apiResponse = postRequest(execution, url, nsOperationKey) + APIResponse apiResponse = postRequest(execution, url, nsOperationKey) String returnCode = apiResponse.getStatus() String aaiResponseAsString = apiResponse.readEntity(String.class) String operationStatus = "error" @@ -240,26 +243,38 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces * url: the url of the request * requestBody: the body of the request */ - private Response postRequest(DelegateExecution execution, String urlString, String requestBody){ + private APIResponse postRequest(DelegateExecution execution, String urlString, String requestBody){ msoLogger.trace("Started Execute VFC adapter Post Process") msoLogger.debug("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 YnBlbDpwYXNzd29yZDEk") - - 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); - throw new BpmnError("MSOWorkflowException") - } + APIResponse apiResponse = null + try{ + // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7' + def basicAuthHeaderValue = "" + RESTConfig config = new RESTConfig(urlString) + RESTClient client = null; + int statusCode = 0; + + // user 'bepl' authHeader is the same with mso.db.auth + String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution) + msoLogger.debug("basicAuthValuedb: " + basicAuthValuedb) + + client = new RESTClient(config) + client.addHeader("Accept", "application/json") + client.addAuthorizationHeader(basicAuthValuedb) + client.addHeader("Content-Type", "application/json") + + apiResponse = client.httpPost(requestBody) + statusCode = apiResponse.getStatusCode() + + msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) + + }catch(Exception e){ + msoLogger.error("Exception occured while executing VF-C Post Call. Exception is: \n" + e.getMessage()); + throw new BpmnError("MSOWorkflowException") + } + + msoLogger.trace("Completed Execute VF-C adapter Post Process ") + return apiResponse } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVFCNetworkServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVFCNetworkServiceInstance.groovy index e0586163f1..5ff93363d2 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVFCNetworkServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVFCNetworkServiceInstance.groovy @@ -25,16 +25,19 @@ import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.client.HttpClient +//import org.onap.so.client.HttpClient import org.onap.so.client.aai.AAIObjectType import org.onap.so.client.aai.entities.uri.AAIResourceUri 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.rest.APIResponse +import org.onap.so.rest.RESTClient +import org.onap.so.rest.RESTConfig +//import org.onap.so.utils.TargetEntity import org.onap.so.bpmn.core.UrnPropertiesReader -import javax.ws.rs.core.Response +//import javax.ws.rs.core.Response /** * This groovy class supports the <class>DoDeleteVFCNetworkServiceInstance.bpmn</class> process. * flow for E2E ServiceInstance Delete @@ -136,8 +139,9 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl") String nsOperationKey = execution.getVariable("nsOperationKey"); String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId") - Response apiResponse = deleteRequest(execution, url, nsOperationKey) - String returnCode = apiResponse.getStatus() + APIResponse apiResponse = deleteRequest(execution, url, nsOperationKey) + String returnCode = apiResponse.getStatusCode() + String aaiResponseAsString = apiResponse.getResponseBodyAsString() String operationStatus = "error"; if(returnCode== "200" || returnCode== "202"){ operationStatus = "finished" @@ -148,7 +152,7 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces } /** - * instantiate NS task + * terminate NS task */ public void terminateNetworkService(DelegateExecution execution) { @@ -156,9 +160,9 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl") String nsOperationKey = execution.getVariable("nsOperationKey") String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId") + "/terminate" - Response apiResponse = postRequest(execution, url, nsOperationKey) - String returnCode = apiResponse.getStatus() - String aaiResponseAsString = apiResponse.readEntity(String.class) + APIResponse apiResponse = postRequest(execution, url, nsOperationKey) + String returnCode = apiResponse.getStatusCode() + String aaiResponseAsString = apiResponse.getResponseBodyAsString() String jobId = ""; if(returnCode== "200" || returnCode== "202"){ jobId = jsonUtil.getJsonValue(aaiResponseAsString, "jobId") @@ -177,9 +181,9 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces String jobId = execution.getVariable("jobId") String nsOperationKey = execution.getVariable("nsOperationKey"); String url = vfcAdapterUrl + "/jobs/" + execution.getVariable("jobId") - Response apiResponse = postRequest(execution, url, nsOperationKey) - String returnCode = apiResponse.getStatus() - String apiResponseAsString = apiResponse.readEntity(String.class) + APIResponse apiResponse = postRequest(execution, url, nsOperationKey) + String returnCode = apiResponse.getStatusCode() + String apiResponseAsString = apiResponse.getResponseBodyAsString() String operationProgress = "100" if(returnCode== "200"){ operationProgress = jsonUtil.getJsonValue(apiResponseAsString, "responseDescriptor.progress") @@ -211,25 +215,34 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces * url: the url of the request * requestBody: the body of the request */ - private Response postRequest(DelegateExecution execution, String urlString, String requestBody){ + private APIResponse postRequest(DelegateExecution execution, String urlString, String requestBody){ msoLogger.trace("Started Execute VFC adapter Post Process ") msoLogger.info("url:"+urlString +"\nrequestBody:"+ requestBody) - Response apiResponse = null + APIResponse 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 YnBlbDpwYXNzd29yZDEk") - - 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 ") + // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7' + def basicAuthHeaderValue = "" + RESTConfig config = new RESTConfig(urlString) + RESTClient client = null; + int statusCode = 0; + + // user 'bepl' authHeader is the same with mso.db.auth + String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution) + msoLogger.debug("basicAuthValuedb: " + basicAuthValuedb) + + client = new RESTClient(config) + client.addHeader("Accept", "application/json") + client.addAuthorizationHeader(basicAuthValuedb) + client.addHeader("Content-Type", "application/json") + + apiResponse = client.httpPost(requestBody) + statusCode = apiResponse.getStatusCode() + + msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) + }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 @@ -239,24 +252,37 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces * url: the url of the request * requestBody: the body of the request */ - private Response deleteRequest(DelegateExecution execution, String url, String requestBody){ + private APIResponse deleteRequest(DelegateExecution execution, String url, String requestBody){ msoLogger.trace("Started Execute VFC adapter Delete Process ") msoLogger.info("url:"+url +"\nrequestBody:"+ requestBody) - Response r - 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 YnBlbDpwYXNzd29yZDEk") - 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); - throw new BpmnError("MSOWorkflowException") - } - return r + + APIResponse apiResponse = null + try{ + // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7' + def basicAuthHeaderValue = "" + RESTConfig config = new RESTConfig(url) + RESTClient client = null; + int statusCode = 0; + + // user 'bepl' authHeader is the same with mso.db.auth + String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution) + msoLogger.debug("basicAuthValuedb: " + basicAuthValuedb) + + client = new RESTClient(config) + client.addHeader("Accept", "application/json") + client.addAuthorizationHeader(basicAuthValuedb) + client.addHeader("Content-Type", "application/json") + + apiResponse = client.httpDelete(requestBody) + statusCode = apiResponse.getStatusCode() + + msoLogger.debug("response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString()) + + }catch(Exception e){ + msoLogger.error("Exception occured while executing VF-C Delete Call. Exception is: \n" + e.getMessage()); + throw new BpmnError("MSOWorkflowException") + } + return apiResponse } } |