diff options
8 files changed, 89 insertions, 69 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java b/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java index ac93d8751..faaf55ae7 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java @@ -22,7 +22,6 @@ package org.onap.vid.controller.filter; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; -import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID; @@ -43,6 +42,7 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import org.onap.vid.logging.Headers; +import org.onap.vid.logging.RequestIdHeader; import org.springframework.web.filter.GenericFilterBean; @WebFilter(urlPatterns = "/*") @@ -53,7 +53,7 @@ public class PromiseRequestIdFilter extends GenericFilterBean { // PROMISED_HEADER_NAME is set to ECOMP_REQUEST_ID as long as // org.onap.portalsdk...UserUtils.getRequestId() is using the header // "X-ECOMP-RequestID". - private static final String PROMISED_HEADER_NAME = ECOMP_REQUEST_ID; + private static final RequestIdHeader PROMISED_HEADER = RequestIdHeader.ECOMP_ID; private static final String REQUEST_ID_RESPONSE_HEADER = ECOMP_REQUEST_ID + "-echo"; private static final Pattern uuidRegex = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", Pattern.CASE_INSENSITIVE); @@ -66,7 +66,7 @@ public class PromiseRequestIdFilter extends GenericFilterBean { request = wrapIfNeeded(request); if (response instanceof HttpServletResponse) { - final String actualRequestId = ((HttpServletRequest) request).getHeader(PROMISED_HEADER_NAME); + final String actualRequestId = PROMISED_HEADER.getHeaderValue((HttpServletRequest) request); ((HttpServletResponse) response).addHeader(REQUEST_ID_RESPONSE_HEADER, actualRequestId); } } @@ -77,8 +77,8 @@ public class PromiseRequestIdFilter extends GenericFilterBean { public ServletRequest wrapIfNeeded(ServletRequest request) { final HttpServletRequest httpRequest = (HttpServletRequest) request; - final String highestPriorityHeader = highestPriorityHeader(httpRequest); - final String originalRequestId = httpRequest.getHeader(highestPriorityHeader); + final RequestIdHeader highestPriorityHeader = highestPriorityHeader(httpRequest); + final String originalRequestId = highestPriorityHeader.getHeaderValue(httpRequest); if (isWrapNeeded(highestPriorityHeader, originalRequestId)) { // Copy originalRequestId to the promised header value @@ -92,9 +92,9 @@ public class PromiseRequestIdFilter extends GenericFilterBean { return isNotEmpty(value) && uuidRegex.matcher(value).matches(); } - private boolean isWrapNeeded(String highestPriorityHeader, String originalRequestId) { + private boolean isWrapNeeded(RequestIdHeader highestPriorityHeader, String originalRequestId) { boolean headerExistsAndValid = - equalsIgnoreCase(highestPriorityHeader, PROMISED_HEADER_NAME) && verifyAndValidateUuid(originalRequestId); + PROMISED_HEADER == highestPriorityHeader && verifyAndValidateUuid(originalRequestId); return !headerExistsAndValid; } @@ -111,8 +111,8 @@ public class PromiseRequestIdFilter extends GenericFilterBean { } } - String highestPriorityHeader(HttpServletRequest httpRequest) { - return defaultIfNull(Headers.highestPriorityHeader(httpRequest), PROMISED_HEADER_NAME); + RequestIdHeader highestPriorityHeader(HttpServletRequest httpRequest) { + return defaultIfNull(Headers.highestPriorityHeader(httpRequest), PROMISED_HEADER); } private static class PromiseRequestIdRequestWrapper extends HttpServletRequestWrapper { @@ -142,9 +142,9 @@ public class PromiseRequestIdFilter extends GenericFilterBean { @Override public Enumeration<String> getHeaderNames() { - if (null == super.getHeader(PROMISED_HEADER_NAME)) { + if (null == super.getHeader(PROMISED_HEADER.getHeaderName())) { return Collections.enumeration(ImmutableList.<String>builder() - .add(PROMISED_HEADER_NAME) + .add(PROMISED_HEADER.getHeaderName()) .addAll(Collections.list(super.getHeaderNames())) .build()); } @@ -153,7 +153,7 @@ public class PromiseRequestIdFilter extends GenericFilterBean { } private boolean isRequestIdHeaderName(String name) { - return equalsIgnoreCase(name, PROMISED_HEADER_NAME); + return PROMISED_HEADER.stringEquals(name); } } } diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt index e710fd973..a0bbceea1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt +++ b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt @@ -2,17 +2,33 @@ package org.onap.vid.logging -import org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID +import org.onap.portalsdk.core.util.SystemProperties +import org.onap.vid.logging.RequestIdHeader.* import javax.servlet.http.HttpServletRequest +enum class RequestIdHeader(val headerName: String) { + + ONAP_ID("X-ONAP-RequestID"), + REQUEST_ID("X-RequestID"), + TRANSACTION_ID("X-TransactionID"), + ECOMP_ID(SystemProperties.ECOMP_REQUEST_ID), + ; + + fun stringEquals(header: String) = headerName.equals(header, true) + + fun getHeaderValue(request: HttpServletRequest): String? = request.getHeader(headerName) +} + fun prioritizedRequestIdHeaders() = listOf( - "X-ONAP-RequestID", - "X-RequestID", - "X-TransactionID", - ECOMP_REQUEST_ID + ONAP_ID, + REQUEST_ID, + TRANSACTION_ID, + ECOMP_ID ) -fun highestPriorityHeader(httpRequest: HttpServletRequest): String? { - val headers = httpRequest.headerNames.asSequence().toSet().map { it.toUpperCase() } - return prioritizedRequestIdHeaders().firstOrNull { headers.contains(it.toUpperCase()) } +fun highestPriorityHeader(httpRequest: HttpServletRequest): RequestIdHeader? { + val headers = httpRequest.headerNames.asSequence().toSet() + return prioritizedRequestIdHeaders().firstOrNull { + requestIdHeader -> headers.any { requestIdHeader.stringEquals(it) } + } } diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js index 20e964c53..d966df8d9 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js @@ -587,18 +587,18 @@ vm.vnfs = []; vm.vfModules = []; - let vnfRole = null; + let nfRole = null; let cloudRegion = null; if ($scope.isNewFilterChangeManagmentEnabled()) { - vnfRole = vm.changeManagement.vnfType ? vm.changeManagement.vnfType : null; + nfRole = vm.changeManagement.vnfType ? vm.changeManagement.vnfType : null; cloudRegion = vm.changeManagement.cloudRegion ? vm.changeManagement.cloudRegion : null; } AaiService.getVnfsByCustomerIdAndServiceType( vm.changeManagement.subscriberId, vm.changeManagement.serviceType["service-type"], - vnfRole, + nfRole, cloudRegion, ).then(function (response) { vm.isSearchedVNF = true; diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js b/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js index d841e299b..d3075764e 100755 --- a/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js @@ -86,13 +86,13 @@ var AaiService = function ($http, $log, PropertyService, UtilityService, COMPONE }).join("&"); } - function getConfigParams(vnfRole, cloudRegion) { + function getConfigParams(nfRole, cloudRegion) { if (!featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH)) { return null } let data = { - vnfRole: vnfRole, + nfRole: nfRole, cloudRegion: cloudRegion, }; @@ -646,13 +646,13 @@ var AaiService = function ($http, $log, PropertyService, UtilityService, COMPONE (UtilityService.runHttpErrorHandler); }, - getVnfsByCustomerIdAndServiceType: function (globalSubscriberId, serviceType, vnfRole, cloudRegion) { + getVnfsByCustomerIdAndServiceType: function (globalSubscriberId, serviceType, nfRole, cloudRegion) { let deferred = $q.defer(); let url = globalSubscriberId + COMPONENT.FORWARD_SLASH + serviceType const path = COMPONENT.AAI_GET_VNF_BY_CUSTOMERID_AND_SERVICETYPE + url; - let config = getConfigParams(vnfRole, cloudRegion); + let config = getConfigParams(nfRole, cloudRegion); if (UtilityService.hasContents(globalSubscriberId) && UtilityService.hasContents(serviceType)) { diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java index 5f80e04a0..d67bd618c 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java @@ -52,6 +52,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.mockito.stubbing.Answer; import org.onap.portalsdk.core.web.support.UserUtils; +import org.onap.vid.logging.RequestIdHeader; import org.springframework.mock.web.MockHttpServletResponse; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -182,37 +183,37 @@ public class PromiseRequestIdFilterTest { return new Object[][]{ { - "header is selected when single", transactionIdHeader, + "header is selected when single", RequestIdHeader.TRANSACTION_ID, ImmutableMap.of( transactionIdHeader, someTxId ) }, { - "header is selected when first", onapRequestIdHeader, + "header is selected when first", RequestIdHeader.ONAP_ID, ImmutableMap.of( onapRequestIdHeader, someTxId, "noise-header", anotherTxId, ECOMP_REQUEST_ID, anotherTxId ) }, { - "header is selected when last", onapRequestIdHeader, + "header is selected when last", RequestIdHeader.ONAP_ID, ImmutableMap.of( ECOMP_REQUEST_ID, anotherTxId, "noise-header", anotherTxId, onapRequestIdHeader, someTxId ) }, { - "header is selected when value is invalid uuid", onapRequestIdHeader, + "header is selected when value is invalid uuid", RequestIdHeader.ONAP_ID, ImmutableMap.of( onapRequestIdHeader, "invalid-uuid" ) }, { - "header is selected when no ecomp-request-id", onapRequestIdHeader, + "header is selected when no ecomp-request-id", RequestIdHeader.ONAP_ID, ImmutableMap.of( requestIdHeader, anotherTxId, onapRequestIdHeader, someTxId ) }, { - "ECOMP_REQUEST_ID is returned when no request-id header", ECOMP_REQUEST_ID, + "ECOMP_REQUEST_ID is returned when no request-id header", RequestIdHeader.ECOMP_ID, ImmutableMap.of( "tsamina-mina", anotherTxId, "waka-waka", anotherTxId @@ -222,13 +223,12 @@ public class PromiseRequestIdFilterTest { } @Test(dataProvider = "severalRequestIdHeaders") - public void highestPriorityHeader_givenSeveralRequestIdHeaders_correctHeaderIsUsed(String description, String expectedHeader, Map<String, String> incomingRequestHeaders) { - PromiseRequestIdFilter testSubject = promiseRequestIdFilter; + public void highestPriorityHeader_givenSeveralRequestIdHeaders_correctHeaderIsUsed(String description, RequestIdHeader expectedHeader, Map<String, String> incomingRequestHeaders) { HttpServletRequest mockedHttpServletRequest = createMockedHttpServletRequest(incomingRequestHeaders); assertThat(description, - testSubject.highestPriorityHeader(mockedHttpServletRequest), equalToIgnoringCase(expectedHeader)); + promiseRequestIdFilter.highestPriorityHeader(mockedHttpServletRequest), is(expectedHeader)); } diff --git a/vid-automation/src/main/java/vid/automation/test/test/ChangeManagementTest.java b/vid-automation/src/main/java/vid/automation/test/test/ChangeManagementTest.java index 500d98130..7c577cabf 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/ChangeManagementTest.java +++ b/vid-automation/src/main/java/vid/automation/test/test/ChangeManagementTest.java @@ -228,15 +228,15 @@ public class ChangeManagementTest extends VidBaseTestCase { String globalCustomerId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"; String serviceType = "vRichardson"; SimulatorApi.registerExpectationFromPreset(new PresetBaseAAICustomQuery( - SIMPLE, - "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" - + serviceType + "/service-instances", - "query/vnfs-fromServiceInstance-filter" + SIMPLE, + "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + + serviceType + "/service-instances", + "query/vnfs-fromServiceInstance-filterByCloudRegion?nfRole=vMobileDNS&cloudRegionID=092eb9e8e4b7412e8787dd091bc58e86" ) { @Override public Object getResponseBody() { return getResourceAsString( - AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS); + AAI_VNFS_FOR_CHANGE_MANAGEMENT_JSON_BY_PARAMS); } }, APPEND); } @@ -546,9 +546,9 @@ public class ChangeManagementTest extends VidBaseTestCase { fillVNFInPlace3Fields(operationsTimeout, existingSwVersion, newSwVersion); assertThatVidToPortalCallbackDataIsOk(VNF_DATA_WITH_IN_PLACE.workflowName, ImmutableMap.of( - "existingSoftwareVersion", existingSwVersion, - "newSoftwareVersion", newSwVersion, - "operationTimeout", operationsTimeout + "existingSoftwareVersion", existingSwVersion, + "newSoftwareVersion", newSwVersion, + "operationTimeout", operationsTimeout )); } @@ -559,10 +559,10 @@ public class ChangeManagementTest extends VidBaseTestCase { Assert.assertEquals(Get.byId(Constants.ChangeManagement.newModalConfigUpdateInputId + "-label").getText(), fileName); Assert.assertTrue(Get.byId(Constants.generalSubmitButtonId).isEnabled()); assertThatVidToPortalCallbackDataIsOk("VNF Config Update", ImmutableMap.of( - "configUpdateFile", - "{\"request-parameters\":{\"vm\":[{\"vnfc\":[" - + "{\"vnfc-name\":\"ibcx0001vm001dbg001\",\"vnfc-function-code\":\"dbg\"}],\"vm-name\":\"ibcx0001vm001\"}," - + "{\"vnfc\":[{\"vnfc-name\":\"ibcx0001vm002dbg001\"}],\"vm-name\":\"ibcx0001vm002\"}]},\"configuration-parameters\":{\"node0_hostname\":\"dbtx0001vm001\"}}" + "configUpdateFile", + "{\"request-parameters\":{\"vm\":[{\"vnfc\":[" + + "{\"vnfc-name\":\"ibcx0001vm001dbg001\",\"vnfc-function-code\":\"dbg\"}],\"vm-name\":\"ibcx0001vm001\"}," + + "{\"vnfc\":[{\"vnfc-name\":\"ibcx0001vm002dbg001\"}],\"vm-name\":\"ibcx0001vm002\"}]},\"configuration-parameters\":{\"node0_hostname\":\"dbtx0001vm001\"}}" )); } @@ -632,28 +632,28 @@ public class ChangeManagementTest extends VidBaseTestCase { String modelInvariantId = "72e465fe-71b1-4e7b-b5ed-9496118ff7a8"; String vnfInstanceId = "8e5e3ba1-3fe6-4d86-966e-f9f03dab4855"; - assertThat(errorMessage, startsWith(SCHEDULE_ERROR_PREFIX)); - assertThat(errorMessage.replace(SCHEDULE_ERROR_PREFIX, ""), jsonEquals( + assertThat(errorMessage, startsWith(SCHEDULE_ERROR_PREFIX)); + assertThat(errorMessage.replace(SCHEDULE_ERROR_PREFIX, ""), jsonEquals( ImmutableMap.of( - "widgetName", "Portal-Common-Scheduler", - "widgetParameter", "", - "widgetData", ImmutableMap.builder() - .put("vnfNames", ImmutableList.of(ImmutableMap.of( - "id", vnfInstanceId, - "invariant-id", modelInvariantId - ))) - .put("workflowParameters", emptyMap()) - .put("subscriberId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - .put("fromVNFVersion", "" + "76e908e0-5201-44d2-a3e2-9e6128d05820" + "") - .put("workflow", "" + workflowName + "") - .put("policyYN", "Y") - .put("sniroYN", "Y") - .put("testApi", "VNF_API") - .put("vnfType", "vMobileDNS") - .putAll(workflowParams) - .build() - ) - ).when(Option.IGNORING_EXTRA_FIELDS)); + "widgetName", "Portal-Common-Scheduler", + "widgetParameter", "", + "widgetData", ImmutableMap.builder() + .put("vnfNames", ImmutableList.of(ImmutableMap.of( + "id", vnfInstanceId, + "invariant-id", modelInvariantId + ))) + .put("workflowParameters", emptyMap()) + .put("subscriberId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + .put("fromVNFVersion", "" + "76e908e0-5201-44d2-a3e2-9e6128d05820" + "") + .put("workflow", "" + workflowName + "") + .put("policyYN", "Y") + .put("sniroYN", "Y") + .put("testApi", "VNF_API") + .put("vnfType", "vMobileDNS") + .putAll(workflowParams) + .build() + ) + ).when(Option.IGNORING_EXTRA_FIELDS)); Click.byId(Constants.generalCancelButtonId); diff --git a/vid-automation/src/test/resources/asyncInstantiation/ServiceTreeForRetry_serviceInstance.json b/vid-automation/src/test/resources/asyncInstantiation/ServiceTreeForRetry_serviceInstance.json index 869ff2d96..5139aa0c0 100644 --- a/vid-automation/src/test/resources/asyncInstantiation/ServiceTreeForRetry_serviceInstance.json +++ b/vid-automation/src/test/resources/asyncInstantiation/ServiceTreeForRetry_serviceInstance.json @@ -10,6 +10,7 @@ "owningEntityId": "038d99af-0427-42c2-9d15-971b99b9b489", "owningEntityName": "Lucine Sarika", "projectName": "zasaki", + "position":null, "globalSubscriberId": "e433710f-9217-458d-a79d-1c7aff376d89", "subscriberName": "SILVIA ROBBINS", "productFamilyId": "ddf9cc0f-6331-4d35-bed0-a37f2d5e9cb3", @@ -44,6 +45,7 @@ "trackById": "TRACK_BY_ID", "isFailed": true, "statusMessage":"Vnf failed.", + "position":null, "lineOfBusiness": "vnf_lineOfBusinessName" } }, diff --git a/vid-automation/src/test/resources/asyncInstantiation/ServiceWithFailedServiceInstance.json b/vid-automation/src/test/resources/asyncInstantiation/ServiceWithFailedServiceInstance.json index d27dd05cd..849cb7e43 100644 --- a/vid-automation/src/test/resources/asyncInstantiation/ServiceWithFailedServiceInstance.json +++ b/vid-automation/src/test/resources/asyncInstantiation/ServiceWithFailedServiceInstance.json @@ -10,6 +10,7 @@ ], "isALaCarte": true, "isFailed": true, + "position":null, "lcpCloudRegionId": "a93f8383-707e-43fa-8191-a6e69a1aab17", "modelInfo": { "modelInvariantId": "0367689e-d41e-483f-b200-eab17e4a7f8d", @@ -62,6 +63,7 @@ "statusMessage": null, "tenantId": "88a6ca3ee0394ade9403f075db23167e", "trackById": "TRACK_BY_ID", + "position":null, "vfModules": { } } |