2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
 
   7  * ================================================================================
 
   8  * Modifications Copyright (c) 2019 Samsung
 
   9  * ================================================================================
 
  10  * Licensed under the Apache License, Version 2.0 (the "License");
 
  11  * you may not use this file except in compliance with the License.
 
  12  * You may obtain a copy of the License at
 
  14  *      http://www.apache.org/licenses/LICENSE-2.0
 
  16  * Unless required by applicable law or agreed to in writing, software
 
  17  * distributed under the License is distributed on an "AS IS" BASIS,
 
  18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  19  * See the License for the specific language governing permissions and
 
  20  * limitations under the License.
 
  21  * ============LICENSE_END=========================================================
 
  24 package org.onap.so.bpmn.infrastructure.scripts
 
  27 import static org.apache.commons.lang3.StringUtils.*;
 
  29 import groovy.xml.XmlUtil
 
  32 import org.onap.so.bpmn.core.json.JsonUtils
 
  33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
 
  35 import org.onap.so.bpmn.core.RollbackData
 
  36 import org.onap.so.bpmn.core.WorkflowException
 
  37 import org.slf4j.Logger
 
  38 import org.slf4j.LoggerFactory
 
  39 import org.onap.so.logger.MessageEnum
 
  40 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
 
  41 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  42 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  43 import org.onap.aaiclient.client.aai.AAIObjectType
 
  44 import org.onap.aaiclient.client.aai.AAIResourcesClient
 
  46 import java.util.UUID;
 
  48 import org.camunda.bpm.engine.delegate.BpmnError
 
  49 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  50 import org.json.JSONObject;
 
  51 import org.apache.commons.lang3.*
 
  52 import org.apache.commons.codec.binary.Base64;
 
  53 import org.springframework.web.util.UriUtils;
 
  55  * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
 
  58  * @param - msoRequestId
 
  59  * @param - rollbackData with
 
  61  *                      subscriptionServiceType
 
  70  * @param - rollbackError
 
  71  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
 
  74 public class DoCreateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
 
  76     private static final Logger logger = LoggerFactory.getLogger( DoCreateE2EServiceInstanceRollback.class);
 
  77         String Prefix="DCRESIRB_"
 
  79         public void preProcessRequest(DelegateExecution execution) {
 
  80                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
 
  81                 execution.setVariable("prefix",Prefix)
 
  83                 logger.trace("Start preProcessRequest")
 
  84                 execution.setVariable("rollbackAAI",false)
 
  85                 execution.setVariable("rollbackSDNC",false)
 
  88                         def rollbackData = execution.getVariable("rollbackData")
 
  89                         logger.debug("RollbackData:" + rollbackData)
 
  91                         if (rollbackData != null) {
 
  92                                 if (rollbackData.hasType("SERVICEINSTANCE")) {
 
  94                                         def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
 
  95                                         execution.setVariable("serviceInstanceId", serviceInstanceId)
 
  97                                         def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
 
  98                                         execution.setVariable("subscriptionServiceType", subscriptionServiceType)
 
 100                                         def globalSubscriberId  = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
 
 101                                         execution.setVariable("globalSubscriberId", globalSubscriberId)
 
 103                                         def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
 
 104                                         if ("true".equals(rollbackAAI))
 
 106                                                 execution.setVariable("rollbackAAI",true)
 
 109                                         def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
 
 110                                         if ("true".equals(rollbackSDNC))
 
 112                                                 execution.setVariable("rollbackSDNC", true)
 
 115                                         if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
 
 117                                                 execution.setVariable("skipRollback", true)
 
 120                                         def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
 
 121                                         execution.setVariable("sdncDelete", sdncDelete)
 
 122                                         def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
 
 123                                         execution.setVariable("sdncDeactivate", sdncDeactivate)
 
 124                                         logger.debug("sdncDeactivate:\n" + sdncDeactivate)
 
 125                                         logger.debug("sdncDelete:\n" + sdncDelete)
 
 128                                         execution.setVariable("skipRollback", true)
 
 132                                 execution.setVariable("skipRollback", true)
 
 134                         if (execution.getVariable("disableRollback").equals("true" ))
 
 136                                 execution.setVariable("skipRollback", true)
 
 139                 } catch (BpmnError e) {
 
 141                 } catch (Exception ex){
 
 142                         msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
 
 144                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) //TODO how does this even compile without exceptionUtil being declared
 
 146                 logger.trace("Exit preProcessRequest ")
 
 149         public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
 
 151                 logger.trace("validateSDNCResponse")
 
 154                         WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 155                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
 
 156                         logger.debug("SDNCResponse: " + response)
 
 157                         logger.debug("workflowException: " + workflowException)
 
 159                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
 
 160                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
 
 162                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
 
 163                                 msg = "SDNC Adapter service-instance rollback successful for " + method
 
 166                                 execution.setVariable("rolledBack", false)
 
 167                                 msg =  "Error Response from SDNC Adapter service-instance rollback for " + method
 
 168                                 execution.setVariable("rollbackError", msg)
 
 170                                 throw new BpmnError("MSOWorkflowException")
 
 172                 } catch (BpmnError e) {
 
 174                 } catch (Exception ex){
 
 175                         msg = "Exception in Create ServiceInstance rollback for "  + method  + " Exception:" + ex.getMessage()
 
 177                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 179                 logger.trace("Exit validateSDNCResponse ")
 
 183          * Deletes the service instance in aai
 
 185         public void deleteServiceInstance(DelegateExecution execution) {
 
 186                 logger.trace("Started Delete Service Instance")
 
 188                         String globalCustId = execution.getVariable("globalSubscriberId")
 
 189                         String serviceType = execution.getVariable("subscriptionServiceType")
 
 190                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 192                         AAIResourcesClient resourceClient = new AAIResourcesClient();
 
 193                         AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustId, serviceType, serviceInstanceId)
 
 194                         resourceClient.delete(serviceInstanceUri)
 
 196                         logger.trace("Completed Delete Service Instance")
 
 198                         logger.debug("Error occured within deleteServiceInstance method: " + e)
 
 202         public void postProcessRequest(DelegateExecution execution) {
 
 204                 logger.trace("postProcessRequest")
 
 207                         execution.setVariable("rollbackData", null)
 
 208                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
 
 209                         boolean rollbackAAI = execution.getVariable("rollbackAAI")
 
 210                         boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
 
 211                         if (rollbackAAI || rollbackSDNC)
 
 213                                 execution.setVariable("rolledBack", true)
 
 217                                 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
 
 219                                         execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
 
 220                                         execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
 
 221                                         logger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
 
 224                         logger.trace("Exit postProcessRequest ")
 
 226                 } catch (BpmnError e) {
 
 227                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
 
 229                 } catch (Exception ex) {
 
 230                         msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
 
 236         public void processRollbackException(DelegateExecution execution){
 
 238                 logger.trace("processRollbackException")
 
 240                         logger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
 
 241                         execution.setVariable("rollbackData", null)
 
 242                         execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
 
 243                         execution.setVariable("WorkflowException", null)
 
 246                         logger.debug("BPMN Error during processRollbackExceptions Method: ")
 
 248                         logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
 
 251                 logger.trace(" Exit processRollbackException")
 
 254         public void processRollbackJavaException(DelegateExecution execution){
 
 256                 logger.trace("processRollbackJavaException")
 
 258                         execution.setVariable("rollbackData", null)
 
 259                         execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
 
 260                         logger.debug("Caught Exception in processRollbackJavaException")
 
 263                         logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
 
 265                 logger.trace("Exit processRollbackJavaException")