aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java4
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java21
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java169
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java3
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java7
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java83
7 files changed, 250 insertions, 40 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
index 21582a1e5f..3c8d732286 100644
--- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
+++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
@@ -32,6 +32,8 @@ import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration;
import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
/**
* @since Version 1.0
@@ -67,4 +69,6 @@ public class MSORequestDBApplication {
.withDefaultLockAtMostFor(Duration.ofMinutes(10))
.build();
}
+
+
}
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java
new file mode 100644
index 0000000000..c0d9955aea
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java
@@ -0,0 +1,21 @@
+package org.onap.so.adapters.requestsdb.client;
+
+
+import org.onap.so.db.request.client.RequestsDbClient;
+import org.springframework.stereotype.Component;
+import java.net.URI;
+@Component
+public class RequestDbClientPortChanger extends RequestsDbClient {
+ private int port;
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ @Override
+ public URI getUri(String uri) {
+ uri = uri.replace("8081", String.valueOf(port));
+ return URI.create(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
new file mode 100644
index 0000000000..e614588407
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java
@@ -0,0 +1,169 @@
+package org.onap.so.adapters.requestsdb.client;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.beans.OperationStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.embedded.LocalServerPort;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+import java.util.List;
+import java.util.UUID;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class RequestsDbClientTest {
+
+ @Autowired
+ private RequestDbClientPortChanger requestsDbClient;
+
+ private InfraActiveRequests infraActiveRequests;
+
+ @LocalServerPort
+ private int port;
+
+ @Before
+ public void setup() {
+ requestsDbClient.setPort(port);
+
+ infraActiveRequests = new InfraActiveRequests();
+ infraActiveRequests.setRequestId(UUID.randomUUID().toString());
+ infraActiveRequests.setOperationalEnvId(UUID.randomUUID().toString());
+ infraActiveRequests.setServiceInstanceId(UUID.randomUUID().toString());
+ infraActiveRequests.setServiceInstanceName("serviceInstanceNameTest");
+ infraActiveRequests.setVnfId(UUID.randomUUID().toString());
+ infraActiveRequests.setVnfName("vnfInstanceNameTest");
+ infraActiveRequests.setVfModuleId(UUID.randomUUID().toString());
+ infraActiveRequests.setVfModuleName("vfModuleInstanceNameTest");
+ infraActiveRequests.setVolumeGroupId(UUID.randomUUID().toString());
+ infraActiveRequests.setVolumeGroupName("volumeGroupInstanceNameTest");
+ infraActiveRequests.setNetworkId(UUID.randomUUID().toString());
+ infraActiveRequests.setNetworkName("networkInstanceNameTest");
+ infraActiveRequests.setConfigurationId(UUID.randomUUID().toString());
+ infraActiveRequests.setConfigurationName("configurationInstanceNameTest");
+ infraActiveRequests.setAicCloudRegion("1");
+ infraActiveRequests.setTenantId(UUID.randomUUID().toString());
+ infraActiveRequests.setRequestScope("operationalEnvironment");
+ infraActiveRequests.setRequestorId(UUID.randomUUID().toString());
+ infraActiveRequests.setSource("sourceTest");
+ infraActiveRequests.setOperationalEnvName(UUID.randomUUID().toString());
+ infraActiveRequests.setRequestStatus("IN_PROGRESS");
+ infraActiveRequests.setAction("create");
+ infraActiveRequests.setRequestAction("someaction");
+ requestsDbClient.save(infraActiveRequests);
+ }
+
+ private void verifyOperationStatus(OperationStatus request,OperationStatus response){
+ assertThat(request, sameBeanAs(response).ignoring("operateAt").ignoring("finishedAt"));
+ }
+
+ private void verifyInfraActiveRequests(InfraActiveRequests infraActiveRequestsResponse) {
+ assertThat(infraActiveRequestsResponse, sameBeanAs(infraActiveRequests).ignoring("modifyTime").ignoring("log"));
+ }
+
+ @Test
+ public void getCloudOrchestrationFiltersFromInfraActiveTest() {
+ Map<String, String> requestMap = new HashMap<>();
+ requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId());
+ requestMap.put("operationalEnvironmentName", infraActiveRequests.getOperationalEnvName());
+ requestMap.put("resourceType", "operationalEnvironment");
+
+ List<InfraActiveRequests> iarr = requestsDbClient.getCloudOrchestrationFiltersFromInfraActive(requestMap);
+
+ assertEquals(1, iarr.size());
+ InfraActiveRequests infraActiveRequestsResponse = iarr.get(0);
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ }
+
+
+ @Test
+ public void checkVnfIdStatusTest() {
+ InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkVnfIdStatus(infraActiveRequests.getOperationalEnvId());
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ assertNull(requestsDbClient.checkVnfIdStatus(UUID.randomUUID().toString()));
+ }
+
+ @Test
+ public void checkInstanceNameDuplicateTest() {
+ InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate(null,infraActiveRequests.getOperationalEnvName(),infraActiveRequests.getRequestScope());
+
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ }
+
+ @Test
+ public void checkInstanceNameDuplicateViaTest() {
+ Map<String, String> requestMap = new HashMap<>();
+ requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId());
+
+ InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate((HashMap<String, String>)requestMap,null,infraActiveRequests.getRequestScope());
+
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ }
+
+ @Test
+ public void getOrchestrationFiltersFromInfraActiveTest() {
+ Map<String, List<String>> requestMap = new HashMap<>();
+ List<String> values = new ArrayList<>();
+ values.add("EQUALS");
+ values.add(infraActiveRequests.getServiceInstanceId());
+ requestMap.put("serviceInstanceId", values);
+
+ values = new ArrayList<>();
+ values.add("EQUALS");
+ values.add(infraActiveRequests.getServiceInstanceName());
+ requestMap.put("serviceInstanceName", values);
+
+ List<InfraActiveRequests> iaar = requestsDbClient.getOrchestrationFiltersFromInfraActive(requestMap);
+
+ assertEquals(1, iaar.size());
+ InfraActiveRequests infraActiveRequestsResponse = iaar.get(0);
+
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ values = new ArrayList<>();
+ values.add("EQUALS");
+ values.add(UUID.randomUUID().toString());
+ requestMap.put("serviceInstanceName", values);
+ requestsDbClient.getOrchestrationFiltersFromInfraActive(requestMap);
+ }
+
+ @Test
+ public void getInfraActiveRequestbyRequestIdTest(){
+ InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.getInfraActiveRequestbyRequestId(infraActiveRequests.getRequestId());
+ verifyInfraActiveRequests(infraActiveRequestsResponse);
+ assertNull(requestsDbClient.getInfraActiveRequestbyRequestId(UUID.randomUUID().toString()));
+ }
+
+ @Test
+ public void getOneByServiceIdAndOperationIdTest(){
+ OperationStatus operationStatus = new OperationStatus();
+ operationStatus.setProgress("IN_PROGRESS");
+ operationStatus.setResult("FAILED");
+ operationStatus.setServiceId(UUID.randomUUID().toString());
+ operationStatus.setOperationContent("operation-content");
+ operationStatus.setOperation("operation");
+ operationStatus.setOperationId(UUID.randomUUID().toString());
+ operationStatus.setReason("reason-test");
+ operationStatus.setUserId(UUID.randomUUID().toString());
+ operationStatus.setServiceName("test-service");
+ requestsDbClient.save(operationStatus);
+
+ OperationStatus operationStatusResponse = requestsDbClient.getOneByServiceIdAndOperationId(operationStatus.getServiceId(),operationStatus.getOperationId());
+
+ verifyOperationStatus(operationStatus,operationStatusResponse);
+
+ assertNull(requestsDbClient.getOneByServiceIdAndOperationId(UUID.randomUUID().toString(),operationStatus.getOperationId()));
+ }
+} \ No newline at end of file
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java
index 6ff6ec9379..62234f910d 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.so.adapters.vfc;
+package org.onap.so.adapters.vfc;
import org.springframework.boot.SpringApplication;
@@ -34,5 +34,4 @@ public class MSOVfcApplication {
public static void main(String... args) {
SpringApplication.run(MSOVfcApplication.class, args);
}
-
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
index 5932f6d206..f634057449 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
@@ -154,6 +154,9 @@ private final ObjectMapper mapper = new ObjectMapper();
@Test
public void getE2EServiceInstanceNullOperationalStatus() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/operations/9b9f02c0-298b-458a-bc9c-be3692e4f35e";
+ stubFor(get(urlPathEqualTo("/operationStatus/search/findOneByServiceIdAndOperationId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.GET);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatusCode().value());
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java
index 00d212a23e..5b6fbc8378 100644
--- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java
+++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java
@@ -22,7 +22,10 @@ package org.onap.so;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
@SpringBootApplication(scanBasePackages = { "org.onap.so.db" })
@Profile("test")
@@ -32,4 +35,8 @@ public class TestApplication {
System.getProperties().setProperty("mso.db", "MARIADB");
System.getProperties().setProperty("server.name", "Springboot");
}
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate( new HttpComponentsClientHttpRequestFactory());
+ }
}
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 54fec3ad4d..2a61a319f3 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
@@ -20,17 +20,6 @@
package org.onap.so.db.request.client;
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-
import org.apache.http.HttpStatus;
import org.onap.so.db.request.beans.ArchivedInfraRequests;
import org.onap.so.db.request.beans.InfraActiveRequests;
@@ -46,7 +35,6 @@ import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
@@ -60,12 +48,21 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
-
import uk.co.blackpepper.bowman.Client;
import uk.co.blackpepper.bowman.ClientFactory;
import uk.co.blackpepper.bowman.Configuration;
import uk.co.blackpepper.bowman.RestTemplateConfigurer;
+import javax.annotation.PostConstruct;
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
@Component("RequestsDbClient")
@Primary
public class RequestsDbClient {
@@ -82,7 +79,6 @@ public class RequestsDbClient {
private static final String TAG = "TAG";
private Client<InfraActiveRequests> infraActiveRequestClient;
- private Client<OperationStatus> operationStatusClient;
private Client<RequestProcessingData> requestProcessingDataClient;
private final Client<OperationalEnvDistributionStatus> distributionStatusClient;
private final Client<OperationalEnvServiceModelStatus> serviceModelStatusClient;
@@ -122,9 +118,6 @@ public class RequestsDbClient {
protected HttpHeaders headers;
- protected ClientFactory clientFactory;
-
- @Autowired
protected RestTemplate restTemplate;
@Autowired
@@ -144,6 +137,7 @@ public class RequestsDbClient {
findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI;
headers = new HttpHeaders();
headers.set("Authorization", msoAdaptersAuth);
+ restTemplate = restTemplate();
}
public RequestsDbClient() {
@@ -163,7 +157,6 @@ public class RequestsDbClient {
}
}).build().buildClientFactory();
infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class);
- operationStatusClient = clientFactory.create(OperationStatus.class);
requestProcessingDataClient = clientFactory.create(RequestProcessingData.class);
distributionStatusClient = clientFactory.create(OperationalEnvDistributionStatus.class);
serviceModelStatusClient = clientFactory.create(OperationalEnvServiceModelStatus.class);
@@ -181,9 +174,21 @@ public class RequestsDbClient {
throw e;
}
}
- public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
- return this.getSingleInfraActiveRequests(this.getUri(endpoint + "/infraActiveRequests/" + requestId));
- }
+
+ public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
+ try {
+ InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody();
+ if (infraActiveRequests != null) {
+ infraActiveRequests.setRequestId(requestId);
+ }
+ return infraActiveRequests;
+ } catch (HttpClientErrorException e) {
+ if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+ return null;
+ }
+ throw e;
+ }
+ }
public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap) {
URI uri = getUri(getOrchestrationFilterURI);
@@ -208,12 +213,25 @@ public class RequestsDbClient {
}
}
-
- public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){
- return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI)
- .queryParam(SERVICE_ID,serviceId)
- .queryParam(OPERATION_ID,operationId)
- .build());
+
+ public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) {
+ try {
+ OperationStatus operationStatus = restTemplate.exchange(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI))
+ .queryParam(SERVICE_ID, serviceId)
+ .queryParam(OPERATION_ID, operationId)
+ .build(), HttpMethod.GET, HttpEntity.EMPTY, OperationStatus.class).getBody();
+ if (operationStatus != null) {
+ operationStatus.setServiceId(serviceId);
+ operationStatus.setOperationId(operationId);
+ }
+
+ return operationStatus;
+ } catch (HttpClientErrorException e) {
+ if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+ return null;
+ }
+ throw e;
+ }
}
public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvironmentId, String serviceModelVersionId) {
@@ -261,10 +279,6 @@ public class RequestsDbClient {
private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){
return distributionStatusClient.get(uri);
}
-
- protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) {
- return infraActiveRequestClient.get(uri);
- }
public void updateInfraActiveRequests(InfraActiveRequests request) {
infraActiveRequestClient.put(request);
@@ -273,12 +287,6 @@ public class RequestsDbClient {
protected URI getUri(String uri) {
return URI.create(uri);
}
-
-
-
- public OperationStatus getSingleOperationStatus(URI uri){
- return operationStatusClient.get(uri);
- }
public void saveRequestProcessingData(RequestProcessingData requestProcessingData) {
URI uri = getUri(endpoint + requestProcessingDataURI);
@@ -322,7 +330,6 @@ public class RequestsDbClient {
return requestProcessingDataClient.getAll(uri);
}
- @Bean
public RestTemplate restTemplate() {
return new RestTemplate( new HttpComponentsClientHttpRequestFactory());
}