aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomController.java5
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java62
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java19
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java5
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java11
5 files changed, 92 insertions, 10 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomController.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomController.java
index f6a0aec86f..28e931a3e1 100644
--- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomController.java
+++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomController.java
@@ -74,4 +74,9 @@ public class InfraActiveRequestsRepositoryCustomController {
@RequestParam(value = "maxResult", required = false) Integer maxResult) {
return infraActiveRequestsRepository.getInfraActiveRequests(filters, startTime, endTime, maxResult);
}
+
+ @RequestMapping(method = RequestMethod.GET, value = "/infraActiveRequests/getInProgressVolumeGroupsAndVfModules")
+ public List<InfraActiveRequests> getInProgressVolumeGroupsAndVfModules() {
+ return infraActiveRequestsRepository.getInProgressVolumeGroupsAndVfModules();
+ }
}
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java
index 4ed3285a70..896138f955 100644
--- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java
@@ -21,8 +21,13 @@
package org.onap.so.adapters.requestsdb;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -33,6 +38,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest;
+import org.onap.so.serviceinstancebeans.ModelType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
@@ -91,14 +97,6 @@ public class InfraActiveRequestsRepositoryCustomControllerTest extends RequestsA
@Before
public void setup() {
-
- headers = new HttpHeaders();
- restTemplate = new TestRestTemplate("test", "test");
-
- headers.set("Accept", MediaType.APPLICATION_JSON);
- headers.set("Content-Type", MediaType.APPLICATION_JSON);
- headers.set("Authorization", msoAdaptersAuth);
-
infraActiveRequests = new InfraActiveRequests();
infraActiveRequests.setRequestId(UUID.randomUUID().toString());
@@ -126,12 +124,22 @@ public class InfraActiveRequestsRepositoryCustomControllerTest extends RequestsA
infraActiveRequests
.setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances");
- HttpEntity<String> entity = new HttpEntity(infraActiveRequests, headers);
+ saveInfraActiveRequest(infraActiveRequests);
+ }
+
+ public void saveInfraActiveRequest(InfraActiveRequests request) {
+ headers = new HttpHeaders();
+ restTemplate = new TestRestTemplate("test", "test");
+
+ headers.set("Accept", MediaType.APPLICATION_JSON);
+ headers.set("Content-Type", MediaType.APPLICATION_JSON);
+ headers.set("Authorization", msoAdaptersAuth);
+
+ HttpEntity<String> entity = new HttpEntity(request, headers);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests"));
ResponseEntity<String> response =
restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
-
assertEquals(201, response.getStatusCodeValue());
}
@@ -297,4 +305,38 @@ public class InfraActiveRequestsRepositoryCustomControllerTest extends RequestsA
assertEquals(200, response.getStatusCodeValue());
assertEquals(null, response.getBody());
}
+
+ @Test
+ public void getInProgressVolumeGroupsAndVfModulesTest() {
+ boolean expectedReturned = false;
+ InfraActiveRequests request = new InfraActiveRequests();
+ request.setRequestId(UUID.randomUUID().toString());
+ request.setVfModuleId(UUID.randomUUID().toString());
+ request.setRequestStatus("IN_PROGRESS");
+ request.setRequestScope(ModelType.vfModule.toString());
+ Instant startInstant = Instant.now().minus(3, ChronoUnit.MINUTES);
+ request.setStartTime(Timestamp.from(startInstant));
+ request.setRequestAction("create");
+ saveInfraActiveRequest(request);
+
+ UriComponentsBuilder builder = UriComponentsBuilder
+ .fromHttpUrl(createURLWithPort("/infraActiveRequests/getInProgressVolumeGroupsAndVfModules"));
+
+ HttpEntity<String> entity = new HttpEntity<String>(headers);
+
+ ResponseEntity<List<InfraActiveRequests>> response = restTemplate.exchange(builder.toUriString(),
+ HttpMethod.GET, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {});
+
+ List<InfraActiveRequests> responseList = response.getBody();
+
+ assertEquals(200, response.getStatusCodeValue());
+
+ for (InfraActiveRequests result : responseList) {
+ if (result.getRequestId().equals(request.getRequestId())) {
+ assertThat(request, sameBeanAs(result).ignoring("modifyTime"));
+ expectedReturned = true;
+ }
+ }
+ assertTrue(expectedReturned);
+ }
}
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 49291b6863..67887378ef 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
@@ -27,6 +27,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -41,6 +43,7 @@ import org.onap.so.db.request.beans.OperationStatus;
import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
import org.onap.so.db.request.beans.RequestProcessingData;
+import org.onap.so.serviceinstancebeans.ModelType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.LocalServerPort;
@@ -314,4 +317,20 @@ public class RequestsDbClientTest extends RequestsAdapterBase {
verifyInfraActiveRequests(infraActiveRequestsResponse.get(0));
}
+
+ @Test
+ public void getInProgressVolumeGroupsAndVfModulesTest() {
+ InfraActiveRequests request = new InfraActiveRequests();
+ request.setRequestId(UUID.randomUUID().toString());
+ request.setVfModuleId(UUID.randomUUID().toString());
+ request.setRequestStatus("IN_PROGRESS");
+ request.setRequestScope(ModelType.vfModule.toString());
+ Instant startInstant = Instant.now().minus(3, ChronoUnit.MINUTES);
+ request.setStartTime(Timestamp.from(startInstant));
+ request.setRequestAction("create");
+ requestsDbClient.save(request);
+
+ List<InfraActiveRequests> infraActiveRequests = requestsDbClient.getInProgressVolumeGroupsAndVfModules();
+ assertThat(request, sameBeanAs(infraActiveRequests.get(0)).ignoring("modifyTime"));
+ }
}
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java
index a14699827d..e2c7aef4f4 100644
--- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java
+++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@@ -47,4 +48,8 @@ public interface InfraActiveRequestsRepository
List<InfraActiveRequests> findByEndTimeLessThan(Date endTime, Pageable request);
List<InfraActiveRequests> findByStartTimeLessThanAndEndTime(Date startTime, Date endTime, Pageable request);
+
+ @Query(value = "SELECT * FROM infra_active_requests WHERE request_status = 'IN_PROGRESS' AND (request_scope = 'volumeGroup' OR request_scope = 'vfModule') AND start_time < (NOW() - INTERVAL 2 MINUTE)",
+ nativeQuery = true)
+ List<InfraActiveRequests> getInProgressVolumeGroupsAndVfModules();
}
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 99c1d1ea72..ef946bfcc8 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
@@ -115,6 +115,8 @@ public class RequestsDbClient {
private String getInfraActiveRequests = "/infraActiveRequests/v1/getInfraActiveRequests";
+ private String getInProgressVolumeGroupsAndVfModules = "/infraActiveRequests/getInProgressVolumeGroupsAndVfModules";
+
private static final String findBySoRequestIdAndGroupIdAndName =
"/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndName";
@@ -185,6 +187,15 @@ public class RequestsDbClient {
}
}
+ public List<InfraActiveRequests> getInProgressVolumeGroupsAndVfModules() {
+ HttpHeaders headers = getHttpHeaders();
+ URI uri = getUri(endpoint + getInProgressVolumeGroupsAndVfModules);
+ HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(headers);
+ return restTemplate
+ .exchange(uri, HttpMethod.GET, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {})
+ .getBody();
+ }
+
public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
try {
HttpEntity<?> entity = getHttpEntity();