2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
 
   6  * ================================================================================
 
   7  * Modifications Copyright (c) 2019 Samsung
 
   8  * ================================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.so.bpmn.infrastructure.scripts
 
  25 import org.json.JSONObject
 
  28 import static org.apache.commons.lang3.StringUtils.*;
 
  29 import groovy.xml.XmlUtil
 
  30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  32 import org.onap.aai.domain.yang.Device
 
  33 import org.onap.so.bpmn.common.recipe.ResourceInput;
 
  34 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
 
  35 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  36 import org.onap.so.bpmn.core.WorkflowException
 
  37 import org.onap.so.bpmn.core.json.JsonUtils
 
  38 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
 
  39 import org.onap.so.client.HttpClient
 
  40 import org.onap.aaiclient.client.aai.AAIObjectType
 
  41 import org.onap.aaiclient.client.aai.AAIResourcesClient
 
  42 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  43 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  44 import org.slf4j.Logger
 
  45 import org.slf4j.LoggerFactory
 
  46 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
 
  48 import java.util.UUID;
 
  49 import javax.ws.rs.core.Response
 
  50 import org.camunda.bpm.engine.delegate.BpmnError
 
  51 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  52 import org.apache.commons.lang3.*
 
  53 import javax.ws.rs.core.MediaType
 
  54 import org.apache.commons.codec.binary.Base64
 
  55 import org.onap.logging.filter.base.ONAPComponents;
 
  59  * This groovy class supports the <class>DeleteDeviceResource.bpmn</class> process.
 
  60  * flow for Device Resource Delete
 
  62 public class DeleteDeviceResource extends AbstractServiceTaskProcessor {
 
  64     String Prefix="DELDEVRES_"
 
  66     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  68     JsonUtils jsonUtil = new JsonUtils()
 
  70     private static final Logger logger = LoggerFactory.getLogger( DeleteDeviceResource.class);
 
  72     public void preProcessRequest(DelegateExecution execution){
 
  73         logger.info(" ***** Started preProcessRequest *****")
 
  76             //get bpmn inputs from resource request.
 
  77             String requestId = execution.getVariable("mso-request-id")
 
  78             String requestAction = execution.getVariable("requestAction")
 
  79             logger.info("The requestAction is: " + requestAction)
 
  80             String recipeParamsFromRequest = execution.getVariable("recipeParams")
 
  81             logger.info("The recipeParams is: " + recipeParamsFromRequest)
 
  82             String resourceInput = execution.getVariable("resourceInput")
 
  83             logger.info("The resourceInput is: " + resourceInput)
 
  84             //Get ResourceInput Object
 
  85             ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
 
  86             execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
 
  87             String resourceInputPrameters = resourceInputObj.getResourceParameters()
 
  88             String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
 
  89             JSONObject inputParameters = new JSONObject(inputParametersJson)
 
  90             execution.setVariable(Prefix + "ResourceRequestInputs", inputParameters)
 
  92             //Deal with recipeParams
 
  93             String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
 
  94             String resourceName = resourceInputObj.getResourceInstanceName()
 
  96             String resourceInstanceId = resourceInputObj.getResourceInstancenUuid()
 
  97             String deviceId = resourceInstanceId
 
  98             execution.setVariable(Prefix + "DeviceId", deviceId)
 
 100             getDeviceInAAI(execution)
 
 102             execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
 
 103             execution.setVariable("mso-request-id", requestId)
 
 105         } catch (Exception ex){
 
 106             String msg = "Exception in preProcessRequest " + ex.getMessage()
 
 108 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 112         private void getDeviceInAAI(DelegateExecution execution) {
 
 113                 logger.info(" ***** Started getDeviceInAAI *****")
 
 115                 String deviceId = execution.getVariable(Prefix + "DeviceId")
 
 117         AAIResourcesClient client = new AAIResourcesClient()
 
 118         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.DEVICE, deviceId)
 
 119         Device dev = client.get(uri).asBean(Device.class).get()
 
 121         String devClass = dev.getClass ()
 
 122         execution.setVariable(Prefix + "DeviceClass", devClass)
 
 123         logger.debug(" DeviceClass is: " + devClass)
 
 125         } catch (Exception ex){
 
 126             String msg = "Exception in getDeviceInAAI " + ex.getMessage()
 
 128 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 131                 logger.info(" ***** Exit getDeviceInAAI *****")
 
 134     public void checkDevType(DelegateExecution execution){
 
 135         logger.info(" ***** Started checkDevType *****")
 
 138             String devType = execution.getVariable(Prefix + "DeviceClass")
 
 140             if(StringUtils.isBlank(devType)) {
 
 144             execution.setVariable("device_class", devType)
 
 146         } catch (Exception ex){
 
 147             String msg = "Exception in checkDevType " + ex.getMessage()
 
 149 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 153         private void setProgressUpdateVariables(DelegateExecution execution, String body) {
 
 154                 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
 
 155                 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
 
 156                 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
 
 159         public void prepareUpdateProgress(DelegateExecution execution) {
 
 160                 logger.info(" ***** Started prepareUpdateProgress *****")
 
 161                 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
 
 162                 String operType = resourceInputObj.getOperationType()
 
 163                 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
 
 164                 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
 
 165                 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
 
 166                 String operationId = resourceInputObj.getOperationId()
 
 167                 String progress = execution.getVariable("progress")
 
 168                 String status = execution.getVariable("status")
 
 169                 String statusDescription = execution.getVariable("statusDescription")
 
 172                 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 
 173                         xmlns:ns="http://org.onap.so/requestsdb">
 
 176                     <ns:updateResourceOperationStatus>
 
 177                                <operType>${operType}</operType>
 
 178                                <operationId>${operationId}</operationId>
 
 179                                <progress>${progress}</progress>
 
 180                                <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
 
 181                                <serviceId>${ServiceInstanceId}</serviceId>
 
 182                                <status>${status}</status>
 
 183                                <statusDescription>${statusDescription}</statusDescription>
 
 184                     </ns:updateResourceOperationStatus>
 
 186                 </soapenv:Envelope>"""
 
 188                 setProgressUpdateVariables(execution, body)
 
 189                 logger.info(" ***** Exit prepareUpdateProgress *****")
 
 192     public void getVNFTemplatefromSDC(DelegateExecution execution){
 
 193         logger.info(" ***** Started getVNFTemplatefromSDC *****")
 
 198         } catch (Exception ex){
 
 199             String msg = "Exception in getVNFTemplatefromSDC " + ex.getMessage()
 
 201 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 205     public void postVNFInfoProcess(DelegateExecution execution){
 
 206         logger.info(" ***** Started postVNFInfoProcess *****")
 
 211         } catch (Exception ex){
 
 212             String msg = "Exception in postVNFInfoProcess " + ex.getMessage()
 
 214 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 218     public void sendSyncResponse (DelegateExecution execution) {
 
 219         logger.debug( " *** sendSyncResponse *** ")
 
 222             String operationStatus = "finished"
 
 223             // RESTResponse for main flow
 
 224             String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
 
 225             logger.debug( " sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
 
 226             sendWorkflowResponse(execution, 202, resourceOperationResp)
 
 227             execution.setVariable("sentSyncResponse", true)
 
 229         } catch (Exception ex) {
 
 230             String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
 
 232 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 234         logger.debug(" ***** Exit sendSyncResopnse *****")