diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
4 files changed, 67 insertions, 35 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy index 5c935e9081..250cdda0a1 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy @@ -19,29 +19,30 @@ */ package org.onap.so.bpmn.common.scripts -import org.camunda.bpm.engine.delegate.BpmnError + + import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor; +import org.onap.logging.ref.slf4j.ONAPLogConstants import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory import org.onap.so.logger.MsoLogger -import org.apache.commons.lang3.StringEscapeUtils -import java.util.regex.Matcher -import java.util.regex.Pattern +import org.onap.so.utils.TargetEntity import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response -import org.onap.so.utils.TargetEntity +import java.util.regex.Matcher +import java.util.regex.Pattern class ExternalAPIUtil { String Prefix="EXTAPI_" - public MsoUtils utils = new MsoUtils() - - ExceptionUtil exceptionUtil = new ExceptionUtil() - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ExternalAPIUtil.class) + private final HttpClientFactory httpClientFactory; + private final MsoUtils utils; + private final ExceptionUtil exceptionUtil; + public static final String PostServiceOrderRequestsTemplate = "{\n" + "\t\"externalId\": <externalId>,\n" + @@ -85,7 +86,10 @@ class ExternalAPIUtil { "\t} \n" + "}" - public ExternalAPIUtil() { + ExternalAPIUtil(HttpClientFactory httpClientFactory, MsoUtils utils, ExceptionUtil exceptionUtil) { + this.httpClientFactory = httpClientFactory + this.utils = utils + this.exceptionUtil = exceptionUtil } // public String getUri(DelegateExecution execution, resourceName) { @@ -137,8 +141,7 @@ class ExternalAPIUtil { msoLogger.debug( "Generated uuid is: " + uuid) msoLogger.debug( "URL to be used is: " + url) - URL Url = new URL(url) - HttpClient client = new HttpClient(Url, MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL) + HttpClient client = httpClientFactory.create(new URL(url), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL) client.addBasicAuthHeader(execution.getVariable("URN_externalapi_auth"), execution.getVariable("URN_mso_msoKey")) client.addAdditionalHeader("X-FromAppId", "MSO") client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, uuid) @@ -166,17 +169,15 @@ class ExternalAPIUtil { * @return Response * */ - public Response executeExternalAPIPostCall(DelegateExecution execution, String urlString, String payload){ + public Response executeExternalAPIPostCall(DelegateExecution execution, String url, String payload){ msoLogger.debug( " ======== Started Execute ExternalAPI Post Process ======== ") Response apiResponse = null try{ String uuid = utils.getRequestID() msoLogger.debug( "Generated uuid is: " + uuid) - msoLogger.debug( "URL to be used is: " + urlString) - - URL url = new URL(urlString); + msoLogger.debug( "URL to be used is: " + url) - HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.AAI) + HttpClient httpClient = httpClientFactory.create(new URL(url), MediaType.APPLICATION_JSON, TargetEntity.AAI) httpClient.addBasicAuthHeader(execution.getVariable("URN_externalapi_auth"), execution.getVariable("URN_mso_msoKey")) httpClient.addAdditionalHeader("X-FromAppId", "MSO") httpClient.addAdditionalHeader("X-TransactionId", uuid) diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilFactory.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilFactory.groovy new file mode 100644 index 0000000000..e7f46464ee --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilFactory.groovy @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ + * 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 org.onap.so.client.HttpClientFactory + +class ExternalAPIUtilFactory { + + ExternalAPIUtil create() { + return new ExternalAPIUtil(new HttpClientFactory(), new MsoUtils(), new ExceptionUtil()) + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy index 6691a82352..354ece9e63 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy @@ -174,14 +174,12 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor { personaModelVersionEntry = updateVfModuleNode(origRequest, 'persona-model-version') } String contrailServiceInstanceFqdnEntry = updateVfModuleNode(origRequest, 'contrail-service-instance-fqdn') - def payload = """ - { ${orchestrationStatusEntry} - ${heatStackIdEntry} - ${personaModelVersionEntry} - ${contrailServiceInstanceFqdnEntry} - "vf-module-id": "${vfModuleId}" - } - """ + org.onap.aai.domain.yang.VfModule payload = new org.onap.aai.domain.yang.VfModule(); + payload.setVfModuleId(vfModuleId) + payload.setOrchestrationStatus(orchestrationStatusEntry) + payload.setHeatStackId(heatStackIdEntry) + payload.setPersonaModelVersion(personaModelVersionEntry) + payload.setContrailServiceInstanceFqdn(contrailServiceInstanceFqdnEntry) try { AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId) @@ -210,16 +208,16 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor { private String updateVfModuleNode(String origRequest, String elementName) { if (!utils.nodeExists(origRequest, elementName)) { - return "" + return null } def elementValue = utils.getNodeText(origRequest, elementName) if (elementValue.equals('DELETE')) { - // Set the element being deleted to null - return """"${elementName}": null,""" + // Set the element being deleted to empty string + return "" } else { - return """"${elementName}": "${elementValue}",""" + return elementValue } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index c0f1c48b76..b1e5d0d208 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -115,7 +115,7 @@ public class BBInputSetup implements JavaDelegate { private BBInputSetupMapperLayer mapperLayer; @Autowired - private CloudInfoFromAAI bbInputSetupHelper; + private CloudInfoFromAAI cloudInfoFromAAI; @Autowired private ExceptionBuilder exceptionUtil; @@ -125,6 +125,10 @@ public class BBInputSetup implements JavaDelegate { public BBInputSetupUtils getBbInputSetupUtils() { return bbInputSetupUtils; } + + public void setCloudInfoFromAAI(CloudInfoFromAAI cloudInfoFromAAI) { + this.cloudInfoFromAAI = cloudInfoFromAAI; + } public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -987,7 +991,7 @@ public class BBInputSetup implements JavaDelegate { ServiceInstance serviceInstance = gBB.getServiceInstance(); CloudRegion cloudRegion = null; if(cloudConfiguration == null) { - Optional<CloudRegion> cloudRegionOp = bbInputSetupHelper.getCloudInfoFromAAI(serviceInstance); + Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance); if(cloudRegionOp.isPresent()) { cloudRegion = cloudRegionOp.get(); } @@ -1040,9 +1044,9 @@ public class BBInputSetup implements JavaDelegate { vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID); this.mapCatalogVnf(vnf, vnfModelInfo, service); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId()); - if (cloudConfiguration != null) { - String volumeGroupCustomizationUUID = this.bbInputSetupUtils.getAAIVolumeGroup(cloudConfiguration.getCloudOwner(), - cloudConfiguration.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()) + if (cloudRegion != null) { + String volumeGroupCustomizationUUID = this.bbInputSetupUtils.getAAIVolumeGroup(cloudRegion.getCloudOwner(), + cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()) .getModelCustomizationId(); ModelInfo volumeGroupModelInfo = new ModelInfo(); volumeGroupModelInfo.setModelCustomizationId(volumeGroupCustomizationUUID); |