diff options
author | Steve Smokowski <ss835w@att.com> | 2020-03-10 14:54:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-10 14:54:10 +0000 |
commit | 43fc1ee27456a17668e5f3f424a0bc6b7973e6e8 (patch) | |
tree | e867127dae70e6f698938a33585b2bc117963859 | |
parent | 4dc7f5c75956c68223003ad10670ef47bdad6e26 (diff) | |
parent | 7b42dee721e03ee3f0a52dda92010e09d748cf72 (diff) |
Merge "false positive on network creates"
20 files changed, 287 insertions, 81 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index 62b9c04e3f..8207c7c589 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -101,8 +101,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { private static final String CREATE_IN_PROGRESS = "CREATE_IN_PROGRESS"; - private static final String DELETE_STACK = "DeleteStack"; - protected static final String HEAT_ERROR = "HeatError"; protected static final String CREATE_STACK = "CreateStack"; @@ -115,14 +113,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { private Environment environment; @Autowired - RequestsDbClient requestDBClient; - - @Autowired StackStatusHandler statusHandler; @Autowired NovaClientImpl novaClient; + @Autowired + RequestsDbClient requestDBClient; + private static final Logger logger = LoggerFactory.getLogger(MsoHeatUtils.class); // Properties names and variables (with default values) @@ -182,6 +180,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { CreateStackParam createStack = createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, nestedTemplates, heatFiles); Stack currentStack = queryHeatStack(stackName, cloudSiteId, tenantId); + boolean operationPerformed = false; if (currentStack != null) { logger.debug("Existing Stack found with Status: {} ", currentStack.getStackStatus()); if (CREATE_COMPLETE.equals(currentStack.getStackStatus())) { @@ -220,8 +219,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { currentStack = queryHeatStack(currentStack.getStackName() + "/" + currentStack.getId(), cloudSiteId, tenantId); } + operationPerformed = true; } - return new StackInfoMapper(currentStack).map(); + StackInfo stackInfo = new StackInfoMapper(currentStack).map(); + stackInfo.setOperationPerformed(operationPerformed); + return stackInfo; } /** @@ -497,14 +499,17 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { public StackInfo deleteStack(String tenantId, String cloudOwner, String cloudSiteId, String stackName, boolean pollForCompletion, int timeoutMinutes) throws MsoException { Stack currentStack = queryHeatStack(stackName, cloudSiteId, tenantId); + StackInfo stackInfo = null; if (currentStack == null || DELETE_COMPLETE.equals(currentStack.getStackStatus())) { - return new StackInfo(stackName, HeatStatus.NOTFOUND); + stackInfo = new StackInfo(stackName, HeatStatus.NOTFOUND); + stackInfo.setOperationPerformed(false); } else { currentStack = deleteStack(currentStack, timeoutMinutes, cloudSiteId, tenantId); - StackInfo stackInfo = new StackInfoMapper(currentStack).map(); + stackInfo = new StackInfoMapper(currentStack).map(); stackInfo.setName(stackName); - return stackInfo; + stackInfo.setOperationPerformed(true); } + return stackInfo; } /** @@ -1182,4 +1187,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } } + public void updateResourceStatus(String requestId, String resourceStatusMessage) { + InfraActiveRequests request = new InfraActiveRequests(); + request.setRequestId(requestId); + request.setResourceStatusMessage(resourceStatusMessage); + requestDBClient.patchInfraActiveRequests(request); + } + } diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/beans/StackInfo.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/beans/StackInfo.java index 76d3667632..7e2071525d 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/beans/StackInfo.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/beans/StackInfo.java @@ -7,9 +7,9 @@ * 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. @@ -26,7 +26,7 @@ import java.util.Map; /* * This Java bean class relays Heat stack status information to ActiveVOS processes. - * + * * This bean is returned by all Heat-specific adapter operations (create, query, delete) */ @@ -36,6 +36,7 @@ public class StackInfo { private String canonicalName = ""; private HeatStatus status = HeatStatus.UNKNOWN; private String statusMessage = ""; + private boolean operationPerformed; private Map<String, Object> outputs = new HashMap<>(); private Map<String, Object> parameters = new HashMap<>(); @@ -106,5 +107,15 @@ public class StackInfo { this.parameters = parameters; } + public boolean isOperationPerformed() { + return operationPerformed; + } + + public void setOperationPerformed(boolean operationPerformed) { + this.operationPerformed = operationPerformed; + } + + + } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java index 5530fad298..257374fdb2 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java @@ -92,6 +92,13 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { private static final String NEUTRON_MODE = "NEUTRON"; private static final String CLOUD_OWNER = "CloudOwner"; private static final String LOG_DEBUG_MSG = "Got Network definition from Catalog: {}"; + private static final String NETWORK_EXIST_STATUS_MESSAGE = + "The network was found to already exist, thus no new network was created in the cloud via this request"; + private static final String NETWORK_CREATED_STATUS_MESSAGE = + "The new network was successfully created in the cloud"; + private static final String NETWORK_NOT_EXIST_STATUS_MESSAGE = + "The network as not found, thus no network was deleted in the cloud via this request"; + private static final String NETWORK_DELETED_STATUS_MESSAGE = "The network was successfully deleted in the cloud"; private static final Logger logger = LoggerFactory.getLogger(MsoNetworkAdapterImpl.class); @@ -225,7 +232,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { // See if the Network already exists (by name) NetworkInfo netInfo = null; - long queryNetworkStarttime = System.currentTimeMillis(); try { netInfo = neutron.queryNetwork(networkName, tenantId, cloudSiteId); } catch (MsoException me) { @@ -254,10 +260,10 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { logger.warn("{} {} Found Existing network, status={} for Neutron mode ", MessageEnum.RA_NETWORK_ALREADY_EXIST, ErrorCode.DataError.getValue(), netInfo.getStatus()); } + heat.updateResourceStatus(msoRequest.getRequestId(), NETWORK_EXIST_STATUS_MESSAGE); return; } - long createNetworkStarttime = System.currentTimeMillis(); try { netInfo = neutron.createNetwork(cloudSiteId, tenantId, neutronNetworkType, networkName, physicalNetworkName, vlans); @@ -360,6 +366,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { MessageEnum.RA_NETWORK_ALREADY_EXIST, ErrorCode.DataError.getValue(), heatStack.getStatus(), networkName, cloudSiteId, tenantId); } + heat.updateResourceStatus(msoRequest.getRequestId(), NETWORK_EXIST_STATUS_MESSAGE); return; } @@ -473,6 +480,12 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { networkRollback.setNetworkCreated(true); networkRollback.setNetworkType(networkType); + try { + heat.updateResourceStatus(msoRequest.getRequestId(), NETWORK_CREATED_STATUS_MESSAGE); + } catch (Exception e) { + logger.warn("Exception while updating infra active request", e); + } + logger.debug("Network {} successfully created via HEAT", networkName); } @@ -1055,8 +1068,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } } else { try { - heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true, timeoutMinutes); - networkDeleted.value = true; + StackInfo stack = heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, true, timeoutMinutes); + networkDeleted.value = stack.isOperationPerformed(); } catch (MsoException me) { me.addContext("DeleteNetwork"); logger.error("{} {} Delete Network (heat): {} in {}/{} ", MessageEnum.RA_DELETE_NETWORK_EXC, @@ -1064,6 +1077,12 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { throw new NetworkException(me); } } + try { + heat.updateResourceStatus(msoRequest.getRequestId(), + networkDeleted.value ? NETWORK_DELETED_STATUS_MESSAGE : NETWORK_NOT_EXIST_STATUS_MESSAGE); + } catch (Exception e) { + logger.warn("Exception while updating infra active request", e); + } } /** diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index 0dc0d1c290..32e88d8cad 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -109,6 +109,12 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { private static final String USER_ERROR = "USER ERROR"; private static final String VERSION_MIN = "VersionMin"; private static final String VERSION_MAX = "VersionMax"; + private static final String VF_EXIST_STATUS_MESSAGE = + "The vf module was found to already exist, thus no new vf module was created in the cloud via this request"; + private static final String VF_CREATED_STATUS_MESSAGE = "The new vf module was successfully created in the cloud"; + private static final String VF_NOT_EXIST_STATUS_MESSAGE = + "The vf module was not, thus no vf module was deleted in the cloud via this request"; + private static final String VF_DELETED_STATUS_MESSAGE = "The vf module was successfully deleted in the cloud"; @Autowired private VFModuleCustomizationRepository vfModuleCustomRepo; @@ -1046,6 +1052,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { heatStack = msoHeatUtils.createStack(cloudSiteId, cloudOwner, tenantId, vfModuleName, null, template, goldenInputs, true, heatTemplate.getTimeoutMinutes(), newEnvironmentString, nestedTemplatesChecked, heatFilesObjects, backout.booleanValue(), failIfExists); + + msoHeatUtils.updateResourceStatus(msoRequest.getRequestId(), + heatStack.isOperationPerformed() ? VF_EXIST_STATUS_MESSAGE : VF_CREATED_STATUS_MESSAGE); } else { throw new MsoHeatNotFoundException(); } @@ -1125,7 +1134,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } try { - msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true, timeoutMinutes); + StackInfo stackInfo = + msoHeatUtils.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true, timeoutMinutes); + msoHeatUtils.updateResourceStatus(msoRequest.getRequestId(), + stackInfo.isOperationPerformed() ? VF_DELETED_STATUS_MESSAGE : VF_NOT_EXIST_STATUS_MESSAGE); } catch (MsoException me) { me.addContext(DELETE_VNF); // Failed to query the Stack due to an openstack exception. diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java index add1918748..284067a766 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,6 +20,9 @@ package org.onap.so.adapters.network; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteNeutronNetwork; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteStack_200; @@ -52,6 +55,7 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; +import com.github.tomakehurst.wiremock.WireMockServer; public class MSONetworkAdapterImplTest extends BaseRestTestUtils { @@ -112,6 +116,8 @@ public class MSONetworkAdapterImplTest extends BaseRestTestUtils { @Test public void createNetworkByModelNameAlreadyExistNeutronMode() throws IOException { + mockUpdateRequestDb(wireMockServer, "9733c8d1-2668-4e5f-8b51-2cacc9b662c0"); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetAllNeutronNetworks_200(wireMockServer, "OpenstackGetNeutronNetworks.json"); @@ -140,6 +146,8 @@ public class MSONetworkAdapterImplTest extends BaseRestTestUtils { @Test public void createNetworkByModelNameHeatMode() throws IOException { + mockUpdateRequestDb(wireMockServer, "9733c8d1-2668-4e5f-8b51-2cacc9b662c0"); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStack_404(wireMockServer, "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"); @@ -158,6 +166,8 @@ public class MSONetworkAdapterImplTest extends BaseRestTestUtils { @Test public void createNetworkByModelNameAlreadyExistHeatMode() throws IOException { + mockUpdateRequestDb(wireMockServer, "9733c8d1-2668-4e5f-8b51-2cacc9b662c0"); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); @@ -236,6 +246,8 @@ public class MSONetworkAdapterImplTest extends BaseRestTestUtils { @Test public void deleteNetworkHeatModeSuccess() throws IOException { + mockUpdateRequestDb(wireMockServer, "5a29d907-b8c7-47bf-85f3-3940c0cce0f7"); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); @@ -292,6 +304,8 @@ public class MSONetworkAdapterImplTest extends BaseRestTestUtils { @Test public void deleteNetworkNeureonMode() throws IOException { + mockUpdateRequestDb(wireMockServer, "5a29d907-b8c7-47bf-85f3-3940c0cce0f7"); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", NETWORK_ID, HttpStatus.SC_OK); @@ -506,4 +520,9 @@ public class MSONetworkAdapterImplTest extends BaseRestTestUtils { String input = new String(Files.readAllBytes(Paths.get(JsonInput))); return input; } + + public static void mockUpdateRequestDb(WireMockServer wireMockServer, String requestId) throws IOException { + wireMockServer.stubFor(patch(urlPathEqualTo("/infraActiveRequests/" + requestId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java index 727f18902a..00961a16b9 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java @@ -7,9 +7,9 @@ * 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. @@ -22,6 +22,7 @@ package org.onap.so.adapters.network; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.onap.so.bpmn.mock.StubOpenStack.getBodyFromFile; @@ -41,6 +42,7 @@ import org.onap.so.entity.MsoRequest; import org.onap.so.openstack.beans.NetworkRollback; import org.onap.so.openstack.beans.Subnet; import org.springframework.beans.factory.annotation.Autowired; +import com.github.tomakehurst.wiremock.WireMockServer; public class MsoNetworkAdapterAsyncImplTest extends BaseRestTestUtils { @Autowired @@ -263,4 +265,5 @@ public class MsoNetworkAdapterAsyncImplTest extends BaseRestTestUtils { false, new ArrayList<>(), new HashMap<String, String>(), "messageId", new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl"); } + } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java index a058378425..9fc2aba948 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java @@ -23,6 +23,7 @@ package org.onap.so.adapters.vnf; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.mockito.Mockito.when; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200; @@ -30,6 +31,7 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStack; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackGetWithResponse; +import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -53,6 +55,7 @@ import org.onap.so.openstack.beans.VnfRollback; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.utils.MsoHeatUtils; import org.springframework.beans.factory.annotation.Autowired; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.stubbing.Scenario; @@ -73,6 +76,7 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { public void createVnfTest() throws Exception { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStackVfModule_200(wireMockServer); + mockUpdateRequestDb(wireMockServer, "12345"); MsoRequest msoRequest = getMsoRequest(); @@ -88,6 +92,7 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { public void createVnfTest_NullFailIfExists() throws Exception { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStackVfModule_200(wireMockServer); + mockUpdateRequestDb(wireMockServer, "12345"); MsoRequest msoRequest = getMsoRequest(); @@ -117,6 +122,8 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { .inScenario("HeatStatusFailure").whenScenarioStateIs("HeatStackFailed") .willSetStateTo("HeatStackSuccess")); + mockUpdateRequestDb(wireMockServer, "12345"); + MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); @@ -133,6 +140,8 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { public void createVnfTest_HeatStatusCreated() throws Exception { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStackVfModule_200(wireMockServer); + mockUpdateRequestDb(wireMockServer, "12345"); + MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); @@ -516,5 +525,10 @@ public class MsoVnfAdapterImplTest extends BaseRestTestUtils { return vfModuleCustomization; } + public static void mockUpdateRequestDb(WireMockServer wireMockServer, String requestId) throws IOException { + wireMockServer.stubFor(patch(urlPathEqualTo("/infraActiveRequests/" + requestId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java index 5a8524fd73..9655e90e46 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java @@ -7,9 +7,9 @@ * 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. @@ -22,6 +22,8 @@ package org.onap.so.adapters.vnf; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.apache.http.HttpStatus; import org.json.JSONException; import org.junit.Ignore; import org.junit.Test; @@ -49,6 +51,9 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; @@ -112,6 +117,8 @@ public class VnfAdapterRestTest extends BaseRestTestUtils { mockOpenStackGetStackVfModule_200(wireMockServer); + mockUpdateRequestDb(wireMockServer, "62265093-277d-4388-9ba6-449838ade586"); + headers.add("Accept", MediaType.APPLICATION_JSON); HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); @@ -208,6 +215,8 @@ public class VnfAdapterRestTest extends BaseRestTestUtils { mockOpenStackGetStackVfModule_200(wireMockServer); + mockUpdateRequestDb(wireMockServer, "62265093-277d-4388-9ba6-449838ade586"); + headers.add("Accept", MediaType.APPLICATION_JSON); HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); @@ -342,6 +351,7 @@ public class VnfAdapterRestTest extends BaseRestTestUtils { mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); + mockUpdateRequestDb(wireMockServer, "62265093-277d-4388-9ba6-449838ade586"); headers.add("Accept", MediaType.APPLICATION_JSON); HttpEntity<DeleteVfModuleRequest> entity = new HttpEntity<DeleteVfModuleRequest>(request, headers); @@ -539,4 +549,9 @@ public class VnfAdapterRestTest extends BaseRestTestUtils { return request; } + + public static void mockUpdateRequestDb(WireMockServer wireMockServer, String requestId) throws IOException { + wireMockServer.stubFor(patch(urlPathEqualTo("/infraActiveRequests/" + requestId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java index 523a6903cc..c2e2b567f1 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,6 +20,7 @@ package org.onap.so.adapters.vnf; +import org.apache.http.HttpStatus; import org.junit.Test; import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; @@ -37,6 +38,9 @@ import org.springframework.http.ResponseEntity; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import java.io.IOException; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackWithBody_200; @@ -50,6 +54,9 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { @Test public void testCreateVNFVolumes() throws IOException { + wireMockServer.stubFor(patch(urlPathEqualTo("/infraActiveRequests/62265093-277d-4388-9ba6-449838ade586")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackPostStacks_200(wireMockServer); mockOpenStackGetStackVfModule_200(wireMockServer); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java index fb4bec69ed..6fd9f02cfe 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java @@ -7,9 +7,9 @@ * 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. @@ -20,6 +20,7 @@ package org.onap.so.adapters.vnf; +import org.apache.http.HttpStatus; import org.junit.Test; import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; @@ -37,6 +38,9 @@ import org.springframework.http.ResponseEntity; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import java.io.IOException; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackWithBody_200; @@ -52,6 +56,9 @@ public class VolumeAdapterRestV2Test extends VolumeGroupAdapterCommon { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackPostStacks_200(wireMockServer); mockOpenStackGetStackVfModule_200(wireMockServer); + wireMockServer.stubFor(patch(urlPathEqualTo("/infraActiveRequests/62265093-277d-4388-9ba6-449838ade586")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + CreateVolumeGroupRequest request = buildCreateVfModuleRequest(); HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); diff --git a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml index 6171e7a624..42955c35c9 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml +++ b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml @@ -61,6 +61,9 @@ ssl-enable: false tomcat: max-threads: 50 mso: + adapters: + requestDb: + endpoint: http://localhost:${wiremock.server.port} audit: lock-time: 240000 logPath: logs diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java index a092099bfb..9f48144eb8 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java @@ -10,9 +10,9 @@ * 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. @@ -142,6 +142,7 @@ public class ArchiveInfraRequestsScheduler { archivedInfra.setVolumeGroupName(iar.getVolumeGroupName()); archivedInfra.setProductFamilyName(iar.getProductFamilyName()); archivedInfra.setTenantName(iar.getTenantName()); + archivedInfra.setResourceStatusMessage(iar.getResourceStatusMessage()); newArchivedReqs.add(archivedInfra); oldInfraReqs.add(iar); diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V7.3.1__AddResourceStatusMessageColumn.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V7.3.1__AddResourceStatusMessageColumn.sql new file mode 100644 index 0000000000..f388a185f5 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V7.3.1__AddResourceStatusMessageColumn.sql @@ -0,0 +1,4 @@ +use requestdb; + +ALTER TABLE infra_active_requests ADD COLUMN IF NOT EXISTS RESOURCE_STATUS_MESSAGE longtext; +ALTER TABLE archived_infra_requests ADD COLUMN IF NOT EXISTS RESOURCE_STATUS_MESSAGE longtext;
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java index 3ada984b58..f39aa3656a 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java @@ -7,9 +7,9 @@ * 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. @@ -32,6 +32,8 @@ public class RequestStatus { protected String requestState; @JsonProperty("statusMessage") protected String statusMessage; + @JsonProperty("resourceStatusMessage") + protected String resourceStatusMessage; @JsonProperty("percentProgress") protected Integer percentProgress; @JsonProperty("timestamp") @@ -95,6 +97,14 @@ public class RequestStatus { this.statusMessage = statusMessage; } + public String getResourceStatusMessage() { + return resourceStatusMessage; + } + + public void setResourceStatusMessage(String resourceStatusMessage) { + this.resourceStatusMessage = resourceStatusMessage; + } + public Integer getPercentProgress() { return percentProgress; } @@ -122,8 +132,8 @@ public class RequestStatus { @Override public String toString() { return new ToStringBuilder(this).append("requestState", requestState).append("statusMessage", statusMessage) - .append("percentProgress", percentProgress).append("timestamp", timeStamp) - .append("extSystemErrorSource", extSystemErrorSource) + .append("resourceStatusMessage", resourceStatusMessage).append("percentProgress", percentProgress) + .append("timestamp", timeStamp).append("extSystemErrorSource", extSystemErrorSource) .append("rollbackExtSystemErrorSource", rollbackExtSystemErrorSource).append("flowStatus", flowStatus) .append("retryStatusMessage", retryStatusMessage).append("rollbackStatusMessage", rollbackStatusMessage) .toString(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index 4e019ca602..33c2ac80be 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -106,7 +106,7 @@ public class OrchestrationRequests { private CamundaRequestHandler camundaRequestHandler; @GET - @Path("/{version:[vV][4-7]}/{requestId}") + @Path("/{version:[vV][4-8]}/{requestId}") @Operation(description = "Find Orchestrated Requests for a given requestId", responses = @ApiResponse( content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) @Produces(MediaType.APPLICATION_JSON) @@ -115,7 +115,6 @@ public class OrchestrationRequests { @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException { - String apiVersion = version.substring(1); GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse(); InfraActiveRequests infraActiveRequest = null; @@ -152,7 +151,7 @@ public class OrchestrationRequests { } } - Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format); + Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format, version); if (null != requestProcessingData && !requestProcessingData.isEmpty()) { request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); @@ -161,11 +160,11 @@ public class OrchestrationRequests { orchestrationResponse.setRequest(request); return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationResponse, - apiVersion); + version); } @GET - @Path("/{version:[vV][4-7]}") + @Path("/{version:[vV][4-8]}") @Operation(description = "Find Orchestrated Requests for a URI Information", responses = @ApiResponse( content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) @Produces(MediaType.APPLICATION_JSON) @@ -206,7 +205,7 @@ public class OrchestrationRequests { for (InfraActiveRequests infraActive : activeRequests) { RequestList requestList = new RequestList(); - Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, format); + Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, format, version); if (isRequestProcessingDataRequired(format)) { List<RequestProcessingData> requestProcessingData = @@ -292,7 +291,7 @@ public class OrchestrationRequests { } protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, - String format) throws ApiException { + String format, String version) throws ApiException { String requestBody = iar.getRequestBody(); Request request = new Request(); @@ -402,7 +401,7 @@ public class OrchestrationRequests { }); } - mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format); + mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format, version); request.setRequestStatus(status); return request; @@ -431,7 +430,7 @@ public class OrchestrationRequests { } protected void mapRequestStatusAndExtSysErrSrcToRequest(InfraActiveRequests iar, RequestStatus status, - String format) { + String format, String version) { String rollbackStatusMessage = iar.getRollbackStatusMessage(); String flowStatusMessage = iar.getFlowStatus(); String retryStatusMessage = iar.getRetryStatusMessage(); @@ -467,6 +466,12 @@ public class OrchestrationRequests { if (rollbackStatusMessage != null) { status.setRollbackStatusMessage(rollbackStatusMessage); } + if (version.matches("v[8-9]|v[1-9][0-9]")) { + if (iar.getResourceStatusMessage() != null) { + status.setResourceStatusMessage(iar.getResourceStatusMessage()); + } + } + status.setExtSystemErrorSource(iar.getExtSystemErrorSource()); status.setRollbackExtSystemErrorSource(iar.getRollbackExtSystemErrorSource()); } else { @@ -492,6 +497,13 @@ public class OrchestrationRequests { statusMessages = "ROLLBACK STATUS: " + rollbackStatusMessage; } } + if (iar.getResourceStatusMessage() != null) { + if (statusMessages != null) { + statusMessages = statusMessages + " " + "RESOURCE STATUS: " + iar.getResourceStatusMessage(); + } else { + statusMessages = "RESOURCE STATUS: " + iar.getResourceStatusMessage(); + } + } } if (statusMessages != null) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java index 22c82bf75c..4631b53bc0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java @@ -7,9 +7,9 @@ * 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. @@ -25,9 +25,9 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.doReturn; import javax.ws.rs.core.Response; import org.apache.commons.lang.StringUtils; @@ -92,6 +92,7 @@ public class OrchestrationRequestsUnitTest { iar.setFlowStatus(FLOW_STATUS); iar.setRollbackStatusMessage(ROLLBACK_STATUS_MESSAGE); iar.setRetryStatusMessage(RETRY_STATUS_MESSAGE); + iar.setResourceStatusMessage("The vf module already exist"); } @Test @@ -101,8 +102,10 @@ public class OrchestrationRequestsUnitTest { instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); - requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s", - FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE)); + requestStatus.setStatusMessage( + String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", + FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, + "The vf module already exist")); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -114,7 +117,7 @@ public class OrchestrationRequestsUnitTest { iar.setOriginalRequestId(ORIGINAL_REQUEST_ID); Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(result, sameBeanAs(expected)); } @@ -125,8 +128,11 @@ public class OrchestrationRequestsUnitTest { instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); - requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s", - FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE)); + requestStatus.setStatusMessage( + String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", + FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, + "The vf module already exist")); + Request expected = new Request(); expected.setRequestId(REQUEST_ID); expected.setInstanceReferences(instanceReferences); @@ -134,7 +140,7 @@ public class OrchestrationRequestsUnitTest { expected.setRequestScope(SERVICE); Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(result, sameBeanAs(expected)); } @@ -145,8 +151,10 @@ public class OrchestrationRequestsUnitTest { instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); - requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s", - FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE)); + requestStatus.setStatusMessage( + String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", + FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, + "The vf module already exist")); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -157,7 +165,7 @@ public class OrchestrationRequestsUnitTest { includeCloudRequest = false; Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(actual, sameBeanAs(expected)); } @@ -183,7 +191,34 @@ public class OrchestrationRequestsUnitTest { includeCloudRequest = false; Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.STATUSDETAIL.toString()); + OrchestrationRequestFormat.STATUSDETAIL.toString(), "v7"); + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void mapRequestStatusAndExtSysErrSrcToRequestStatusDetailV8Test() throws ApiException { + doReturn(null).when(camundaRequestHandler).getTaskName(REQUEST_ID); + InstanceReferences instanceReferences = new InstanceReferences(); + instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); + RequestStatus requestStatus = new RequestStatus(); + requestStatus.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE); + requestStatus.setRollbackExtSystemErrorSource(ROLLBACK_EXT_SYSTEM_ERROR_SOURCE); + requestStatus.setRequestState(iar.getRequestStatus()); + requestStatus.setFlowStatus(FLOW_STATUS); + requestStatus.setRollbackStatusMessage(ROLLBACK_STATUS_MESSAGE); + requestStatus.setRetryStatusMessage(RETRY_STATUS_MESSAGE); + requestStatus.setResourceStatusMessage("The vf module already exist"); + + Request expected = new Request(); + expected.setRequestId(REQUEST_ID); + expected.setInstanceReferences(instanceReferences); + expected.setRequestStatus(requestStatus); + expected.setRequestScope(SERVICE); + + includeCloudRequest = false; + + Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, + OrchestrationRequestFormat.STATUSDETAIL.toString(), "v8"); assertThat(actual, sameBeanAs(expected)); } @@ -194,7 +229,7 @@ public class OrchestrationRequestsUnitTest { RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); requestStatus.setStatusMessage( - "FLOW STATUS: FlowStatus RETRY STATUS: RetryStatusMessage ROLLBACK STATUS: RollbackStatusMessage"); + "FLOW STATUS: FlowStatus RETRY STATUS: RetryStatusMessage ROLLBACK STATUS: RollbackStatusMessage RESOURCE STATUS: The vf module already exist"); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -205,7 +240,7 @@ public class OrchestrationRequestsUnitTest { includeCloudRequest = false; Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.SIMPLENOTASKINFO.toString()); + OrchestrationRequestFormat.SIMPLENOTASKINFO.toString(), "v7"); assertThat(expected, sameBeanAs(actual)); } @@ -217,7 +252,7 @@ public class OrchestrationRequestsUnitTest { RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); requestStatus.setStatusMessage( - "FLOW STATUS: FlowStatus TASK INFORMATION: TaskName RETRY STATUS: RetryStatusMessage ROLLBACK STATUS: RollbackStatusMessage"); + "FLOW STATUS: FlowStatus TASK INFORMATION: TaskName RETRY STATUS: RetryStatusMessage ROLLBACK STATUS: RollbackStatusMessage RESOURCE STATUS: The vf module already exist"); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -227,7 +262,7 @@ public class OrchestrationRequestsUnitTest { includeCloudRequest = false; - Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, null); + Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, null, "v7"); assertThat(expected, sameBeanAs(actual)); } @@ -238,8 +273,10 @@ public class OrchestrationRequestsUnitTest { instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); - requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s", - FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE)); + requestStatus.setStatusMessage( + String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", + FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, + "The vf module already exist")); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -250,7 +287,7 @@ public class OrchestrationRequestsUnitTest { includeCloudRequest = false; Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(actual, sameBeanAs(expected)); } @@ -272,9 +309,10 @@ public class OrchestrationRequestsUnitTest { includeCloudRequest = false; iar.setFlowStatus(null); + iar.setResourceStatusMessage(null); Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(actual, sameBeanAs(expected)); } @@ -288,7 +326,7 @@ public class OrchestrationRequestsUnitTest { iar.setStatusMessage("Error retrieving cloud region from AAI"); Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertTrue(actual.getRequestStatus().getStatusMessage() .contains("Error Source: " + ROLLBACK_EXT_SYSTEM_ERROR_SOURCE)); @@ -300,8 +338,10 @@ public class OrchestrationRequestsUnitTest { instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); - requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s", - "Successfully completed all Building Blocks", RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE)); + requestStatus.setStatusMessage( + String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", + "Successfully completed all Building Blocks", RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, + "The vf module already exist")); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -313,7 +353,7 @@ public class OrchestrationRequestsUnitTest { iar.setFlowStatus("Successfully completed all Building Blocks"); Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(actual, sameBeanAs(expected)); } @@ -324,8 +364,10 @@ public class OrchestrationRequestsUnitTest { instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID); RequestStatus requestStatus = new RequestStatus(); requestStatus.setRequestState(iar.getRequestStatus()); - requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s", - "All Rollback flows have completed successfully", RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE)); + requestStatus.setStatusMessage( + String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", + "All Rollback flows have completed successfully", RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, + "The vf module already exist")); Request expected = new Request(); expected.setRequestId(REQUEST_ID); @@ -337,7 +379,7 @@ public class OrchestrationRequestsUnitTest { iar.setFlowStatus("All Rollback flows have completed successfully"); Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, - OrchestrationRequestFormat.DETAIL.toString()); + OrchestrationRequestFormat.DETAIL.toString(), "v7"); assertThat(actual, sameBeanAs(expected)); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql index 85a17dd369..19855bc85e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql @@ -1299,6 +1299,7 @@ CREATE TABLE `infra_active_requests` ( `ROLLBACK_EXT_SYSTEM_ERROR_SOURCE` varchar(80) DEFAULT NULL, `TENANT_NAME` varchar(200) DEFAULT NULL, `PRODUCT_FAMILY_NAME` varchar(200) DEFAULT NULL, + `RESOURCE_STATUS_MESSAGE` longtext, PRIMARY KEY (`REQUEST_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; @@ -1342,6 +1343,7 @@ CREATE TABLE `archived_infra_requests` ( `OPERATIONAL_ENV_ID` varchar(45) DEFAULT NULL, `OPERATIONAL_ENV_NAME` varchar(200) DEFAULT NULL, `REQUEST_URL` varchar(500) DEFAULT NULL, + `RESOURCE_STATUS_MESSAGE` longtext, PRIMARY KEY (`REQUEST_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql index 5212feb885..4c376c7af8 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql @@ -102,7 +102,8 @@ CREATE TABLE IF NOT EXISTS PUBLIC.INFRA_ACTIVE_REQUESTS( EXT_SYSTEM_ERROR_SOURCE VARCHAR SELECTIVITY 1, ROLLBACK_EXT_SYSTEM_ERROR_SOURCE VARCHAR SELECTIVITY 1, TENANT_NAME VARCHAR SELECTIVITY 1, - PRODUCT_FAMILY_NAME VARCHAR SELECTIVITY 1 + PRODUCT_FAMILY_NAME VARCHAR SELECTIVITY 1, + RESOURCE_STATUS_MESSAGE VARCHAR SELECTIVITY 36 ); @@ -175,7 +176,8 @@ CREATE CACHED TABLE PUBLIC.ARCHIVED_INFRA_REQUESTS( INSTANCE_GROUP_NAME VARCHAR SELECTIVITY 1, REQUEST_URL VARCHAR SELECTIVITY 1, TENANT_NAME VARCHAR SELECTIVITY 1, - PRODUCT_FAMILY_NAME VARCHAR SELECTIVITY 1 + PRODUCT_FAMILY_NAME VARCHAR SELECTIVITY 1, + RESOURCE_STATUS_MESSAGE VARCHAR SELECTIVITY 36 ); CREATE TABLE IF NOT EXISTS cloud_api_requests( diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java index 66768ea349..a6d6af8a07 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java @@ -7,9 +7,9 @@ * 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. @@ -55,6 +55,8 @@ public abstract class InfraRequests implements java.io.Serializable { private String requestId; @Column(name = "REQUEST_STATUS", length = 20) private String requestStatus; + @Column(name = "RESOURCE_STATUS_MESSAGE", length = 2000) + private String resourceStatusMessage; @Column(name = "STATUS_MESSAGE", length = 2000) private String statusMessage; @Column(name = "ROLLBACK_STATUS_MESSAGE", length = 2000) @@ -179,6 +181,14 @@ public abstract class InfraRequests implements java.io.Serializable { this.requestStatus = requestStatus; } + public String getResourceStatusMessage() { + return resourceStatusMessage; + } + + public void setResourceStatusMessage(String resourceStatusMessage) { + this.resourceStatusMessage = resourceStatusMessage; + } + public String getStatusMessage() { return this.statusMessage; } @@ -608,11 +618,12 @@ public abstract class InfraRequests implements java.io.Serializable { @Override public String toString() { return new ToStringBuilder(this).append("requestId", getRequestId()).append("requestStatus", getRequestStatus()) - .append("statusMessage", getStatusMessage()).append("rollbackStatusMessage", getRollbackStatusMessage()) - .append("flowStatus", getFlowStatus()).append("retryStatusMessage", getRetryStatusMessage()) - .append("progress", getProgress()).append("startTime", getStartTime()).append("endTime", getEndTime()) - .append("source", getSource()).append("vnfId", getVnfId()).append("vnfName", getVnfName()) - .append("pnfName", getPnfName()).append("vnfType", getVnfType()).append("serviceType", getServiceType()) + .append("resourceStatusMessage", getResourceStatusMessage()).append("statusMessage", getStatusMessage()) + .append("rollbackStatusMessage", getRollbackStatusMessage()).append("flowStatus", getFlowStatus()) + .append("retryStatusMessage", getRetryStatusMessage()).append("progress", getProgress()) + .append("startTime", getStartTime()).append("endTime", getEndTime()).append("source", getSource()) + .append("vnfId", getVnfId()).append("vnfName", getVnfName()).append("pnfName", getPnfName()) + .append("vnfType", getVnfType()).append("serviceType", getServiceType()) .append("tenantId", getTenantId()).append("vnfParams", getVnfParams()) .append("vnfOutputs", getVnfOutputs()).append("requestBody", getRequestBody()) .append("responseBody", getResponseBody()).append("lastModifiedBy", getLastModifiedBy()) diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 7b642ab831..6aa00caeed 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -360,6 +360,7 @@ public class RequestsDbClient { restTemplate.postForLocation(uri, entity); } + // TODO really this should be called save as its doing a put public void updateInfraActiveRequests(InfraActiveRequests request) { HttpHeaders headers = getHttpHeaders(); URI uri = getUri(infraActiveRequestURI + request.getRequestId()); @@ -371,8 +372,7 @@ public class RequestsDbClient { HttpHeaders headers = getHttpHeaders(); URI uri = getUri(infraActiveRequestURI + request.getRequestId()); HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers); - restTemplate.exchange(uri, HttpMethod.PATCH, new HttpEntity<InfraActiveRequests>(request, headers), - String.class); + restTemplate.exchange(uri, HttpMethod.PATCH, entity, String.class); } public InfraActiveRequests getInfraActiveRequests(String requestId, String basicAuth, String host) { |