diff options
author | Steve Smokowski <ss835w@att.com> | 2019-04-29 13:35:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-29 13:35:51 +0000 |
commit | 81c1466f6657d41dc01b5271b18430875fd2e3f9 (patch) | |
tree | 47c5fd0479bbc0d2a318162ecfa75e529a27fb74 | |
parent | 702ab6907b58bfac82a17c52ecdc70ef4084ef6f (diff) | |
parent | a10606e383ce6c872cb7c95fe1d5e65565827813 (diff) |
Merge "Store Cloud Request in Database"
19 files changed, 439 insertions, 135 deletions
diff --git a/adapters/mso-adapter-utils/pom.xml b/adapters/mso-adapter-utils/pom.xml index 7918072323..aa9a1cea9e 100644 --- a/adapters/mso-adapter-utils/pom.xml +++ b/adapters/mso-adapter-utils/pom.xml @@ -147,5 +147,10 @@ <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf.version}</version> </dependency> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>mso-requests-db</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project> 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 3dba412237..8093f045eb 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 @@ -23,6 +23,7 @@ package org.onap.so.openstack.utils; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.base.client.OpenStackConnectException; @@ -47,6 +48,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.vdu.CloudInfo; import org.onap.so.adapters.vdu.PluginAction; import org.onap.so.adapters.vdu.VduArtifact; @@ -67,6 +69,9 @@ import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.HeatTemplate; import org.onap.so.db.catalog.beans.HeatTemplateParam; import org.onap.so.db.catalog.beans.ServerType; +import org.onap.so.db.request.beans.CloudApiRequests; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.HeatStatus; @@ -82,6 +87,7 @@ import org.onap.so.openstack.mappers.StackInfoMapper; import org.onap.so.utils.CryptoUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; @@ -121,6 +127,9 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { @Autowired private KeystoneV3Authentication keystoneV3Authentication; + @Autowired + RequestsDbClient requestDBClient; + private static final Logger logger = LoggerFactory.getLogger(MsoHeatUtils.class); // Properties names and variables (with default values) @@ -241,6 +250,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Stack heatStack = null; try { OpenStackRequest<Stack> request = heatClient.getStacks().create(stack); + saveStackRequest(request, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), stackName); CloudIdentity cloudIdentity = cloudSite.getIdentityService(); request.header("X-Auth-User", cloudIdentity.getMsoId()); request.header("X-Auth-Key", CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); @@ -276,6 +286,22 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { return new StackInfoMapper(heatStack).map(); } + private void saveStackRequest(OpenStackRequest<Stack> request, String requestId, String stackName) { + try { + ObjectMapper mapper = new ObjectMapper(); + InfraActiveRequests foundRequest = requestDBClient.getInfraActiveRequestbyRequestId(requestId); + String stackRequest = mapper.writeValueAsString(request.entity()); + CloudApiRequests cloudReq = new CloudApiRequests(); + cloudReq.setCloudIdentifier(stackName); + cloudReq.setRequestBody(stackRequest); + cloudReq.setRequestId(requestId); + foundRequest.getCloudApiRequests().add(cloudReq); + requestDBClient.updateInfraActiveRequests(foundRequest); + } catch (Exception e) { + logger.error("Error updating in flight request with Openstack Create Request", e); + } + } + private Stack pollStackForCompletion(String cloudSiteId, String tenantId, String stackName, int timeoutMinutes, boolean backout, Heat heatClient, Stack heatStack, String canonicalName) throws MsoException, MsoOpenstackException { diff --git a/adapters/mso-openstack-adapters/src/main/resources/application.yaml b/adapters/mso-openstack-adapters/src/main/resources/application.yaml index f66d77db48..1982961ae7 100644 --- a/adapters/mso-openstack-adapters/src/main/resources/application.yaml +++ b/adapters/mso-openstack-adapters/src/main/resources/application.yaml @@ -25,10 +25,10 @@ spring: driver-class-name: org.mariadb.jdbc.Driver initialization-mode: never jpa: - show-sql: true + show-sql: false hibernate: dialect: org.hibernate.dialect.MySQL5Dialect - ddl-auto: validate + ddl-auto: none naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy enable-lazy-load-no-trans: true org: diff --git a/adapters/mso-openstack-adapters/src/test/resources/GetResources.json b/adapters/mso-openstack-adapters/src/test/resources/GetResources.json index 0d403a62b5..d4e84fb3c9 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/GetResources.json +++ b/adapters/mso-openstack-adapters/src/test/resources/GetResources.json @@ -90,7 +90,7 @@ "resource_status_reason": "state changed", "resource_type": "OS::Heat::ResourceGroup", "updated_time": "2019-01-23T19:34:15Z" - }, + }, { "links": [ { 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 058c1d2627..ce576f00e1 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml +++ b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml @@ -92,7 +92,7 @@ spring: generate-ddl: false show-sql: false hibernate: - ddl-auto: validate + ddl-auto: none database-platform: org.hibernate.dialect.MySQL5InnoDBDialect security: usercredentials: diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.7__Add_OpenStack_Request_Information.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.7__Add_OpenStack_Request_Information.sql new file mode 100644 index 0000000000..5635a1eb80 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V5.7__Add_OpenStack_Request_Information.sql @@ -0,0 +1,13 @@ +use requestdb; + +CREATE TABLE IF NOT EXISTS cloud_api_requests( +`ID` INT(13) NOT NULL AUTO_INCREMENT, +`REQUEST_BODY` LONGTEXT NOT NULL, +`CLOUD_IDENTIFIER` VARCHAR(200) NULL, +`SO_REQUEST_ID` VARCHAR(45) NOT NULL, +`CREATE_TIME` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`ID`), +CONSTRAINT fk_cloud_api_req_infra_requests + FOREIGN KEY (SO_REQUEST_ID) + REFERENCES infra_active_requests (REQUEST_ID)) +ENGINE = InnoDB DEFAULT CHARSET=latin1;
\ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java index 514e5ad923..9faba0df67 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java @@ -50,35 +50,10 @@ public class HealthCheckHandlerTest extends RequestsAdapterBase { @Test public void testHealthcheck() throws JSONException { - TestAppender.events.clear(); HttpEntity<String> entity = new HttpEntity<String>(null, headers); - ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("/manage/health"), HttpMethod.GET, entity, String.class); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - for (ILoggingEvent logEvent : TestAppender.events) - if (logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") - && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) { - Map<String, String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - assertEquals("", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - assertEquals("/manage/health", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); - assertEquals("INPROGRESS", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - } else if (logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") - && logEvent.getMarker() != null && logEvent.getMarker() != null - && logEvent.getMarker().getName().equals("EXIT")) { - Map<String, String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - assertEquals("200", mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); - assertEquals("", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - assertEquals("/manage/health", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); - assertEquals("COMPLETED", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - } - TestAppender.events.clear(); } private String createURLWithPort(String uri) { diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java index 3b737c6768..03df115574 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.adapters.requestsdb.RequestsAdapterBase; import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; +import org.onap.so.db.request.beans.CloudApiRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; @@ -41,9 +42,9 @@ import java.util.Map; import java.util.HashMap; import java.util.ArrayList; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertFalse; @@ -87,6 +88,14 @@ public class RequestsDbClientTest extends RequestsAdapterBase { infraActiveRequests.setRequestAction("someaction"); infraActiveRequests .setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances"); + List<CloudApiRequests> cloudApiRequests = new ArrayList<>(); + CloudApiRequests cloudRequest = new CloudApiRequests(); + cloudRequest.setCloudIdentifier("heatstackanme/id"); + cloudRequest.setId(1); + cloudRequest.setRequestBody("requestBody"); + cloudRequest.setRequestId(infraActiveRequests.getRequestId()); + cloudApiRequests.add(cloudRequest); + infraActiveRequests.setCloudApiRequests(cloudApiRequests); requestsDbClient.save(infraActiveRequests); } @@ -96,7 +105,8 @@ public class RequestsDbClientTest extends RequestsAdapterBase { private void verifyInfraActiveRequests(InfraActiveRequests infraActiveRequestsResponse) { - assertThat(infraActiveRequestsResponse, sameBeanAs(infraActiveRequests).ignoring("modifyTime").ignoring("log")); + assertThat(infraActiveRequestsResponse, sameBeanAs(infraActiveRequests).ignoring("modifyTime").ignoring("log") + .ignoring("cloudApiRequests.created").ignoring("cloudApiRequests.id")); } @Test @@ -113,7 +123,6 @@ public class RequestsDbClientTest extends RequestsAdapterBase { verifyInfraActiveRequests(infraActiveRequestsResponse); } - @Test public void checkVnfIdStatusTest() { InfraActiveRequests infraActiveRequestsResponse = @@ -182,7 +191,7 @@ public class RequestsDbClientTest extends RequestsAdapterBase { public void getInfraActiveRequestbyRequestIdWhereRequestUrlNullTest() { // requestUrl setup to null and save infraActiveRequests.setRequestUrl(null); - requestsDbClient.save(infraActiveRequests); + requestsDbClient.updateInfraActiveRequests(infraActiveRequests); InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.getInfraActiveRequestbyRequestId(infraActiveRequests.getRequestId()); verifyInfraActiveRequests(infraActiveRequestsResponse); diff --git a/adapters/mso-requests-db-adapter/src/test/resources/logback-test.xml b/adapters/mso-requests-db-adapter/src/test/resources/logback-test.xml index d1596cd374..a63bd27378 100644 --- a/adapters/mso-requests-db-adapter/src/test/resources/logback-test.xml +++ b/adapters/mso-requests-db-adapter/src/test/resources/logback-test.xml @@ -1,18 +1,7 @@ <configuration> - <property name="p_tim" value="%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC}"/> - <property name="p_lvl" value="%level"/> - <property name="p_log" value="%logger"/> - <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}"/> - <property name="p_msg" value="%replace(%replace(%msg){'\t', '\\\\t'}){'\n','\\\\n'}"/> - <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/> - <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/> - <property name="p_thr" value="%thread"/> - <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/> - - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> - <pattern>${pattern}</pattern> + <pattern>%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n</pattern> </encoder> </appender> @@ -44,6 +33,10 @@ <logger name="ch.vorburger" level="WARN" additivity="false"> <appender-ref ref="STDOUT" /> </logger> + + <logger name="org.hibernate" level="DEBUG" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> <root level="WARN"> diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java b/common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java new file mode 100644 index 0000000000..abaef26562 --- /dev/null +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.onap.so.serviceinstancebeans; + +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class CloudRequestData { + + Object cloudRequest; + String cloudIdentifier; + + public CloudRequestData() {} + + public CloudRequestData(Object cloudRequest, String cloudIdentifier) { + this.cloudRequest = cloudRequest; + this.cloudIdentifier = cloudIdentifier; + } + + public Object getCloudRequest() { + return cloudRequest; + } + + public void setCloudRequest(Object cloudRequest) { + this.cloudRequest = cloudRequest; + } + + public String getCloudIdentifier() { + return cloudIdentifier; + } + + public void setCloudIdentifier(String cloudIdentifier) { + this.cloudIdentifier = cloudIdentifier; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("cloudRequest", cloudRequest).append("cloudIdentifier", cloudIdentifier) + .toString(); + } +} diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java b/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java index 8635af5b94..fbdb27c0ec 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java @@ -20,7 +20,9 @@ package org.onap.so.serviceinstancebeans; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -38,6 +40,7 @@ public class Request { protected InstanceReferences instanceReferences; protected RequestStatus requestStatus; protected List<RequestProcessingData> requestProcessingData; + protected List<CloudRequestData> cloudRequestData = new ArrayList<>(); public String getRequestId() { @@ -112,12 +115,22 @@ public class Request { this.requestProcessingData = requestProcessingData; } + + public List<CloudRequestData> getCloudRequestData() { + return cloudRequestData; + } + + public void setCloudRequestData(List<CloudRequestData> cloudRequestData) { + this.cloudRequestData = cloudRequestData; + } + @Override public String toString() { return new ToStringBuilder(this).append("requestId", requestId).append("startTime", startTime) .append("finishTime", finishTime).append("requestScope", requestScope) .append("requestType", requestType).append("requestDetails", requestDetails) .append("instanceReferences", instanceReferences).append("requestStatus", requestStatus) - .append("requestProcessingData", requestProcessingData).toString(); + .append("requestProcessingData", requestProcessingData).append("cloudRequestData", cloudRequestData) + .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 34dcd4b0c4..1bbe858859 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 @@ -35,12 +35,14 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringEscapeUtils; import org.apache.http.HttpStatus; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandler.common.ResponseBuilder; @@ -53,6 +55,7 @@ import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.CloudRequestData; import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse; import org.onap.so.serviceinstancebeans.GetOrchestrationResponse; import org.onap.so.serviceinstancebeans.InstanceReferences; @@ -65,6 +68,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -92,7 +97,9 @@ public class OrchestrationRequests { @Produces(MediaType.APPLICATION_JSON) @Transactional public Response getOrchestrationRequest(@PathParam("requestId") String requestId, - @PathParam("version") String version) throws ApiException { + @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest) + throws ApiException { + String apiVersion = version.substring(1); GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse(); @@ -135,7 +142,7 @@ public class OrchestrationRequests { throw validateException; } - Request request = mapInfraActiveRequestToRequest(infraActiveRequest); + Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest); if (!requestProcessingData.isEmpty()) { request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); } @@ -150,8 +157,8 @@ public class OrchestrationRequests { @ApiOperation(value = "Find Orchestrated Requests for a URI Information", response = Response.class) @Produces(MediaType.APPLICATION_JSON) @Transactional - public Response getOrchestrationRequest(@Context UriInfo ui, @PathParam("version") String version) - throws ApiException { + public Response getOrchestrationRequest(@Context UriInfo ui, @PathParam("version") String version, + @QueryParam("includeCloudRequest") boolean includeCloudRequest) throws ApiException { long startTime = System.currentTimeMillis(); @@ -188,7 +195,7 @@ public class OrchestrationRequests { List<RequestProcessingData> requestProcessingData = requestsDbClient.getRequestProcessingDataBySoRequestId(infraActive.getRequestId()); RequestList requestList = new RequestList(); - Request request = mapInfraActiveRequestToRequest(infraActive); + Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest); if (!requestProcessingData.isEmpty()) { request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); } @@ -286,8 +293,8 @@ public class OrchestrationRequests { return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build(); } - private Request mapInfraActiveRequestToRequest(InfraActiveRequests iar) throws ApiException { - + private Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest) + throws ApiException { String requestBody = iar.getRequestBody(); Request request = new Request(); @@ -329,8 +336,6 @@ public class OrchestrationRequests { if (iar.getInstanceGroupName() != null) ir.setInstanceGroupName(iar.getInstanceGroupName()); - - request.setInstanceReferences(ir); RequestDetails requestDetails = null; @@ -410,8 +415,19 @@ public class OrchestrationRequests { status.setPercentProgress(iar.getProgress().intValue()); } - request.setRequestStatus(status); + if (iar.getCloudApiRequests() != null && !iar.getCloudApiRequests().isEmpty() && includeCloudRequest) { + iar.getCloudApiRequests().stream().forEach(cloudRequest -> { + try { + request.getCloudRequestData() + .add(new CloudRequestData(mapper.readValue(cloudRequest.getRequestBody(), Object.class), + cloudRequest.getCloudIdentifier())); + } catch (Exception e) { + logger.error("Error reading Cloud Request", e); + } + }); + } + request.setRequestStatus(status); return request; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index 321ea3ac7d..c678fab03e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -48,6 +48,7 @@ import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; +import org.onap.so.serviceinstancebeans.CloudRequestData; import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse; import org.onap.so.serviceinstancebeans.GetOrchestrationResponse; import org.onap.so.serviceinstancebeans.Request; @@ -64,6 +65,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class OrchestrationRequestsTest extends BaseTest { @@ -149,13 +151,24 @@ public class OrchestrationRequestsTest extends BaseTest { } @Test - public void testGetOrchestrationRequestRequestDetails() throws Exception { - setupTestGetOrchestrationRequestRequestDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED"); + public void testGetOrchestrationRequestWithOpenstackDetails() throws Exception { + setupTestGetOrchestrationRequestOpenstackDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED"); // Test request with modelInfo request body GetOrchestrationResponse testResponse = new GetOrchestrationResponse(); Request request = ORCHESTRATION_LIST.getRequestList().get(0).getRequest(); + List<CloudRequestData> cloudRequestData = new ArrayList<>(); + CloudRequestData cloudData = new CloudRequestData(); + cloudData.setCloudIdentifier("heatstackName/123123"); + ObjectMapper mapper = new ObjectMapper(); + Object reqData = mapper.readValue( + "{\r\n \"test\": \"00032ab7-3fb3-42e5-965d-8ea592502016\",\r\n \"test2\": \"deleteInstance\",\r\n \"test3\": \"COMPLETE\",\r\n \"test4\": \"Vf Module has been deleted successfully.\",\r\n \"test5\": 100\r\n}", + Object.class); + cloudData.setCloudRequest(reqData); + cloudRequestData.add(cloudData); + request.setCloudRequestData(cloudRequestData); testResponse.setRequest(request); + String testRequestId = request.getRequestId(); HttpHeaders headers = new HttpHeaders(); @@ -163,15 +176,17 @@ public class OrchestrationRequestsTest extends BaseTest { headers.set("Content-Type", MediaType.APPLICATION_JSON); HttpEntity<Request> entity = new HttpEntity<Request>(null, headers); - UriComponentsBuilder builder = UriComponentsBuilder - .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId)); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort( + "/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true")); ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class); - + System.out.println("Response :" + response.getBody().toString()); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime") .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp")); + assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); @@ -323,70 +338,7 @@ public class OrchestrationRequestsTest extends BaseTest { // properly called to update. } - @Ignore // What is this testing? - @Test - public void testGetOrchestrationRequestRequestDetailsWhiteSpace() throws Exception { - InfraActiveRequests requests = new InfraActiveRequests(); - requests.setAction("create"); - requests.setRequestBody(" "); - requests.setRequestId("requestId"); - requests.setRequestScope("service"); - requests.setRequestType("createInstance"); - ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(requests); - - requestsDbClient.save(requests); - HttpHeaders headers = new HttpHeaders(); - headers.set("Accept", MediaType.APPLICATION_JSON); - headers.set("Content-Type", MediaType.APPLICATION_JSON); - HttpEntity<Request> entity = new HttpEntity<Request>(null, headers); - - UriComponentsBuilder builder = UriComponentsBuilder - .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/requestId")); - - ResponseEntity<GetOrchestrationResponse> response = - restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); - assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); - assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); - assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0)); - assertEquals("requestId", response.getHeaders().get("X-TransactionID").get(0)); - } - - @Ignore // What is this testing? - @Test - public void testGetOrchestrationRequestRequestDetailsAlaCarte() throws IOException { - InfraActiveRequests requests = new InfraActiveRequests(); - - String requestJSON = new String( - Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/AlaCarteRequest.json"))); - - requests.setAction("create"); - requests.setRequestBody(requestJSON); - requests.setRequestId("requestId"); - requests.setRequestScope("service"); - requests.setRequestType("createInstance"); - // iar.save(requests); - HttpHeaders headers = new HttpHeaders(); - headers.set("Accept", MediaType.APPLICATION_JSON); - headers.set("Content-Type", MediaType.APPLICATION_JSON); - HttpEntity<Request> entity = new HttpEntity<Request>(null, headers); - UriComponentsBuilder builder = UriComponentsBuilder - .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/requestId")); - - ResponseEntity<GetOrchestrationResponse> response = - restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); - assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); - assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); - assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0)); - assertEquals("requestId", response.getHeaders().get("X-TransactionID").get(0)); - } @Test public void mapRequestProcessingDataTest() throws JsonParseException, JsonMappingException, IOException { @@ -461,6 +413,15 @@ public class OrchestrationRequestsTest extends BaseTest { .withStatus(HttpStatus.SC_OK))); } + + private void setupTestGetOrchestrationRequestOpenstackDetails(String requestId, String status) throws Exception { + wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse() + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths + .get("src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json")))) + .withStatus(HttpStatus.SC_OK))); + } + private void setupTestUnlockOrchestrationRequest(String requestId, String status) { wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(requestId))) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) @@ -473,7 +434,6 @@ public class OrchestrationRequestsTest extends BaseTest { private void setupTestUnlockOrchestrationRequest_invalid_Json() { wireMockServer.stubFor(get(urlPathEqualTo(getTestUrl(INVALID_REQUEST_ID))).willReturn(aResponse() .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND))); - } private void setupTestUnlockOrchestrationRequest_Valid_Status(String requestID, String status) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json new file mode 100644 index 0000000000..41d7e4d706 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationOpenstackRequestDetails.json @@ -0,0 +1,62 @@ +{ + "clientRequestId": "00032ab7-3fb3-42e5-965d-8ea592502016", + "action": "deleteInstance", + "requestStatus": "COMPLETE", + "statusMessage": "Vf Module has been deleted successfully.", + "progress": 100, + "startTime": "2016-12-22T13:29:54.000+0000", + "endTime": "2016-12-22T13:30:28.000+0000", + "source": "VID", + "vnfId": "b92f60c8-8de3-46c1-8dc1-e4390ac2b005", + "vnfName": null, + "vnfType": null, + "serviceType": null, + "aicNodeClli": null, + "tenantId": "6accefef3cb442ff9e644d589fb04107", + "provStatus": null, + "vnfParams": null, + "vnfOutputs": null, + "requestBody": "{\"modelInfo\":{\"modelType\":\"vfModule\",\"modelName\":\"test::base::module-0\"},\"requestInfo\":{\"source\":\"VID\"},\"cloudConfiguration\":{\"tenantId\":\"6accefef3cb442ff9e644d589fb04107\",\"lcpCloudRegionId\":\"n6\"}}", + "responseBody": null, + "lastModifiedBy": "BPMN", + "modifyTime": "2016-12-22T13:30:28.000+0000", + "requestType": null, + "volumeGroupId": null, + "volumeGroupName": null, + "vfModuleId": "c7d527b1-7a91-49fd-b97d-1c8c0f4a7992", + "vfModuleName": null, + "vfModuleModelName": "test::base::module-0", + "aaiServiceId": null, + "aicCloudRegion": "n6", + "callBackUrl": null, + "correlator": null, + "serviceInstanceId": "e3b5744d-2ad1-4cdd-8390-c999a38829bc", + "serviceInstanceName": null, + "requestScope": "vfModule", + "requestAction": "deleteInstance", + "networkId": null, + "networkName": null, + "networkType": null, + "requestorId": null, + "configurationId": null, + "configurationName": null, + "operationalEnvId": null, + "operationalEnvName": null, + "cloudApiRequests":[ + { + "id": 1, + "cloudIdentifier": "heatstackName/123123", + "requestBody":"{\r\n \"test\": \"00032ab7-3fb3-42e5-965d-8ea592502016\",\r\n \"test2\": \"deleteInstance\",\r\n \"test3\": \"COMPLETE\",\r\n \"test4\": \"Vf Module has been deleted successfully.\",\r\n \"test5\": 100\r\n}", + "created": "2016-12-22T13:29:54.000+0000" + } + ], + "requestURI": "00032ab7-3fb3-42e5-965d-8ea592502017", + "_links": { + "self": { + "href": "http://localhost:8087/infraActiveRequests/00032ab7-3fb3-42e5-965d-8ea592502017" + }, + "infraActiveRequests": { + "href": "http://localhost:8087/infraActiveRequests/00032ab7-3fb3-42e5-965d-8ea592502017" + } + } +} 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 765740e864..c2eb21b18e 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 @@ -1463,6 +1463,16 @@ create table if not exists model ( FOREIGN KEY (`RECIPE`) REFERENCES `model_recipe` (`MODEL_ID`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +CREATE TABLE IF NOT EXISTS `requestdb`.`cloud_api_requests` ( +`ID` INT(13) NOT NULL AUTO_INCREMENT, +`REQUEST_BODY` LONGTEXT NOT NULL, +`CLOUD_IDENTIFIER` VARCHAR(200) NULL, +`SO_REQUEST_ID` VARCHAR(45) NOT NULL, +`CREATE_TIME` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`ID`), +INDEX `fk_cloud_api_requests__so_request_id_idx` (`SO_REQUEST_ID` ASC)) +ENGINE = InnoDB DEFAULT CHARSET=latin1; + CREATE TABLE IF NOT EXISTS `workflow` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `ARTIFACT_UUID` varchar(200) NOT NULL, @@ -1480,8 +1490,3 @@ CREATE TABLE IF NOT EXISTS `workflow` ( PRIMARY KEY (`ID`), UNIQUE KEY `UK_workflow` (`ARTIFACT_UUID`,`NAME`,`VERSION`,`SOURCE`) ) 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 2bd9936b3a..65372b7b48 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 @@ -1,5 +1,5 @@ -create table ACTIVATE_OPERATIONAL_ENV_SERVICE_MODEL_DISTRIBUTION_STATUS ( +create table IF NOT EXISTS ACTIVATE_OPERATIONAL_ENV_SERVICE_MODEL_DISTRIBUTION_STATUS ( REQUEST_ID varchar(255) not null, OPERATIONAL_ENV_ID varchar(255) not null, SERVICE_MODEL_VERSION_ID varchar(255) not null, @@ -13,7 +13,7 @@ create table ACTIVATE_OPERATIONAL_ENV_SERVICE_MODEL_DISTRIBUTION_STATUS ( primary key (REQUEST_ID,OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID) ); -create table OPERATION_STATUS ( +create table IF NOT EXISTS OPERATION_STATUS ( SERVICE_ID varchar(255) not null, OPERATION_ID varchar(255) not null, SERVICE_NAME varchar(255), @@ -46,7 +46,7 @@ INSERT INTO PUBLIC.OPERATION_STATUS(SERVICE_ID, OPERATION_ID, OPERATION_TYPE, US primary key (SERVICE_ID,OPERATION_ID,RESOURCE_TEMPLATE_UUID) ); -CREATE CACHED TABLE PUBLIC.INFRA_ACTIVE_REQUESTS( +CREATE TABLE IF NOT EXISTS PUBLIC.INFRA_ACTIVE_REQUESTS( REQUEST_ID VARCHAR NOT NULL SELECTIVITY 100, CLIENT_REQUEST_ID VARCHAR SELECTIVITY 6, ACTION VARCHAR SELECTIVITY 1, @@ -168,6 +168,17 @@ CREATE CACHED TABLE PUBLIC.ARCHIVED_INFRA_REQUESTS( REQUEST_URL VARCHAR SELECTIVITY 1 ); +CREATE TABLE IF NOT EXISTS cloud_api_requests( +`ID` INT(13) NOT NULL AUTO_INCREMENT, +`REQUEST_BODY` LONGTEXT NOT NULL, +`CLOUD_IDENTIFIER` VARCHAR(200) NULL, +`SO_REQUEST_ID` VARCHAR(45) NOT NULL, +`CREATE_TIME` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`ID`), +CONSTRAINT fk_cloud_api_req_infra_requests + FOREIGN KEY (SO_REQUEST_ID) + REFERENCES infra_active_requests (REQUEST_ID)); + CREATE CACHED TABLE PUBLIC.SITE_STATUS( SITE_NAME VARCHAR NOT NULL, STATUS VARCHAR, diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java new file mode 100644 index 0000000000..690d0ffbaf --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/CloudApiRequests.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.onap.so.db.request.beans; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.PrePersist; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.openpojo.business.annotation.BusinessKey; + + +@Entity +@JsonInclude(Include.NON_NULL) +@Table(name = "cloud_api_requests") +public class CloudApiRequests implements Serializable { + + + /** + * + */ + private static final long serialVersionUID = 4686890103198488984L; + + @JsonIgnore + @Id + @BusinessKey + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID") + private Integer id; + + + @Column(name = "SO_REQUEST_ID") + private String requestId; + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + @Column(name = "CLOUD_IDENTIFIER") + private String cloudIdentifier; + + @Column(name = "REQUEST_BODY", columnDefinition = "LONGTEXT") + private String requestBody; + + @Column(name = "CREATE_TIME", insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + private Date created = null; + + + @Override + public boolean equals(final Object other) { + if (!(other instanceof CloudApiRequests)) { + return false; + } + CloudApiRequests castOther = (CloudApiRequests) other; + return new EqualsBuilder().append(id, castOther.id).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(id).toHashCode(); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("id", id).append("cloudIdentifier", cloudIdentifier) + .append("requestBody", requestBody).append("created", created).toString(); + } + + @PrePersist + protected void createdAt() { + this.created = new Date(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getCloudIdentifier() { + return cloudIdentifier; + } + + public void setCloudIdentifier(String cloudIdentifier) { + this.cloudIdentifier = cloudIdentifier; + } + + + public String getRequestBody() { + return requestBody; + } + + public void setRequestBody(String requestBody) { + this.requestBody = requestBody; + } + + public Date getCreated() { + return created; + } +} 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 a1010a349c..7c58c6171e 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 @@ -23,10 +23,15 @@ package org.onap.so.db.request.beans; import java.net.URI; import java.sql.Timestamp; import java.util.Date; +import java.util.List; import java.util.Objects; +import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.FetchType; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.MappedSuperclass; +import javax.persistence.OneToMany; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; import javax.persistence.Temporal; @@ -34,6 +39,7 @@ import javax.persistence.TemporalType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.apache.commons.lang3.builder.ToStringBuilder; import org.onap.so.requestsdb.TimestampXMLAdapter; +import uk.co.blackpepper.bowman.annotation.LinkedResource; import uk.co.blackpepper.bowman.annotation.ResourceId; @MappedSuperclass @@ -147,6 +153,10 @@ public abstract class InfraRequests implements java.io.Serializable { @Column(name = "REQUEST_URL", length = 500) private String requestUrl; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "SO_REQUEST_ID", referencedColumnName = "REQUEST_ID") + private List<CloudApiRequests> cloudApiRequests; + @ResourceId public URI getRequestURI() { return URI.create(this.requestId); @@ -458,6 +468,15 @@ public abstract class InfraRequests implements java.io.Serializable { return requestAction; } + @LinkedResource + public List<CloudApiRequests> getCloudApiRequests() { + return cloudApiRequests; + } + + public void setCloudApiRequests(List<CloudApiRequests> cloudApiRequests) { + this.cloudApiRequests = cloudApiRequests; + } + public void setRequestAction(String requestAction) { this.requestAction = requestAction; } 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 f2ff6fac00..103410701c 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 @@ -72,10 +72,10 @@ public class RequestsDbClient { private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; - @Value("${mso.adapters.requestDb.endpoint}") + @Value("${mso.adapters.requestDb.endpoint:#{null}}") protected String endpoint; - @Value("${mso.adapters.requestDb.auth}") + @Value("${mso.adapters.requestDb.auth:#{null}}") private String msoAdaptersAuth; private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"; |