diff options
author | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2018-12-13 14:02:30 +0100 |
---|---|---|
committer | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2018-12-13 14:05:45 +0100 |
commit | 516b8f0c8b4ed43532abfaca95d2ca014bde885f (patch) | |
tree | 843c938a8caa9e0f5e1ac023939839e6d367eb2b | |
parent | c08a515bbb5a63401f13d260e2d41c6e472caf95 (diff) |
Add junit tests for CatalogDBUtils
Change-Id: I1ea3e92b6dcb3fbca837513e11451be47d8c488b
Issue-ID: SO-784
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
15 files changed, 229 insertions, 155 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy index 103326a693..22b5de2e4b 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy @@ -20,24 +20,22 @@ package org.onap.so.bpmn.common.scripts -import org.json.JSONObject; -import org.json.JSONArray; +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.json.JSONArray +import org.json.JSONObject import org.onap.logging.ref.slf4j.ONAPLogConstants -import org.onap.so.bpmn.core.UrnPropertiesReader; -import org.springframework.web.util.UriUtils; - +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.logger.MessageEnum +import org.onap.so.logger.MsoLogger +import org.onap.so.utils.TargetEntity +import org.springframework.web.util.UriUtils import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response -import org.camunda.bpm.engine.delegate.DelegateExecution - -import org.onap.so.logger.MsoLogger; -import org.onap.so.utils.TargetEntity -import org.onap.so.logger.MessageEnum - - /*** * Utilities for accessing Catalog DB Adapter to retrieve Networks, VNF/VFModules, AllottedResources and complete ServiceResources information @@ -47,29 +45,15 @@ import org.onap.so.logger.MessageEnum class CatalogDbUtils { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CatalogDbUtils.class); - - MsoUtils utils = new MsoUtils() - JsonUtils jsonUtils = new JsonUtils() + private HttpClientFactory httpClientFactory + private MsoUtils msoUtils + private JsonUtils jsonUtils static private String defaultDbAdapterVersion = "v2" - public JSONArray getAllVnfsByVnfModelCustomizationUuid(DelegateExecution execution, String vnfModelCustomizationUuid) { - JSONArray vnfsList = null - String endPoint = "/serviceVnfs?vnfModelCustomizationUuid=" + UriUtils.encode(vnfModelCustomizationUuid, "UTF-8") - try { - msoLogger.debug("ENDPOINT: " + endPoint) - String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint) - - if (catalogDbResponse != null) { - vnfsList = parseVnfsJson(catalogDbResponse, "serviceVnfs", "v1") - } - - } - catch (Exception e) { - msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message); - throw e - } - - return vnfsList + CatalogDbUtils(HttpClientFactory httpClientFactory, MsoUtils msoUtils, JsonUtils jsonUtils) { + this.httpClientFactory = httpClientFactory + this.msoUtils = msoUtils + this.jsonUtils = jsonUtils } public JSONArray getAllVnfsByVnfModelCustomizationUuid(DelegateExecution execution, String vnfModelCustomizationUuid, String catalogUtilsVersion) { @@ -114,7 +98,7 @@ class CatalogDbUtils { } } catch (Exception e) { - utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message) + msoUtils.log("ERROR", "Exception in Querying Catalog DB: " + e.message) throw e } @@ -122,23 +106,14 @@ class CatalogDbUtils { } public String getServiceResourcesByServiceModelInvariantUuidString(DelegateExecution execution, String serviceModelInvariantUuid) { - String resources = null String endPoint = "/serviceResources?serviceModelInvariantUuid=" + UriUtils.encode(serviceModelInvariantUuid, "UTF-8") try { - String catalogDbResponse = getResponseFromCatalogDb(execution, endPoint) - - if (catalogDbResponse != null) { - - resources = catalogDbResponse - } - + return getResponseFromCatalogDb(execution, endPoint) } catch (Exception e) { msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception in Querying Catalog DB", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.message); throw e } - - return resources } public JSONObject getServiceResourcesByServiceModelInvariantUuid(DelegateExecution execution, String serviceModelInvariantUuid, String catalogUtilsVersion) { @@ -443,19 +418,12 @@ class CatalogDbUtils { String catalogDbEndpoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint",execution) String queryEndpoint = catalogDbEndpoint + "/" + defaultDbAdapterVersion + endPoint def responseData = '' - def bpmnRequestId = UUID.randomUUID().toString() - - URL url = new URL(queryEndpoint) - HttpClient client = new HttpClient(url, MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB) - client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, bpmnRequestId) + HttpClient client = httpClientFactory.create(new URL(queryEndpoint), MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB) + client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, UUID.randomUUID().toString()) client.addAdditionalHeader('X-FromAppId', "BPMN") client.addAdditionalHeader('Accept', MediaType.APPLICATION_JSON) String basicAuthCred = execution.getVariable("BasicAuthHeaderValueDB") - if (basicAuthCred != null && !"".equals(basicAuthCred)) { - client.addAdditionalHeader("Authorization", basicAuthCred) - }else { - client.addAdditionalHeader("Authorization", getBasicDBAuthHeader(execution)) - } + client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution))) msoLogger.debug('sending GET to Catalog DB endpoint: ' + endPoint) Response response = client.get() @@ -497,7 +465,7 @@ class CatalogDbUtils { } } catch (Exception e) { - utils.log("ERROR", "Exception in Querying Catalog DB: " + e.message) + msoUtils.log("ERROR", "Exception in Querying Catalog DB: " + e.message) throw e } @@ -509,13 +477,13 @@ class CatalogDbUtils { String encodedString = null try { String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution) - utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB) + msoUtils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB) - encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution)) + encodedString = msoUtils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution)) execution.setVariable("BasicAuthHeaderValueDB",encodedString) } catch (IOException ex) { String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage() - utils.log("ERROR", dataErrorMessage) + msoUtils.log("ERROR", dataErrorMessage) } return encodedString } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy new file mode 100644 index 0000000000..faa0037169 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsFactory.groovy @@ -0,0 +1,31 @@ +/*- + * ============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.bpmn.core.json.JsonUtils +import org.onap.so.client.HttpClientFactory + +public class CatalogDbUtilsFactory { + + CatalogDbUtils create() { + return new CatalogDbUtils(new HttpClientFactory(), new MsoUtils(), new JsonUtils()) + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy index 739bc4b7ed..1c1d5eb0e3 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DecomposeService.groovy @@ -20,9 +20,6 @@ package org.onap.so.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.delegate.DelegateExecution import org.json.JSONObject; @@ -56,7 +53,7 @@ public class DecomposeService extends AbstractServiceTaskProcessor { String Prefix="DDS_" ExceptionUtil exceptionUtil = new ExceptionUtil() - CatalogDbUtils catalogDbUtils = new CatalogDbUtils() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() JsonUtils jsonUtils = new JsonUtils() public void preProcessRequest (DelegateExecution execution) { diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy new file mode 100644 index 0000000000..723fb9e32e --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy @@ -0,0 +1,145 @@ +/*- + * ============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.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake +import org.json.JSONArray +import org.json.JSONObject +import org.junit.Before +import org.junit.Test +import org.onap.logging.ref.slf4j.ONAPLogConstants +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.utils.TargetEntity +import org.skyscreamer.jsonassert.JSONAssert +import org.skyscreamer.jsonassert.JSONCompareMode +import org.springframework.core.env.Environment + +import javax.ws.rs.core.MediaType +import javax.ws.rs.core.Response + +import static org.assertj.core.api.Assertions.assertThat +import static org.mockito.ArgumentMatchers.anyString +import static org.mockito.Mockito.eq +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.when +import static org.mockito.Mockito.verify + +class CatalogDbUtilsTest { + + private static final String AUTHORIZATION_HEADER = "AuthHeaderTest" + private static final String RESPONSE_FROM_CATALOG_DB = "{\"serviceVnfs\": [{\"name\": \"service1\"," + + "\"vfModules\": [{\"name\": \"module1\", \"isBase\":true, \"initialCount\":1}]}]}" + private HttpClientFactory httpClientFactoryMock + private MsoUtils msoUtilsMock + private JsonUtils jsonUtilsMock + private HttpClient httpClientMock + private DelegateExecutionFake executionFake + private CatalogDbUtils testedObject + + + @Before + void setUp() { + httpClientFactoryMock = mock(HttpClientFactory.class) + msoUtilsMock = mock(MsoUtils.class) + jsonUtilsMock = mock(JsonUtils.class) + httpClientMock = mock(HttpClient.class) + executionFake = new DelegateExecutionFake() + testedObject = new CatalogDbUtils(httpClientFactoryMock, msoUtilsMock, jsonUtilsMock) + } + + @Test + void getAllVnfsByVnfModelCustomizationUuid_CatVer1_success() { + // given + executionFake.setVariable("BasicAuthHeaderValueDB", AUTHORIZATION_HEADER) + mockGetResponseFromCatalogDb("http://testUrl/v2/serviceVnfs?vnfModelCustomizationUuid=testModel") + //when + JSONArray vnfsListResult = testedObject.getAllVnfsByVnfModelCustomizationUuid(executionFake, "testModel", "v1") + //then + verifyHeadersInHttpClient() + JSONAssert.assertEquals("[{\"vfModules\":[{\"initialCount\":1,\"modelInfo\":{\"modelType\":\"vfModule\"},\"isBase\":true}],\"modelInfo\":{\"modelType\":\"vnf\"}}]", vnfsListResult, JSONCompareMode.LENIENT) + } + + @Test + void getAllVnfsByVnfModelCustomizationUuid_CatVer2_success() { + // given + executionFake.setVariable("BasicAuthHeaderValueDB", AUTHORIZATION_HEADER) + mockGetResponseFromCatalogDb("http://testUrl/v2/serviceVnfs?vnfModelCustomizationUuid=testModel") + // when + JSONArray vnfsListResult = testedObject.getAllVnfsByVnfModelCustomizationUuid(executionFake, "testModel", "v2") + // then + verifyHeadersInHttpClient() + JSONAssert.assertEquals("[{\"vfModules\":[{\"initialCount\":1,\"name\":\"module1\",\"isBase\":true}],\"name\":\"service1\"}]", vnfsListResult, JSONCompareMode.LENIENT) + } + + @Test + void getServiceResourcesByServiceModelUuid_success() { + // given + executionFake.setVariable("BasicAuthHeaderValueDB", AUTHORIZATION_HEADER) + mockGetResponseFromCatalogDb("http://testUrl/v2/serviceResources?serviceModelUuid=testModel") + // when + JSONObject result = testedObject.getServiceResourcesByServiceModelUuid(executionFake, "testModel", "v2") + // then + verifyHeadersInHttpClient() + JSONAssert.assertEquals("{\"serviceVnfs\": [{\"name\": \"service1\",\"vfModules\": [{\"name\": \"module1\", \"isBase\":true, \"initialCount\":1}]}]}", result, JSONCompareMode.LENIENT) + } + + + @Test + void getServiceResourcesByServiceModelInvariantUuidString_success() { + // given + executionFake.setVariable("BasicAuthHeaderValueDB", AUTHORIZATION_HEADER) + mockGetResponseFromCatalogDb("http://testUrl/v2/serviceResources?serviceModelInvariantUuid=testModel") + // when + String result = testedObject.getServiceResourcesByServiceModelInvariantUuidString(executionFake, "testModel") + // then + verifyHeadersInHttpClient() + assertThat(result).isEqualTo(RESPONSE_FROM_CATALOG_DB) + } + + private Environment createEnvironmentMock() { + Environment mockEnvironment = mock(Environment.class) + UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader() + urnPropertiesReader.setEnvironment(mockEnvironment) + return mockEnvironment + } + + private void mockGetResponseFromCatalogDb(String queryEndpoint) { + Environment environmentMock = createEnvironmentMock() + when(environmentMock.getProperty("mso.catalog.db.endpoint")).thenReturn("http://testUrl") + when(httpClientFactoryMock.create(new URL(queryEndpoint), MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB)).thenReturn(httpClientMock) + + Response responseMock = mock(Response.class) + when(httpClientMock.get()).thenReturn(responseMock) + when(responseMock.readEntity(String.class)) thenReturn(RESPONSE_FROM_CATALOG_DB) + when(responseMock.getStatus()).thenReturn(200) + } + + private void verifyHeadersInHttpClient() { + verify(httpClientMock).addAdditionalHeader(eq(ONAPLogConstants.Headers.REQUEST_ID), anyString()) + verify(httpClientMock).addAdditionalHeader("X-FromAppId", "BPMN") + verify(httpClientMock).addAdditionalHeader("Accept", MediaType.APPLICATION_JSON) + verify(httpClientMock).addAdditionalHeader("Authorization", AUTHORIZATION_HEADER) + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVnfInfra.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVnfInfra.groovy index 9c25a57adc..af46bf65b8 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVnfInfra.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVnfInfra.groovy @@ -20,6 +20,8 @@ package org.onap.so.bpmn.infrastructure.scripts +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory + import static org.apache.commons.lang3.StringUtils.*; import org.camunda.bpm.engine.delegate.BpmnError @@ -55,8 +57,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor { ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() VidUtils vidUtils = new VidUtils(this) - CatalogDbUtils cutils = new CatalogDbUtils() - AAICreateResources aaiCR = new AAICreateResources() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() /** * This method gets and validates the incoming @@ -448,7 +449,7 @@ class CreateVnfInfra extends AbstractServiceTaskProcessor { String vnfModelCustomizationUuid = jsonUtil.getJsonValueForKey(vnfModelInfo, "modelCustomizationUuid") msoLogger.debug("querying Catalog DB by vnfModelCustomizationUuid: " + vnfModelCustomizationUuid) - JSONArray vnfs = cutils.getAllVnfsByVnfModelCustomizationUuid(execution, + JSONArray vnfs = catalogDbUtils.getAllVnfsByVnfModelCustomizationUuid(execution, vnfModelCustomizationUuid, "v2") msoLogger.debug("obtained VNF list: " + vnfs) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy index 9c9ed933e0..24071d38f6 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy @@ -20,42 +20,14 @@ package org.onap.so.bpmn.infrastructure.scripts; import static org.apache.commons.lang3.StringUtils.*; -import groovy.xml.XmlUtil -import groovy.json.* import org.onap.so.bpmn.core.domain.ServiceDecomposition -import org.onap.so.bpmn.core.domain.ServiceInstance -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.NetworkResource -import org.onap.so.bpmn.core.domain.VnfResource -import org.onap.so.bpmn.common.recipe.ResourceInput -import org.onap.so.bpmn.common.recipe.BpmnRestClient import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils -import org.onap.so.bpmn.common.scripts.CatalogDbUtils; -import org.onap.so.bpmn.core.RollbackData -import org.onap.so.bpmn.core.WorkflowException -import java.util.List; -import java.util.UUID; - -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.runtime.Execution import org.camunda.bpm.engine.delegate.DelegateExecution -import org.json.JSONObject; -import org.json.JSONArray; -import org.apache.commons.lang3.* -import org.apache.commons.codec.binary.Base64; -import org.springframework.web.util.UriUtils; -import org.onap.so.logger.MessageEnum -import org.onap.so.logger.MsoLogger - - /** * This groovy class supports the <class>DoCompareModelVersions.bpmn</class> process. @@ -76,7 +48,6 @@ public class DoCompareModelVersions extends AbstractServiceTaskProcessor { String Prefix="DCMPMDV_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - CatalogDbUtils cutils = new CatalogDbUtils() public void preProcessRequest (DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy index 194e7ff3e1..2168dab736 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy @@ -24,12 +24,10 @@ import static org.apache.commons.lang3.StringUtils.*; import javax.ws.rs.NotFoundException -import org.apache.commons.lang3.* import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.aai.domain.yang.ServiceInstance import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor -import org.onap.so.bpmn.common.scripts.CatalogDbUtils; import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.core.RollbackData @@ -37,7 +35,6 @@ import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.domain.Resource import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory import org.onap.so.client.aai.AAIObjectType import org.onap.so.client.aai.AAIResourcesClient import org.onap.so.client.aai.entities.AAIResultWrapper @@ -50,10 +47,6 @@ import org.onap.so.logger.MsoLogger import org.springframework.web.util.UriUtils import org.onap.so.bpmn.core.UrnPropertiesReader -import groovy.json.* - - - /** * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process. * @@ -86,7 +79,6 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { String Prefix="DCRESI_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - CatalogDbUtils cutils = new CatalogDbUtils() public void preProcessRequest (DelegateExecution execution) { String msg = "" diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy index f6e4fcc2ba..aa1eed95bb 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy @@ -20,21 +20,12 @@ package org.onap.so.bpmn.infrastructure.scripts +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory import org.onap.so.bpmn.infrastructure.properties.BPMNProperties - -import java.util.ArrayList -import java.util.Iterator -import java.util.List import org.apache.commons.lang3.StringUtils import org.apache.http.HttpResponse import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.codehaus.groovy.runtime.ArrayUtil -import org.codehaus.groovy.runtime.ScriptBytecodeAdapter -import org.codehaus.groovy.runtime.callsite.CallSite -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation -import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling -import org.json.JSONArray import org.json.JSONObject import org.onap.so.bpmn.common.recipe.BpmnRestClient import org.onap.so.bpmn.common.recipe.ResourceInput @@ -48,7 +39,6 @@ import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.bpmn.common.resource.ResourceRequestBuilder -import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger @@ -75,7 +65,7 @@ public class DoCreateResources extends AbstractServiceTaskProcessor{ ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - CatalogDbUtils cutils = new CatalogDbUtils() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() public void preProcessRequest(DelegateExecution execution) { msoLogger.trace("preProcessRequest ") @@ -260,7 +250,7 @@ public class DoCreateResources extends AbstractServiceTaskProcessor{ // requestAction is action, not opertiontype //String requestAction = resourceInput.getOperationType() String requestAction = "createInstance" - JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceModelUUID, requestAction) + JSONObject resourceRecipe = catalogDbUtils.getResourceRecipe(execution, resourceModelUUID, requestAction) if (resourceRecipe != null) { String recipeURL = BPMNProperties.getProperty("bpelURL", "http://so-bpmn-infra.onap:8081") + resourceRecipe.getString("orchestrationUri") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy index 4bda803da0..c04bbd4806 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy @@ -22,13 +22,12 @@ package org.onap.so.bpmn.infrastructure.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.delegate.DelegateExecution import org.onap.aai.domain.yang.OwningEntity -import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.CatalogDbUtils +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils @@ -42,16 +41,11 @@ import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.bpmn.infrastructure.aai.groovyflows.AAICreateResources import org.onap.so.client.aai.AAIObjectType import org.onap.so.client.aai.AAIResourcesClient -import org.onap.so.client.aai.entities.AAIResultWrapper import org.onap.so.client.aai.entities.uri.AAIResourceUri import org.onap.so.client.aai.entities.uri.AAIUri import org.onap.so.client.aai.entities.uri.AAIUriFactory -import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger - -import groovy.json.* - /** * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process. * @@ -84,7 +78,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { String Prefix="DCRESI_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - CatalogDbUtils cutils = new CatalogDbUtils() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() public void preProcessRequest (DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") @@ -330,7 +324,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { String modelInvariantUuid = execution.getVariable("modelInvariantUuid") try{ - String json = cutils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) + String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) msoLogger.debug("JSON IS: "+json) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModule.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModule.groovy index 50fe75e3df..a09f22f808 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModule.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModule.groovy @@ -20,6 +20,8 @@ package org.onap.so.bpmn.infrastructure.scripts +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory + import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response import javax.xml.parsers.DocumentBuilder @@ -44,7 +46,6 @@ import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.DecomposeJsonUtil import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.client.graphinventory.entities.uri.Depth import org.onap.so.client.HttpClient import org.onap.so.client.aai.AAIObjectPlurals import org.onap.so.client.aai.AAIObjectType; @@ -59,7 +60,6 @@ import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger import org.onap.so.utils.TargetEntity -import org.springframework.web.util.UriUtils import org.w3c.dom.Document import org.w3c.dom.Element import org.w3c.dom.NamedNodeMap @@ -78,8 +78,7 @@ public class DoCreateVfModule extends VfModuleBase { ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) - CatalogDbUtils catalog = new CatalogDbUtils() - DecomposeJsonUtil decomposeJsonUtils = new DecomposeJsonUtil() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() /** * Validates the request message and sets up the workflow. @@ -261,7 +260,7 @@ public class DoCreateVfModule extends VfModuleBase { String serviceType ="" try{ - String json = catalog.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) + String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) serviceType = jsonUtil.getJsonValue(json, "serviceResources.serviceType") }catch(BpmnError e){ throw e @@ -2004,7 +2003,7 @@ public class DoCreateVfModule extends VfModuleBase { msoLogger.debug("vnfModelCustomizationUuid: " + vnfModelCustomizationUuid) - JSONArray vnfs = catalog.getAllVnfsByVnfModelCustomizationUuid(execution, vnfModelCustomizationUuid, "v2") + JSONArray vnfs = catalogDbUtils.getAllVnfsByVnfModelCustomizationUuid(execution, vnfModelCustomizationUuid, "v2") msoLogger.debug("Incoming Query Catalog DB for Vnf Response is: " + vnfModelCustomizationUuid) // Only one match here diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy index d3dbd9107e..232336b0ee 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy @@ -20,14 +20,11 @@ package org.onap.so.bpmn.infrastructure.scripts -import java.util.UUID; - -import java.util.List - import org.json.JSONObject; import org.json.JSONArray; import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.CatalogDbUtils +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.VidUtils import org.onap.so.bpmn.core.RollbackData @@ -59,7 +56,7 @@ class DoCreateVnfAndModules extends AbstractServiceTaskProcessor { ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() VidUtils vidUtils = new VidUtils(this) - CatalogDbUtils cutils = new CatalogDbUtils() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() /** * This method gets and validates the incoming @@ -189,8 +186,8 @@ class DoCreateVnfAndModules extends AbstractServiceTaskProcessor { } msoLogger.debug("querying Catalog DB by vnfModelCustomizationUuid: " + vnfModelCustomizationUuid) - JSONArray vnfs = cutils.getAllVnfsByVnfModelCustomizationUuid(execution, - vnfModelCustomizationUuid) + JSONArray vnfs = catalogDbUtils.getAllVnfsByVnfModelCustomizationUuid(execution, + vnfModelCustomizationUuid, "v1") msoLogger.debug("obtained VNF list") // Only one match here JSONObject vnfObject = vnfs[0] diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy index 122cc08e89..9116b5ab14 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy @@ -20,6 +20,8 @@ */ package org.onap.so.bpmn.infrastructure.scripts +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory + import static org.apache.commons.lang3.StringUtils.isBlank import org.apache.commons.lang3.StringUtils @@ -65,7 +67,7 @@ public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor { String Prefix="DDR_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - CatalogDbUtils cutils = new CatalogDbUtils() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() public void preProcessRequest (DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") @@ -247,7 +249,7 @@ public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor { Resource currentResource = execution.getVariable("currentResource") String action = "deleteInstance" - JSONObject resourceRecipe = cutils.getResourceRecipe(execution, currentResource.getModelInfo().getModelUuid(), action) + JSONObject resourceRecipe = catalogDbUtils.getResourceRecipe(execution, currentResource.getModelInfo().getModelUuid(), action) String recipeUri = resourceRecipe.getString("orchestrationUri") int recipeTimeout = resourceRecipe.getInt("recipeTimeout") String recipeParamXsd = resourceRecipe.get("paramXSD") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy index f6a8a1558c..06c7002dff 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy @@ -25,11 +25,11 @@ import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.aai.domain.yang.GenericVnf import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.CatalogDbUtils +import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.NetworkUtils import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils -import org.onap.so.bpmn.common.scripts.VfModule import org.onap.so.bpmn.common.scripts.VfModuleBase import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.WorkflowException @@ -38,7 +38,6 @@ import org.onap.so.client.graphinventory.entities.uri.Depth import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient import org.onap.so.client.aai.entities.AAIResultWrapper -import org.onap.so.client.aai.entities.uri.AAIResourceUri import org.onap.so.client.aai.entities.uri.AAIUri import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.entities.uri.AAIResourceUri @@ -46,14 +45,12 @@ import org.onap.so.constants.Defaults import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger -import org.springframework.web.util.UriUtils - public class DoUpdateVfModule extends VfModuleBase { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateVfModule.class); ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - CatalogDbUtils catalog = new CatalogDbUtils() + CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() /** * Initialize the flow's variables. @@ -255,7 +252,7 @@ public class DoUpdateVfModule extends VfModuleBase { String serviceType ="" try{ - String json = catalog.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) + String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) serviceType = jsonUtil.getJsonValue(json, "serviceResources.serviceType") }catch(BpmnError e){ throw e diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy index 1a47ef88e2..a8e3b2040b 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy @@ -24,7 +24,6 @@ import static org.apache.commons.lang3.StringUtils.* 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.so.bpmn.common.scripts.CatalogDbUtils import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.VidUtils @@ -55,7 +54,6 @@ public class CreateVcpeResCustService extends AbstractServiceTaskProcessor { ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() VidUtils vidUtils = new VidUtils() - CatalogDbUtils catalogDbUtils = new CatalogDbUtils() /** * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process. diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy index 7a6fd72a7d..7a40ef978b 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy @@ -21,13 +21,10 @@ package org.onap.so.bpmn.vcpe.scripts import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor -import org.onap.so.bpmn.common.scripts.CatalogDbUtils import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.NetworkUtils import org.onap.so.bpmn.common.scripts.VidUtils -import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.logger.MessageEnum @@ -40,10 +37,6 @@ import org.onap.so.client.aai.entities.Relationships import org.onap.so.client.aai.entities.uri.AAIResourceUri import org.onap.so.client.aai.entities.uri.AAIUriFactory import javax.ws.rs.NotFoundException -import org.json.JSONObject - -import static org.apache.commons.lang3.StringUtils.isBlank - /** * This groovy class supports the <class>DeleteVcpeResCustService.bpmn</class> process. @@ -60,7 +53,6 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() VidUtils vidUtils = new VidUtils() - CatalogDbUtils catalogDbUtils = new CatalogDbUtils() NetworkUtils networkUtils = new NetworkUtils() /** |