diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/groovy')
3 files changed, 400 insertions, 228 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy new file mode 100644 index 0000000000..644cf5e387 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. 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.onap.so.bpmn.common.scripts + +import javax.ws.rs.core.Response + +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.logging.filter.base.ONAPComponents +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory +import org.onap.so.client.oof.adapter.beans.payload.OofRequest +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import com.fasterxml.jackson.databind.ObjectMapper + + +import static org.onap.so.bpmn.common.scripts.GenericUtils.* + + +class DoHandleOofRequest extends AbstractServiceTaskProcessor { + + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + private static final Logger logger = LoggerFactory.getLogger(DoHandleOofRequest.class) + + @Override + public void preProcessRequest(DelegateExecution execution) { + logger.debug("In Preprocess Oof Request Handler") + String apiPath = execution.getVariable("apiPath") + if (isBlank(apiPath)) { + String msg = "Cannot process OOF adapter call : API PATH is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + //msoRequestId is used for correlation + String requestId = execution.getVariable("correlator") + if (isBlank(requestId)) { + String msg = "Cannot process OOF adapter call : correlator is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String messageType = execution.getVariable("messageType") + if (isBlank(messageType)) { + String msg = "Cannot process OOF adapter call : messageType is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String timeout = execution.getVariable("timeout") + if (isBlank(timeout)) { + timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + if (isBlank(timeout)) { + logger.debug("Setting OOF timeout to default : PT30M") + timeout = "PT30M" + } + } + + Object requestDetails = execution.getVariable("oofRequest") + OofRequest oofRequestPayload = new OofRequest() + oofRequestPayload.setApiPath(apiPath) + oofRequestPayload.setRequestDetails(requestDetails) + ObjectMapper objectMapper = new ObjectMapper() + String requestJson = objectMapper.writeValueAsString(oofRequestPayload) + execution.setVariable("oofRequestPayload", requestJson) + } + + public void callOofAdapter(DelegateExecution execution) { + logger.debug("Start callOofAdapter") + String requestId = execution.getVariable("msoRequestId") + String oofAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution) + String basicAuthCred = execution.getVariable("BasicAuthHeaderValue") + URL requestUrl = new URL(oofAdapterEndpoint) + String oofRequest = execution.getVariable("oofRequestPayload") + logger.debug("oofRequest : " + oofRequest) + HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL) + Response httpResponse = httpClient.post(oofRequest) + int responseCode = httpResponse.getStatus() + logger.debug("OOF sync response code is: " + responseCode) + if(responseCode != 200){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") + } + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 69dfacd9bc..040fc26f23 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -22,42 +22,29 @@ package org.onap.so.bpmn.common.scripts -import com.fasterxml.jackson.databind.ObjectMapper +import static org.onap.so.bpmn.common.scripts.GenericUtils.* + +import javax.ws.rs.core.UriBuilder + 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.common.util.OofInfraUtils import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.domain.AllottedResource import org.onap.so.bpmn.core.domain.HomingSolution import org.onap.so.bpmn.core.domain.ModelInfo import org.onap.so.bpmn.core.domain.Resource -import org.onap.so.bpmn.core.domain.AllottedResource import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.ServiceInstance import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.client.HttpClient -import org.onap.so.client.HttpClientFactory import org.onap.so.db.catalog.beans.CloudSite import org.onap.so.db.catalog.beans.HomingInstance -import org.onap.logging.filter.base.ONAPComponents; -import org.springframework.http.HttpEntity -import org.springframework.http.HttpHeaders -import org.springframework.http.HttpMethod -import org.springframework.http.ResponseEntity -import org.springframework.http.client.BufferingClientHttpRequestFactory -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory -import org.springframework.web.client.RestTemplate -import org.springframework.web.util.UriComponentsBuilder import org.slf4j.Logger import org.slf4j.LoggerFactory +import com.google.gson.JsonObject -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response -import javax.ws.rs.core.UriBuilder - -import static org.onap.so.bpmn.common.scripts.GenericUtils.* +import com.fasterxml.jackson.databind.ObjectMapper class OofUtils { private static final Logger logger = LoggerFactory.getLogger( OofUtils.class); @@ -530,10 +517,11 @@ class OofUtils { return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString() } - public String buildSelectNSTRequest(String requestId, Map<String, Object> profileInfo) { + public String buildSelectNSTRequest(String requestId,String messageType, Map<String, Object> profileInfo) { def transactionId = requestId logger.debug( "transactionId is: " + transactionId) - String callbackUrl = "http://0.0.0.0:9000/callback/" + String correlator = requestId + String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator ObjectMapper objectMapper = new ObjectMapper() String json = objectMapper.writeValueAsString(profileInfo) StringBuilder response = new StringBuilder() @@ -554,11 +542,12 @@ class OofUtils { return response.toString() } - public String buildSelectNSIRequest(String requestId, String nstInfo, Map<String, Object> profileInfo){ + public String buildSelectNSIRequest(String requestId, String nstInfo,String messageType, Map<String, Object> profileInfo){ def transactionId = requestId logger.debug( "transactionId is: " + transactionId) - String callbackUrl = "http://0.0.0.0:9000/callback/" + String correlator = requestId + String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(profileInfo); StringBuilder response = new StringBuilder(); @@ -583,5 +572,82 @@ class OofUtils { response.append("\n }\n") return response.toString() } - +/** +* Method to create select NSSI request +* @param requestId - mso-request-id +* @param messageType - Message type for callback correlation +* @param UUID - UUID of NSST +* @param invariantUUID - Invariant UUID of NSST +* @param name - name of the NSST model +* @param profileInfo - A JSON object containing slice profile parameters +* @return +*/ +public String buildSelectNSSIRequest(String requestId, String messageType, String UUID,String invariantUUID, +String name, Map<String, Object> profileInfo){ + +def transactionId = requestId +logger.debug( "transactionId is: " + transactionId) +String correlator = requestId +String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator +ObjectMapper objectMapper = new ObjectMapper(); +String profileJson = objectMapper.writeValueAsString(profileInfo); + +//Prepare requestInfo object +JsonObject requestInfo = new JsonObject() +requestInfo.addProperty("transactionId", transactionId) +requestInfo.addProperty("requestId", requestId) +requestInfo.addProperty("callbackUrl", callbackUrl) +requestInfo.addProperty("sourceId","SO" ) +requestInfo.addProperty("timeout", 600) +requestInfo.addProperty("numSolutions", 1) + +//Prepare serviceInfo object +JsonObject nsstInfo = new JsonObject() +nsstInfo.addProperty("UUID", UUID) +nsstInfo.addProperty("invariantUUID", invariantUUID) +nsstInfo.addProperty("name", name) + +JsonObject json = new JsonObject() +json.add("requestInfo", requestInfo) +json.add("NSSTInfo", nsstInfo) +json.addProperty("sliceProfile", profileJson) +return json.toString() +} +/** +* Method to create NSI/NSSI termination request +* (OOF response will be synchronous in G-Release) +* @param requestId - mso-request-id +* @param nxlId - NSI/NSSI Id to be terminated +* @param messageType - Message type for callback correlation +* @param serviceInstanceId - NSI/NSSI Id related to nxlId +* @return +*/ +public String buildTerminateNxiRequest(String requestId,String nxlId, String nxlType, String messageType, String serviceInstanceId) { +def transactionId = requestId +logger.debug( "transactionId is: " + transactionId) +String correlator = requestId +String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator +//Prepare Terminate Nxl Json +JsonObject json = new JsonObject() +json.addProperty("type", nxlType) +json.addProperty("NxIId", nxlId) + +//Prepare requestInfo object +JsonObject requestInfo = new JsonObject() +requestInfo.addProperty("transactionId", transactionId) +requestInfo.addProperty("requestId", requestId) +requestInfo.addProperty("callbackUrl", callbackUrl) +requestInfo.addProperty("sourceId","SO" ) +requestInfo.addProperty("timeout", 600) + +//Prepare addtnlArgs object +JsonObject addtnlArgs = new JsonObject() +addtnlArgs.addProperty("serviceInstanceId", serviceInstanceId) + +requestInfo.add("addtnlArgs", addtnlArgs) +json.add("requestInfo", requestInfo) + +return json.toString() + +} } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1.groovy index 08c032fba3..146889351a 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1.groovy @@ -64,208 +64,211 @@ import org.slf4j.LoggerFactory class SniroHomingV1 extends AbstractServiceTaskProcessor{ private static final Logger logger = LoggerFactory.getLogger( SniroHomingV1.class); - ExceptionUtil exceptionUtil = new ExceptionUtil() - JsonUtils jsonUtil = new JsonUtils() - SniroUtils sniroUtils = new SniroUtils(this) - - /** - * This method validates the incoming variables. - * The method then prepares the sniro request - * and posts it to sniro's rest api. - * - * @param execution - * - * @author cb645j - */ - public void callSniro(DelegateExecution execution){ - execution.setVariable("prefix","HOME_") - logger.trace("Started Sniro Homing Call Sniro ") - try{ - execution.setVariable("rollbackData", null) - execution.setVariable("rolledBack", false) - - String requestId = execution.getVariable("msoRequestId") - logger.debug("Incoming Request Id is: " + requestId) - String serviceInstanceId = execution.getVariable("serviceInstanceId") - logger.debug("Incoming Service Instance Id is: " + serviceInstanceId) - ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") - logger.debug("Incoming Service Decomposition is: " + serviceDecomposition) - String subscriberInfo = execution.getVariable("subscriberInfo") - logger.debug("Incoming Subscriber Information is: " + subscriberInfo) - - if(isBlank(requestId) || isBlank(serviceInstanceId) || isBlank(serviceDecomposition.toString()) || isBlank(subscriberInfo)){ - exceptionUtil.buildAndThrowWorkflowException(execution, 4000, "A required input variable is missing or null") - }else{ - String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId") - String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName") - String subCommonSiteId = "" - if(jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")){ - subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId") - } - Subscriber subscriber = new Subscriber(subId, subName, subCommonSiteId) - - String cloudConfiguration = execution.getVariable("cloudConfiguration") // TODO Currently not being used - String homingParameters = execution.getVariable("homingParameters") // (aka. request parameters) Should be json format. TODO confirm its json format - - //Authentication - String authHeader = UrnPropertiesReader.getVariable("sniro.manager.headers.auth", execution) - execution.setVariable("BasicAuthHeaderValue", authHeader) - - //Prepare Callback - String timeout = execution.getVariable("timeout") - if(isBlank(timeout)){ - timeout = UrnPropertiesReader.getVariable("sniro.manager.timeout", execution) - if(isBlank(timeout)) { - timeout = "PT30M"; - } - } - logger.debug("Async Callback Timeout will be: " + timeout) - - execution.setVariable("timeout", timeout); - execution.setVariable("correlator", requestId); - execution.setVariable("messageType", "SNIROResponse"); - - //Build Request & Call Sniro - String sniroRequest = sniroUtils.buildRequest(execution, requestId, serviceDecomposition, subscriber, homingParameters) - execution.setVariable("sniroRequest", sniroRequest) - logger.debug("SNIRO Request is: " + sniroRequest) - - String endpoint = UrnPropertiesReader.getVariable("sniro.manager.uri.v1", execution) - String host = UrnPropertiesReader.getVariable("sniro.manager.host", execution) - String urlString = host + endpoint - logger.debug("Sniro Url is: " + urlString) - - URL url = new URL(urlString); - HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.SNIRO) - httpClient.addAdditionalHeader("Authorization", authHeader) - Response httpResponse = httpClient.post(sniroRequest) - - int responseCode = httpResponse.getStatus() - - logger.debug("Sniro sync response code is: " + responseCode) - if(httpResponse.hasEntity()){ - logger.debug("Sniro sync response is: " + httpResponse.readEntity(String.class)) - } - - if(responseCode != 202){ - exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from Sniro.") - } - - logger.trace("Completed Sniro Homing Call Sniro") - } - }catch(BpmnError b){ - throw b - }catch(Exception e){ - logger.debug("Error encountered within Homing CallSniro method: " + e) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Homing CallSniro: " + e.getMessage()) - } - } - - /** - * This method processes the callback response - * and the contained homing solution. It sets - * homing solution assignment and license - * information to the corresponding resources - * - * @param execution - * - * @author cb645j - */ - public void processHomingSolution(DelegateExecution execution){ - logger.trace("Started Sniro Homing Process Homing Solution") - try{ - String response = execution.getVariable("asyncCallbackResponse") - logger.debug("Sniro Async Callback Response is: " + response) - - sniroUtils.validateCallbackResponse(execution, response) - - ServiceDecomposition decomposition = execution.getVariable("serviceDecomposition") - List<Resource> resourceList = decomposition.getServiceResources() - - if(JsonUtils.jsonElementExist(response, "solutionInfo.placementInfo")){ - String placements = jsonUtil.getJsonValue(response, "solutionInfo.placementInfo") - JSONArray arr = new JSONArray(placements) - for(int i = 0; i < arr.length(); i++){ - JSONObject placement = arr.getJSONObject(i) - String jsonServiceResourceId = placement.getString("serviceResourceId") - for(Resource resource:resourceList){ - String serviceResourceId = resource.getResourceId() - if(serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)){ - //match - String inventoryType = placement.getString("inventoryType") - resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType)) - resource.getHomingSolution().setCloudRegionId(placement.getString("cloudRegionId")) - resource.getHomingSolution().setRehome(placement.getBoolean("isRehome")) - JSONArray assignmentArr = placement.getJSONArray("assignmentInfo") - Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, assignmentArr.toString(), "variableName", "variableValue") - resource.getHomingSolution().setCloudOwner(assignmentMap.get("cloudOwner")) - resource.getHomingSolution().setAicClli(assignmentMap.get("aicClli")) - resource.getHomingSolution().setAicVersion(assignmentMap.get("aicVersion")) - if(inventoryType.equalsIgnoreCase("service")){ - VnfResource vnf = new VnfResource() - vnf.setVnfHostname(assignmentMap.get("vnfHostName")) - resource.getHomingSolution().setVnf(vnf) - resource.getHomingSolution().setServiceInstanceId(placement.getString("serviceInstanceId")) - } - } - } - } - } - - if(JsonUtils.jsonElementExist(response, "solutionInfo.licenseInfo")){ - String licenseInfo = jsonUtil.getJsonValue(response, "solutionInfo.licenseInfo") - JSONArray licenseArr = new JSONArray(licenseInfo) - for(int l = 0; l < licenseArr.length(); l++){ - JSONObject license = licenseArr.getJSONObject(l) - String jsonServiceResourceId = license.getString("serviceResourceId") - for(Resource resource:resourceList){ - String serviceResourceId = resource.getResourceId() - if(serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)){ - //match - String jsonEntitlementPoolList = jsonUtil.getJsonValue(license.toString(), "entitlementPoolList") - List<String> entitlementPoolList = jsonUtil.StringArrayToList(execution, jsonEntitlementPoolList) - resource.getHomingSolution().getLicense().setEntitlementPoolList(entitlementPoolList) - - String jsonLicenseKeyGroupList = jsonUtil.getJsonValue(license.toString(), "licenseKeyGroupList") - List<String> licenseKeyGroupList = jsonUtil.StringArrayToList(execution, jsonLicenseKeyGroupList) - resource.getHomingSolution().getLicense().setLicenseKeyGroupList(licenseKeyGroupList) - } - } - } - } - execution.setVariable("serviceDecomposition", decomposition) - - logger.trace("Completed Sniro Homing Process Homing Solution") - }catch(BpmnError b){ - throw b - }catch(Exception e){ - logger.debug("Error encountered within Homing ProcessHomingSolution method: " + e) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Sniro Homing Process Solution") - } - } - - /** - * This method logs the start of DHVCreateService - * to make debugging easier. - * - * @param - execution - * @author cb645j - */ - public String logStart(DelegateExecution execution){ - String requestId = execution.getVariable("testReqId") - if(isBlank(requestId)){ - requestId = execution.getVariable("msoRequestId") - } - execution.setVariable("DHVCS_requestId", requestId) - logger.trace("STARTED Homing Subflow for request: " + requestId + " ") - logger.debug("****** Homing Subflow Global Debug Enabled: " + execution.getVariable("isDebugLogEnabled") + " *****") - logger.trace("STARTED Homing Subflow for request: " + requestId + " ") - } - - - /** - * Auto-generated method stub - */ - public void preProcessRequest(DelegateExecution execution){} + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + SniroUtils sniroUtils = new SniroUtils(this) + + /** + * This method validates the incoming variables. + * The method then prepares the sniro request + * and posts it to sniro's rest api. + * + * @param execution + * + * @author cb645j + */ + public void callSniro(DelegateExecution execution){ + execution.setVariable("prefix","HOME_") + logger.trace("Started Sniro Homing Call Sniro ") + try{ + execution.setVariable("rollbackData", null) + execution.setVariable("rolledBack", false) + + String requestId = execution.getVariable("msoRequestId") + logger.debug("Incoming Request Id is: " + requestId) + String serviceInstanceId = execution.getVariable("serviceInstanceId") + logger.debug("Incoming Service Instance Id is: " + serviceInstanceId) + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") + logger.debug("Incoming Service Decomposition is: " + serviceDecomposition) + String subscriberInfo = execution.getVariable("subscriberInfo") + logger.debug("Incoming Subscriber Information is: " + subscriberInfo) + + if(isBlank(requestId) || isBlank(serviceInstanceId) || isBlank(serviceDecomposition.toString()) || isBlank(subscriberInfo)){ + exceptionUtil.buildAndThrowWorkflowException(execution, 4000, "A required input variable is missing or null") + }else{ + String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId") + String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName") + String subCommonSiteId = "" + if(jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")){ + subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId") + } + Subscriber subscriber = new Subscriber(subId, subName, subCommonSiteId) + + String cloudConfiguration = execution.getVariable("cloudConfiguration") // TODO Currently not being used + String homingParameters = execution.getVariable("homingParameters") // (aka. request parameters) Should be json format. TODO confirm its json format + + //Authentication + String authHeader = UrnPropertiesReader.getVariable("sniro.manager.headers.auth", execution) + execution.setVariable("BasicAuthHeaderValue", authHeader) + + //Prepare Callback + String timeout = execution.getVariable("timeout") + if(isBlank(timeout)){ + timeout = UrnPropertiesReader.getVariable("sniro.manager.timeout", execution) + if(isBlank(timeout)) { + timeout = "PT30M"; + } + } + logger.debug("Async Callback Timeout will be: " + timeout) + + execution.setVariable("timeout", timeout); + execution.setVariable("correlator", requestId); + execution.setVariable("messageType", "SNIROResponse"); + + //Build Request & Call Sniro + String sniroRequest = sniroUtils.buildRequest(execution, requestId, serviceDecomposition, subscriber, homingParameters) + execution.setVariable("sniroRequest", sniroRequest) + logger.debug("SNIRO Request is: " + sniroRequest) + + String endpoint = UrnPropertiesReader.getVariable("sniro.manager.uri.v1", execution) + String host = UrnPropertiesReader.getVariable("sniro.manager.host", execution) + String urlString = host + endpoint + logger.debug("Sniro Url is: " + urlString) + + URL url = new URL(urlString); + HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.SNIRO) + httpClient.addAdditionalHeader("Authorization", authHeader) + Response httpResponse = httpClient.post(sniroRequest) + + int responseCode = httpResponse.getStatus() + + logger.debug("Sniro sync response code is: " + responseCode) + if(httpResponse.hasEntity()){ + logger.debug("Sniro sync response is: " + httpResponse.readEntity(String.class)) + } + + if(responseCode != 202){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from Sniro.") + } + + logger.trace("Completed Sniro Homing Call Sniro") + } + }catch(BpmnError b){ + throw b + }catch(Exception e){ + logger.debug("Error encountered within Homing CallSniro method: " + e) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Homing CallSniro: " + e.getMessage()) + } + } + + /** + * This method processes the callback response + * and the contained homing solution. It sets + * homing solution assignment and license + * information to the corresponding resources + * + * @param execution + * + * @author cb645j + */ + public void processHomingSolution(DelegateExecution execution){ + logger.trace("Started Sniro Homing Process Homing Solution") + try{ + String response = execution.getVariable("asyncCallbackResponse") + logger.debug("Sniro Async Callback Response is: " + response) + + sniroUtils.validateCallbackResponse(execution, response) + + ServiceDecomposition decomposition = execution.getVariable("serviceDecomposition") + List<Resource> resourceList = decomposition.getServiceResources() + + if(JsonUtils.jsonElementExist(response, "solutionInfo.placementInfo")){ + String placements = jsonUtil.getJsonValue(response, "solutionInfo.placementInfo") + JSONArray arr = new JSONArray(placements) + for(int i = 0; i < arr.length(); i++){ + JSONObject placement = arr.getJSONObject(i) + String jsonServiceResourceId = placement.getString("serviceResourceId") + for(Resource resource:resourceList){ + String serviceResourceId = resource.getResourceId() + if(serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)){ + //match + String inventoryType = placement.getString("inventoryType") + resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType)) + resource.getHomingSolution().setCloudRegionId(placement.getString("cloudRegionId")) + resource.getHomingSolution().setRehome(placement.getBoolean("isRehome")) + JSONArray assignmentArr = placement.getJSONArray("assignmentInfo") + Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, assignmentArr.toString(), "variableName", "variableValue") + resource.getHomingSolution().setCloudOwner(assignmentMap.get("cloudOwner")) + resource.getHomingSolution().setAicClli(assignmentMap.get("aicClli")) + resource.getHomingSolution().setAicVersion(assignmentMap.get("aicVersion")) + if(inventoryType.equalsIgnoreCase("service")){ + VnfResource vnf = new VnfResource() + vnf.setVnfHostname(assignmentMap.get("vnfHostName")) + resource.getHomingSolution().setVnf(vnf) + resource.getHomingSolution().setServiceInstanceId(placement.getString("serviceInstanceId")) + } + if(placement.getBoolean("isRehome")) { + resource.getHomingSolution().setAllottedResourceId(assignmentMap.get("serviceResourceId")) + } + } + } + } + } + + if(JsonUtils.jsonElementExist(response, "solutionInfo.licenseInfo")){ + String licenseInfo = jsonUtil.getJsonValue(response, "solutionInfo.licenseInfo") + JSONArray licenseArr = new JSONArray(licenseInfo) + for(int l = 0; l < licenseArr.length(); l++){ + JSONObject license = licenseArr.getJSONObject(l) + String jsonServiceResourceId = license.getString("serviceResourceId") + for(Resource resource:resourceList){ + String serviceResourceId = resource.getResourceId() + if(serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)){ + //match + String jsonEntitlementPoolList = jsonUtil.getJsonValue(license.toString(), "entitlementPoolList") + List<String> entitlementPoolList = jsonUtil.StringArrayToList(execution, jsonEntitlementPoolList) + resource.getHomingSolution().getLicense().setEntitlementPoolList(entitlementPoolList) + + String jsonLicenseKeyGroupList = jsonUtil.getJsonValue(license.toString(), "licenseKeyGroupList") + List<String> licenseKeyGroupList = jsonUtil.StringArrayToList(execution, jsonLicenseKeyGroupList) + resource.getHomingSolution().getLicense().setLicenseKeyGroupList(licenseKeyGroupList) + } + } + } + } + execution.setVariable("serviceDecomposition", decomposition) + + logger.trace("Completed Sniro Homing Process Homing Solution") + }catch(BpmnError b){ + throw b + }catch(Exception e){ + logger.debug("Error encountered within Homing ProcessHomingSolution method: " + e) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Sniro Homing Process Solution") + } + } + + /** + * This method logs the start of DHVCreateService + * to make debugging easier. + * + * @param - execution + * @author cb645j + */ + public String logStart(DelegateExecution execution){ + String requestId = execution.getVariable("testReqId") + if(isBlank(requestId)){ + requestId = execution.getVariable("msoRequestId") + } + execution.setVariable("DHVCS_requestId", requestId) + logger.trace("STARTED Homing Subflow for request: " + requestId + " ") + logger.debug("****** Homing Subflow Global Debug Enabled: " + execution.getVariable("isDebugLogEnabled") + " *****") + logger.trace("STARTED Homing Subflow for request: " + requestId + " ") + } + + + /** + * Auto-generated method stub + */ + public void preProcessRequest(DelegateExecution execution){} } |