-/*-
- * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.bpmn.common.scripts
-
-import static org.apache.commons.lang3.StringUtils.*
-
-import org.apache.commons.lang3.*
-import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.runtime.Execution
-import org.openecomp.mso.rest.APIResponse
-import org.springframework.web.util.UriUtils
-
-/**
- * TODO: Support Putting vnf type = vpe and vce
- *
- * This class supports the GenericPutVnf Sub Flow.
- * This Generic sub flow can be used by any flow for accomplishing
- * the goal of Creating/Updating(PUT) a Vnf Object (in AAI). The flow
- * supports the Creating/Updating of 3 types of Vnfs (generic-vnf, vce, and vpe).
- * The "type" must be provided by the calling flow and this type should
- * be mapped to the variable GENPV_type. The type should either be
- * "generic-vnf", "vce", or "vpe". In addition, the Vnf Id and
- * payload should be provided.
- *
- * Upon successful completion of this sub flow the
- * GENPV_SuccessIndicator. An MSOWorkflowException will
- * be thrown if an error occurs at any time during this
- * sub flow. Please map input variables to the corresponding
- * variable names below.
- *
- *
- * Incoming Required Variables:
- * @param - GENPV_vnfId
- * @param - GENPV_vnfPayload
- * @param - GENPV_type
- *
- *
- * Outgoing Variables:
- * @param - GENPV_SuccessIndicator
- * @param - WorkflowException
- */
-class GenericPutVnf extends AbstractServiceTaskProcessor{
-
- String Prefix = "GENPV_"
- ExceptionUtil exceptionUtil = new ExceptionUtil()
-
- /**
- * This method validates the incoming variables and
- * generates a Vnf Id if one is not provided.
- *
- * @param - execution
- */
- public void preProcessRequest(Execution execution) {
- def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
- execution.setVariable("prefix",Prefix)
- utils.log("DEBUG", " *** STARTED GenericPutVnf PreProcessRequest Process*** ", isDebugEnabled)
-
- execution.setVariable("GENPV_SuccessIndicator", false)
- execution.setVariable("GENPV_FoundIndicator", false)
-
- try{
- // Get Variables
- String payload = execution.getVariable("GENPV_vnfPayload")
- utils.log("DEBUG", "Incoming Vnf Payload is: " + payload, isDebugEnabled)
- String type = execution.getVariable("GENPV_type")
- utils.log("DEBUG", "Incoming Type of Vnf is: " + type, isDebugEnabled)
-
- if(isBlank(payload) || isBlank(type)){
- utils.log("ERROR", "Incoming Vnf Payload and/or Type is null. These Variables are required!", isDebugEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Vnf Payload and/or Type is null. These Variables are required!")
- }else{
- String vnfId = execution.getVariable("GENPV_vnfId")
- if(isBlank(vnfId)){
- vnfId = UUID.randomUUID().toString()
- utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
- execution.setVariable("GENPV_vnfId", vnfId)
- }else{
- utils.log("DEBUG", "Incoming Vnf Id is: " + vnfId, isDebugEnabled)
- }
- }
- }catch(BpmnError b){
- utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
- throw b
- }catch(Exception e){
- utils.log("ERROR", " Error encountered within GenericPutVnf PreProcessRequest method!" + e, isDebugEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in GenericPutVnf PreProcessRequest")
-
- }
- utils.log("DEBUG", "*** COMPLETED GenericPutVnf PreProcessRequest Process ***", isDebugEnabled)
- }
-
- /**
- * This method executes a Put call to AAI to create
- * or update a Vnf Object using the provided payload
- *
- * @param - execution
- */
- public void putVnf(Execution execution){
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
- execution.setVariable("prefix",Prefix)
- utils.log("DEBUG", " *** STARTED GenericPutVnf PutVnf Process*** ", isDebugEnabled)
- try {
- String vnfId = execution.getVariable("GENPV_vnfId")
- String payload = execution.getVariable("GENPV_vnfPayload")
- String type = execution.getVariable("GENPV_type")
-
- AaiUtil aaiUtil = new AaiUtil(this)
- def aai_uri = ""
- if(type.equals("generic-vnf")){
- aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)
- }else if(type.equals("vce")){
- aai_uri = aaiUtil.getNetworkVceUri(execution)
- }else if(type.equals("vpe")){
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "GenericPutVnf does not yet support getting type of vnf = vpe")
- }else{
- utils.log("DEBUG", "Invalid Incoming GENGV_type", isDebugEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Invalid Incoming GENPV_type")
- }
- utils.log("DEBUG", "Using AAI Uri: " + aai_uri, isDebugEnabled)
-
- String path = "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8")
- utils.log("DEBUG", "PUT Vnf Endpoint is: " + path, isDebugEnabled)
-
- String putVnfAAIPath = execution.getVariable("URN_aai_endpoint") + path
- execution.setVariable("GENPV_putVnfAAIPath", putVnfAAIPath)
- utils.logAudit("PUT Vnf Url is: " + putVnfAAIPath)
-
- APIResponse apiResponse = aaiUtil.executeAAIPutCall(execution, putVnfAAIPath, payload)
- int responseCode = apiResponse.getStatusCode()
- execution.setVariable("GENPV_putVnfResponseCode", responseCode)
- utils.logAudit("AAI Response Code: " + responseCode)
- String aaiResponse = apiResponse.getResponseBodyAsString()
- aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
- execution.setVariable("GENPV_putVnfResponse", aaiResponse)
- utils.logAudit("AAI Response: " + aaiResponse)
-
- if(responseCode == 200 || responseCode == 201){
- utils.log("DEBUG", "PUT Vnf Received a Good Response Code.", isDebugEnabled)
- }else{
- utils.log("DEBUG", "PUT Vnf Received a Bad Response Code. Response Code is: " + responseCode, isDebugEnabled)
- exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
- throw new BpmnError("MSOWorkflowException")
- }
- }catch(BpmnError b){
- utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
- throw b
- }catch(Exception e){
- utils.log("ERROR", " Error encountered within GenericPutVnf PutVnf method!" + e, isDebugEnabled)
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During PutVnf")
- }
- utils.log("DEBUG", " *** COMPLETED GenericPutVnf PutVnf Process*** ", isDebugEnabled)
- }
-
-}
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.common.scripts\r
+\r
+import static org.apache.commons.lang3.StringUtils.*\r
+\r
+import org.apache.commons.lang3.*\r
+import org.camunda.bpm.engine.delegate.BpmnError\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
+import org.openecomp.mso.rest.APIResponse\r
+import org.springframework.web.util.UriUtils\r
+\r
+/**\r
+ * TODO: Support Putting vnf type = vpe and vce\r
+ *\r
+ * This class supports the GenericPutVnf Sub Flow.\r
+ * This Generic sub flow can be used by any flow for accomplishing\r
+ * the goal of Creating/Updating(PUT) a Vnf Object (in AAI). The flow\r
+ * supports the Creating/Updating of 3 types of Vnfs (generic-vnf, vce, and vpe).\r
+ * The "type" must be provided by the calling flow and this type should\r
+ * be mapped to the variable GENPV_type. The type should either be\r
+ * "generic-vnf", "vce", or "vpe". In addition, the Vnf Id and\r
+ * payload should be provided.\r
+ *\r
+ * Upon successful completion of this sub flow the\r
+ * GENPV_SuccessIndicator. An MSOWorkflowException will\r
+ * be thrown if an error occurs at any time during this\r
+ * sub flow. Please map input variables to the corresponding\r
+ * variable names below.\r
+ *\r
+ *\r
+ * Incoming Required Variables:\r
+ * @param - GENPV_vnfId\r
+ * @param - GENPV_vnfPayload\r
+ * @param - GENPV_type\r
+ *\r
+ *\r
+ * Outgoing Variables:\r
+ * @param - GENPV_SuccessIndicator\r
+ * @param - WorkflowException\r
+ */\r
+class GenericPutVnf extends AbstractServiceTaskProcessor{\r
+\r
+ String Prefix = "GENPV_"\r
+ ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+\r
+ /**\r
+ * This method validates the incoming variables and\r
+ * generates a Vnf Id if one is not provided.\r
+ *\r
+ * @param - execution\r
+ */\r
+ public void preProcessRequest(DelegateExecution execution) {\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ execution.setVariable("prefix",Prefix)\r
+ utils.log("DEBUG", " *** STARTED GenericPutVnf PreProcessRequest Process*** ", isDebugEnabled)\r
+\r
+ execution.setVariable("GENPV_SuccessIndicator", false)\r
+ execution.setVariable("GENPV_FoundIndicator", false)\r
+\r
+ try{\r
+ // Get Variables\r
+ String payload = execution.getVariable("GENPV_vnfPayload")\r
+ utils.log("DEBUG", "Incoming Vnf Payload is: " + payload, isDebugEnabled)\r
+ String type = execution.getVariable("GENPV_type")\r
+ utils.log("DEBUG", "Incoming Type of Vnf is: " + type, isDebugEnabled)\r
+\r
+ if(isBlank(payload) || isBlank(type)){\r
+ utils.log("ERROR", "Incoming Vnf Payload and/or Type is null. These Variables are required!", isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Vnf Payload and/or Type is null. These Variables are required!")\r
+ }else{\r
+ String vnfId = execution.getVariable("GENPV_vnfId")\r
+ if(isBlank(vnfId)){\r
+ vnfId = UUID.randomUUID().toString()\r
+ utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)\r
+ execution.setVariable("GENPV_vnfId", vnfId)\r
+ }else{\r
+ utils.log("DEBUG", "Incoming Vnf Id is: " + vnfId, isDebugEnabled)\r
+ }\r
+ }\r
+ }catch(BpmnError b){\r
+ utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
+ throw b\r
+ }catch(Exception e){\r
+ utils.log("ERROR", " Error encountered within GenericPutVnf PreProcessRequest method!" + e, isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in GenericPutVnf PreProcessRequest")\r
+\r
+ }\r
+ utils.log("DEBUG", "*** COMPLETED GenericPutVnf PreProcessRequest Process ***", isDebugEnabled)\r
+ }\r
+\r
+ /**\r
+ * This method executes a Put call to AAI to create\r
+ * or update a Vnf Object using the provided payload\r
+ *\r
+ * @param - execution\r
+ */\r
+ public void putVnf(DelegateExecution execution){\r
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+ execution.setVariable("prefix",Prefix)\r
+ utils.log("DEBUG", " *** STARTED GenericPutVnf PutVnf Process*** ", isDebugEnabled)\r
+ try {\r
+ String vnfId = execution.getVariable("GENPV_vnfId")\r
+ String payload = execution.getVariable("GENPV_vnfPayload")\r
+ String type = execution.getVariable("GENPV_type")\r
+\r
+ AaiUtil aaiUtil = new AaiUtil(this)\r
+ def aai_uri = ""\r
+ if(type.equals("generic-vnf")){\r
+ aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)\r
+ }else if(type.equals("vce")){\r
+ aai_uri = aaiUtil.getNetworkVceUri(execution)\r
+ }else if(type.equals("vpe")){\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "GenericPutVnf does not yet support getting type of vnf = vpe")\r
+ }else{\r
+ utils.log("DEBUG", "Invalid Incoming GENGV_type", isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Invalid Incoming GENPV_type")\r
+ }\r
+ utils.log("DEBUG", "Using AAI Uri: " + aai_uri, isDebugEnabled)\r
+\r
+ String path = "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8")\r
+ utils.log("DEBUG", "PUT Vnf Endpoint is: " + path, isDebugEnabled)\r
+\r
+ String putVnfAAIPath = execution.getVariable("URN_aai_endpoint") + path\r
+ execution.setVariable("GENPV_putVnfAAIPath", putVnfAAIPath)\r
+ utils.logAudit("PUT Vnf Url is: " + putVnfAAIPath)\r
+\r
+ APIResponse apiResponse = aaiUtil.executeAAIPutCall(execution, putVnfAAIPath, payload)\r
+ int responseCode = apiResponse.getStatusCode()\r
+ execution.setVariable("GENPV_putVnfResponseCode", responseCode)\r
+ utils.logAudit("AAI Response Code: " + responseCode)\r
+ String aaiResponse = apiResponse.getResponseBodyAsString()\r
+ aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
+ execution.setVariable("GENPV_putVnfResponse", aaiResponse)\r
+ utils.logAudit("AAI Response: " + aaiResponse)\r
+\r
+ if(responseCode == 200 || responseCode == 201){\r
+ utils.log("DEBUG", "PUT Vnf Received a Good Response Code.", isDebugEnabled)\r
+ }else{\r
+ utils.log("DEBUG", "PUT Vnf Received a Bad Response Code. Response Code is: " + responseCode, isDebugEnabled)\r
+ exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
+ throw new BpmnError("MSOWorkflowException")\r
+ }\r
+ }catch(BpmnError b){\r
+ utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
+ throw b\r
+ }catch(Exception e){\r
+ utils.log("ERROR", " Error encountered within GenericPutVnf PutVnf method!" + e, isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During PutVnf")\r
+ }\r
+ utils.log("DEBUG", " *** COMPLETED GenericPutVnf PutVnf Process*** ", isDebugEnabled)\r
+ }\r
+\r
+}\r